0

私はこのドキュメントに従っています: http://gemfire.docs.pivotal.io/docs-gemfire/latest/developing/distributed_regions/locking_in_global_regions.html を使用して、グローバルスコープでリージョンを作成し、分散ロックを使用します。

キャッシュ.xml:

<client-cache>
<pool>…definition…&lt;/pool>
…
<!--region-attributes For Lock region-->
<region-attributes id="GZ_GLOBAL_REGION_LOCK_ATTRIBUTES" scope="global" pool-name="Zero"/>
…
</client-cache>

gemfire.properties および cache.xml から作成された GemFireCache の後のコード:

private Region<String, Object> getOrCreateLockRegion(GemFireCache gemfireCache) {
    Region<String, Object> region = gemfireCache.getRegion(lockRegionName);
    if (region == null) {
        if(!isUsingClientCache) {
            region = createRegionFactory((Cache)gemfireCache, String.class, Object.class, lockRegionAttributesID).create(lockRegionName);
        } else {
            region = createClientRegionFactory((ClientCache) gemfireCache, String.class, Object.class, lockRegionAttributesID).create(lockRegionName);
        }
    }
    return region;
}

protected <K, V> RegionFactory<K, V> createRegionFactory(Cache gemfireCache, Class<K> keyClass, Class<V> valueClass, String regionAttributeRefID) {
    return gemfireCache
            .<K, V>createRegionFactory(regionAttributeRefID)
            .setKeyConstraint(keyClass)
            .setValueConstraint(valueClass);
}

protected <K, V> ClientRegionFactory<K, V> createClientRegionFactory(ClientCache gemfireCache, Class<K> keyClass, Class<V> valueClass, String regionAttributeRefID) {
    return gemfireCache
            .<K, V>createClientRegionFactory(regionAttributeRefID)
            .setKeyConstraint(keyClass)
            .setValueConstraint(valueClass);
}

これで のリージョンが得られるScope.Globalので、region.getDistributedLock(“entrykey”); を呼び出すことができると思います。次に、インスタンス間で調整するためのロックを設定します。

しかし、私が電話したときgetDistributedLock、私はIllegalStateException: only supported for GLOBAL scope, not LOCAL

そして、ClientRegionFactoryImpl のコンストラクターは、リージョン属性で構成されているものに関係なく、スコープをローカルに強制することがわかりました。それを上書きする API がありません。この行: https://github.com/apache/incubator-geode/blob/develop/geode-core/src/main/java/org/apache/geode/cache/client/internal/ClientRegionFactoryImpl.java#L85

問題は、クライアント サーバー DS 構成を使用している場合、クライアントから分散ロックを使用することになっているのでしょうか? そうでない場合、必要に応じてクライアントを相互にロックして同期させるにはどうすればよいですか?

4

1 に答える 1

0

Region クラスの DistributedLock および RegionDistributedLock API は、サーバー内でのみ使用できます。クライアントからこれらのロックを使用するには、サーバーにデプロイする関数を作成する必要があります。次に、クライアントはサーバーに、Region および DistributedLock API と RegionDistributedLock API を操作できる Function を実行するように指示します。FunctionService の詳細については、次を参照してください。

http://geode.apache.org/docs/guide/developing/function_exec/chapter_overview.html .

于 2016-11-30T01:33:27.797 に答える