Skip to content

Commit 7c3e850

Browse files
Clear per-shard failure earlier in AbstractSearchAsyncAction.onShardResult (#126933)
We can clean the failure before we potentially go async for a partial merge here to save some heap and needless reference chains to the per-shard result.
1 parent b972364 commit 7c3e850

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,18 +500,18 @@ protected void onShardResult(Result result) {
500500
if (logger.isTraceEnabled()) {
501501
logger.trace("got first-phase result from {}", result != null ? result.getSearchShardTarget() : null);
502502
}
503-
results.consumeResult(result, () -> onShardResultConsumed(result));
504-
}
505-
506-
private void onShardResultConsumed(Result result) {
507-
successfulOps.incrementAndGet();
508503
// clean a previous error on this shard group (note, this code will be serialized on the same shardIndex value level
509504
// so its ok concurrency wise to miss potentially the shard failures being created because of another failure
510505
// in the #addShardFailure, because by definition, it will happen on *another* shardIndex
511506
AtomicArray<ShardSearchFailure> shardFailures = this.shardFailures.get();
512507
if (shardFailures != null) {
513508
shardFailures.set(result.getShardIndex(), null);
514509
}
510+
results.consumeResult(result, this::onShardResultConsumed);
511+
}
512+
513+
private void onShardResultConsumed() {
514+
successfulOps.incrementAndGet();
515515
// we need to increment successful ops first before we compare the exit condition otherwise if we
516516
// are fast we could concurrently update totalOps but then preempt one of the threads which can
517517
// cause the successor to read a wrong value from successfulOps if second phase is very fast ie. count etc.

0 commit comments

Comments
 (0)