Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply the reader wrapper on can_match source #78988

Merged
merged 3 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,7 @@ public final Searcher acquireSearcher(String source) {
throw new AlreadyClosedException("SearcherSupplier was closed");
}
final Searcher searcher = acquireSearcherInternal(source);
return CAN_MATCH_SEARCH_SOURCE.equals(source) ? searcher : wrapper.apply(searcher);
return wrapper.apply(searcher);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ public void testCanMatch() throws Exception {
searchRequest.source(new SearchSourceBuilder().query(new MatchNoneQueryBuilder()));
assertFalse(service.canMatch(new ShardSearchRequest(OriginalIndices.NONE, searchRequest, indexShard.shardId(), 0, 1,
new AliasFilter(null, Strings.EMPTY_ARRAY), 1f, -1, null)).canMatch());
assertEquals(0, numWrapInvocations.get());
assertEquals(6, numWrapInvocations.get());

ShardSearchRequest request = new ShardSearchRequest(OriginalIndices.NONE, searchRequest, indexShard.shardId(), 0, 1,
new AliasFilter(null, Strings.EMPTY_ARRAY), 1.0f, -1, null);
Expand All @@ -782,12 +782,13 @@ public void testCanMatch() throws Exception {

CountDownLatch latch = new CountDownLatch(1);
SearchShardTask task = new SearchShardTask(123L, "", "", "", null, Collections.emptyMap());
assertEquals(8, numWrapInvocations.get());
service.executeQueryPhase(request, task, new ActionListener<SearchPhaseResult>() {
@Override
public void onResponse(SearchPhaseResult searchPhaseResult) {
try {
// make sure that the wrapper is called when the query is actually executed
assertEquals(1, numWrapInvocations.get());
assertEquals(9, numWrapInvocations.get());
} finally {
latch.countDown();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ protected void doClose() {

@Override
public CacheHelper getReaderCacheHelper() {
throw new UnsupportedOperationException();
// this reader is used for fast operations that don't require caching
return null;
}

// except of a couple of selected methods everything else will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.elasticsearch.common.cache.CacheBuilder;
import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.lucene.index.SequentialStoredFieldsLeafReader;
import org.elasticsearch.transport.Transports;

import java.io.IOException;
import java.io.UncheckedIOException;
Expand Down Expand Up @@ -177,6 +178,7 @@ private void computeNumDocsIfNeeded() {
if (numDocs == -1) {
synchronized (this) {
if (numDocs == -1) {
assert Transports.assertNotTransportThread("resolving role query");
try {
roleQueryBits = bitsetCache.getBitSet(roleQuery, in.getContext());
numDocs = getNumDocs(in, roleQuery, roleQueryBits);
Expand Down