From 0c42f9c0b1740cb75d511118dca90459d9bdc38c Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Sun, 6 Sep 2020 19:40:42 -0400 Subject: [PATCH] Hold searcher in LegacyReaderContext --- .../search/internal/LegacyReaderContext.java | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/internal/LegacyReaderContext.java b/server/src/main/java/org/elasticsearch/search/internal/LegacyReaderContext.java index 98a722a6abac5..8f6ccb526cf34 100644 --- a/server/src/main/java/org/elasticsearch/search/internal/LegacyReaderContext.java +++ b/server/src/main/java/org/elasticsearch/search/internal/LegacyReaderContext.java @@ -35,8 +35,7 @@ public class LegacyReaderContext extends ReaderContext { private AggregatedDfs aggregatedDfs; private RescoreDocIds rescoreDocIds; - private Engine.Searcher searcher; - private Releasable onClose; + private volatile Engine.Searcher searcher; public LegacyReaderContext(long id, IndexService indexService, IndexShard indexShard, Engine.SearcherSupplier reader, ShardSearchRequest shardSearchRequest, long keepAliveInMillis) { @@ -59,8 +58,8 @@ public Engine.Searcher acquireSearcher(String source) { // This ensures that we wrap the searcher's reader with the user's permissions // when they are available. if (searcher == null) { - Engine.Searcher delegate = searcherSupplier.acquireSearcher(source); - onClose = delegate::close; + final Engine.Searcher delegate = searcherSupplier.acquireSearcher(source); + addOnClose(delegate); // wrap the searcher so that closing is a noop, the actual closing happens when this context is closed searcher = new Engine.Searcher(delegate.source(), delegate.getDirectoryReader(), delegate.getSimilarity(), delegate.getQueryCache(), delegate.getQueryCachingPolicy(), () -> {}); @@ -70,12 +69,6 @@ public Engine.Searcher acquireSearcher(String source) { return super.acquireSearcher(source); } - - @Override - void doClose() { - Releasables.close(onClose, super::doClose); - } - @Override public ShardSearchRequest getShardSearchRequest(ShardSearchRequest other) { return shardSearchRequest;