remove any Reentrant locks in favor of a CAS linked list by andimarek · Pull Request #241 · graphql-java/java-dataloader

This PR removes any usage of Reentrant Lock in DataLoader in favor of using a self made Linked List and updates to it via AtomicReference CAS.

CacheMap change

This is a breaking change for the future cache CacheMap.

In order to avoid any locking

    CacheMap<K, V> set(K key, CompletableFuture<V> value);

was replaced with

    CompletableFuture<V> setIfAbsent(K key, CompletableFuture<V> value);

which is required to be atomic (like for example offered by ConcurrendHashMap)

This requirement also means that the underlying cache implementation must support this atomic operation.

Concurrent loads without batching, but with caching

Previously it was guaranteed that for one key with caching enabled and batching disabled, the dispatching only happens once.
Now because we avoid any form on lock this is not guaranteed anymore: there could be unnecessary dispatch calls when concurrent load calls are happening.

TODO: Update tests to avoid Collections.reverse

See https://github.com/graphql-java/java-dataloader/pull/241/files#diff-e44f0238fddb1d168a414ceef18d7194686b83ecf167cb794d2d03e714494c88R259