Skip to content

Commit aae9466

Browse files
craig[bot]tbg
andcommitted
Merge #144613
144613: kvserver: hard-code RangeKeysInOrder=true r=tbg a=tbg In the 24.3 release, this bool was introduced and unconditionally set to true in #129088: $ git log v24.3.0 -1 --oneline --grep 'kvserver: reenable splitting of snapshot sstables' 129088: kvserver: reenable splitting of snapshot sstables r=aadityasondhi a=itsbilal This change updates the snapshot strategy's sender side to iterate over points and ranges together, instead of only iterating on points first, then only ranges. This allows us to more efficiently split snapshot sstables on the receiver side. To avoid the need to add a version gate on the receiver side, we propagate a bool, RangeKeysInOrder, to the receiver which is a signal to it to enable sstable splits. Since we are now in the v25.3 release cycle, we can safely assume that this bool is always set on all incoming snapshots headers. This is because the v25.2 release is not skippable and both possible upgrade paths into it go through v24.3, which already sets this bool. The same will be true for the v25.3 release, which can only be reached through v25.2. ![image](https://github.com/user-attachments/assets/04aa9dd3-7e95-495f-ae83-cfdef4c3ed6f) *However*, we cannot remove the header field yet. This can only be done in a follow-up migration in a few releases, since the absence of the field would communicate to receivers who are not running with this first step of the migration (25.2 and before) that the range keys are out of order, but they would not be. Perhaps the code would support this, but it's not a risk we're interested in taking. We can only remove the proto field in the v26.1 release: v26.1 is the first release that has 25.4 in its required upgrade path, and since 25.3 is skippable, 25.4 still has to interop with 25.2 which precedes the hard-coding of the bool. A comment to this effect was added on the proto. Epic: CRDB-46488 Release note: none Co-authored-by: Tobias Grieger <[email protected]>
2 parents c157bb6 + 2094de2 commit aae9466

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

pkg/kv/kvserver/kv_snapshot_strategy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (kvSS *kvBatchSnapshotStrategy) Receive(
118118
// The last key range is the user key span.
119119
localRanges := keyRanges[:len(keyRanges)-1]
120120
mvccRange := keyRanges[len(keyRanges)-1]
121-
msstw, err := newMultiSSTWriter(ctx, kvSS.st, kvSS.scratch, localRanges, mvccRange, kvSS.sstChunkSize, header.RangeKeysInOrder)
121+
msstw, err := newMultiSSTWriter(ctx, kvSS.st, kvSS.scratch, localRanges, mvccRange, kvSS.sstChunkSize)
122122
if err != nil {
123123
return noSnap, err
124124
}

pkg/kv/kvserver/kvserverpb/raft.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ message SnapshotRequest {
244244
// keys in key order, as opposed to iterating over point keys first
245245
// and range keys second. The receiver can take advantage of this
246246
// to split points/range keys into multiple sstables for ingestion.
247+
//
248+
// MIGRATION: v24.3 and newer will always set this field to true, and v25.3
249+
// and newer stop consulting the field altogether (assume it is true). In
250+
// v26.1, we can then drop this field altogether, since v26.1 is the first
251+
// version that does not have to interop with v25.2 (the last version to
252+
// attach meaning to this field being unset/absent) or older.
247253
bool range_keys_in_order = 14;
248254

249255
reserved 1, 4, 6, 7, 8, 9;

pkg/kv/kvserver/multi_sst_writer.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ func newMultiSSTWriter(
7070
localKeySpans []roachpb.Span,
7171
mvccKeySpan roachpb.Span,
7272
sstChunkSize int64,
73-
rangeKeysInOrder bool,
7473
) (*multiSSTWriter, error) {
7574
msstw := &multiSSTWriter{
7675
st: st,
@@ -82,15 +81,7 @@ func newMultiSSTWriter(
8281
End: storage.EngineKey{Key: mvccKeySpan.EndKey},
8382
}},
8483
sstChunkSize: sstChunkSize,
85-
}
86-
if rangeKeysInOrder {
87-
// We disable snapshot sstable splitting unless the sender has
88-
// specified in its snapshot header that it is sending range keys in
89-
// key order alongside point keys, as opposed to sending them at the end
90-
// of the snapshot. This is necessary to efficiently produce fragmented
91-
// snapshot sstables, as otherwise range keys will arrive out-of-order
92-
// wrt. point keys.
93-
msstw.maxSSTSize = MaxSnapshotSSTableSize.Get(&st.SV)
84+
maxSSTSize: MaxSnapshotSSTableSize.Get(&st.SV),
9485
}
9586
msstw.rangeKeyFrag = rangekey.Fragmenter{
9687
Cmp: storage.EngineComparer.Compare,

pkg/kv/kvserver/replica_sst_snapshot_storage_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,7 @@ func testMultiSSTWriterInitSSTInner(t *testing.T, interesting bool) {
298298
// Disabling columnar blocks causes stats changes.
299299
storage.ColumnarBlocksEnabled.Override(context.Background(), &st.SV, true)
300300

301-
msstw, err := newMultiSSTWriter(
302-
ctx, st, scratch, localSpans, mvccSpan, 0,
303-
false, /* rangeKeysInOrder */
304-
)
301+
msstw, err := newMultiSSTWriter(ctx, st, scratch, localSpans, mvccSpan, 0)
305302
require.NoError(t, err)
306303

307304
var buf redact.StringBuilder
@@ -430,7 +427,7 @@ func TestMultiSSTWriterSize(t *testing.T) {
430427
mvccSpan := keySpans[len(keySpans)-1]
431428

432429
// Make a reference msstw with the default size.
433-
referenceMsstw, err := newMultiSSTWriter(ctx, settings, ref, localSpans, mvccSpan, 0, true /* rangeKeysInOrder */)
430+
referenceMsstw, err := newMultiSSTWriter(ctx, settings, ref, localSpans, mvccSpan, 0)
434431
require.NoError(t, err)
435432
require.Equal(t, int64(0), referenceMsstw.dataSize)
436433
now := timeutil.Now().UnixNano()
@@ -462,7 +459,7 @@ func TestMultiSSTWriterSize(t *testing.T) {
462459

463460
MaxSnapshotSSTableSize.Override(ctx, &settings.SV, 100)
464461

465-
multiSSTWriter, err := newMultiSSTWriter(ctx, settings, scratch, localSpans, mvccSpan, 0, true)
462+
multiSSTWriter, err := newMultiSSTWriter(ctx, settings, scratch, localSpans, mvccSpan, 0)
466463
require.NoError(t, err)
467464
require.Equal(t, int64(0), multiSSTWriter.dataSize)
468465

@@ -544,7 +541,7 @@ func TestMultiSSTWriterAddLastSpan(t *testing.T) {
544541
localSpans := keySpans[:len(keySpans)-1]
545542
mvccSpan := keySpans[len(keySpans)-1]
546543

547-
msstw, err := newMultiSSTWriter(ctx, cluster.MakeTestingClusterSettings(), scratch, localSpans, mvccSpan, 0, false)
544+
msstw, err := newMultiSSTWriter(ctx, cluster.MakeTestingClusterSettings(), scratch, localSpans, mvccSpan, 0)
548545
require.NoError(t, err)
549546
testKey := storage.MVCCKey{Key: roachpb.RKey("d1").AsRawKey(), Timestamp: hlc.Timestamp{WallTime: 1}}
550547
testEngineKey, _ := storage.DecodeEngineKey(storage.EncodeMVCCKey(testKey))

0 commit comments

Comments
 (0)