diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cache/filter/IndicesNodeFilterCache.java b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cache/filter/IndicesNodeFilterCache.java index 4730b9cc88c..9a37dd980bd 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cache/filter/IndicesNodeFilterCache.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/indices/cache/filter/IndicesNodeFilterCache.java @@ -24,15 +24,17 @@ import org.elasticsearch.common.concurrentlinkedhashmap.ConcurrentLinkedHashMap; import org.elasticsearch.common.concurrentlinkedhashmap.EvictionListener; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.docset.DocSet; -import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeValue; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.cache.filter.support.AbstractWeightedFilterCache; import org.elasticsearch.index.cache.filter.support.FilterCacheValue; import org.elasticsearch.monitor.jvm.JvmInfo; +import org.elasticsearch.threadpool.ThreadPool; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.TimeUnit; public class IndicesNodeFilterCache extends AbstractComponent implements EvictionListener> { @@ -43,11 +45,7 @@ public class IndicesNodeFilterCache extends AbstractComponent implements Evictio private final CopyOnWriteArrayList>> evictionListeners = new CopyOnWriteArrayList>>(); - public IndicesNodeFilterCache() { - this(ImmutableSettings.Builder.EMPTY_SETTINGS); - } - - @Inject public IndicesNodeFilterCache(Settings settings) { + @Inject public IndicesNodeFilterCache(Settings settings, ThreadPool threadPool) { super(settings); String size = componentSettings.get("size", "20%"); @@ -57,6 +55,7 @@ public class IndicesNodeFilterCache extends AbstractComponent implements Evictio } else { sizeInBytes = ByteSizeValue.parseBytesSizeValue(size).bytes(); } + TimeValue catchupTime = componentSettings.getAsTime("catchup", TimeValue.timeValueSeconds(10)); int weightedSize = (int) Math.min(sizeInBytes / AbstractWeightedFilterCache.FilterCacheValueWeigher.FACTOR, Integer.MAX_VALUE); @@ -64,6 +63,7 @@ public class IndicesNodeFilterCache extends AbstractComponent implements Evictio .maximumWeightedCapacity(weightedSize) .weigher(new AbstractWeightedFilterCache.FilterCacheValueWeigher()) .listener(this) + .catchup(threadPool.scheduler(), catchupTime.millis(), TimeUnit.MILLISECONDS) .build(); logger.debug("using [node] filter cache with size [{}]", new ByteSizeValue(sizeInBytes)); diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index 66b0394bdb7..c0f52a29f78 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -112,6 +112,10 @@ public class ThreadPool extends AbstractComponent { return executor; } + public ScheduledExecutorService scheduler() { + return this.scheduler; + } + public ScheduledFuture scheduleWithFixedDelay(Runnable command, TimeValue interval) { return scheduler.scheduleWithFixedDelay(new LoggingRunnable(command), interval.millis(), interval.millis(), TimeUnit.MILLISECONDS); }