1010package org .elasticsearch .action .support .replication ;
1111
1212import org .apache .logging .log4j .Logger ;
13+ import org .apache .lucene .store .AlreadyClosedException ;
1314import org .elasticsearch .action .ActionListener ;
1415import org .elasticsearch .action .ActionRunnable ;
1516import 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