简体   繁体   English

在与谓词键[Hazelcast]相同的节点上获取IMap条目

[英]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). 我正在使用Hazelcast 3.6 IMap来分布式存储大量数据(我已经在1B项目上进行了测试)。 I want to join 2 IMap instances by keys, but it seems there no any built-in functionality to do it. 我想通过键加入2个IMap实例,但是似乎没有任何内置功能可以做到这一点。 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(); 因此,如果密钥相等,我将使用@PatritionAware将这些映射的条目存储在同一节点中,然后使用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. 但是似乎getAll(Set<K> keys)不在同一节点上执行此操作。 Does anybody already have the same issue ? 有人已经有同样的问题吗? Is it possible to resolve it based on Hazelcast functionality ? 是否可以基于Hazelcast功能解决该问题?

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 . 我猜您正在寻找的是EntryProcessor This EP also has to implement HazelcastInstanceAware to get access to other data structures. 该EP还必须实现HazelcastInstanceAware才能访问其他数据结构。 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 ). 有关EntryProcessor的更多信息,请参阅文档( http://docs.hazelcast.org/docs/3.6/manual/html-single/#entry-processing-with-imap-methods ),并在我们的示例中找到示例仓库( https://github.com/hazelcast/hazelcast-code-samples/tree/master/distributed-map/entry-processor )。

Feel free to ask further information. 随时询问更多信息。

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

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