Hazelcast: merge two Caribula instances

Suppose we have two examples of Caribbean eyes:

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

Now I'm trying to remove everything from firstInstance , and then add everything from secondInstance to firstInstance .

Is there any way to achieve this?

+6
source share
1 answer

Firstly, according to the initialization of the two instances shown in your code, both are cluster members belonging to the same cluster group, and, given the default configuration, they will contain all the common data. In other words, you do not need to โ€œtransmitโ€ information.

If the above value is true, by the time you finish the deletion from the first instance, you will not have any copy of the data (except for its corresponding source).

If, however, the instances are initialized with configurations linking them to different groups of clusters (remember that your code doesnโ€™t do this in the question), simply copy it using the Java Map / Collections API (which Hazelcast uses to create data types):

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

Distributed lists can be handled in the same way. Also, be careful with such "bulk copies", as your member may hit an error from memory (of course, it depends on the size of your data).

You can read more about this here: http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#preventing-out-of-memory-exceptions

+5
source

All Articles