@@ -264,15 +264,14 @@ && isTargetSameHistory()
264
264
deleteRetentionLeaseStep .whenComplete (ignored -> {
265
265
assert Transports .assertNotTransportThread (RecoverySourceHandler .this + "[phase1]" );
266
266
267
- final Consumer <ActionListener <Long >> getGlobalCheckpoint ;
267
+ final Consumer <ActionListener <Long >> getInitialGlobalCheckpoint ;
268
268
if (useRetentionLeases ) {
269
- getGlobalCheckpoint = l -> createRetentionLease (startingSeqNo , l );
269
+ getInitialGlobalCheckpoint = l -> createRetentionLease (startingSeqNo , l );
270
270
} else {
271
- final long globalCheckpoint = shard .getLastKnownGlobalCheckpoint ();
272
- getGlobalCheckpoint = l -> l .onResponse (globalCheckpoint );
271
+ getInitialGlobalCheckpoint = l -> l .onResponse (SequenceNumbers .UNASSIGNED_SEQ_NO );
273
272
}
274
273
275
- phase1 (safeCommitRef .getIndexCommit (), getGlobalCheckpoint , () -> estimateNumOps , sendFileStep );
274
+ phase1 (safeCommitRef .getIndexCommit (), getInitialGlobalCheckpoint , () -> estimateNumOps , sendFileStep );
276
275
}, onFailure );
277
276
278
277
} catch (final Exception e ) {
@@ -428,7 +427,7 @@ static final class SendFileResult {
428
427
* segments that are missing. Only segments that have the same size and
429
428
* checksum can be reused
430
429
*/
431
- void phase1 (IndexCommit snapshot , Consumer <ActionListener <Long >> getGlobalCheckpoint ,
430
+ void phase1 (IndexCommit snapshot , Consumer <ActionListener <Long >> getInitialGlobalCheckpoint ,
432
431
IntSupplier translogOps , ActionListener <SendFileResult > listener ) {
433
432
cancellableThreads .checkForCancel ();
434
433
// Total size of segment files that are recovered
@@ -492,7 +491,7 @@ void phase1(IndexCommit snapshot, Consumer<ActionListener<Long>> getGlobalCheckp
492
491
phase1ExistingFileNames .size (), new ByteSizeValue (existingTotalSizeInBytes ));
493
492
final StepListener <Void > sendFileInfoStep = new StepListener <>();
494
493
final StepListener <Void > sendFilesStep = new StepListener <>();
495
- final StepListener <Long > getGlobalCheckpointStep = new StepListener <>();
494
+ final StepListener <Long > getInitialGlobalCheckpointStep = new StepListener <>();
496
495
final StepListener <Void > cleanFilesStep = new StepListener <>();
497
496
cancellableThreads .execute (() ->
498
497
recoveryTarget .receiveFileInfo (phase1FileNames , phase1FileSizes , phase1ExistingFileNames ,
@@ -501,10 +500,13 @@ void phase1(IndexCommit snapshot, Consumer<ActionListener<Long>> getGlobalCheckp
501
500
sendFileInfoStep .whenComplete (r ->
502
501
sendFiles (store , phase1Files .toArray (new StoreFileMetaData [0 ]), translogOps , sendFilesStep ), listener ::onFailure );
503
502
504
- sendFilesStep .whenComplete (r -> getGlobalCheckpoint .accept (getGlobalCheckpointStep ), listener ::onFailure );
503
+ sendFilesStep .whenComplete (r -> getInitialGlobalCheckpoint .accept (getInitialGlobalCheckpointStep ), listener ::onFailure );
505
504
506
- getGlobalCheckpointStep .whenComplete (globalCheckpoint ->
507
- cleanFiles (store , recoverySourceMetadata , translogOps , globalCheckpoint , cleanFilesStep ), listener ::onFailure );
505
+ getInitialGlobalCheckpointStep .whenComplete (initialGlobalCheckpoint ->
506
+ cleanFiles (store , recoverySourceMetadata , translogOps ,
507
+ Math .max (initialGlobalCheckpoint , Long .parseLong (snapshot .getUserData ().get (SequenceNumbers .MAX_SEQ_NO ))),
508
+ cleanFilesStep ),
509
+ listener ::onFailure );
508
510
509
511
final long totalSize = totalSizeInBytes ;
510
512
final long existingTotalSize = existingTotalSizeInBytes ;
@@ -527,7 +529,7 @@ void phase1(IndexCommit snapshot, Consumer<ActionListener<Long>> getGlobalCheckp
527
529
}
528
530
}
529
531
530
- private void createRetentionLease (final long startingSeqNo , ActionListener <Long > listener ) {
532
+ private void createRetentionLease (final long startingSeqNo , ActionListener <Long > initialGlobalCheckpointListener ) {
531
533
runUnderPrimaryPermit (() -> {
532
534
// Clone the peer recovery retention lease belonging to the source shard. We are retaining history between the the local
533
535
// checkpoint of the safe commit we're creating and this lease's retained seqno with the retention lock, and by cloning an
@@ -545,8 +547,8 @@ private void createRetentionLease(final long startingSeqNo, ActionListener<Long>
545
547
ThreadPool .Names .GENERIC , cloneRetentionLeaseStep , false ));
546
548
logger .trace ("cloned primary's retention lease as [{}]" , clonedLease );
547
549
cloneRetentionLeaseStep .whenComplete (
548
- rr -> listener .onResponse (clonedLease .retainingSequenceNumber () - 1 ),
549
- listener ::onFailure );
550
+ rr -> initialGlobalCheckpointListener .onResponse (clonedLease .retainingSequenceNumber () - 1 ),
551
+ initialGlobalCheckpointListener ::onFailure );
550
552
} catch (RetentionLeaseNotFoundException e ) {
551
553
// it's possible that the primary has no retention lease yet if we are doing a rolling upgrade from a version before
552
554
// 7.4, and in that case we just create a lease using the local checkpoint of the safe commit which we're using for
@@ -558,8 +560,8 @@ private void createRetentionLease(final long startingSeqNo, ActionListener<Long>
558
560
estimatedGlobalCheckpoint , new ThreadedActionListener <>(logger , shard .getThreadPool (),
559
561
ThreadPool .Names .GENERIC , addRetentionLeaseStep , false ));
560
562
addRetentionLeaseStep .whenComplete (
561
- rr -> listener .onResponse (estimatedGlobalCheckpoint ),
562
- listener ::onFailure );
563
+ rr -> initialGlobalCheckpointListener .onResponse (estimatedGlobalCheckpoint ),
564
+ initialGlobalCheckpointListener ::onFailure );
563
565
logger .trace ("created retention lease with estimated checkpoint of [{}]" , estimatedGlobalCheckpoint );
564
566
}
565
567
}, shardId + " establishing retention lease for [" + request .targetAllocationId () + "]" ,
0 commit comments