diff --git a/src/main/java/org/elasticsearch/index/cache/IndexCache.java b/src/main/java/org/elasticsearch/index/cache/IndexCache.java index de263a69ccd..f5d754581ff 100644 --- a/src/main/java/org/elasticsearch/index/cache/IndexCache.java +++ b/src/main/java/org/elasticsearch/index/cache/IndexCache.java @@ -81,7 +81,7 @@ public class IndexCache extends AbstractIndexComponent implements CloseableCompo filterCache.close(); queryParserCache.close(); docSetCache.clear("close"); - fixedBitSetFilterCache.clear("close"); + fixedBitSetFilterCache.close(); if (clusterService != null) { clusterService.remove(this); } diff --git a/src/main/java/org/elasticsearch/index/cache/fixedbitset/FixedBitSetFilterCache.java b/src/main/java/org/elasticsearch/index/cache/fixedbitset/FixedBitSetFilterCache.java index 66380a2648b..176008d4314 100644 --- a/src/main/java/org/elasticsearch/index/cache/fixedbitset/FixedBitSetFilterCache.java +++ b/src/main/java/org/elasticsearch/index/cache/fixedbitset/FixedBitSetFilterCache.java @@ -30,8 +30,10 @@ import org.apache.lucene.search.DocIdSetIterator; import org.apache.lucene.search.Filter; import org.apache.lucene.util.Bits; import org.apache.lucene.util.FixedBitSet; +import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.component.CloseableComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.lucene.SegmentReaderUtils; import org.elasticsearch.common.lucene.search.NoCacheFilter; @@ -70,25 +72,29 @@ import java.util.concurrent.Executor; * and require that it should always be around should use this cache, otherwise the * {@link org.elasticsearch.index.cache.filter.FilterCache} should be used instead. */ -public class FixedBitSetFilterCache extends AbstractIndexComponent implements AtomicReader.CoreClosedListener, RemovalListener> { +public class FixedBitSetFilterCache extends AbstractIndexComponent implements AtomicReader.CoreClosedListener, RemovalListener>, CloseableComponent { public static final String LOAD_RANDOM_ACCESS_FILTERS_EAGERLY = "index.load_fixed_bitset_filters_eagerly"; private final boolean loadRandomAccessFiltersEagerly; private final Cache> loadedFilters; + private final FixedBitSetFilterWarmer warmer; private IndexService indexService; + private IndicesWarmer indicesWarmer; @Inject public FixedBitSetFilterCache(Index index, @IndexSettings Settings indexSettings) { super(index, indexSettings); this.loadRandomAccessFiltersEagerly = indexSettings.getAsBoolean(LOAD_RANDOM_ACCESS_FILTERS_EAGERLY, true); this.loadedFilters = CacheBuilder.newBuilder().removalListener(this).build(); + this.warmer = new FixedBitSetFilterWarmer(); } @Inject(optional = true) public void setIndicesWarmer(IndicesWarmer indicesWarmer) { - indicesWarmer.addListener(new FixedBitSetFilterWarmer()); + this.indicesWarmer = indicesWarmer; + indicesWarmer.addListener(warmer); } public FixedBitSetFilter getFixedBitSetFilter(Filter filter) { @@ -102,6 +108,11 @@ public class FixedBitSetFilterCache extends AbstractIndexComponent implements At loadedFilters.invalidate(ownerCoreCacheKey); } + public void close() throws ElasticsearchException { + indicesWarmer.removeListener(warmer); + clear("close"); + } + public void clear(String reason) { logger.debug("Clearing all FixedBitSets because [{}]", reason); loadedFilters.invalidateAll();