Skip to content

Commit 28f51e4

Browse files
Fix small mistake in listener wrapping in SearchService (#122190)
`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 e706193 commit 28f51e4

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
@@ -583,32 +583,35 @@ private void loadOrExecuteQueryPhase(final ShardSearchRequest request, final Sea
583583
}
584584

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

614617
private <T extends RefCounted> void ensureAfterSeqNoRefreshed(

0 commit comments

Comments
 (0)