简体   繁体   English

Hazelcast IMap有时会返回空值对象,即使它存在于地图中

[英]Hazelcast IMap sometime returns null value object even if it is present in map

I have one map in Hazelcast with key and values are like IMap . 我在Hazelcast中有一张带有键的地图,其值类似于IMap Now I have two nodes with me. 现在我有两个节点。 Problem is when I am trying to get value object from Hazelcast map, some time it returns me NULL and very next call, it works fine. 问题是,当我尝试从Hazelcast映射中获取值对象时,有时它返回我NULL然后再次调用它,效果很好。 As this is working fine for some time, I think there is no issue with code. 由于这可以正常工作一段时间,因此我认为代码没有问题。 Here I am sharing my map configurations from hazelcast.xml file. 在这里,我从hazelcast.xml文件共享地图配置。

<map name="MY_HAZELCAST_MAP">
       <in-memory-format>OBJECT</in-memory-format>
       <backup-count>1</backup-count>
       <async-backup-count>0</async-backup-count>
       <time-to-live-seconds>1000</time-to-live-seconds>
       <eviction-percentage>25</eviction-percentage>
       <max-size policy="PER_NODE">3000</max-size>
       <cache-deserialized-values>ALWAYS</cache-deserialized-values>
       <merge-policy>com.hazelcast.map.merge.PassThroughMergePolicy</merge-policy>
</map>

Please let me know if I am configuring something wrong. 如果我配置有误,请告诉我。 Using hazelcast-all-3.7.3.jar . 使用hazelcast-all-3.7.3.jar

Here is hazelcast.xml file 这是hazelcast.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.6.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <properties>
        <property name="instance.name">MY_INSTANCE</property>
        <property name="hazelcast.logging.type">log4j</property>
    </properties>
    <group>
        <name>dev1</name>
        <password>dev-pass</password>
    </group>
    <management-center enabled="false">http://localhost:8080/mancenter</management-center>
    <network>
        <port auto-increment="false" port-count="100">51253</port>
        <outbound-ports>
            <ports>0</ports>
        </outbound-ports>
        <join>
            <multicast enabled="false"/>
            <tcp-ip enabled="true">
                <member-list>
                    <member>192.168.1.87:51253</member>
                </member-list>
            </tcp-ip>
            <discovery-strategies>
            </discovery-strategies>
        </join>
        <ssl enabled="false"/>
        <socket-interceptor enabled="false"/>
        <symmetric-encryption enabled="false">
            <algorithm>PBEWithMD5AndDES</algorithm>
            <salt>thesalt</salt>
            <password>thepass</password>
            <iteration-count>19</iteration-count>
        </symmetric-encryption>
    </network>
    <partition-group enabled="false"/>
    <executor-service name="default">
        <pool-size>16</pool-size>
        <queue-capacity>0</queue-capacity>
    </executor-service>
    <queue name="default">
        <max-size>0</max-size>
        <backup-count>1</backup-count>
        <async-backup-count>0</async-backup-count>
        <empty-queue-ttl>-1</empty-queue-ttl>
    </queue>
    <map name="MY_HAZELCAST_MAP">
           <in-memory-format>OBJECT</in-memory-format>
           <backup-count>1</backup-count>
           <async-backup-count>0</async-backup-count>
           <time-to-live-seconds>1000</time-to-live-seconds>
           <eviction-percentage>25</eviction-percentage>
           <max-size policy="PER_NODE">3000</max-size>
           <cache-deserialized-values>ALWAYS</cache-deserialized-values>
           <merge-policy>com.hazelcast.map.merge.PassThroughMergePolicy</merge-policy>
    </map>
    <map name="default">
        <in-memory-format>BINARY</in-memory-format>
        <backup-count>1</backup-count>
        <async-backup-count>0</async-backup-count>
        <time-to-live-seconds>0</time-to-live-seconds>
        <max-idle-seconds>0</max-idle-seconds>
        <eviction-policy>NONE</eviction-policy>
        <max-size policy="PER_NODE">0</max-size>
        <eviction-percentage>25</eviction-percentage>
        <min-eviction-check-millis>100</min-eviction-check-millis>
        <merge-policy>com.hazelcast.map.merge.PutIfAbsentMapMergePolicy</merge-policy>
        <cache-deserialized-values>INDEX-ONLY</cache-deserialized-values>
    </map>

    <multimap name="default">
        <backup-count>1</backup-count>
        <value-collection-type>SET</value-collection-type>
    </multimap>

    <list name="default">
        <backup-count>1</backup-count>
    </list>

    <set name="default">
        <backup-count>1</backup-count>
    </set>

    <jobtracker name="default">
        <max-thread-size>0</max-thread-size>
        <queue-size>0</queue-size>
        <retry-count>0</retry-count>
        <chunk-size>1000</chunk-size>
        <communicate-stats>true</communicate-stats>
        <topology-changed-strategy>CANCEL_RUNNING_OPERATION</topology-changed-strategy>
    </jobtracker>

    <semaphore name="default">
        <initial-permits>0</initial-permits>
        <backup-count>1</backup-count>
        <async-backup-count>0</async-backup-count>
    </semaphore>

    <reliable-topic name="default">
        <read-batch-size>10</read-batch-size>
        <topic-overload-policy>BLOCK</topic-overload-policy>
        <statistics-enabled>true</statistics-enabled>
    </reliable-topic>

    <ringbuffer name="default">
        <capacity>10000</capacity>
        <backup-count>1</backup-count>
        <async-backup-count>0</async-backup-count>
        <time-to-live-seconds>30</time-to-live-seconds>
        <in-memory-format>BINARY</in-memory-format>
    </ringbuffer>

    <serialization>
        <portable-version>0</portable-version>
    </serialization>
    <services enable-defaults="true"/>
    <lite-member enabled="false"/>
</hazelcast>

For sample code please refer Not able to retrieve element from Hazelcast's Map if using custom object as a key which I have posted. 有关示例代码,请参阅如果使用自定义对象作为我发布的键则无法从Hazelcast的地图中检索元素 My key contains time variable which can be changed. 我的钥匙包含可以更改的时间变量。 As Mr. Desai mentioned about Hazelcast key searching on basis of binary data, Here is line which I am using to et actual key from IMap and using further to get value object. 正如Desai先生提到的有关基于二进制数据的Hazelcast密钥搜索一样,这是我用来从IMap获取实际密钥并进一步用于获取值对象的行。

HazelcastInstance instance = Hazelcast.newHazelcastInstance();
private static ConcurrentMap<HMapKey, String> testMap = instance.getMap("MY_HAZELCAST_MAP");
testMap.put(new HMapKey("code1",123), "This is Code 1");
....
....
....
// While retrieving
private static ConcurrentMap<HMapKey, String> testMap2 = instance.getMap("MY_HAZELCAST_MAP");
HMapKey key = new HMapKey("code1",0);
key = ArrayList<HMapKey>(testMap2.keySet()).get(new ArrayList<HMapKey>(testMap2.keySet()).indexOf(key));

String MapValue = testMap2.get(key);

Please let me know if I make you understand. 如果让您理解,请告诉我。 Also I am connecting this question with my previous one. 我还将这个问题与上一个问题联系在一起。 If this didn't work, will add that content in this question also. 如果这不起作用,也将在该问题中添加该内容。

The key class HMapKey on Not able to retrieve element from Hazelcast's Map if using custom object as a key is what is causing the problem. 如果使用自定义对象作为键,无法从Hazelcast的Map中检索元素的键类HMapKey是导致此问题的原因。

For a key, all fields should be part of equality testing. 对于一个键,所有字段都应该是相等性测试的一部分。

Additionally for Hazelcast, keys are compared serialized. 此外,对于Hazelcast,将对密钥进行序列化比较。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM