Skip to content

Commit 1b50a75

Browse files
committed
Separate reset and skip
1 parent 56571d8 commit 1b50a75

File tree

5 files changed

+23
-8
lines changed

5 files changed

+23
-8
lines changed

server/src/main/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhase.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,10 @@ private GroupShardsIterator<SearchShardIterator> getIterator(
516516
// shards available in order to produce a valid search result.
517517
int shardIndexToQuery = 0;
518518
for (int i = 0; i < shardsIts.size(); i++) {
519-
if (shardsIts.get(i).size() > 0) {
519+
SearchShardIterator it = shardsIts.get(i);
520+
if (it.size() > 0) {
520521
shardIndexToQuery = i;
522+
it.skip(false); // un-skip which is needed when all the remote shards were skipped by the remote can_match
521523
break;
522524
}
523525
}
@@ -526,8 +528,13 @@ private GroupShardsIterator<SearchShardIterator> getIterator(
526528
SearchSourceBuilder source = request.source();
527529
int i = 0;
528530
for (SearchShardIterator iter : shardsIts) {
531+
iter.reset();
529532
boolean match = possibleMatches.get(i++);
530-
iter.reset(match == false);
533+
if (match) {
534+
assert iter.skip() == false;
535+
} else {
536+
iter.skip(true);
537+
}
531538
}
532539
if (shouldSortShards(results.minAndMaxes) == false) {
533540
return shardsIts;

server/src/main/java/org/elasticsearch/action/search/SearchShardIterator.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ List<String> getTargetNodeIds() {
130130
return targetNodesIterator.asList();
131131
}
132132

133-
void reset(boolean skip) {
134-
this.skip = skip;
133+
void reset() {
135134
targetNodesIterator.reset();
136135
}
137136

@@ -142,6 +141,13 @@ boolean skip() {
142141
return skip;
143142
}
144143

144+
/**
145+
* Specifies if the search execution should skip this shard copies
146+
*/
147+
void skip(boolean skip) {
148+
this.skip = skip;
149+
}
150+
145151
/**
146152
* Returns {@code true} if this iterator was applied pre-filtered
147153
*/

server/src/main/java/org/elasticsearch/action/search/TransportSearchShardsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private static List<SearchShardsGroup> toGroups(GroupShardsIterator<SearchShardI
144144
List<SearchShardsGroup> groups = new ArrayList<>(shardIts.size());
145145
for (SearchShardIterator shardIt : shardIts) {
146146
boolean skip = shardIt.skip();
147-
shardIt.reset(skip);
147+
shardIt.reset();
148148
List<String> targetNodes = new ArrayList<>();
149149
SearchShardTarget target;
150150
while ((target = shardIt.nextOrNull()) != null) {

server/src/test/java/org/elasticsearch/action/search/AbstractSearchAsyncActionTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ public void testShardNotAvailableWithDisallowPartialFailures() {
241241
AbstractSearchAsyncAction<SearchPhaseResult> action = createAction(searchRequest, phaseResults, listener, false, new AtomicLong());
242242
// skip one to avoid the "all shards failed" failure.
243243
SearchShardIterator skipIterator = new SearchShardIterator(null, null, Collections.emptyList(), null);
244-
skipIterator.reset(true);
244+
skipIterator.skip(true);
245+
skipIterator.reset();
245246
action.skipShard(skipIterator);
246247
assertThat(exception.get(), instanceOf(SearchPhaseExecutionException.class));
247248
SearchPhaseExecutionException searchPhaseExecutionException = (SearchPhaseExecutionException) exception.get();

server/src/test/java/org/elasticsearch/action/search/SearchAsyncActionTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void testSkipSearchShards() throws InterruptedException {
8181
int numSkipped = 0;
8282
for (SearchShardIterator iter : shardsIter) {
8383
if (iter.shardId().id() % 2 == 0) {
84-
iter.reset(true);
84+
iter.skip(true);
8585
numSkipped++;
8686
}
8787
}
@@ -633,7 +633,8 @@ public void testSkipUnavailableSearchShards() throws InterruptedException {
633633
originalIndices
634634
);
635635
// Skip all the shards
636-
searchShardIterator.reset(true);
636+
searchShardIterator.skip(true);
637+
searchShardIterator.reset();
637638
searchShardIterators.add(searchShardIterator);
638639
}
639640
GroupShardsIterator<SearchShardIterator> shardsIter = new GroupShardsIterator<>(searchShardIterators);

0 commit comments

Comments
 (0)