diff --git a/core/src/main/java/org/elasticsearch/common/cache/Cache.java b/core/src/main/java/org/elasticsearch/common/cache/Cache.java index d39b609e7ea..a62ec312c74 100644 --- a/core/src/main/java/org/elasticsearch/common/cache/Cache.java +++ b/core/src/main/java/org/elasticsearch/common/cache/Cache.java @@ -367,9 +367,10 @@ public class Cache { * {@link org.elasticsearch.common.cache.RemovalNotification.RemovalReason} INVALIDATED. */ public void invalidateAll() { - Entry h = head; + Entry h; Arrays.stream(segments).forEach(segment -> segment.segmentLock.writeLock().lock()); try (ReleasableLock ignored = lruLock.acquire()) { + h = head; Arrays.stream(segments).forEach(segment -> segment.map = new HashMap<>()); Entry current = head; while (current != null) {