Skip to content

Commit f295bd8

Browse files
craig[bot]AlexTalks
andcommitted
107680: storage: refactor mvcc write parameters r=AlexTalks a=AlexTalks This change introduces `MVCCWriteOptions`, a structure for bundling parameters for `MVCCPut`, `MVCCDelete`, and their many variants, and refactors usages of these functions across the code base in order to move the existing function arguments into this structure. In addition to allowing the code to eliminate specifying default values in many callers, this enables the ability to pass new flags to write operations such as the replay protection needed to address cockroachdb#103817. Part of: cockroachdb#103817 Release note: None Co-authored-by: Alex Sarkesian <[email protected]>
2 parents 6fe7152 + 2b18f4f commit f295bd8

File tree

81 files changed

+673
-624
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+673
-624
lines changed

pkg/ccl/storageccl/engineccl/bench_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func loadTestData(
9393
timestamp := hlc.Timestamp{WallTime: minWallTime + rand.Int63n(int64(batchTimeSpan))}
9494
value := roachpb.MakeValueFromBytes(randutil.RandBytes(rng, valueBytes))
9595
value.InitChecksum(key)
96-
if err := storage.MVCCPut(ctx, batch, nil, key, timestamp, hlc.ClockTimestamp{}, value, nil); err != nil {
96+
if err := storage.MVCCPut(ctx, batch, key, timestamp, value, storage.MVCCWriteOptions{}); err != nil {
9797
tb.Fatal(err)
9898
}
9999
}

pkg/ccl/storageccl/engineccl/encrypted_fs_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,10 @@ func TestPebbleEncryption2(t *testing.T) {
397397
err = storage.MVCCPut(
398398
context.Background(),
399399
db,
400-
nil, /* ms */
401400
roachpb.Key(key),
402401
hlc.Timestamp{},
403-
hlc.ClockTimestamp{},
404402
roachpb.MakeValueFromBytes([]byte(val)),
405-
nil, /* txn */
403+
storage.MVCCWriteOptions{},
406404
)
407405
require.NoError(t, err)
408406
require.NoError(t, db.Flush())

pkg/kv/kvclient/kvcoord/dist_sender_server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func TestRangeLookupWithOpenTransaction(t *testing.T) {
8080
key := testutils.MakeKey(keys.Meta1Prefix, roachpb.KeyMax)
8181
now := s.Clock().Now()
8282
txn := roachpb.MakeTransaction("txn", roachpb.Key("foobar"), isolation.Serializable, 0, now, 0, int32(s.SQLInstanceID()))
83-
if err := storage.MVCCPutProto(context.Background(), s.Engines()[0], nil, key, now, hlc.ClockTimestamp{}, &txn, &roachpb.RangeDescriptor{}); err != nil {
83+
if err := storage.MVCCPutProto(context.Background(), s.Engines()[0], key, now, &roachpb.RangeDescriptor{}, storage.MVCCWriteOptions{Txn: &txn}); err != nil {
8484
t.Fatal(err)
8585
}
8686

pkg/kv/kvserver/abortspan/abortspan.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func (sc *AbortSpan) Del(
120120
ctx context.Context, reader storage.ReadWriter, ms *enginepb.MVCCStats, txnID uuid.UUID,
121121
) error {
122122
key := keys.AbortSpanKey(sc.rangeID, txnID)
123-
_, err := storage.MVCCDelete(ctx, reader, ms, key, hlc.Timestamp{}, hlc.ClockTimestamp{}, nil /* txn */)
123+
_, err := storage.MVCCDelete(ctx, reader, key, hlc.Timestamp{}, storage.MVCCWriteOptions{Stats: ms})
124124
return err
125125
}
126126

@@ -134,7 +134,7 @@ func (sc *AbortSpan) Put(
134134
) error {
135135
log.VEventf(ctx, 2, "writing abort span entry for %s", txnID.Short())
136136
key := keys.AbortSpanKey(sc.rangeID, txnID)
137-
return storage.MVCCPutProto(ctx, readWriter, ms, key, hlc.Timestamp{}, hlc.ClockTimestamp{}, nil /* txn */, entry)
137+
return storage.MVCCPutProto(ctx, readWriter, key, hlc.Timestamp{}, entry, storage.MVCCWriteOptions{Stats: ms})
138138
}
139139

140140
// CopyTo copies the abort span entries to the abort span for the range
@@ -178,9 +178,9 @@ func (sc *AbortSpan) CopyTo(
178178
if err != nil {
179179
return err
180180
}
181-
return storage.MVCCPutProto(ctx, w, ms,
181+
return storage.MVCCPutProto(ctx, w,
182182
keys.AbortSpanKey(newRangeID, txnID),
183-
hlc.Timestamp{}, hlc.ClockTimestamp{}, nil, &entry,
183+
hlc.Timestamp{}, &entry, storage.MVCCWriteOptions{Stats: ms},
184184
)
185185
}); err != nil {
186186
return errors.Wrap(err, "AbortSpan.CopyTo")

pkg/kv/kvserver/batch_spanset_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,10 @@ func TestSpanSetMVCCResolveWriteIntentRange(t *testing.T) {
545545
if err := storage.MVCCPut(
546546
ctx,
547547
eng,
548-
nil, // ms
549548
roachpb.Key("b"),
550549
hlc.Timestamp{WallTime: 10}, // irrelevant
551-
hlc.ClockTimestamp{}, // irrelevant
552550
value,
553-
nil, // txn
551+
storage.MVCCWriteOptions{}, // irrelevant
554552
); err != nil {
555553
t.Fatal(err)
556554
}

pkg/kv/kvserver/batcheval/cmd_add_sstable_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ func TestEvalAddSSTable(t *testing.T) {
11421142
kv.Key.Timestamp.WallTime *= 1e9
11431143
v, err := storage.DecodeMVCCValue(kv.Value)
11441144
require.NoError(t, err)
1145-
require.NoError(t, storage.MVCCPut(ctx, b, nil, kv.Key.Key, kv.Key.Timestamp, hlc.ClockTimestamp{}, v.Value, txn))
1145+
require.NoError(t, storage.MVCCPut(ctx, b, kv.Key.Key, kv.Key.Timestamp, v.Value, storage.MVCCWriteOptions{Txn: txn}))
11461146
case storage.MVCCRangeKeyValue:
11471147
v, err := storage.DecodeMVCCValue(kv.Value)
11481148
require.NoError(t, err)

pkg/kv/kvserver/batcheval/cmd_clear_range_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ func TestCmdClearRange(t *testing.T) {
152152
// Write some random point keys within the cleared span, above the range tombstones.
153153
for i := 0; i < tc.keyCount; i++ {
154154
key := roachpb.Key(fmt.Sprintf("%04d", i))
155-
require.NoError(t, storage.MVCCPut(ctx, eng, nil, key,
156-
hlc.Timestamp{WallTime: int64(4+i%2) * 1e9}, hlc.ClockTimestamp{}, value, nil))
155+
require.NoError(t, storage.MVCCPut(ctx, eng, key,
156+
hlc.Timestamp{WallTime: int64(4+i%2) * 1e9}, value, storage.MVCCWriteOptions{}))
157157
}
158158

159159
// Calculate the range stats.

pkg/kv/kvserver/batcheval/cmd_conditional_put.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,20 @@ func ConditionalPut(
5757
}
5858

5959
handleMissing := storage.CPutMissingBehavior(args.AllowIfDoesNotExist)
60+
61+
opts := storage.MVCCWriteOptions{
62+
Txn: h.Txn,
63+
LocalTimestamp: cArgs.Now,
64+
Stats: cArgs.Stats,
65+
}
66+
6067
var err error
6168
if args.Blind {
6269
err = storage.MVCCBlindConditionalPut(
63-
ctx, readWriter, cArgs.Stats, args.Key, ts, cArgs.Now, args.Value, args.ExpBytes, handleMissing, h.Txn)
70+
ctx, readWriter, args.Key, ts, args.Value, args.ExpBytes, handleMissing, opts)
6471
} else {
6572
err = storage.MVCCConditionalPut(
66-
ctx, readWriter, cArgs.Stats, args.Key, ts, cArgs.Now, args.Value, args.ExpBytes, handleMissing, h.Txn)
73+
ctx, readWriter, args.Key, ts, args.Value, args.ExpBytes, handleMissing, opts)
6774
}
6875
if err != nil {
6976
return result.Result{}, err

pkg/kv/kvserver/batcheval/cmd_delete.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@ func Delete(
3131
h := cArgs.Header
3232
reply := resp.(*kvpb.DeleteResponse)
3333

34+
opts := storage.MVCCWriteOptions{
35+
Txn: h.Txn,
36+
LocalTimestamp: cArgs.Now,
37+
Stats: cArgs.Stats,
38+
}
39+
3440
var err error
3541
reply.FoundKey, err = storage.MVCCDelete(
36-
ctx, readWriter, cArgs.Stats, args.Key, h.Timestamp, cArgs.Now, h.Txn,
42+
ctx, readWriter, args.Key, h.Timestamp, opts,
3743
)
3844
if err != nil {
3945
return result.Result{}, err

pkg/kv/kvserver/batcheval/cmd_delete_range.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,10 @@ func DeleteRange(
228228
// can update the Result's AcquiredLocks field.
229229
returnKeys := args.ReturnKeys || h.Txn != nil
230230
deleted, resumeSpan, num, err := storage.MVCCDeleteRange(
231-
ctx, readWriter, cArgs.Stats, args.Key, args.EndKey,
232-
h.MaxSpanRequestKeys, timestamp, cArgs.Now, h.Txn, returnKeys)
231+
ctx, readWriter, args.Key, args.EndKey,
232+
h.MaxSpanRequestKeys, timestamp,
233+
storage.MVCCWriteOptions{Txn: h.Txn, LocalTimestamp: cArgs.Now, Stats: cArgs.Stats},
234+
returnKeys)
233235
if err != nil {
234236
return result.Result{}, err
235237
}

0 commit comments

Comments
 (0)