From 65ce5acfb41b4abd0c527aa0e870c2a1076d76cd Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Fri, 23 May 2014 16:12:22 +0200 Subject: [PATCH] Explicitly clean up fielddata cache when clearing entire cache --- .../fielddata/cache/IndicesFieldDataCache.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java b/src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java index dd4f2aa87f2..aa1174d1438 100644 --- a/src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java +++ b/src/main/java/org/elasticsearch/indices/fielddata/cache/IndicesFieldDataCache.java @@ -217,11 +217,24 @@ public class IndicesFieldDataCache extends AbstractComponent implements RemovalL @Override public void clear() { + // TODO: determine whether there is ever anything in this cache that doesn't share the index and consider .invalidateAll() instead for (Key key : cache.asMap().keySet()) { if (key.indexCache.index.equals(index)) { cache.invalidate(key); } } + // There is an explicit call to cache.cleanUp() here because cache + // invalidation in Guava does not immediately remove values from the + // cache. In the case of a cache with a rare write or read rate, + // it's possible for values to persist longer than desired. In the + // case of the circuit breaker, when clearing the entire cache all + // entries should immediately be evicted so that their sizes are + // removed from the breaker estimates. + // + // Note this is intended by the Guava developers, see: + // https://code.google.com/p/guava-libraries/wiki/CachesExplained#Eviction + // (the "When Does Cleanup Happen" section) + cache.cleanUp(); } @Override