@@ -517,9 +517,9 @@ void phase1(IndexCommit snapshot, Consumer<ActionListener<RetentionLease>> creat
517
517
final StepListener <Void > sendFilesStep = new StepListener <>();
518
518
final StepListener <RetentionLease > createRetentionLeaseStep = new StepListener <>();
519
519
final StepListener <Void > cleanFilesStep = new StepListener <>();
520
- cancellableThreads .execute (() ->
521
- recoveryTarget .receiveFileInfo (phase1FileNames , phase1FileSizes , phase1ExistingFileNames ,
522
- phase1ExistingFileSizes , translogOps .getAsInt (), sendFileInfoStep )) ;
520
+ cancellableThreads .checkForCancel ();
521
+ recoveryTarget .receiveFileInfo (phase1FileNames , phase1FileSizes , phase1ExistingFileNames ,
522
+ phase1ExistingFileSizes , translogOps .getAsInt (), sendFileInfoStep );
523
523
524
524
sendFileInfoStep .whenComplete (r ->
525
525
sendFiles (store , phase1Files .toArray (new StoreFileMetaData [0 ]), translogOps , sendFilesStep ), listener ::onFailure );
@@ -634,8 +634,8 @@ void prepareTargetForTranslog(int totalTranslogOps, ActionListener<TimeValue> li
634
634
// Send a request preparing the new shard's translog to receive operations. This ensures the shard engine is started and disables
635
635
// garbage collection (not the JVM's GC!) of tombstone deletes.
636
636
logger .trace ("recovery [phase1]: prepare remote engine for translog" );
637
- cancellableThreads .execute (() ->
638
- recoveryTarget .prepareForTranslogOperations (totalTranslogOps , wrappedListener ) );
637
+ cancellableThreads .checkForCancel ();
638
+ recoveryTarget .prepareForTranslogOperations (totalTranslogOps , wrappedListener );
639
639
}
640
640
641
641
/**
@@ -741,30 +741,29 @@ private void sendBatch(
741
741
final List <Translog .Operation > operations = nextBatch .get ();
742
742
// send the leftover operations or if no operations were sent, request the target to respond with its local checkpoint
743
743
if (operations .isEmpty () == false || firstBatch ) {
744
- cancellableThreads .execute (() -> {
745
- recoveryTarget .indexTranslogOperations (
746
- operations ,
747
- totalTranslogOps ,
748
- maxSeenAutoIdTimestamp ,
749
- maxSeqNoOfUpdatesOrDeletes ,
750
- retentionLeases ,
751
- mappingVersionOnPrimary ,
752
- ActionListener .wrap (
753
- newCheckpoint -> {
754
- sendBatch (
755
- nextBatch ,
756
- false ,
757
- SequenceNumbers .max (targetLocalCheckpoint , newCheckpoint ),
758
- totalTranslogOps ,
759
- maxSeenAutoIdTimestamp ,
760
- maxSeqNoOfUpdatesOrDeletes ,
761
- retentionLeases ,
762
- mappingVersionOnPrimary ,
763
- listener );
764
- },
765
- listener ::onFailure
766
- ));
767
- });
744
+ cancellableThreads .checkForCancel ();
745
+ recoveryTarget .indexTranslogOperations (
746
+ operations ,
747
+ totalTranslogOps ,
748
+ maxSeenAutoIdTimestamp ,
749
+ maxSeqNoOfUpdatesOrDeletes ,
750
+ retentionLeases ,
751
+ mappingVersionOnPrimary ,
752
+ ActionListener .wrap (
753
+ newCheckpoint -> {
754
+ sendBatch (
755
+ nextBatch ,
756
+ false ,
757
+ SequenceNumbers .max (targetLocalCheckpoint , newCheckpoint ),
758
+ totalTranslogOps ,
759
+ maxSeenAutoIdTimestamp ,
760
+ maxSeqNoOfUpdatesOrDeletes ,
761
+ retentionLeases ,
762
+ mappingVersionOnPrimary ,
763
+ listener );
764
+ },
765
+ listener ::onFailure
766
+ ));
768
767
} else {
769
768
listener .onResponse (targetLocalCheckpoint );
770
769
}
@@ -787,7 +786,8 @@ void finalizeRecovery(long targetLocalCheckpoint, long trimAboveSeqNo, ActionLis
787
786
shardId + " marking " + request .targetAllocationId () + " as in sync" , shard , cancellableThreads , logger );
788
787
final long globalCheckpoint = shard .getLastKnownGlobalCheckpoint (); // this global checkpoint is persisted in finalizeRecovery
789
788
final StepListener <Void > finalizeListener = new StepListener <>();
790
- cancellableThreads .executeIO (() -> recoveryTarget .finalizeRecovery (globalCheckpoint , trimAboveSeqNo , finalizeListener ));
789
+ cancellableThreads .checkForCancel ();
790
+ recoveryTarget .finalizeRecovery (globalCheckpoint , trimAboveSeqNo , finalizeListener );
791
791
finalizeListener .whenComplete (r -> {
792
792
runUnderPrimaryPermit (() -> shard .updateGlobalCheckpointForShard (request .targetAllocationId (), globalCheckpoint ),
793
793
shardId + " updating " + request .targetAllocationId () + "'s global checkpoint" , shard , cancellableThreads , logger );
@@ -894,8 +894,9 @@ protected FileChunk nextChunkRequest(StoreFileMetaData md) throws IOException {
894
894
895
895
@ Override
896
896
protected void sendChunkRequest (FileChunk request , ActionListener <Void > listener ) {
897
- cancellableThreads .execute (() -> recoveryTarget .writeFileChunk (
898
- request .md , request .position , request .content , request .lastChunk , translogOps .getAsInt (), listener ));
897
+ cancellableThreads .checkForCancel ();
898
+ recoveryTarget .writeFileChunk (
899
+ request .md , request .position , request .content , request .lastChunk , translogOps .getAsInt (), listener );
899
900
}
900
901
901
902
@ Override
@@ -922,13 +923,14 @@ private void cleanFiles(Store store, Store.MetadataSnapshot sourceMetadata, IntS
922
923
// Once the files have been renamed, any other files that are not
923
924
// related to this recovery (out of date segments, for example)
924
925
// are deleted
925
- cancellableThreads .execute (() -> recoveryTarget .cleanFiles (translogOps .getAsInt (), globalCheckpoint , sourceMetadata ,
926
+ cancellableThreads .checkForCancel ();
927
+ recoveryTarget .cleanFiles (translogOps .getAsInt (), globalCheckpoint , sourceMetadata ,
926
928
ActionListener .delegateResponse (listener , (l , e ) -> ActionListener .completeWith (l , () -> {
927
929
StoreFileMetaData [] mds = StreamSupport .stream (sourceMetadata .spliterator (), false ).toArray (StoreFileMetaData []::new );
928
930
ArrayUtil .timSort (mds , Comparator .comparingLong (StoreFileMetaData ::length )); // check small files first
929
931
handleErrorOnSendFiles (store , e , mds );
930
932
throw e ;
931
- })))) ;
933
+ })));
932
934
}
933
935
934
936
private void handleErrorOnSendFiles (Store store , Exception e , StoreFileMetaData [] mds ) throws Exception {
0 commit comments