Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
55998: storage: renaming functions in the Reader interface r=sumeerbhola a=sumeerbhola

- Get to MVCCGet
- GetProto to MVCCGetProto
- Iterate to MVCCIterate
- ExportToSst to ExportMVCCToSst

Also added MVCCIterKind.

Release note: None


Co-authored-by: sumeerbhola <[email protected]>
  • Loading branch information
craig[bot] and sumeerbhola committed Oct 27, 2020
2 parents 9390144 + 2167922 commit 5e3c201
Show file tree
Hide file tree
Showing 25 changed files with 186 additions and 159 deletions.
4 changes: 2 additions & 2 deletions pkg/ccl/storageccl/engineccl/encrypted_fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func TestPebbleEncryption(t *testing.T) {
require.NoError(t, batch.Put(storage.MVCCKey{Key: roachpb.Key("a")}, []byte("a")))
require.NoError(t, batch.Commit(true))
require.NoError(t, db.Flush())
val, err := db.Get(storage.MVCCKey{Key: roachpb.Key("a")})
val, err := db.MVCCGet(storage.MVCCKey{Key: roachpb.Key("a")})
require.NoError(t, err)
require.Equal(t, "a", string(val))
db.Close()
Expand All @@ -266,7 +266,7 @@ func TestPebbleEncryption(t *testing.T) {
Opts: opts2,
})
require.NoError(t, err)
val, err = db.Get(storage.MVCCKey{Key: roachpb.Key("a")})
val, err = db.MVCCGet(storage.MVCCKey{Key: roachpb.Key("a")})
require.NoError(t, err)
require.Equal(t, "a", string(val))

Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/storageccl/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func evalExport(
maxSize = targetSize + uint64(allowedOverage)
}
for start := args.Key; start != nil; {
data, summary, resume, err := e.ExportToSst(start, args.EndKey, args.StartTime,
data, summary, resume, err := e.ExportMVCCToSst(start, args.EndKey, args.StartTime,
h.Timestamp, exportAllRevisions, targetSize, maxSize, io)
if err != nil {
return result.Result{}, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/storageccl/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ func assertEqualKVs(
var summary roachpb.BulkOpSummary
maxSize := uint64(0)
prevStart := start
sst, summary, start, err = e.ExportToSst(start, endKey, startTime, endTime,
sst, summary, start, err = e.ExportMVCCToSst(start, endKey, startTime, endTime,
exportAllRevisions, targetSize, maxSize, io)
require.NoError(t, err)
loaded := loadSST(t, sst, startKey, endKey)
Expand Down Expand Up @@ -472,7 +472,7 @@ func assertEqualKVs(
if dataSizeWhenExceeded == maxSize {
maxSize--
}
_, _, _, err = e.ExportToSst(prevStart, endKey, startTime, endTime,
_, _, _, err = e.ExportMVCCToSst(prevStart, endKey, startTime, endTime,
exportAllRevisions, targetSize, maxSize, io)
require.Regexp(t, fmt.Sprintf("export size \\(%d bytes\\) exceeds max size \\(%d bytes\\)",
dataSizeWhenExceeded, maxSize), err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ccl/storageccl/writebatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func clearExistingData(
) (enginepb.MVCCStats, error) {
{
isEmpty := true
if err := batch.Iterate(start, end, func(_ storage.MVCCKeyValue) error {
if err := batch.MVCCIterate(start, end, func(_ storage.MVCCKeyValue) error {
isEmpty = false
return iterutil.StopIteration() // stop right away
}); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func runDebugKeys(cmd *cobra.Command, args []string) error {
}

results := 0
return db.Iterate(debugCtx.startKey.Key, debugCtx.endKey.Key, func(kv storage.MVCCKeyValue) error {
return db.MVCCIterate(debugCtx.startKey.Key, debugCtx.endKey.Key, func(kv storage.MVCCKeyValue) error {
done, err := printer(kv)
if err != nil {
return err
Expand Down Expand Up @@ -380,7 +380,7 @@ func loadRangeDescriptor(
start := keys.LocalRangePrefix
end := keys.LocalRangeMax

if err := db.Iterate(start, end, handleKV); err != nil {
if err := db.MVCCIterate(start, end, handleKV); err != nil {
return roachpb.RangeDescriptor{}, err
}
if desc.RangeID == rangeID {
Expand All @@ -401,7 +401,7 @@ func runDebugRangeDescriptors(cmd *cobra.Command, args []string) error {
start := keys.LocalRangePrefix
end := keys.LocalRangeMax

return db.Iterate(start, end, func(kv storage.MVCCKeyValue) error {
return db.MVCCIterate(start, end, func(kv storage.MVCCKeyValue) error {
if kvserver.IsRangeDescriptorKey(kv.Key) != nil {
return nil
}
Expand Down Expand Up @@ -531,7 +531,7 @@ func runDebugRaftLog(cmd *cobra.Command, args []string) error {
string(storage.EncodeKey(storage.MakeMVCCMetadataKey(start))),
string(storage.EncodeKey(storage.MakeMVCCMetadataKey(end))))

return db.Iterate(start, end, func(kv storage.MVCCKeyValue) error {
return db.MVCCIterate(start, end, func(kv storage.MVCCKeyValue) error {
kvserver.PrintKeyValue(kv)
return nil
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/debug_check_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func checkStoreRaftState(
return err
}

// Iterate over the entire range-id-local space.
// MVCCIterate over the entire range-id-local space.
start := roachpb.Key(keys.LocalRangeIDPrefix)
end := start.PrefixEnd()

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/debug_synctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func runSyncer(
}

fmt.Fprintf(stderr, "verifying existing sequence numbers...")
if err := db.Iterate(roachpb.KeyMin, roachpb.KeyMax, check); err != nil {
if err := db.MVCCIterate(roachpb.KeyMin, roachpb.KeyMax, check); err != nil {
return 0, err
}
// We must not lose writes, but sometimes we get extra ones (i.e. we caught an
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvclient/kvcoord/txn_coord_sender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ func verifyCleanup(key roachpb.Key, eng storage.Engine, t *testing.T, coords ...
}
}
meta := &enginepb.MVCCMetadata{}
//lint:ignore SA1019 historical usage of deprecated eng.GetProto is OK
ok, _, _, err := eng.GetProto(storage.MakeMVCCMetadataKey(key), meta)
//lint:ignore SA1019 historical usage of deprecated eng.MVCCGetProto is OK
ok, _, _, err := eng.MVCCGetProto(storage.MakeMVCCMetadataKey(key), meta)
if err != nil {
return fmt.Errorf("error getting MVCC metadata: %s", err)
}
Expand Down
52 changes: 26 additions & 26 deletions pkg/kv/kvserver/batch_spanset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,21 @@ func TestSpanSetBatchBoundaries(t *testing.T) {

t.Run("reads inside range", func(t *testing.T) {
//lint:ignore SA1019 historical usage of deprecated batch.Get is OK
if value, err := batch.Get(insideKey); err != nil {
if value, err := batch.MVCCGet(insideKey); err != nil {
t.Errorf("failed to read inside the range: %+v", err)
} else if !bytes.Equal(value, []byte("value")) {
t.Errorf("failed to read previously written value, got %q", value)
}
//lint:ignore SA1019 historical usage of deprecated batch.GetProto is OK
if _, _, _, err := batch.GetProto(insideKey, nil); err != nil {
t.Errorf("GetProto: unexpected error %v", err)
//lint:ignore SA1019 historical usage of deprecated batch.MVCCGetProto is OK
if _, _, _, err := batch.MVCCGetProto(insideKey, nil); err != nil {
t.Errorf("MVCCGetProto: unexpected error %v", err)
}
if err := batch.Iterate(insideKey.Key, insideKey2.Key,
if err := batch.MVCCIterate(insideKey.Key, insideKey2.Key,
func(v storage.MVCCKeyValue) error {
return nil
},
); err != nil {
t.Errorf("Iterate: unexpected error %v", err)
t.Errorf("MVCCIterate: unexpected error %v", err)
}
})

Expand All @@ -143,37 +143,37 @@ func TestSpanSetBatchBoundaries(t *testing.T) {

t.Run("reads before range", func(t *testing.T) {
//lint:ignore SA1019 historical usage of deprecated batch.Get is OK
if _, err := batch.Get(outsideKey); !isReadSpanErr(err) {
if _, err := batch.MVCCGet(outsideKey); !isReadSpanErr(err) {
t.Errorf("Get: unexpected error %v", err)
}
//lint:ignore SA1019 historical usage of deprecated batch.GetProto is OK
if _, _, _, err := batch.GetProto(outsideKey, nil); !isReadSpanErr(err) {
t.Errorf("GetProto: unexpected error %v", err)
//lint:ignore SA1019 historical usage of deprecated batch.MVCCGetProto is OK
if _, _, _, err := batch.MVCCGetProto(outsideKey, nil); !isReadSpanErr(err) {
t.Errorf("MVCCGetProto: unexpected error %v", err)
}
if err := batch.Iterate(outsideKey.Key, insideKey2.Key,
if err := batch.MVCCIterate(outsideKey.Key, insideKey2.Key,
func(v storage.MVCCKeyValue) error {
return errors.Errorf("unexpected callback: %v", v)
},
); !isReadSpanErr(err) {
t.Errorf("Iterate: unexpected error %v", err)
t.Errorf("MVCCIterate: unexpected error %v", err)
}
})

t.Run("reads after range", func(t *testing.T) {
//lint:ignore SA1019 historical usage of deprecated batch.Get is OK
if _, err := batch.Get(outsideKey3); !isReadSpanErr(err) {
if _, err := batch.MVCCGet(outsideKey3); !isReadSpanErr(err) {
t.Errorf("Get: unexpected error %v", err)
}
//lint:ignore SA1019 historical usage of deprecated batch.GetProto is OK
if _, _, _, err := batch.GetProto(outsideKey3, nil); !isReadSpanErr(err) {
t.Errorf("GetProto: unexpected error %v", err)
//lint:ignore SA1019 historical usage of deprecated batch.MVCCGetProto is OK
if _, _, _, err := batch.MVCCGetProto(outsideKey3, nil); !isReadSpanErr(err) {
t.Errorf("MVCCGetProto: unexpected error %v", err)
}
if err := batch.Iterate(insideKey2.Key, outsideKey4.Key,
if err := batch.MVCCIterate(insideKey2.Key, outsideKey4.Key,
func(v storage.MVCCKeyValue) error {
return errors.Errorf("unexpected callback: %v", v)
},
); !isReadSpanErr(err) {
t.Errorf("Iterate: unexpected error %v", err)
t.Errorf("MVCCIterate: unexpected error %v", err)
}
})

Expand Down Expand Up @@ -349,7 +349,7 @@ func TestSpanSetBatchTimestamps(t *testing.T) {
// Reads.
for _, batch := range []storage.Batch{batchBefore, batchDuring} {
//lint:ignore SA1019 historical usage of deprecated batch.Get is OK
if res, err := batch.Get(rkey); err != nil {
if res, err := batch.MVCCGet(rkey); err != nil {
t.Errorf("failed to read inside the range: %+v", err)
} else if !bytes.Equal(res, value) {
t.Errorf("failed to read previously written value, got %q", res)
Expand All @@ -362,20 +362,20 @@ func TestSpanSetBatchTimestamps(t *testing.T) {

for _, batch := range []storage.Batch{batchAfter, batchNonMVCC} {
//lint:ignore SA1019 historical usage of deprecated batch.Get is OK
if _, err := batch.Get(rkey); !isReadSpanErr(err) {
if _, err := batch.MVCCGet(rkey); !isReadSpanErr(err) {
t.Errorf("Get: unexpected error %v", err)
}

//lint:ignore SA1019 historical usage of deprecated batch.GetProto is OK
if _, _, _, err := batch.GetProto(rkey, nil); !isReadSpanErr(err) {
t.Errorf("GetProto: unexpected error %v", err)
//lint:ignore SA1019 historical usage of deprecated batch.MVCCGetProto is OK
if _, _, _, err := batch.MVCCGetProto(rkey, nil); !isReadSpanErr(err) {
t.Errorf("MVCCGetProto: unexpected error %v", err)
}
if err := batch.Iterate(rkey.Key, rkey.Key,
if err := batch.MVCCIterate(rkey.Key, rkey.Key,
func(v storage.MVCCKeyValue) error {
return errors.Errorf("unexpected callback: %v", v)
},
); !isReadSpanErr(err) {
t.Errorf("Iterate: unexpected error %v", err)
t.Errorf("MVCCIterate: unexpected error %v", err)
}
}
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func TestSpanSetNonMVCCBatch(t *testing.T) {
// Reads.
for _, batch := range []storage.Batch{batchNonMVCC, batchMVCC} {
//lint:ignore SA1019 historical usage of deprecated batch.Get is OK
if res, err := batch.Get(rkey); err != nil {
if res, err := batch.MVCCGet(rkey); err != nil {
t.Errorf("read disallowed through non-MVCC latch: %+v", err)
} else if !bytes.Equal(res, value) {
t.Errorf("failed to read previously written value, got %q", res)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/batcheval/cmd_clear_range.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func ClearRange(
// instead of using a range tombstone (inefficient for small ranges).
if total := statsDelta.Total(); total < ClearRangeBytesThreshold {
log.VEventf(ctx, 2, "delta=%d < threshold=%d; using non-range clear", total, ClearRangeBytesThreshold)
if err := readWriter.Iterate(from, to,
if err := readWriter.MVCCIterate(from, to,
func(kv storage.MVCCKeyValue) error {
return readWriter.Clear(kv.Key)
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/batcheval/cmd_clear_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestCmdClearRangeBytesThreshold(t *testing.T) {
if err := batch.Commit(true /* commit */); err != nil {
t.Fatal(err)
}
if err := eng.Iterate(startKey, endKey,
if err := eng.MVCCIterate(startKey, endKey,
func(kv storage.MVCCKeyValue) error {
return errors.New("expected no data in underlying engine")
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/batcheval/cmd_revert_range_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
func hashRange(t *testing.T, reader storage.Reader, start, end roachpb.Key) []byte {
t.Helper()
h := sha256.New()
if err := reader.Iterate(start, end,
if err := reader.MVCCIterate(start, end,
func(kv storage.MVCCKeyValue) error {
h.Write(kv.Key.Key)
h.Write(kv.Value)
Expand Down
8 changes: 4 additions & 4 deletions pkg/kv/kvserver/compactor/compactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (c *Compactor) fetchSuggestions(
delBatch := c.eng.NewBatch()
defer delBatch.Close()

err = c.eng.Iterate(
err = c.eng.MVCCIterate(
keys.LocalStoreSuggestedCompactionsMin,
keys.LocalStoreSuggestedCompactionsMax,
func(kv storage.MVCCKeyValue) error {
Expand Down Expand Up @@ -462,7 +462,7 @@ func (c *Compactor) aggregateCompaction(
// BytesQueued gauge.
func (c *Compactor) examineQueue(ctx context.Context) (int64, error) {
var totalBytes int64
if err := c.eng.Iterate(
if err := c.eng.MVCCIterate(
keys.LocalStoreSuggestedCompactionsMin,
keys.LocalStoreSuggestedCompactionsMax,
func(kv storage.MVCCKeyValue) error {
Expand All @@ -488,8 +488,8 @@ func (c *Compactor) Suggest(ctx context.Context, sc kvserverpb.SuggestedCompacti
// Check whether a suggested compaction already exists for this key span.
key := keys.StoreSuggestedCompactionKey(sc.StartKey, sc.EndKey)
var existing kvserverpb.Compaction
//lint:ignore SA1019 historical usage of deprecated c.eng.GetProto is OK
ok, _, _, err := c.eng.GetProto(storage.MVCCKey{Key: key}, &existing)
//lint:ignore SA1019 historical usage of deprecated c.eng.MVCCGetProto is OK
ok, _, _, err := c.eng.MVCCGetProto(storage.MVCCKey{Key: key}, &existing)
if err != nil {
log.VErrEventf(ctx, 2, "unable to record suggested compaction: %s", err)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/compactor/compactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ func TestCompactorThresholds(t *testing.T) {
// Read the remaining suggestions in the queue; verify compacted
// spans have been cleared and uncompacted spans remain.
var idx int
return we.Iterate(
return we.MVCCIterate(
keys.LocalStoreSuggestedCompactionsMin,
keys.LocalStoreSuggestedCompactionsMax,
func(kv storage.MVCCKeyValue) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/gc_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -967,12 +967,12 @@ func TestGCQueueIntentResolution(t *testing.T) {
}
assert.True(t, processed, "queue not processed")

// Iterate through all values to ensure intents have been fully resolved.
// MVCCIterate through all values to ensure intents have been fully resolved.
// This must be done in a SucceedsSoon loop because intent resolution
// is initiated asynchronously from the GC queue.
testutils.SucceedsSoon(t, func() error {
meta := &enginepb.MVCCMetadata{}
return tc.store.Engine().Iterate(roachpb.KeyMin, roachpb.KeyMax,
return tc.store.Engine().MVCCIterate(roachpb.KeyMin, roachpb.KeyMax,
func(kv storage.MVCCKeyValue) error {
if !kv.Key.IsValue() {
if err := protoutil.Unmarshal(kv.Value, meta); err != nil {
Expand Down
22 changes: 12 additions & 10 deletions pkg/kv/kvserver/spanset/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,18 +233,18 @@ func (s spanSetReader) Closed() bool {
return s.r.Closed()
}

// ExportToSst is part of the engine.Reader interface.
func (s spanSetReader) ExportToSst(
// ExportMVCCToSst is part of the engine.Reader interface.
func (s spanSetReader) ExportMVCCToSst(
startKey, endKey roachpb.Key,
startTS, endTS hlc.Timestamp,
exportAllRevisions bool,
targetSize, maxSize uint64,
io storage.IterOptions,
) ([]byte, roachpb.BulkOpSummary, roachpb.Key, error) {
return s.r.ExportToSst(startKey, endKey, startTS, endTS, exportAllRevisions, targetSize, maxSize, io)
return s.r.ExportMVCCToSst(startKey, endKey, startTS, endTS, exportAllRevisions, targetSize, maxSize, io)
}

func (s spanSetReader) Get(key storage.MVCCKey) ([]byte, error) {
func (s spanSetReader) MVCCGet(key storage.MVCCKey) ([]byte, error) {
if s.spansOnly {
if err := s.spans.CheckAllowed(SpanReadOnly, roachpb.Span{Key: key.Key}); err != nil {
return nil, err
Expand All @@ -255,10 +255,10 @@ func (s spanSetReader) Get(key storage.MVCCKey) ([]byte, error) {
}
}
//lint:ignore SA1019 implementing deprecated interface function (Get) is OK
return s.r.Get(key)
return s.r.MVCCGet(key)
}

func (s spanSetReader) GetProto(
func (s spanSetReader) MVCCGetProto(
key storage.MVCCKey, msg protoutil.Message,
) (bool, int64, int64, error) {
if s.spansOnly {
Expand All @@ -270,11 +270,13 @@ func (s spanSetReader) GetProto(
return false, 0, 0, err
}
}
//lint:ignore SA1019 implementing deprecated interface function (GetProto) is OK
return s.r.GetProto(key, msg)
//lint:ignore SA1019 implementing deprecated interface function (MVCCGetProto) is OK
return s.r.MVCCGetProto(key, msg)
}

func (s spanSetReader) Iterate(start, end roachpb.Key, f func(storage.MVCCKeyValue) error) error {
func (s spanSetReader) MVCCIterate(
start, end roachpb.Key, f func(storage.MVCCKeyValue) error,
) error {
if s.spansOnly {
if err := s.spans.CheckAllowed(SpanReadOnly, roachpb.Span{Key: start, EndKey: end}); err != nil {
return err
Expand All @@ -284,7 +286,7 @@ func (s spanSetReader) Iterate(start, end roachpb.Key, f func(storage.MVCCKeyVal
return err
}
}
return s.r.Iterate(start, end, f)
return s.r.MVCCIterate(start, end, f)
}

func (s spanSetReader) NewIterator(opts storage.IterOptions) storage.MVCCIterator {
Expand Down
Loading

0 comments on commit 5e3c201

Please sign in to comment.