From 99016206345eaad71443cfb6aaaf330846f63f12 Mon Sep 17 00:00:00 2001 From: Bilal Akhtar Date: Wed, 6 Jul 2022 17:39:07 -0400 Subject: [PATCH] storage/metamorphic: Add MVCC delete range using tombstone 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. --- pkg/storage/metamorphic/generator.go | 2 +- pkg/storage/metamorphic/operations.go | 53 ++++++++++++++++++++++++++- pkg/storage/metamorphic/options.go | 4 ++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/pkg/storage/metamorphic/generator.go b/pkg/storage/metamorphic/generator.go index ee9fa6066871..7adacd23ad28 100644 --- a/pkg/storage/metamorphic/generator.go +++ b/pkg/storage/metamorphic/generator.go @@ -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 diff --git a/pkg/storage/metamorphic/operations.go b/pkg/storage/metamorphic/operations.go index c435188abdb7..ce51ee381198 100644 --- a/pkg/storage/metamorphic/operations.go +++ b/pkg/storage/metamorphic/operations.go @@ -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 @@ -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", diff --git a/pkg/storage/metamorphic/options.go b/pkg/storage/metamorphic/options.go index e1fac10fef0f..8a6c42fe9c61 100644 --- a/pkg/storage/metamorphic/options.go +++ b/pkg/storage/metamorphic/options.go @@ -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)