Skip to content

Commit a422586

Browse files
committed
bug
1 parent c5153c1 commit a422586

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

server/src/main/java/org/elasticsearch/action/support/replication/TransportWriteAction.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
package org.elasticsearch.action.support.replication;
1111

1212
import org.apache.logging.log4j.Logger;
13+
import org.apache.lucene.store.AlreadyClosedException;
1314
import org.elasticsearch.action.ActionListener;
1415
import org.elasticsearch.action.ActionRunnable;
1516
import org.elasticsearch.action.support.ActionFilters;
@@ -456,6 +457,7 @@ static final class AsyncAfterWriteAction {
456457
// read the values back from the engine as it could deadlock.
457458
private final AtomicLong globalCheckpoint;
458459
private final AtomicLong localCheckpoint;
460+
private final AtomicReference<Exception> checkpointFailure = new AtomicReference<>(null);
459461

460462
AsyncAfterWriteAction(
461463
final IndexShard indexShard,
@@ -503,7 +505,11 @@ private void maybeFinish() {
503505
if (refreshFailure.get() != null) {
504506
respond.onFailure(globalCheckpoint, localCheckpoint, refreshFailure.get());
505507
} else {
506-
respond.onSuccess(globalCheckpoint, localCheckpoint, refreshed.get());
508+
if (checkpointFailure.get() != null) {
509+
respond.onFailure(globalCheckpoint, localCheckpoint, checkpointFailure.get());
510+
} else {
511+
respond.onSuccess(globalCheckpoint, localCheckpoint, refreshed.get());
512+
}
507513
}
508514
}
509515
}
@@ -512,11 +518,14 @@ private void maybeFinish() {
512518

513519
private void updateCheckpoints() {
514520
try {
515-
this.globalCheckpoint.accumulateAndGet(indexShard.getLastSyncedGlobalCheckpoint(), Math::max);
516-
this.localCheckpoint.accumulateAndGet(indexShard.getLocalCheckpoint(), Math::max);
521+
if (checkpointFailure.get() != null) {
522+
this.globalCheckpoint.accumulateAndGet(indexShard.getLastSyncedGlobalCheckpoint(), Math::max);
523+
this.localCheckpoint.accumulateAndGet(indexShard.getLocalCheckpoint(), Math::max);
524+
}
525+
} catch (AlreadyClosedException e) {
526+
// the index was deleted or this shard was never activated after a relocation; fall through and finish normally
517527
} catch (Exception e) {
518-
logger.warn("Failed to retrieve checkpoints", e);
519-
assert false : e;
528+
checkpointFailure.set(e);
520529
}
521530
}
522531

0 commit comments

Comments
 (0)