Skip to content

Commit 439431f

Browse files
committed
kvserver: move an assertion
1 parent c613f94 commit 439431f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pkg/kv/kvserver/snapshot_apply_prepare.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,17 @@ func clearSubsumedReplicaDiskData(
225225
// before it completes. It is reasonable for a snapshot for r1 from S3 to
226226
// subsume both r1 and r2 in S1.
227227
for i := range keySpans {
228+
// The snapshot must never subsume a replica that extends the range of the
229+
// replica to the left. This is because splits and merges (the only
230+
// operation that change the key bounds) always leave the start key intact.
231+
// Extending to the left implies that either we merged "to the left" (we
232+
// don't), or that we're applying a snapshot for another range (we don't do
233+
// that either). Something is severely wrong for this to happen.
234+
if totalKeySpans[i].Key.Compare(keySpans[i].Key) < 0 {
235+
log.Fatalf(ctx, "subsuming replica to our left; key span: %v; total key span %v",
236+
keySpans[i], totalKeySpans[i])
237+
}
238+
228239
if totalKeySpans[i].EndKey.Compare(keySpans[i].EndKey) > 0 {
229240
subsumedReplSSTFile := &storage.MemObject{}
230241
subsumedReplSST := storage.MakeIngestionSSTWriter(
@@ -255,16 +266,6 @@ func clearSubsumedReplicaDiskData(
255266
}
256267
}
257268
}
258-
// The snapshot must never subsume a replica that extends the range of the
259-
// replica to the left. This is because splits and merges (the only
260-
// operation that change the key bounds) always leave the start key intact.
261-
// Extending to the left implies that either we merged "to the left" (we
262-
// don't), or that we're applying a snapshot for another range (we don't do
263-
// that either). Something is severely wrong for this to happen.
264-
if totalKeySpans[i].Key.Compare(keySpans[i].Key) < 0 {
265-
log.Fatalf(ctx, "subsuming replica to our left; key span: %v; total key span %v",
266-
keySpans[i], totalKeySpans[i])
267-
}
268269
}
269270
return clearedSpans, nil
270271
}

0 commit comments

Comments
 (0)