@@ -415,16 +415,16 @@ void phase1(IndexCommit snapshot, long globalCheckpoint, IntSupplier translogOps
415
415
phase1FileNames .size (), new ByteSizeValue (totalSizeInBytes ),
416
416
phase1ExistingFileNames .size (), new ByteSizeValue (existingTotalSizeInBytes ));
417
417
final StepListener <Void > sendFileInfoStep = new StepListener <>();
418
- final StepListener <Void > sendFileChunkStep = new StepListener <>();
418
+ final StepListener <Void > sendFilesStep = new StepListener <>();
419
419
final StepListener <Void > cleanFilesStep = new StepListener <>();
420
420
cancellableThreads .execute (() ->
421
421
recoveryTarget .receiveFileInfo (phase1FileNames , phase1FileSizes , phase1ExistingFileNames ,
422
422
phase1ExistingFileSizes , translogOps .getAsInt (), sendFileInfoStep ));
423
423
424
424
sendFileInfoStep .whenComplete (r ->
425
- sendFiles (store , phase1Files .toArray (new StoreFileMetaData [0 ]), translogOps , sendFileChunkStep ), listener ::onFailure );
425
+ sendFiles (store , phase1Files .toArray (new StoreFileMetaData [0 ]), translogOps , sendFilesStep ), listener ::onFailure );
426
426
427
- sendFileChunkStep .whenComplete (r ->
427
+ sendFilesStep .whenComplete (r ->
428
428
cleanFiles (store , recoverySourceMetadata , translogOps , globalCheckpoint , cleanFilesStep ), listener ::onFailure );
429
429
430
430
final long totalSize = totalSizeInBytes ;
@@ -726,10 +726,20 @@ protected void doRun() throws Exception {
726
726
assert Transports .assertNotTransportThread (RecoverySourceHandler .this + "[send file chunk]" );
727
727
while (true ) {
728
728
assert semaphore .availablePermits () == 0 ;
729
+ cancellableThreads .checkForCancel ();
729
730
if (error .get () != null ) {
730
731
handleErrorOnSendFiles (store , error .get ().v2 (), new StoreFileMetaData []{error .get ().v1 ()});
731
732
throw error .get ().v2 ();
732
733
}
734
+ if (canSendMore () == false ) {
735
+ semaphore .release ();
736
+ // Here we have to retry before abort to avoid a race situation where the other threads have flipped `canSendMore`
737
+ // condition but they are not going to resume the sending process because this thread still holds the semaphore.
738
+ final boolean changed = canSendMore () || error .get () != null ;
739
+ if (changed == false || semaphore .tryAcquire () == false ) {
740
+ break ;
741
+ }
742
+ }
733
743
final FileChunk chunk = readNextChunk ();
734
744
if (chunk == null ) {
735
745
semaphore .release (); // allow other threads respond if we are not done yet.
@@ -757,15 +767,6 @@ protected void doRun() throws Exception {
757
767
})
758
768
)
759
769
);
760
- if (canSendMore () == false ) {
761
- semaphore .release ();
762
- // Here we have to retry before abort to avoid a race situation where the other threads have flipped `canSendMore`
763
- // condition but they are not going to resume the sending process because this thread still holds the semaphore.
764
- final boolean changed = canSendMore () || error .get () != null ;
765
- if (changed == false || semaphore .tryAcquire () == false ) {
766
- break ;
767
- }
768
- }
769
770
}
770
771
}
771
772
0 commit comments