@@ -158,14 +158,12 @@ public void recoverToTarget(ActionListener<RecoveryResponse> listener) {
158158 final Closeable retentionLock = shard .acquireRetentionLock ();
159159 resources .add (retentionLock );
160160 final long startingSeqNo ;
161- final long requiredSeqNoRangeStart ;
162161 final boolean isSequenceNumberBasedRecovery = request .startingSeqNo () != SequenceNumbers .UNASSIGNED_SEQ_NO &&
163162 isTargetSameHistory () && shard .hasCompleteHistoryOperations ("peer-recovery" , request .startingSeqNo ());
164163 final SendFileResult sendFileResult ;
165164 if (isSequenceNumberBasedRecovery ) {
166165 logger .trace ("performing sequence numbers based recovery. starting at [{}]" , request .startingSeqNo ());
167166 startingSeqNo = request .startingSeqNo ();
168- requiredSeqNoRangeStart = startingSeqNo ;
169167 sendFileResult = SendFileResult .EMPTY ;
170168 } else {
171169 final Engine .IndexCommitRef phase1Snapshot ;
@@ -174,13 +172,15 @@ public void recoverToTarget(ActionListener<RecoveryResponse> listener) {
174172 } catch (final Exception e ) {
175173 throw new RecoveryEngineException (shard .shardId (), 1 , "snapshot failed" , e );
176174 }
177- // We must have everything above the local checkpoint in the commit
178- requiredSeqNoRangeStart =
179- Long .parseLong (phase1Snapshot .getIndexCommit ().getUserData ().get (SequenceNumbers .LOCAL_CHECKPOINT_KEY )) + 1 ;
180175 // If soft-deletes enabled, we need to transfer only operations after the local_checkpoint of the commit to have
181176 // the same history on the target. However, with translog, we need to set this to 0 to create a translog roughly
182177 // according to the retention policy on the target. Note that it will still filter out legacy operations without seqNo.
183- startingSeqNo = shard .indexSettings ().isSoftDeleteEnabled () ? requiredSeqNoRangeStart : 0 ;
178+ if (shard .indexSettings ().isSoftDeleteEnabled ()) {
179+ startingSeqNo = Long .parseLong (
180+ phase1Snapshot .getIndexCommit ().getUserData ().get (SequenceNumbers .LOCAL_CHECKPOINT_KEY )) + 1 ;
181+ } else {
182+ startingSeqNo = 0 ;
183+ }
184184 try {
185185 final int estimateNumOps = shard .estimateNumberOfHistoryOperations ("peer-recovery" , startingSeqNo );
186186 sendFileResult = phase1 (phase1Snapshot .getIndexCommit (), () -> estimateNumOps );
@@ -195,8 +195,6 @@ public void recoverToTarget(ActionListener<RecoveryResponse> listener) {
195195 }
196196 }
197197 assert startingSeqNo >= 0 : "startingSeqNo must be non negative. got: " + startingSeqNo ;
198- assert requiredSeqNoRangeStart >= startingSeqNo : "requiredSeqNoRangeStart [" + requiredSeqNoRangeStart + "] is lower than ["
199- + startingSeqNo + "]" ;
200198
201199 final StepListener <TimeValue > prepareEngineStep = new StepListener <>();
202200 // For a sequence based recovery, the target can keep its local translog
@@ -214,13 +212,7 @@ public void recoverToTarget(ActionListener<RecoveryResponse> listener) {
214212 shardId + " initiating tracking of " + request .targetAllocationId (), shard , cancellableThreads , logger );
215213
216214 final long endingSeqNo = shard .seqNoStats ().getMaxSeqNo ();
217- /*
218- * We need to wait for all operations up to the current max to complete, otherwise we can not guarantee that all
219- * operations in the required range will be available for replaying from the translog of the source.
220- */
221- cancellableThreads .execute (() -> shard .waitForOpsToComplete (endingSeqNo ));
222215 if (logger .isTraceEnabled ()) {
223- logger .trace ("all operations up to [{}] completed, which will be used as an ending sequence number" , endingSeqNo );
224216 logger .trace ("snapshot translog for recovery; current size is [{}]" ,
225217 shard .estimateNumberOfHistoryOperations ("peer-recovery" , startingSeqNo ));
226218 }
@@ -233,15 +225,8 @@ public void recoverToTarget(ActionListener<RecoveryResponse> listener) {
233225 final long maxSeenAutoIdTimestamp = shard .getMaxSeenAutoIdTimestamp ();
234226 final long maxSeqNoOfUpdatesOrDeletes = shard .getMaxSeqNoOfUpdatesOrDeletes ();
235227 final RetentionLeases retentionLeases = shard .getRetentionLeases ();
236- phase2 (
237- startingSeqNo ,
238- requiredSeqNoRangeStart ,
239- endingSeqNo ,
240- phase2Snapshot ,
241- maxSeenAutoIdTimestamp ,
242- maxSeqNoOfUpdatesOrDeletes ,
243- retentionLeases ,
244- sendSnapshotStep );
228+ phase2 (startingSeqNo , endingSeqNo , phase2Snapshot , maxSeenAutoIdTimestamp , maxSeqNoOfUpdatesOrDeletes ,
229+ retentionLeases , sendSnapshotStep );
245230 sendSnapshotStep .whenComplete (
246231 r -> IOUtils .close (phase2Snapshot ),
247232 e -> {
@@ -519,7 +504,6 @@ void prepareTargetForTranslog(boolean fileBasedRecovery, int totalTranslogOps, A
519504 *
520505 * @param startingSeqNo the sequence number to start recovery from, or {@link SequenceNumbers#UNASSIGNED_SEQ_NO} if all
521506 * ops should be sent
522- * @param requiredSeqNoRangeStart the lower sequence number of the required range (ending with endingSeqNo)
523507 * @param endingSeqNo the highest sequence number that should be sent
524508 * @param snapshot a snapshot of the translog
525509 * @param maxSeenAutoIdTimestamp the max auto_id_timestamp of append-only requests on the primary
@@ -528,26 +512,19 @@ void prepareTargetForTranslog(boolean fileBasedRecovery, int totalTranslogOps, A
528512 */
529513 void phase2 (
530514 final long startingSeqNo ,
531- final long requiredSeqNoRangeStart ,
532515 final long endingSeqNo ,
533516 final Translog .Snapshot snapshot ,
534517 final long maxSeenAutoIdTimestamp ,
535518 final long maxSeqNoOfUpdatesOrDeletes ,
536519 final RetentionLeases retentionLeases ,
537520 final ActionListener <SendSnapshotResult > listener ) throws IOException {
538- assert requiredSeqNoRangeStart <= endingSeqNo + 1 :
539- "requiredSeqNoRangeStart " + requiredSeqNoRangeStart + " is larger than endingSeqNo " + endingSeqNo ;
540- assert startingSeqNo <= requiredSeqNoRangeStart :
541- "startingSeqNo " + startingSeqNo + " is larger than requiredSeqNoRangeStart " + requiredSeqNoRangeStart ;
542521 if (shard .state () == IndexShardState .CLOSED ) {
543522 throw new IndexShardClosedException (request .shardId ());
544523 }
545- logger .trace ("recovery [phase2]: sending transaction log operations (seq# from [" + startingSeqNo + "], " +
546- "required [" + requiredSeqNoRangeStart + ":" + endingSeqNo + "]" );
524+ logger .trace ("recovery [phase2]: sending transaction log operations (from [" + startingSeqNo + "] to [" + endingSeqNo + "]" );
547525
548526 final AtomicInteger skippedOps = new AtomicInteger ();
549527 final AtomicInteger totalSentOps = new AtomicInteger ();
550- final LocalCheckpointTracker requiredOpsTracker = new LocalCheckpointTracker (endingSeqNo , requiredSeqNoRangeStart - 1 );
551528 final AtomicInteger lastBatchCount = new AtomicInteger (); // used to estimate the count of the subsequent batch.
552529 final CheckedSupplier <List <Translog .Operation >, IOException > readNextBatch = () -> {
553530 // We need to synchronized Snapshot#next() because it's called by different threads through sendBatch.
@@ -569,7 +546,6 @@ void phase2(
569546 ops .add (operation );
570547 batchSizeInBytes += operation .estimateSize ();
571548 totalSentOps .incrementAndGet ();
572- requiredOpsTracker .markSeqNoAsCompleted (seqNo );
573549
574550 // check if this request is past bytes threshold, and if so, send it off
575551 if (batchSizeInBytes >= chunkSizeInBytes ) {
@@ -587,11 +563,6 @@ void phase2(
587563 assert snapshot .totalOperations () == snapshot .skippedOperations () + skippedOps .get () + totalSentOps .get ()
588564 : String .format (Locale .ROOT , "expected total [%d], overridden [%d], skipped [%d], total sent [%d]" ,
589565 snapshot .totalOperations (), snapshot .skippedOperations (), skippedOps .get (), totalSentOps .get ());
590- if (requiredOpsTracker .getCheckpoint () < endingSeqNo ) {
591- throw new IllegalStateException ("translog replay failed to cover required sequence numbers" +
592- " (required range [" + requiredSeqNoRangeStart + ":" + endingSeqNo + "). first missing op is ["
593- + (requiredOpsTracker .getCheckpoint () + 1 ) + "]" );
594- }
595566 stopWatch .stop ();
596567 final TimeValue tookTime = stopWatch .totalTime ();
597568 logger .trace ("recovery [phase2]: took [{}]" , tookTime );
0 commit comments