@@ -430,14 +430,6 @@ static final class SendFileResult {
430430 void phase1 (IndexCommit snapshot , Consumer <ActionListener <RetentionLease >> createRetentionLease ,
431431 IntSupplier translogOps , ActionListener <SendFileResult > listener ) {
432432 cancellableThreads .checkForCancel ();
433- // Total size of segment files that are recovered
434- long totalSizeInBytes = 0 ;
435- // Total size of segment files that were able to be re-used
436- long existingTotalSizeInBytes = 0 ;
437- final List <String > phase1FileNames = new ArrayList <>();
438- final List <Long > phase1FileSizes = new ArrayList <>();
439- final List <String > phase1ExistingFileNames = new ArrayList <>();
440- final List <Long > phase1ExistingFileSizes = new ArrayList <>();
441433 final Store store = shard .store ();
442434 try {
443435 StopWatch stopWatch = new StopWatch ().start ();
@@ -457,6 +449,16 @@ void phase1(IndexCommit snapshot, Consumer<ActionListener<RetentionLease>> creat
457449 }
458450 }
459451 if (canSkipPhase1 (recoverySourceMetadata , request .metadataSnapshot ()) == false ) {
452+ final List <String > phase1FileNames = new ArrayList <>();
453+ final List <Long > phase1FileSizes = new ArrayList <>();
454+ final List <String > phase1ExistingFileNames = new ArrayList <>();
455+ final List <Long > phase1ExistingFileSizes = new ArrayList <>();
456+
457+ // Total size of segment files that are recovered
458+ long totalSizeInBytes = 0 ;
459+ // Total size of segment files that were able to be re-used
460+ long existingTotalSizeInBytes = 0 ;
461+
460462 // Generate a "diff" of all the identical, different, and missing
461463 // segment files on the target node, using the existing files on
462464 // the source node
@@ -524,15 +526,21 @@ void phase1(IndexCommit snapshot, Consumer<ActionListener<RetentionLease>> creat
524526 phase1ExistingFileSizes , existingTotalSize , took ));
525527 }, listener ::onFailure );
526528 } else {
527- logger .trace ("skipping [phase1]- identical sync id [{}] found on both source and target" ,
528- recoverySourceMetadata .getSyncId ());
529- final TimeValue took = stopWatch .totalTime ();
530- logger .trace ("recovery [phase1]: took [{}]" , took );
531- listener .onResponse (new SendFileResult (phase1FileNames , phase1FileSizes , totalSizeInBytes , phase1ExistingFileNames ,
532- phase1ExistingFileSizes , existingTotalSizeInBytes , took ));
529+ logger .trace ("skipping [phase1] since source and target have identical sync id [{}]" , recoverySourceMetadata .getSyncId ());
530+
531+ // but we must still create a retention lease
532+ final StepListener <RetentionLease > createRetentionLeaseStep = new StepListener <>();
533+ createRetentionLease .accept (createRetentionLeaseStep );
534+ createRetentionLeaseStep .whenComplete (retentionLease -> {
535+ final TimeValue took = stopWatch .totalTime ();
536+ logger .trace ("recovery [phase1]: took [{}]" , took );
537+ listener .onResponse (new SendFileResult (Collections .emptyList (), Collections .emptyList (), 0L , Collections .emptyList (),
538+ Collections .emptyList (), 0L , took ));
539+ }, listener ::onFailure );
540+
533541 }
534542 } catch (Exception e ) {
535- throw new RecoverFilesRecoveryException (request .shardId (), phase1FileNames . size () , new ByteSizeValue (totalSizeInBytes ), e );
543+ throw new RecoverFilesRecoveryException (request .shardId (), 0 , new ByteSizeValue (0L ), e );
536544 }
537545 }
538546
0 commit comments