Skip to content

Commit

Permalink
Hold searcher in LegacyReaderContext
Browse files Browse the repository at this point in the history
  • Loading branch information
dnhatn committed Sep 6, 2020
1 parent f89a0a6 commit 0c42f9c
Showing 1 changed file with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(), () -> {});
Expand All @@ -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;
Expand Down

0 comments on commit 0c42f9c

Please sign in to comment.