Hazelcast:合并两个 hazelcast 实例

Hazelcast: Merge two hazelcast instances

假设我们有两个 hazelcast 实例:

HazelcastInstance firstInstance = Hazelcast.newHazelcastInstance(new Config());
HazelcastInstance secondInstance = Hazelcast.newHazelcastInstance(new Config());
// Add entries to firstInstance
// Add entries to secondInstance

现在我试图删除 firstInstanceadd everything from secondInstance to firstInstance.

中的所有内容

有办法实现吗?

首先,根据代码中显示的两个实例的初始化,它们都是属于同一集群组的集群成员,并且在默认配置下,它们都将包含所有共享数据。换句话说,您不需要 'transfer' 信息。

如果上述情况属实,当您从第一个实例中完成删除时,您将没有任何数据副本(除了它们各自的来源)。

但是,如果实例是使用将它们绑定到不同集群组的配置初始化的(请记住,问题中的代码没有这样做),只需 'copy' 使用 Java Map/Collections API(Hazelcast 共享数据结构类型实现):

secondInstance.getMap("myMap").putAll(firstInstance.getMap("myMap"));
firstInstance.getMap("myMap").clear(); //please confirm this.

可以用类似的方式处理分布式列表。 另外,请小心 'bulk copies',因为您的成员可能会遇到内存不足的错误(当然,这取决于您的数据大小)。

可在此处阅读更多相关信息:http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#preventing-out-of-memory-exceptions