Hazelcast - IMap如何使用仲裁进行锁定操作?

时间:2017-07-19 08:11:41

标签: java locking hazelcast hazelcast-imap

我想将Quorum用于我的地图的地图锁定操作:myMap。

我使用编程配置进行仲裁。

        QuorumConfig quorumConfig = new QuorumConfig();
        quorumConfig.setName("xxx");
        quorumConfig.setEnabled(true);

        quorumConfig.setQuorumFunctionImplementation(new QuorumFunction() {
            @Override
            public boolean apply(Collection<Member> members) {
                ...
            }
        });

我使用com.hazelcast.config.MapConfig.setQuorumName方法设置quorumımpl。

我的地图配置如下所示,因为仲裁设置为xxx。

MapConfig {name ='myMap',inMemoryFormat = BINARY',....,mapAttributeConfigs = null,quorumName = xxx,queryCacheConfigs = null,cacheDeserializedValues = INDEX_ONLY}

问题是,对于锁定操作,不会调用仲裁函数。

对于map put / remove操作,我看到quorum函数受到尊重。

com.hazelcast.quorum.QuorumException: Cluster quorum failed at com.hazelcast.quorum.impl.QuorumImpl.newQuorumException(QuorumImpl.java:164) at com.hazelcast.quorum.impl.QuorumImpl.ensureQuorumPresent(QuorumImpl.java:158) at com.hazelcast.quorum.impl.QuorumServiceImpl.ensureQuorumPresent(QuorumServiceImpl.java:127) at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.ensureQuorumPresent(OperationRunnerImpl.java:237) at com.hazelcast.spi.impl.operationservice.impl.OperationRunnerImpl.run(OperationRunnerImpl.java:178) at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.process(OperationThread.java:120) at com.hazelcast.spi.impl.operationexecutor.impl.OperationThread.run(OperationThread.java:100) at ------ submitted from ------.(Unknown Source) at java.lang.Thread.getStackTrace(Thread.java:1117) at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolve(InvocationFuture.java:114) at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveAndThrowIfException(InvocationFuture.java:75) at com.hazelcast.spi.impl.AbstractInvocationFuture.get(AbstractInvocationFuture.java:155) at com.hazelcast.map.impl.proxy.MapProxySupport.invokeOperation(MapProxySupport.java:373) at com.hazelcast.map.impl.proxy.MapProxySupport.removeInternal(MapProxySupport.java:508) at com.hazelcast.map.impl.proxy.MapProxyImpl.remove(MapProxyImpl.java:211)

但是,仲裁不用于锁定操作。

在文档中,为锁定操作提供了xml配置。

http://docs.hazelcast.org/docs/latest-development/manual/html/Distributed_Data_Structures/Map/Locking_Maps.html

  

示例配置为:

     

声明性配置的一个示例:

<map name="myMap">
  <quorum-ref>map-actions-quorum</quorum-ref>
</map>

<lock name="myMap">
    <quorum-ref>map-lock-actions-quorum</quorum-ref>
</lock>
     

此处配置的地图将使用map-lock-actions-quorum仲裁   用于其他地图的地图锁定操作和map-actions-quorum仲裁   动作。

这与程序相同的是什么?

此致

1 个答案:

答案 0 :(得分:1)

以下是配置Quorum for Lock的示例:

Config config = new Config();
LockConfig lockConfig = new LockConfig();
lockConfig.setName("myLock")
          .setQuorumName("quorum-name");
config.addLockConfig(lockConfig);

查看详情链接:http://docs.hazelcast.org/docs/3.8.3/manual/html-single/index.html#lock-configuration