I have an Apache Ignite Server node cluster and some IgniteCache
s defined. The first node in the cluster has populated the cache with some values. When a new node joins, it gets an instance of that cache but when I try to iterate through the existing values the iterator
has no next element. If I try to access a specific entry via .get(String key)
then the entry is fetched.
This makes me think that values are not immediately made available to new nodes, even though the replication mode is REPLICATED
and the rebalance mode is SYNC
. SYNC
mode javadoc says that the cache won't start until all necessary data is loaded from other grid nodes which doesn't seem to be the case. I have tried everything from listening to CACHE_STARTED
events to trying to force a load but nothing works.
I'm just looking to run some logic after the IgniteCache
instance has been created and populated with the grid data.
The solution is to add a listener to EventType.EVT_CACHE_REBALANCE_STOPPED
and execute any logic inside since this event is triggered after the cache has been populated with its respective data (in this case all of the entries since we have REPLICATED
mode).
ignite.events().enableLocal(EventType.EVT_CACHE_REBALANCE_STOPPED);
ignite.events().localListen(event -> {
if(event instanceof CacheRebalancingEvent && ((CacheRebalancingEvent) event).cacheName().equals("myCacheName")) {
for (Cache.Entry<String, Object> entry : myCache) {
logic(null, entry.getValue());
}
ignite.events().disableLocal(EventType.EVT_CACHE_REBALANCE_STOPPED);
return false;
}
return true;
}, EventType.EVT_CACHE_REBALANCE_STOPPED);
// ...
IgniteCache myCache = ignite.getOrCreateCache(cacheConfiguration("myCacheName"));