File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -559,6 +559,27 @@ func (r *replicaLogStorage) stageApplySnapshot(truncState kvserverpb.RaftTruncat
559
559
r .shMu .sizeTrusted = true
560
560
}
561
561
562
+ func (r * replicaLogStorage ) finalizeApplySnapshotRaftMuLocked (ctx context.Context ) {
563
+ r .raftMu .AssertHeld ()
564
+ // This mirrors finalizeTruncationRaftMuLocked, but a snapshot may regress the last
565
+ // index (to discard a divergent log). For example:
566
+ //
567
+ // Raft log (before snapshot):
568
+ // - entry 100-150: term 1 [committed]
569
+ // - entry 151-200: term 2
570
+ // Committed raft log (on leader):
571
+ // - entry 100-150: term 1
572
+ // - entry 151: term 3
573
+ //
574
+ // The replica may receive a snapshot at index 151. If we don't clear the
575
+ // sideloaded storage all the way up to the *old* last index, we may leak
576
+ // sideloaded entries. Rather than remember the old last index, we instead
577
+ // clear the sideloaded storage entirely. This is equivalent.
578
+ if err := r .ls .Sideload .Clear (ctx ); err != nil {
579
+ log .Errorf (ctx , "while clearing sideloaded storage after snapshot: %+v" , err )
580
+ }
581
+ }
582
+
562
583
func (r * replicaLogStorage ) stagePendingTruncationRaftMuLocked (pt pendingTruncation ) {
563
584
r .raftMu .AssertHeld ()
564
585
// NB: The expected first index can be zero if this proposal is from before
Original file line number Diff line number Diff line change @@ -651,7 +651,7 @@ func (r *Replica) applySnapshotRaftMuLocked(
651
651
writeBytes = uint64 (inSnap .SSTSize )
652
652
}
653
653
// The snapshot is visible, so finalize the truncation.
654
- r . finalizeTruncationRaftMuLocked (ctx )
654
+ ls . finalizeApplySnapshotRaftMuLocked (ctx )
655
655
656
656
// The "ignored" here is to ignore the writes to create the AC linear models
657
657
// for LSM writes. Since these writes typically correspond to actual writes
You can’t perform that action at this time.
0 commit comments