Skip to content

Commit eb37a59

Browse files
committed
remove use of recycled set in filters eviction
closes #7012
1 parent d9ff42f commit eb37a59

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

src/main/java/org/elasticsearch/indices/cache/filter/IndicesFilterCache.java

+21-24
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
import com.google.common.cache.RemovalListener;
2727
import com.google.common.cache.RemovalNotification;
2828
import org.apache.lucene.search.DocIdSet;
29-
import org.elasticsearch.cache.recycler.CacheRecycler;
3029
import org.elasticsearch.common.component.AbstractComponent;
3130
import org.elasticsearch.common.inject.Inject;
32-
import org.elasticsearch.common.recycler.Recycler;
3331
import org.elasticsearch.common.settings.Settings;
3432
import org.elasticsearch.common.unit.ByteSizeValue;
3533
import org.elasticsearch.common.unit.MemorySizeValue;
@@ -47,7 +45,6 @@
4745
public class IndicesFilterCache extends AbstractComponent implements RemovalListener<WeightedFilterCache.FilterCacheKey, DocIdSet> {
4846

4947
private final ThreadPool threadPool;
50-
private final CacheRecycler cacheRecycler;
5148

5249
private Cache<WeightedFilterCache.FilterCacheKey, DocIdSet> cache;
5350

@@ -91,10 +88,9 @@ public void onRefreshSettings(Settings settings) {
9188
}
9289

9390
@Inject
94-
public IndicesFilterCache(Settings settings, ThreadPool threadPool, CacheRecycler cacheRecycler, NodeSettingsService nodeSettingsService) {
91+
public IndicesFilterCache(Settings settings, ThreadPool threadPool, NodeSettingsService nodeSettingsService) {
9592
super(settings);
9693
this.threadPool = threadPool;
97-
this.cacheRecycler = cacheRecycler;
9894
this.size = componentSettings.get("size", "10%");
9995
this.expire = componentSettings.getAsTime("expire", null);
10096
this.cleanInterval = componentSettings.getAsTime("clean_interval", TimeValue.timeValueSeconds(60));
@@ -167,6 +163,10 @@ public void onRemoval(RemovalNotification<WeightedFilterCache.FilterCacheKey, Do
167163
*/
168164
class ReaderCleaner implements Runnable {
169165

166+
// this is thread safe since we only schedule the next cleanup once the current one is
167+
// done, so no concurrent execution
168+
private final ObjectOpenHashSet<Object> keys = ObjectOpenHashSet.newInstance();
169+
170170
@Override
171171
public void run() {
172172
if (closed) {
@@ -180,33 +180,30 @@ public void run() {
180180
threadPool.executor(ThreadPool.Names.GENERIC).execute(new Runnable() {
181181
@Override
182182
public void run() {
183-
Recycler.V<ObjectOpenHashSet<Object>> keys = cacheRecycler.hashSet(-1);
184-
try {
185-
for (Iterator<Object> it = readersKeysToClean.iterator(); it.hasNext(); ) {
186-
keys.v().add(it.next());
187-
it.remove();
188-
}
189-
cache.cleanUp();
190-
if (!keys.v().isEmpty()) {
191-
for (Iterator<WeightedFilterCache.FilterCacheKey> it = cache.asMap().keySet().iterator(); it.hasNext(); ) {
192-
WeightedFilterCache.FilterCacheKey filterCacheKey = it.next();
193-
if (keys.v().contains(filterCacheKey.readerKey())) {
194-
// same as invalidate
195-
it.remove();
196-
}
183+
keys.clear();
184+
for (Iterator<Object> it = readersKeysToClean.iterator(); it.hasNext(); ) {
185+
keys.add(it.next());
186+
it.remove();
187+
}
188+
cache.cleanUp();
189+
if (!keys.isEmpty()) {
190+
for (Iterator<WeightedFilterCache.FilterCacheKey> it = cache.asMap().keySet().iterator(); it.hasNext(); ) {
191+
WeightedFilterCache.FilterCacheKey filterCacheKey = it.next();
192+
if (keys.contains(filterCacheKey.readerKey())) {
193+
// same as invalidate
194+
it.remove();
197195
}
198196
}
199-
schedule();
200-
} finally {
201-
keys.close();
202197
}
198+
schedule();
199+
keys.clear();
203200
}
204201
});
205202
} catch (EsRejectedExecutionException ex) {
206203
logger.debug("Can not run ReaderCleaner - execution rejected", ex);
207-
}
204+
}
208205
}
209-
206+
210207
private void schedule() {
211208
try {
212209
threadPool.schedule(cleanInterval, ThreadPool.Names.SAME, this);

0 commit comments

Comments
 (0)