@@ -165,12 +165,12 @@ public void recoverToTarget(ActionListener<RecoveryResponse> listener) {
165165 throw new DelayRecoveryException ("source node does not have the shard listed in its state as allocated on the node" );
166166 }
167167 assert targetShardRouting .initializing () : "expected recovery target to be initializing but was " + targetShardRouting ;
168- retentionLeaseRef .set (softDeletesEnabled ? shard . getRetentionLeases (). get (
169- ReplicationTracker .getPeerRecoveryRetentionLeaseId (targetShardRouting )) : null );
168+ retentionLeaseRef .set (
169+ shard . getRetentionLeases (). get ( ReplicationTracker .getPeerRecoveryRetentionLeaseId (targetShardRouting )));
170170 }, shardId + " validating recovery target [" + request .targetAllocationId () + "] registered " ,
171171 shard , cancellableThreads , logger );
172172 final Engine .HistorySource historySource ;
173- if (shard .useRetentionLeasesInPeerRecovery () || retentionLeaseRef .get () != null ) {
173+ if (softDeletesEnabled && ( shard .useRetentionLeasesInPeerRecovery () || retentionLeaseRef .get () != null ) ) {
174174 historySource = Engine .HistorySource .INDEX ;
175175 } else {
176176 historySource = Engine .HistorySource .TRANSLOG ;
@@ -190,7 +190,7 @@ && isTargetSameHistory()
190190 // Also it's pretty cheap when soft deletes are enabled, and it'd be a disaster if we tried a sequence-number-based recovery
191191 // without having a complete history.
192192
193- if (isSequenceNumberBasedRecovery && retentionLeaseRef .get () != null ) {
193+ if (isSequenceNumberBasedRecovery && softDeletesEnabled && retentionLeaseRef .get () != null ) {
194194 // all the history we need is retained by an existing retention lease, so we do not need a separate retention lock
195195 retentionLock .close ();
196196 logger .trace ("history is retained by {}" , retentionLeaseRef .get ());
@@ -209,7 +209,7 @@ && isTargetSameHistory()
209209 if (isSequenceNumberBasedRecovery ) {
210210 logger .trace ("performing sequence numbers based recovery. starting at [{}]" , request .startingSeqNo ());
211211 startingSeqNo = request .startingSeqNo ();
212- if (softDeletesEnabled && retentionLeaseRef .get () == null ) {
212+ if (retentionLeaseRef .get () == null ) {
213213 createRetentionLease (startingSeqNo , ActionListener .map (sendFileStep , ignored -> SendFileResult .EMPTY ));
214214 } else {
215215 sendFileStep .onResponse (SendFileResult .EMPTY );
@@ -251,36 +251,24 @@ && isTargetSameHistory()
251251 });
252252
253253 final StepListener <ReplicationResponse > deleteRetentionLeaseStep = new StepListener <>();
254- if (softDeletesEnabled ) {
255- runUnderPrimaryPermit (() -> {
256- try {
257- // If the target previously had a copy of this shard then a file-based recovery might move its global
258- // checkpoint backwards. We must therefore remove any existing retention lease so that we can create a
259- // new one later on in the recovery.
260- shard .removePeerRecoveryRetentionLease (request .targetNode ().getId (),
261- new ThreadedActionListener <>(logger , shard .getThreadPool (), ThreadPool .Names .GENERIC ,
262- deleteRetentionLeaseStep , false ));
263- } catch (RetentionLeaseNotFoundException e ) {
264- logger .debug ("no peer-recovery retention lease for " + request .targetAllocationId ());
265- deleteRetentionLeaseStep .onResponse (null );
266- }
267- }, shardId + " removing retention leaes for [" + request .targetAllocationId () + "]" ,
268- shard , cancellableThreads , logger );
269- } else {
270- deleteRetentionLeaseStep .onResponse (null );
271- }
254+ runUnderPrimaryPermit (() -> {
255+ try {
256+ // If the target previously had a copy of this shard then a file-based recovery might move its global
257+ // checkpoint backwards. We must therefore remove any existing retention lease so that we can create a
258+ // new one later on in the recovery.
259+ shard .removePeerRecoveryRetentionLease (request .targetNode ().getId (),
260+ new ThreadedActionListener <>(logger , shard .getThreadPool (), ThreadPool .Names .GENERIC ,
261+ deleteRetentionLeaseStep , false ));
262+ } catch (RetentionLeaseNotFoundException e ) {
263+ logger .debug ("no peer-recovery retention lease for " + request .targetAllocationId ());
264+ deleteRetentionLeaseStep .onResponse (null );
265+ }
266+ }, shardId + " removing retention lease for [" + request .targetAllocationId () + "]" ,
267+ shard , cancellableThreads , logger );
272268
273269 deleteRetentionLeaseStep .whenComplete (ignored -> {
274270 assert Transports .assertNotTransportThread (RecoverySourceHandler .this + "[phase1]" );
275-
276- final Consumer <ActionListener <RetentionLease >> createRetentionLeaseAsync ;
277- if (softDeletesEnabled ) {
278- createRetentionLeaseAsync = l -> createRetentionLease (startingSeqNo , l );
279- } else {
280- createRetentionLeaseAsync = l -> l .onResponse (null );
281- }
282-
283- phase1 (safeCommitRef .getIndexCommit (), createRetentionLeaseAsync , () -> estimateNumOps , sendFileStep );
271+ phase1 (safeCommitRef .getIndexCommit (), startingSeqNo , () -> estimateNumOps , sendFileStep );
284272 }, onFailure );
285273
286274 } catch (final Exception e ) {
@@ -451,8 +439,7 @@ static final class SendFileResult {
451439 * segments that are missing. Only segments that have the same size and
452440 * checksum can be reused
453441 */
454- void phase1 (IndexCommit snapshot , Consumer <ActionListener <RetentionLease >> createRetentionLease ,
455- IntSupplier translogOps , ActionListener <SendFileResult > listener ) {
442+ void phase1 (IndexCommit snapshot , long startingSeqNo , IntSupplier translogOps , ActionListener <SendFileResult > listener ) {
456443 cancellableThreads .checkForCancel ();
457444 final Store store = shard .store ();
458445 try {
@@ -526,7 +513,7 @@ void phase1(IndexCommit snapshot, Consumer<ActionListener<RetentionLease>> creat
526513 sendFileInfoStep .whenComplete (r ->
527514 sendFiles (store , phase1Files .toArray (new StoreFileMetaData [0 ]), translogOps , sendFilesStep ), listener ::onFailure );
528515
529- sendFilesStep .whenComplete (r -> createRetentionLease . accept ( createRetentionLeaseStep ), listener ::onFailure );
516+ sendFilesStep .whenComplete (r -> createRetentionLease ( startingSeqNo , createRetentionLeaseStep ), listener ::onFailure );
530517
531518 createRetentionLeaseStep .whenComplete (retentionLease ->
532519 {
@@ -554,7 +541,7 @@ void phase1(IndexCommit snapshot, Consumer<ActionListener<RetentionLease>> creat
554541
555542 // but we must still create a retention lease
556543 final StepListener <RetentionLease > createRetentionLeaseStep = new StepListener <>();
557- createRetentionLease . accept ( createRetentionLeaseStep );
544+ createRetentionLease ( startingSeqNo , createRetentionLeaseStep );
558545 createRetentionLeaseStep .whenComplete (retentionLease -> {
559546 final TimeValue took = stopWatch .totalTime ();
560547 logger .trace ("recovery [phase1]: took [{}]" , took );
@@ -590,7 +577,8 @@ private void createRetentionLease(final long startingSeqNo, ActionListener<Reten
590577 // it's possible that the primary has no retention lease yet if we are doing a rolling upgrade from a version before
591578 // 7.4, and in that case we just create a lease using the local checkpoint of the safe commit which we're using for
592579 // recovery as a conservative estimate for the global checkpoint.
593- assert shard .indexSettings ().getIndexVersionCreated ().before (Version .V_7_4_0 );
580+ assert shard .indexSettings ().getIndexVersionCreated ().before (Version .V_7_4_0 )
581+ || shard .indexSettings ().isSoftDeleteEnabled () == false ;
594582 final StepListener <ReplicationResponse > addRetentionLeaseStep = new StepListener <>();
595583 final long estimatedGlobalCheckpoint = startingSeqNo - 1 ;
596584 final RetentionLease newLease = shard .addPeerRecoveryRetentionLease (request .targetNode ().getId (),
0 commit comments