Skip to content

Commit

Permalink
storage/metamorphic: Add MVCC delete range using tombstone
Browse files Browse the repository at this point in the history
This change adds MVCCDeleteRangeUsingTombstone to the MVCC
metamorphic tests. MVCCDeleteRange had already existed in
this test suite, so this ended up being a relatively simple
addition.

One part of #82545, with possibly more parts to follow
as other MVCC-level operations are added that utilize
`writer.{Put,Clear}{MVCC,Engine}RangeKey`.

Release note: None.
  • Loading branch information
itsbilal committed Jul 7, 2022
1 parent 8b6e3c3 commit 9901620
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/storage/metamorphic/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (e *engineConfig) String() string {
return e.name
}

var engineConfigStandard = engineConfig{"standard=0", storage.DefaultPebbleOptions()}
var engineConfigStandard = engineConfig{"standard=0", standardOptions(0)}

type engineSequence struct {
name string
Expand Down
53 changes: 52 additions & 1 deletion pkg/storage/metamorphic/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,30 @@ func (m mvccDeleteRangeOp) run(ctx context.Context) string {
return builder.String()
}

type mvccDeleteRangeUsingRangeTombstoneOp struct {
m *metaTestRunner
writer readWriterID
key roachpb.Key
endKey roachpb.Key
ts hlc.Timestamp
}

func (m mvccDeleteRangeUsingRangeTombstoneOp) run(ctx context.Context) string {
writer := m.m.getReadWriter(m.writer)
if m.key.Compare(m.endKey) >= 0 {
// Empty range. No-op.
return "no-op due to no non-conflicting key range"
}

err := storage.MVCCDeleteRangeUsingTombstone(ctx, writer, nil, m.key, m.endKey,
m.ts, hlc.ClockTimestamp{}, m.key, m.endKey, math.MaxInt64 /* maxIntents */)
if err != nil {
return fmt.Sprintf("error: %s", err)
}

return fmt.Sprintf("deleted range = %s - %s", m.key, m.endKey)
}

type mvccClearTimeRangeOp struct {
m *metaTestRunner
key roachpb.Key
Expand Down Expand Up @@ -923,7 +947,34 @@ var opGenerators = []opGenerator{
operandUnusedMVCCKey,
operandUnusedMVCCKey,
},
weight: 20,
weight: 10,
},
{
name: "mvcc_delete_range_using_range_tombstone",
generate: func(ctx context.Context, m *metaTestRunner, args ...string) mvccOp {
writer := readWriterID(args[0])
key := m.keyGenerator.parse(args[1]).Key
endKey := m.keyGenerator.parse(args[2]).Key
ts := m.nextTSGenerator.parse(args[3])

if endKey.Compare(key) < 0 {
key, endKey = endKey, key
}
return &mvccDeleteRangeUsingRangeTombstoneOp{
m: m,
writer: writer,
key: key,
endKey: endKey,
ts: ts,
}
},
operands: []operandType{
operandReadWriter,
operandMVCCKey,
operandMVCCKey,
operandNextTS,
},
weight: 10,
},
{
name: "mvcc_clear_time_range",
Expand Down
4 changes: 4 additions & 0 deletions pkg/storage/metamorphic/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,15 @@ func standardOptions(i int) *pebble.Options {
if err := opts.Parse(stdOpts[i], nil); err != nil {
panic(err)
}
// Enable range keys in all options.
opts.FormatMajorVersion = pebble.FormatRangeKeys
return opts
}

func randomOptions() *pebble.Options {
opts := storage.DefaultPebbleOptions()
// Enable range keys in all options.
opts.FormatMajorVersion = pebble.FormatRangeKeys

rng, _ := randutil.NewTestRand()
opts.BytesPerSync = 1 << rngIntRange(rng, 8, 30)
Expand Down

0 comments on commit 9901620

Please sign in to comment.