0
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);
prost0
  • 19
  • 5
  • What is the type of `key`? – Pavel Tupitsyn Jan 29 '22 at 14:14
  • Key is my type "CurrencyPair". Here is hashCode: public int hashCode() { return 31 * left.hashCode() + right.hashCode(); } And here is left/right hashCode: public int hashCode() { int hash = currencyType.ordinal(); // currencyType is ordinal hash ^= (hash << 13); hash ^= (hash >> 17); hash ^= (hash << 5); return hash; } – prost0 Jan 29 '22 at 15:25
  • 1
    Please share a code snippet with reproducer, there is definitely a bug in your code – Alexandr Shapkin Jan 30 '22 at 00:16
  • That's the problem. I can't reproduce it. And moreover the NPE disappeared after service restart. – prost0 Jan 31 '22 at 09:24
  • Sounds good. Just in case - aren't there any removal operations by chance? Is it possible that a NULL value could be inserted as a value? – Alexandr Shapkin Jan 31 '22 at 16:15
  • No. Only putIfAbsent with not null key/value. – prost0 Feb 01 '22 at 07:45

1 Answers1

0

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.

Stanislav Lukyanov
  • 2,147
  • 10
  • 20