Apach Ignite ClientCache::putIfAbsent don't actually update cache?

159 Views Asked by At
cache.putIfAbsent(key, value);
cache.get(key).method();

Given code produces NPE at second line. Here is how I create cache:

ClientCacheConfiguration cacheConfig = new ClientCacheConfiguration().setCacheMode(CacheMode.REPLICATED)                                                                                .setName("POSITION");
cache = igniteClient.getOrCreateCache(cacheConfig);
1

There are 1 best solutions below

0
On

It's possible to come up with a number of edge cases in which put(1, "foo"); get(1) returns null. This is confusing, I know - distributed systems often are.

The root problem is always the cache settings. Ignite historically has a couple of defaults which lean towards performance instead of consistency:

While both of these options have their perfectly valid use cases, you may want to set writeSynchronizationMode=FULL_SYNC and readFromBackup=false to enforce stronger consistency and avoid the mess.