简体   繁体   中英

Get IMap entries on same node as Predicate keys [Hazelcast]

I'm using Hazelcast 3.6 IMap to distributed store large amount of data (I've tested on 1B items). I want to join 2 IMap instances by keys, but it seems there no any built-in functionality to do it. So, I'm using @PatritionAware to store entries of these maps in the same node if keys are equal and then use Set<K> localKeySet(); of the first map on each member of the claster. After that I try to get values from the second map also on the same node to avoid transferring predicate keys by the network. But seems getAll(Set<K> keys) doesn't do it on the same node. Does anybody already have the same issue ? Is it possible to resolve it based on Hazelcast functionality ?

See code example below


public class PartitionAwareKey implements PartitionAware, Serializable {

    private Integer key;

    public PartitionAwareKey(Integer key) {
        this.key = key;
    }

    @Override
    public Integer getPartitionKey() {
        return this.key;
    }
}




public class FindDataWithPredicateTask implements HazelcastInstanceAware, Serializable, Callable>> {
 ...
    @Override
    public IMap call() throws Exception {
        IMap map1 = hazelcastInstance.getMap("map1");
        Set localKeySet = map1.localKeySet();

        IMap, String> map2 = hazelcastInstance.getMap("map2");

        return map2.getAll(localKeySet);
    }
...

I guess what you're looking for is an EntryProcessor . This EP also has to implement HazelcastInstanceAware to get access to other data structures. It still is important to apply data affinity as you already do to make sure data that belong together are stored inside the same partition to be accessible.

More information on EntryProcessor is available in the documentation ( http://docs.hazelcast.org/docs/3.6/manual/html-single/#entry-processing-with-imap-methods ) and an examples can be found in our examples repository ( https://github.com/hazelcast/hazelcast-code-samples/tree/master/distributed-map/entry-processor ).

Feel free to ask further information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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