Skip to content

Commit

Permalink
Cleanup some redundancies around DfsQueryPhase (elastic#116057)
Browse files Browse the repository at this point in the history
No need to add the result consumer to teh context another time, it's
already added to it in the constructor of `SearchDfsQueryThenFetchAsyncAction`.
Also, no need to feed `this` and `this.results` to `getNextPhase`
explicitly, there's only a single call to this method so we can safely
clean up the redundant arguments.
  • Loading branch information
original-brownbear authored Nov 7, 2024
1 parent 9ebe95a commit d66b5ae
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ private void raisePhaseFailure(SearchPhaseExecutionException exception) {
* @see #onShardResult(SearchPhaseResult, SearchShardIterator)
*/
final void onPhaseDone() { // as a tribute to @kimchy aka. finishHim()
executeNextPhase(this, () -> getNextPhase(results, this));
executeNextPhase(this, this::getNextPhase);
}

@Override
Expand Down Expand Up @@ -746,11 +746,8 @@ protected final ShardSearchRequest buildShardSearchRequest(SearchShardIterator s

/**
* Returns the next phase based on the results of the initial search phase
* @param results the results of the initial search phase. Each non null element in the result array represent a successfully
* executed shard request
* @param context the search context for the next phase
*/
protected abstract SearchPhase getNextPhase(SearchPhaseResults<Result> results, SearchPhaseContext context);
protected abstract SearchPhase getNextPhase();

private static final class PendingExecutions {
private final Semaphore semaphore;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ final class DfsQueryPhase extends SearchPhase {
this.nextPhaseFactory = nextPhaseFactory;
this.context = context;
this.searchTransportService = context.getSearchTransport();

// register the release of the query consumer to free up the circuit breaker memory
// at the end of the search
context.addReleasable(queryResult);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void executePhaseOnShard(
}

@Override
protected SearchPhase getNextPhase(final SearchPhaseResults<DfsSearchResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
final List<DfsSearchResult> dfsSearchResults = results.getAtomicArray().asList();
final AggregatedDfs aggregatedDfs = SearchPhaseController.aggregateDfs(dfsSearchResults);
final List<DfsKnnResults> mergedKnnResults = SearchPhaseController.mergeKnnResults(getRequest(), dfsSearchResults);
Expand All @@ -107,8 +107,8 @@ protected SearchPhase getNextPhase(final SearchPhaseResults<DfsSearchResult> res
aggregatedDfs,
mergedKnnResults,
queryPhaseResultConsumer,
(queryResults) -> SearchQueryThenFetchAsyncAction.nextPhase(client, context, queryResults, aggregatedDfs),
context
(queryResults) -> SearchQueryThenFetchAsyncAction.nextPhase(client, this, queryResults, aggregatedDfs),
this
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static SearchPhase nextPhase(
}

@Override
protected SearchPhase getNextPhase(final SearchPhaseResults<SearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return nextPhase(client, this, results, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ protected void executePhaseOnShard(
}

@Override
protected SearchPhase getNextPhase(SearchPhaseResults<SearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return new SearchPhase(getName()) {

private void onExecuteFailure(Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private AbstractSearchAsyncAction<SearchPhaseResult> createAction(
SearchResponse.Clusters.EMPTY
) {
@Override
protected SearchPhase getNextPhase(final SearchPhaseResults<SearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected void executePhaseOnShard(
}

@Override
protected SearchPhase getNextPhase(SearchPhaseResults<TestSearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return new SearchPhase("test") {
@Override
public void run() {
Expand Down Expand Up @@ -255,7 +255,7 @@ protected void executePhaseOnShard(
}

@Override
protected SearchPhase getNextPhase(SearchPhaseResults<TestSearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return new SearchPhase("test") {
@Override
public void run() {
Expand Down Expand Up @@ -359,7 +359,7 @@ protected void executePhaseOnShard(
}

@Override
protected SearchPhase getNextPhase(SearchPhaseResults<TestSearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return new SearchPhase("test") {
@Override
public void run() {
Expand Down Expand Up @@ -488,7 +488,7 @@ protected void executePhaseOnShard(
}

@Override
protected SearchPhase getNextPhase(SearchPhaseResults<TestSearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return new SearchPhase("test") {
@Override
public void run() {
Expand Down Expand Up @@ -600,7 +600,7 @@ protected void executePhaseOnShard(
}

@Override
protected SearchPhase getNextPhase(SearchPhaseResults<TestSearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return new SearchPhase("test") {
@Override
public void run() {
Expand Down Expand Up @@ -680,7 +680,7 @@ protected void executePhaseOnShard(
}

@Override
protected SearchPhase getNextPhase(SearchPhaseResults<TestSearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return new SearchPhase("test") {
@Override
public void run() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public void sendExecuteQuery(
null
) {
@Override
protected SearchPhase getNextPhase(SearchPhaseResults<SearchPhaseResult> results, SearchPhaseContext context) {
protected SearchPhase getNextPhase() {
return new SearchPhase("test") {
@Override
public void run() {
Expand Down

0 comments on commit d66b5ae

Please sign in to comment.