Skip to content

Commit 2437ed2

Browse files
comment and assert
1 parent 93eaa31 commit 2437ed2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,10 @@ private void onShardFailure(final int shardIndex, SearchShardTarget shard, final
457457
if (lastShard == false) {
458458
performPhaseOnShard(shardIndex, shardIt, nextShard);
459459
} else {
460-
if ((int) OUTSTANDING_SHARDS.getAndAdd(this, -1) == 1) {
460+
// count down outstanding shards, we're done with this shard as there's no more copies to try
461+
final int outstanding = (int) OUTSTANDING_SHARDS.getAndAdd(this, -1);
462+
assert outstanding > 0 : "outstanding: " + outstanding;
463+
if (outstanding == 1) {
461464
onPhaseDone();
462465
}
463466
}
@@ -555,7 +558,9 @@ private void onShardResultConsumed(Result result) {
555558
}
556559

557560
private void successfulShardExecution() {
558-
if ((int) OUTSTANDING_SHARDS.getAndAdd(this, -1) == 1) {
561+
final int outstanding = (int) OUTSTANDING_SHARDS.getAndAdd(this, -1);
562+
assert outstanding > 0 : "outstanding: " + outstanding;
563+
if (outstanding == 1) {
559564
onPhaseDone();
560565
}
561566
}

0 commit comments

Comments
 (0)