让我们说我们有两个hazelcast的例子:
HazelcastInstance firstInstance = Hazelcast.newHazelcastInstance(new Config());
HazelcastInstance secondInstance = Hazelcast.newHazelcastInstance(new Config());
// Add entries to firstInstance
// Add entries to secondInstance现在,我正在尝试删除firstInstance和add everything from secondInstance to firstInstance中的所有内容。
有办法做到这一点吗?
发布于 2016-03-02 07:55:32
首先,根据代码中所示的两个实例的初始化,它们都是属于同一个集群组的集群成员,并且在默认配置的情况下,它们都将包含所有共享数据。换句话说,您不需要“传输”信息。
如果上述情况属实,则在从第一个实例中删除数据时,将不会有数据的任何副本(除了各自的源之外)。
但是,如果使用将实例绑定到不同集群组的配置来初始化实例(请记住,问题中的代码没有这样做),那么使用Java Map/Collections API ( Hazelcast共享数据结构类型实现的)就可以简单地“复制”:
secondInstance.getMap("myMap").putAll(firstInstance.getMap("myMap"));
firstInstance.getMap("myMap").clear(); //please confirm this.分布式列表可以以类似的方式处理。此外,要小心这样的“批量复制”,因为您的成员可能会遇到内存不足的错误(当然,这取决于数据的大小)。
有关此问题的更多信息,请参阅:http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#preventing-out-of-memory-exceptions
https://stackoverflow.com/questions/35741194
复制相似问题