-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fold InitialSearchPhase into AbstractSearchAsyncAction (#47182)
Historically, we have two base classes for search actions that generally need to fan out to multiple shards and then move on to the following phase: InitialSearchPhase and AbstractSearchAsyncAction that extends it. Practically, every search action extends the latter, and there are no direct subclasses of InitialSearchPhase in our codebase. This commit folds InitialSearchPhase into AbstractSearchAsyncAction in the attempt of simplifying things and making the search code running on the coordinating node easier to reason about.
- Loading branch information
Showing
13 changed files
with
572 additions
and
577 deletions.
There are no files selected for viewing
362 changes: 330 additions & 32 deletions
362
server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java
Large diffs are not rendered by default.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
server/src/main/java/org/elasticsearch/action/search/ArraySearchPhaseResults.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.search; | ||
|
||
import org.elasticsearch.common.util.concurrent.AtomicArray; | ||
import org.elasticsearch.search.SearchPhaseResult; | ||
|
||
import java.util.stream.Stream; | ||
|
||
/** | ||
* This class acts as a basic result collection that can be extended to do on-the-fly reduction or result processing | ||
*/ | ||
class ArraySearchPhaseResults<Result extends SearchPhaseResult> extends SearchPhaseResults<Result> { | ||
final AtomicArray<Result> results; | ||
|
||
ArraySearchPhaseResults(int size) { | ||
super(size); | ||
this.results = new AtomicArray<>(size); | ||
} | ||
|
||
Stream<Result> getSuccessfulResults() { | ||
return results.asList().stream(); | ||
} | ||
|
||
void consumeResult(Result result) { | ||
assert results.get(result.getShardIndex()) == null : "shardIndex: " + result.getShardIndex() + " is already set"; | ||
results.set(result.getShardIndex(), result); | ||
} | ||
|
||
boolean hasResult(int shardIndex) { | ||
return results.get(shardIndex) != null; | ||
} | ||
|
||
@Override | ||
AtomicArray<Result> getAtomicArray() { | ||
return results; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.