Skip to content

Commit 535cca8

Browse files
Fix small mistake in listener wrapping in SearchService
`l` is the same as the `finalListener` here, that's kind of the point of the API. Fixing this here and removing the local variable the enabled the mistake in the first place. Not a bug, but a needless capture that at times makes heap dumps harder to read and wastes a couple cycles.
1 parent 8cfc622 commit 535cca8

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

server/src/main/java/org/elasticsearch/search/SearchService.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -582,32 +582,35 @@ private void loadOrExecuteQueryPhase(final ShardSearchRequest request, final Sea
582582
}
583583

584584
public void executeQueryPhase(ShardSearchRequest request, SearchShardTask task, ActionListener<SearchPhaseResult> listener) {
585-
ActionListener<SearchPhaseResult> finalListener = maybeWrapListenerForStackTrace(listener, request.getChannelVersion(), threadPool);
586585
assert request.canReturnNullResponseIfMatchNoDocs() == false || request.numberOfShards() > 1
587586
: "empty responses require more than one shard";
588587
final IndexShard shard = getShard(request);
589-
rewriteAndFetchShardRequest(shard, request, finalListener.delegateFailure((l, orig) -> {
590-
// check if we can shortcut the query phase entirely.
591-
if (orig.canReturnNullResponseIfMatchNoDocs()) {
592-
assert orig.scroll() == null;
593-
ShardSearchRequest clone = new ShardSearchRequest(orig);
594-
CanMatchContext canMatchContext = new CanMatchContext(
595-
clone,
596-
indicesService::indexServiceSafe,
597-
this::findReaderContext,
598-
defaultKeepAlive,
599-
maxKeepAlive
600-
);
601-
CanMatchShardResponse canMatchResp = canMatch(canMatchContext, false);
602-
if (canMatchResp.canMatch() == false) {
603-
finalListener.onResponse(QuerySearchResult.nullInstance());
604-
return;
588+
rewriteAndFetchShardRequest(
589+
shard,
590+
request,
591+
maybeWrapListenerForStackTrace(listener, request.getChannelVersion(), threadPool).delegateFailure((l, orig) -> {
592+
// check if we can shortcut the query phase entirely.
593+
if (orig.canReturnNullResponseIfMatchNoDocs()) {
594+
assert orig.scroll() == null;
595+
ShardSearchRequest clone = new ShardSearchRequest(orig);
596+
CanMatchContext canMatchContext = new CanMatchContext(
597+
clone,
598+
indicesService::indexServiceSafe,
599+
this::findReaderContext,
600+
defaultKeepAlive,
601+
maxKeepAlive
602+
);
603+
CanMatchShardResponse canMatchResp = canMatch(canMatchContext, false);
604+
if (canMatchResp.canMatch() == false) {
605+
l.onResponse(QuerySearchResult.nullInstance());
606+
return;
607+
}
605608
}
606-
}
607-
// TODO: i think it makes sense to always do a canMatch here and
608-
// return an empty response (not null response) in case canMatch is false?
609-
ensureAfterSeqNoRefreshed(shard, orig, () -> executeQueryPhase(orig, task), l);
610-
}));
609+
// TODO: i think it makes sense to always do a canMatch here and
610+
// return an empty response (not null response) in case canMatch is false?
611+
ensureAfterSeqNoRefreshed(shard, orig, () -> executeQueryPhase(orig, task), l);
612+
})
613+
);
611614
}
612615

613616
private <T extends RefCounted> void ensureAfterSeqNoRefreshed(

0 commit comments

Comments
 (0)