From 11ac7504530aa51cb185aeeeb8a75a6b33d1593c Mon Sep 17 00:00:00 2001 From: Artem Barger Date: Tue, 11 Feb 2020 01:31:16 +0200 Subject: [PATCH] engine: remove unwrapMVCCScan #44823 This PR Refactors pkg/storage/engine/mvcc_test.go. *Modifies mvcc_test.go to clean up and remove unwrapMVCCScan. Release note: None Signed-off-by: Artem Barger --- pkg/storage/engine/mvcc_test.go | 387 ++++++++++++++++---------------- 1 file changed, 192 insertions(+), 195 deletions(-) diff --git a/pkg/storage/engine/mvcc_test.go b/pkg/storage/engine/mvcc_test.go index 838f6ee898b2..5bad412e7c54 100644 --- a/pkg/storage/engine/mvcc_test.go +++ b/pkg/storage/engine/mvcc_test.go @@ -77,18 +77,6 @@ var ( }...) ) -func unwrapMVCCScan( - ctx context.Context, - reader Reader, - key, endKey roachpb.Key, - max int64, - timestamp hlc.Timestamp, - opts MVCCScanOptions, -) ([]roachpb.KeyValue, *roachpb.Span, []roachpb.Intent, error) { - res, err := MVCCScan(ctx, reader, key, endKey, max, timestamp, opts) - return res.KVs, res.ResumeSpan, res.Intents, err -} - // createTestRocksDBEngine returns a new in-memory RocksDB engine with 1MB of // storage capacity. func createTestRocksDBEngine() Engine { @@ -482,13 +470,13 @@ func TestMVCCGetUncertainty(t *testing.T) { } else if val == nil || !bytes.Equal(val.RawBytes, value1.RawBytes) { t.Fatalf("wanted %q, got %v", value1.RawBytes, val) } - if kvs, _, _, err := unwrapMVCCScan( + if res, err := MVCCScan( ctx, engine, testKey1, testKey1.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxn, ); err != nil { t.Fatal(err) - } else if len(kvs) != 1 { - t.Fatalf("wanted 1 kv, got %d", len(kvs)) - } else if val := kvs[0].Value; !bytes.Equal(val.RawBytes, value1.RawBytes) { + } else if len(res.KVs) != 1 { + t.Fatalf("wanted 1 kv, got %d", len(res.KVs)) + } else if val := res.KVs[0].Value; !bytes.Equal(val.RawBytes, value1.RawBytes) { t.Fatalf("wanted %q, got %v", value1.RawBytes, val) } @@ -511,7 +499,7 @@ func TestMVCCGetUncertainty(t *testing.T) { } else if _, ok := err.(*roachpb.ReadWithinUncertaintyIntervalError); !ok { t.Fatalf("wanted a ReadWithinUncertaintyIntervalError, got %+v", err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey2, testKey2.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxn, ); err == nil { t.Fatal("wanted an error") @@ -532,7 +520,7 @@ func TestMVCCGetUncertainty(t *testing.T) { } else if _, ok := err.(*roachpb.ReadWithinUncertaintyIntervalError); !ok { t.Fatalf("wanted a ReadWithinUncertaintyIntervalError, got %+v", err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey2, testKey2.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxnMaxTS9, ); err == nil { t.Fatal("wanted an error") @@ -550,7 +538,7 @@ func TestMVCCGetUncertainty(t *testing.T) { if _, _, err := mvccGet(ctx, engine, testKey2, hlc.Timestamp{WallTime: 7}, getOptsTxnMaxTS7); err != nil { t.Fatal(err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey2, testKey2.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxnMaxTS7, ); err != nil { t.Fatal(err) @@ -581,7 +569,7 @@ func TestMVCCGetUncertainty(t *testing.T) { } else if _, ok := err.(*roachpb.WriteIntentError); !ok { t.Fatalf("wanted a WriteIntentError, got %+v", err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey3, testKey3.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxn, ); err == nil { t.Fatal("wanted an error") @@ -601,7 +589,7 @@ func TestMVCCGetUncertainty(t *testing.T) { } else if _, ok := err.(*roachpb.WriteIntentError); !ok { t.Fatalf("wanted a WriteIntentError, got %+v", err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey3, testKey3.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxnMaxTS9, ); err == nil { t.Fatal("wanted an error") @@ -619,7 +607,7 @@ func TestMVCCGetUncertainty(t *testing.T) { if _, _, err := mvccGet(ctx, engine, testKey3, hlc.Timestamp{WallTime: 7}, getOptsTxnMaxTS7); err != nil { t.Fatal(err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey3, testKey3.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxnMaxTS7, ); err != nil { t.Fatal(err) @@ -649,7 +637,7 @@ func TestMVCCGetUncertainty(t *testing.T) { } else if _, ok := err.(*roachpb.ReadWithinUncertaintyIntervalError); !ok { t.Fatalf("wanted a ReadWithinUncertaintyIntervalError, got %+v", err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey4, testKey4.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxn, ); err == nil { t.Fatal("wanted an error") @@ -672,7 +660,7 @@ func TestMVCCGetUncertainty(t *testing.T) { } else if _, ok := err.(*roachpb.ReadWithinUncertaintyIntervalError); !ok { t.Fatalf("wanted a ReadWithinUncertaintyIntervalError, got %+v", err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey4, testKey4.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxnMaxTS9, ); err == nil { t.Fatal("wanted an error") @@ -692,7 +680,7 @@ func TestMVCCGetUncertainty(t *testing.T) { if _, _, err := mvccGet(ctx, engine, testKey4, hlc.Timestamp{WallTime: 7}, getOptsTxnMaxTS7); err != nil { t.Fatal(err) } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey4, testKey4.PrefixEnd(), 10, hlc.Timestamp{WallTime: 7}, scanOptsTxnMaxTS7, ); err != nil { t.Fatal(err) @@ -1070,7 +1058,7 @@ func TestMVCCScanWriteIntentError(t *testing.T) { if scan.consistent { cStr = "consistent" } - kvs, _, intents, err := unwrapMVCCScan(ctx, engine, testKey1, testKey4.Next(), math.MaxInt64, + res, err := MVCCScan(ctx, engine, testKey1, testKey4.Next(), math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Inconsistent: !scan.consistent, Txn: scan.txn}) wiErr, _ := err.(*roachpb.WriteIntentError) if (err == nil) != (wiErr == nil) { @@ -1082,6 +1070,8 @@ func TestMVCCScanWriteIntentError(t *testing.T) { continue } + intents := res.Intents + kvs := res.KVs if len(intents) > 0 != !scan.consistent { t.Errorf("%s(%d): expected different intents slice; got %+v", cStr, i, intents) continue @@ -1328,7 +1318,7 @@ func TestMVCCInvalidateIterator(t *testing.T) { case "get": _, _, err = MVCCGet(ctx, batch, key, ts2, MVCCGetOptions{}) case "scan": - _, _, _, err = unwrapMVCCScan(ctx, batch, key, roachpb.KeyMax, math.MaxInt64, ts2, MVCCScanOptions{}) + _, err = MVCCScan(ctx, batch, key, roachpb.KeyMax, math.MaxInt64, ts2, MVCCScanOptions{}) case "findSplitKey": _, err = MVCCFindSplitKey(ctx, batch, roachpb.RKeyMin, roachpb.RKeyMax, 64<<20) case "computeStats": @@ -1443,11 +1433,13 @@ func mvccScanTest(ctx context.Context, t *testing.T, engine Engine) { t.Fatal(err) } - kvs, resumeSpan, _, err := unwrapMVCCScan(ctx, engine, testKey2, testKey4, math.MaxInt64, + res, err := MVCCScan(ctx, engine, testKey2, testKey4, math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } + kvs := res.KVs + resumeSpan := res.ResumeSpan if len(kvs) != 2 || !bytes.Equal(kvs[0].Key, testKey2) || !bytes.Equal(kvs[1].Key, testKey3) || @@ -1459,11 +1451,13 @@ func mvccScanTest(ctx context.Context, t *testing.T, engine Engine) { t.Fatalf("resumeSpan = %+v", resumeSpan) } - kvs, resumeSpan, _, err = unwrapMVCCScan(ctx, engine, testKey2, testKey4, math.MaxInt64, + res, err = MVCCScan(ctx, engine, testKey2, testKey4, math.MaxInt64, hlc.Timestamp{WallTime: 4}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } + kvs = res.KVs + resumeSpan = res.ResumeSpan if len(kvs) != 2 || !bytes.Equal(kvs[0].Key, testKey2) || !bytes.Equal(kvs[1].Key, testKey3) || @@ -1475,11 +1469,13 @@ func mvccScanTest(ctx context.Context, t *testing.T, engine Engine) { t.Fatalf("resumeSpan = %+v", resumeSpan) } - kvs, resumeSpan, _, err = unwrapMVCCScan(ctx, engine, testKey4, keyMax, math.MaxInt64, + res, err = MVCCScan(ctx, engine, testKey4, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } + kvs = res.KVs + resumeSpan = res.ResumeSpan if len(kvs) != 1 || !bytes.Equal(kvs[0].Key, testKey4) || !bytes.Equal(kvs[0].Value.RawBytes, value4.RawBytes) { @@ -1494,11 +1490,12 @@ func mvccScanTest(ctx context.Context, t *testing.T, engine Engine) { }); err != nil { t.Fatal(err) } - kvs, _, _, err = unwrapMVCCScan(ctx, engine, keyMin, testKey2, math.MaxInt64, + res, err = MVCCScan(ctx, engine, keyMin, testKey2, math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } + kvs = res.KVs if len(kvs) != 1 || !bytes.Equal(kvs[0].Key, testKey1) || !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) { @@ -1545,56 +1542,56 @@ func TestMVCCScanMaxNum(t *testing.T) { t.Fatal(err) } - kvs, resumeSpan, _, err := unwrapMVCCScan(ctx, engine, testKey2, testKey4, 1, + res, err := MVCCScan(ctx, engine, testKey2, testKey4, 1, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey2) || - !bytes.Equal(kvs[0].Value.RawBytes, value2.RawBytes) { + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey2) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value2.RawBytes) { t.Fatal("the value should not be empty") } - if expected := (roachpb.Span{Key: testKey3, EndKey: testKey4}); !resumeSpan.EqualValue(expected) { - t.Fatalf("expected = %+v, resumeSpan = %+v", expected, resumeSpan) + if expected := (roachpb.Span{Key: testKey3, EndKey: testKey4}); !res.ResumeSpan.EqualValue(expected) { + t.Fatalf("expected = %+v, resumeSpan = %+v", expected, res.ResumeSpan) } - kvs, resumeSpan, _, err = unwrapMVCCScan(ctx, engine, testKey2, testKey4, 0, + res, err = MVCCScan(ctx, engine, testKey2, testKey4, 0, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } - if len(kvs) != 0 { + if len(res.KVs) != 0 { t.Fatal("the value should be empty") } - if expected := (roachpb.Span{Key: testKey2, EndKey: testKey4}); !resumeSpan.EqualValue(expected) { - t.Fatalf("expected = %+v, resumeSpan = %+v", expected, resumeSpan) + if expected := (roachpb.Span{Key: testKey2, EndKey: testKey4}); !res.ResumeSpan.EqualValue(expected) { + t.Fatalf("expected = %+v, resumeSpan = %+v", expected, res.ResumeSpan) } // Note: testKey6, though not scanned directly, is important in testing that // the computed resume span does not extend beyond the upper bound of a scan. - kvs, resumeSpan, _, err = unwrapMVCCScan(ctx, engine, testKey4, testKey5, 1, + res, err = MVCCScan(ctx, engine, testKey4, testKey5, 1, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 { - t.Fatalf("expected 1 key but got %d", len(kvs)) + if len(res.KVs) != 1 { + t.Fatalf("expected 1 key but got %d", len(res.KVs)) } - if resumeSpan != nil { - t.Fatalf("resumeSpan = %+v", resumeSpan) + if res.ResumeSpan != nil { + t.Fatalf("resumeSpan = %+v", res.ResumeSpan) } - kvs, resumeSpan, _, err = unwrapMVCCScan(ctx, engine, testKey5, testKey6.Next(), 1, + res, err = MVCCScan(ctx, engine, testKey5, testKey6.Next(), 1, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 { - t.Fatalf("expected 1 key but got %d", len(kvs)) + if len(res.KVs) != 1 { + t.Fatalf("expected 1 key but got %d", len(res.KVs)) } - if resumeSpan != nil { - t.Fatalf("resumeSpan = %+v", resumeSpan) + if res.ResumeSpan != nil { + t.Fatalf("resumeSpan = %+v", res.ResumeSpan) } }) } @@ -1636,16 +1633,16 @@ func TestMVCCScanWithKeyPrefix(t *testing.T) { t.Fatal(err) } - kvs, _, _, err := unwrapMVCCScan(ctx, engine, roachpb.Key("/a"), roachpb.Key("/b"), math.MaxInt64, + res, err := MVCCScan(ctx, engine, roachpb.Key("/a"), roachpb.Key("/b"), math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } - if len(kvs) != 2 || - !bytes.Equal(kvs[0].Key, roachpb.Key("/a")) || - !bytes.Equal(kvs[1].Key, roachpb.Key("/aa")) || - !bytes.Equal(kvs[0].Value.RawBytes, value2.RawBytes) || - !bytes.Equal(kvs[1].Value.RawBytes, value2.RawBytes) { + if len(res.KVs) != 2 || + !bytes.Equal(res.KVs[0].Key, roachpb.Key("/a")) || + !bytes.Equal(res.KVs[1].Key, roachpb.Key("/aa")) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value2.RawBytes) || + !bytes.Equal(res.KVs[1].Value.RawBytes, value2.RawBytes) { t.Fatal("the value should not be empty") } }) @@ -1675,20 +1672,20 @@ func TestMVCCScanInTxn(t *testing.T) { t.Fatal(err) } - kvs, _, _, err := unwrapMVCCScan(ctx, engine, testKey2, testKey4, math.MaxInt64, + res, err := MVCCScan(ctx, engine, testKey2, testKey4, math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Txn: txn1}) if err != nil { t.Fatal(err) } - if len(kvs) != 2 || - !bytes.Equal(kvs[0].Key, testKey2) || - !bytes.Equal(kvs[1].Key, testKey3) || - !bytes.Equal(kvs[0].Value.RawBytes, value2.RawBytes) || - !bytes.Equal(kvs[1].Value.RawBytes, value3.RawBytes) { + if len(res.KVs) != 2 || + !bytes.Equal(res.KVs[0].Key, testKey2) || + !bytes.Equal(res.KVs[1].Key, testKey3) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value2.RawBytes) || + !bytes.Equal(res.KVs[1].Value.RawBytes, value3.RawBytes) { t.Fatal("the value should not be empty") } - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, testKey2, testKey4, math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{}, ); err == nil { t.Fatal("expected error on uncommitted write intent") @@ -1709,7 +1706,7 @@ func TestMVCCScanInconsistent(t *testing.T) { defer engine.Close() // A scan with consistent=false should fail in a txn. - if _, _, _, err := unwrapMVCCScan( + if _, err := MVCCScan( ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Inconsistent: true, Txn: txn1}, ); err == nil { @@ -1747,15 +1744,15 @@ func TestMVCCScanInconsistent(t *testing.T) { {Span: roachpb.Span{Key: testKey1}, Txn: txn1ts2.TxnMeta}, {Span: roachpb.Span{Key: testKey3}, Txn: txn2ts5.TxnMeta}, } - kvs, _, intents, err := unwrapMVCCScan( + res, err := MVCCScan( ctx, engine, testKey1, testKey4.Next(), math.MaxInt64, hlc.Timestamp{WallTime: 7}, MVCCScanOptions{Inconsistent: true}, ) if err != nil { t.Fatal(err) } - if !reflect.DeepEqual(intents, expIntents) { - t.Fatalf("expected %v, but found %v", expIntents, intents) + if !reflect.DeepEqual(res.Intents, expIntents) { + t.Fatalf("expected %v, but found %v", expIntents, res.Intents) } makeTimestampedValue := func(v roachpb.Value, ts hlc.Timestamp) roachpb.Value { @@ -1768,23 +1765,23 @@ func TestMVCCScanInconsistent(t *testing.T) { {Key: testKey2, Value: makeTimestampedValue(value2, ts4)}, {Key: testKey4, Value: makeTimestampedValue(value4, ts6)}, } - if !reflect.DeepEqual(kvs, expKVs) { - t.Errorf("expected key values equal %v != %v", kvs, expKVs) + if !reflect.DeepEqual(res.KVs, expKVs) { + t.Errorf("expected key values equal %v != %v", res.KVs, expKVs) } // Now try a scan at a historical timestamp. expIntents = expIntents[:1] - kvs, _, intents, err = unwrapMVCCScan(ctx, engine, testKey1, testKey4.Next(), math.MaxInt64, + res, err = MVCCScan(ctx, engine, testKey1, testKey4.Next(), math.MaxInt64, hlc.Timestamp{WallTime: 3}, MVCCScanOptions{Inconsistent: true}) - if !reflect.DeepEqual(intents, expIntents) { + if !reflect.DeepEqual(res.Intents, expIntents) { t.Fatal(err) } expKVs = []roachpb.KeyValue{ {Key: testKey1, Value: makeTimestampedValue(value1, ts1)}, {Key: testKey2, Value: makeTimestampedValue(value1, ts3)}, } - if !reflect.DeepEqual(kvs, expKVs) { - t.Errorf("expected key values equal %v != %v", kvs, expKVs) + if !reflect.DeepEqual(res.KVs, expKVs) { + t.Errorf("expected key values equal %v != %v", res.Intents, expKVs) } }) } @@ -1834,22 +1831,22 @@ func TestMVCCDeleteRange(t *testing.T) { if expected := (roachpb.Span{Key: testKey4, EndKey: testKey6}); !resumeSpan.EqualValue(expected) { t.Fatalf("expected = %+v, resumeSpan = %+v", expected, resumeSpan) } - kvs, _, _, _ := unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, + res, _ := MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) - if len(kvs) != 4 || - !bytes.Equal(kvs[0].Key, testKey1) || - !bytes.Equal(kvs[1].Key, testKey4) || - !bytes.Equal(kvs[2].Key, testKey5) || - !bytes.Equal(kvs[3].Key, testKey6) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) || - !bytes.Equal(kvs[1].Value.RawBytes, value4.RawBytes) || - !bytes.Equal(kvs[2].Value.RawBytes, value5.RawBytes) || - !bytes.Equal(kvs[3].Value.RawBytes, value6.RawBytes) { + if len(res.KVs) != 4 || + !bytes.Equal(res.KVs[0].Key, testKey1) || + !bytes.Equal(res.KVs[1].Key, testKey4) || + !bytes.Equal(res.KVs[2].Key, testKey5) || + !bytes.Equal(res.KVs[3].Key, testKey6) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) || + !bytes.Equal(res.KVs[1].Value.RawBytes, value4.RawBytes) || + !bytes.Equal(res.KVs[2].Value.RawBytes, value5.RawBytes) || + !bytes.Equal(res.KVs[3].Value.RawBytes, value6.RawBytes) { t.Fatal("the value should not be empty") } // Try again, but with tombstones set to true to fetch the deleted keys as well. - kvs = []roachpb.KeyValue{} + kvs := []roachpb.KeyValue{} if _, err = MVCCIterate( ctx, engine, keyMin, keyMax, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{Tombstones: true}, func(kv roachpb.KeyValue) (bool, error) { @@ -1890,17 +1887,17 @@ func TestMVCCDeleteRange(t *testing.T) { if expected := (roachpb.Span{Key: testKey2, EndKey: testKey6}); !resumeSpan.EqualValue(expected) { t.Fatalf("expected = %+v, resumeSpan = %+v", expected, resumeSpan) } - kvs, _, _, _ = unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, + res, _ = MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) - if len(kvs) != 4 || - !bytes.Equal(kvs[0].Key, testKey1) || - !bytes.Equal(kvs[1].Key, testKey4) || - !bytes.Equal(kvs[2].Key, testKey5) || - !bytes.Equal(kvs[3].Key, testKey6) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) || - !bytes.Equal(kvs[1].Value.RawBytes, value4.RawBytes) || - !bytes.Equal(kvs[2].Value.RawBytes, value5.RawBytes) || - !bytes.Equal(kvs[3].Value.RawBytes, value6.RawBytes) { + if len(res.KVs) != 4 || + !bytes.Equal(res.KVs[0].Key, testKey1) || + !bytes.Equal(res.KVs[1].Key, testKey4) || + !bytes.Equal(res.KVs[2].Key, testKey5) || + !bytes.Equal(res.KVs[3].Key, testKey6) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) || + !bytes.Equal(res.KVs[1].Value.RawBytes, value4.RawBytes) || + !bytes.Equal(res.KVs[2].Value.RawBytes, value5.RawBytes) || + !bytes.Equal(res.KVs[3].Value.RawBytes, value6.RawBytes) { t.Fatal("the value should not be empty") } @@ -1918,11 +1915,11 @@ func TestMVCCDeleteRange(t *testing.T) { if resumeSpan != nil { t.Fatalf("wrong resume key: expected nil, found %v", resumeSpan) } - kvs, _, _, _ = unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, + res, _ = MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey1) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) { + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey1) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) { t.Fatal("the value should not be empty") } @@ -1940,9 +1937,9 @@ func TestMVCCDeleteRange(t *testing.T) { if resumeSpan != nil { t.Fatalf("wrong resume key: expected nil, found %v", resumeSpan) } - kvs, _, _, _ = unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, + res, _ = MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) - if len(kvs) != 0 { + if len(res.KVs) != 0 { t.Fatal("the value should be empty") } }) @@ -1998,17 +1995,17 @@ func TestMVCCDeleteRangeReturnKeys(t *testing.T) { if expected := (roachpb.Span{Key: testKey4, EndKey: testKey6}); !resumeSpan.EqualValue(expected) { t.Fatalf("expected = %+v, resumeSpan = %+v", expected, resumeSpan) } - kvs, _, _, _ := unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, + res, _ := MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) - if len(kvs) != 4 || - !bytes.Equal(kvs[0].Key, testKey1) || - !bytes.Equal(kvs[1].Key, testKey4) || - !bytes.Equal(kvs[2].Key, testKey5) || - !bytes.Equal(kvs[3].Key, testKey6) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) || - !bytes.Equal(kvs[1].Value.RawBytes, value4.RawBytes) || - !bytes.Equal(kvs[2].Value.RawBytes, value5.RawBytes) || - !bytes.Equal(kvs[3].Value.RawBytes, value6.RawBytes) { + if len(res.KVs) != 4 || + !bytes.Equal(res.KVs[0].Key, testKey1) || + !bytes.Equal(res.KVs[1].Key, testKey4) || + !bytes.Equal(res.KVs[2].Key, testKey5) || + !bytes.Equal(res.KVs[3].Key, testKey6) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) || + !bytes.Equal(res.KVs[1].Value.RawBytes, value4.RawBytes) || + !bytes.Equal(res.KVs[2].Value.RawBytes, value5.RawBytes) || + !bytes.Equal(res.KVs[3].Value.RawBytes, value6.RawBytes) { t.Fatal("the value should not be empty") } @@ -2027,17 +2024,17 @@ func TestMVCCDeleteRangeReturnKeys(t *testing.T) { if expected := (roachpb.Span{Key: testKey2, EndKey: testKey6}); !resumeSpan.EqualValue(expected) { t.Fatalf("expected = %+v, resumeSpan = %+v", expected, resumeSpan) } - kvs, _, _, _ = unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, + res, _ = MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) - if len(kvs) != 4 || - !bytes.Equal(kvs[0].Key, testKey1) || - !bytes.Equal(kvs[1].Key, testKey4) || - !bytes.Equal(kvs[2].Key, testKey5) || - !bytes.Equal(kvs[3].Key, testKey6) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) || - !bytes.Equal(kvs[1].Value.RawBytes, value4.RawBytes) || - !bytes.Equal(kvs[2].Value.RawBytes, value5.RawBytes) || - !bytes.Equal(kvs[3].Value.RawBytes, value6.RawBytes) { + if len(res.KVs) != 4 || + !bytes.Equal(res.KVs[0].Key, testKey1) || + !bytes.Equal(res.KVs[1].Key, testKey4) || + !bytes.Equal(res.KVs[2].Key, testKey5) || + !bytes.Equal(res.KVs[3].Key, testKey6) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) || + !bytes.Equal(res.KVs[1].Value.RawBytes, value4.RawBytes) || + !bytes.Equal(res.KVs[2].Value.RawBytes, value5.RawBytes) || + !bytes.Equal(res.KVs[3].Value.RawBytes, value6.RawBytes) { t.Fatal("the value should not be empty") } @@ -2064,11 +2061,11 @@ func TestMVCCDeleteRangeReturnKeys(t *testing.T) { if resumeSpan != nil { t.Fatalf("wrong resume key: expected nil, found %v", resumeSpan) } - kvs, _, _, _ = unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, + res, _ = MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey1) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) { + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey1) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) { t.Fatal("the value should not be empty") } @@ -2089,9 +2086,9 @@ func TestMVCCDeleteRangeReturnKeys(t *testing.T) { if resumeSpan != nil { t.Fatalf("wrong resume key: %v", resumeSpan) } - kvs, _, _, _ = unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, + res, _ = MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) - if len(kvs) != 0 { + if len(res.KVs) != 0 { t.Fatal("the value should be empty") } }) @@ -2214,10 +2211,10 @@ func TestMVCCUncommittedDeleteRangeVisible(t *testing.T) { } txn.Epoch++ - kvs, _, _, _ := unwrapMVCCScan(ctx, engine, testKey1, testKey4, math.MaxInt64, + res, _ := MVCCScan(ctx, engine, testKey1, testKey4, math.MaxInt64, hlc.Timestamp{WallTime: 3}, MVCCScanOptions{Txn: txn}) - if e := 2; len(kvs) != e { - t.Fatalf("e = %d, got %d", e, len(kvs)) + if e := 2; len(res.KVs) != e { + t.Fatalf("e = %d, got %d", e, len(res.KVs)) } }) } @@ -2312,21 +2309,21 @@ func TestMVCCDeleteRangeInline(t *testing.T) { Value: value6, }, } - kvs, _, _, err := unwrapMVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, + res, err := MVCCScan(ctx, engine, keyMin, keyMax, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{}) if err != nil { t.Fatal(err) } - if a, e := len(kvs), len(expectedKvs); a != e { + if a, e := len(res.KVs), len(expectedKvs); a != e { t.Fatalf("engine scan found %d keys; expected %d", a, e) } - kvs[3].Value.Timestamp = hlc.Timestamp{} - if !reflect.DeepEqual(expectedKvs, kvs) { + res.KVs[3].Value.Timestamp = hlc.Timestamp{} + if !reflect.DeepEqual(expectedKvs, res.KVs) { t.Fatalf( "engine scan found key/values: %v; expected %v. Diff: %s", - kvs, + res.KVs, expectedKvs, - pretty.Diff(kvs, expectedKvs), + pretty.Diff(res.KVs, expectedKvs), ) } }) @@ -2394,9 +2391,9 @@ func TestMVCCClearTimeRange(t *testing.T) { assertKVs := func(t *testing.T, reader Reader, at hlc.Timestamp, expected []roachpb.KeyValue) { t.Helper() - actual, _, _, err := unwrapMVCCScan(ctx, reader, keyMin, keyMax, 100, at, MVCCScanOptions{}) + res, err := MVCCScan(ctx, reader, keyMin, keyMax, 100, at, MVCCScanOptions{}) require.NoError(t, err) - require.Equal(t, expected, actual) + require.Equal(t, expected, res.KVs) } t.Run("clear > ts0", func(t *testing.T) { @@ -2521,19 +2518,19 @@ func TestMVCCClearTimeRange(t *testing.T) { // Scan (< k3 to avoid intent) to confirm that k2 was indeed reverted to // value as of ts3 (i.e. v4 was cleared to expose v2). - actual, _, _, err := unwrapMVCCScan(ctx, e, keyMin, testKey3, 100, ts5, MVCCScanOptions{}) + res, err := MVCCScan(ctx, e, keyMin, testKey3, 100, ts5, MVCCScanOptions{}) require.NoError(t, err) - require.Equal(t, ts3Content[:2], actual) + require.Equal(t, ts3Content[:2], res.KVs) // Verify the intent was left alone. - _, _, _, err = unwrapMVCCScan(ctx, e, testKey3, testKey4, 100, ts5, MVCCScanOptions{}) + _, err = MVCCScan(ctx, e, testKey3, testKey4, 100, ts5, MVCCScanOptions{}) require.Error(t, err) // Scan (> k3 to avoid intent) to confirm that k5 was indeed reverted to // value as of ts3 (i.e. v4 was cleared to expose v2). - actual, _, _, err = unwrapMVCCScan(ctx, e, testKey4, keyMax, 100, ts5, MVCCScanOptions{}) + res, err = MVCCScan(ctx, e, testKey4, keyMax, 100, ts5, MVCCScanOptions{}) require.NoError(t, err) - require.Equal(t, ts3Content[2:], actual) + require.Equal(t, ts3Content[2:], res.KVs) }) t.Run("clear below intent", func(t *testing.T) { @@ -2645,7 +2642,7 @@ func TestMVCCClearTimeRangeOnRandomData(t *testing.T) { t.Run(fmt.Sprintf("revert-%d", i), func(t *testing.T) { revertTo := hlc.Timestamp{WallTime: int64(reverts[i])} // MVCC-Scan at the revert time. - scannedBefore, _, _, err := unwrapMVCCScan(ctx, e, keyMin, keyMax, numKVs, revertTo, MVCCScanOptions{}) + resBefore, err := MVCCScan(ctx, e, keyMin, keyMax, numKVs, revertTo, MVCCScanOptions{}) require.NoError(t, err) // Revert to the revert time. @@ -2662,9 +2659,9 @@ func TestMVCCClearTimeRangeOnRandomData(t *testing.T) { require.Equal(t, computeStats(t, e, keyMin, keyMax, 2000), ms) // Scanning at "now" post-revert should yield the same result as scanning // at revert-time pre-revert. - scannedAfter, _, _, err := unwrapMVCCScan(ctx, e, keyMin, keyMax, numKVs, now, MVCCScanOptions{}) + resAfter, err := MVCCScan(ctx, e, keyMin, keyMax, numKVs, now, MVCCScanOptions{}) require.NoError(t, err) - require.Equal(t, scannedBefore, scannedAfter) + require.Equal(t, resBefore.KVs, resAfter.KVs) }) } }) @@ -2859,90 +2856,90 @@ func TestMVCCReverseScan(t *testing.T) { t.Fatal(err) } - kvs, resumeSpan, _, err := unwrapMVCCScan(ctx, engine, testKey2, testKey4, math.MaxInt64, + res, err := MVCCScan(ctx, engine, testKey2, testKey4, math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 2 || - !bytes.Equal(kvs[0].Key, testKey3) || - !bytes.Equal(kvs[1].Key, testKey2) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) || - !bytes.Equal(kvs[1].Value.RawBytes, value3.RawBytes) { - t.Fatalf("unexpected value: %v", kvs) + if len(res.KVs) != 2 || + !bytes.Equal(res.KVs[0].Key, testKey3) || + !bytes.Equal(res.KVs[1].Key, testKey2) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) || + !bytes.Equal(res.KVs[1].Value.RawBytes, value3.RawBytes) { + t.Fatalf("unexpected value: %v", res.KVs) } - if resumeSpan != nil { - t.Fatalf("resumeSpan = %+v", resumeSpan) + if res.ResumeSpan != nil { + t.Fatalf("resumeSpan = %+v", res.ResumeSpan) } - kvs, resumeSpan, _, err = unwrapMVCCScan(ctx, engine, testKey2, testKey4, 1, hlc.Timestamp{WallTime: 1}, + res, err = MVCCScan(ctx, engine, testKey2, testKey4, 1, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey3) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) { - t.Fatalf("unexpected value: %v", kvs) + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey3) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) { + t.Fatalf("unexpected value: %v", res.KVs) } - if expected := (roachpb.Span{Key: testKey2, EndKey: testKey2.Next()}); !resumeSpan.EqualValue(expected) { - t.Fatalf("expected = %+v, resumeSpan = %+v", expected, resumeSpan) + if expected := (roachpb.Span{Key: testKey2, EndKey: testKey2.Next()}); !res.ResumeSpan.EqualValue(expected) { + t.Fatalf("expected = %+v, resumeSpan = %+v", expected, res.ResumeSpan) } - kvs, resumeSpan, _, err = unwrapMVCCScan(ctx, engine, testKey2, testKey4, 0, hlc.Timestamp{WallTime: 1}, + res, err = MVCCScan(ctx, engine, testKey2, testKey4, 0, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 0 { - t.Fatalf("unexpected value: %v", kvs) + if len(res.KVs) != 0 { + t.Fatalf("unexpected value: %v", res.KVs) } - if expected := (roachpb.Span{Key: testKey2, EndKey: testKey4}); !resumeSpan.EqualValue(expected) { - t.Fatalf("expected = %+v, resumeSpan = %+v", expected, resumeSpan) + if expected := (roachpb.Span{Key: testKey2, EndKey: testKey4}); !res.ResumeSpan.EqualValue(expected) { + t.Fatalf("expected = %+v, resumeSpan = %+v", expected, res.ResumeSpan) } // The first key we encounter has multiple versions and we need to read the // latest. - kvs, _, _, err = unwrapMVCCScan(ctx, engine, testKey2, testKey3, 1, hlc.Timestamp{WallTime: 4}, + res, err = MVCCScan(ctx, engine, testKey2, testKey3, 1, hlc.Timestamp{WallTime: 4}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey2) || - !bytes.Equal(kvs[0].Value.RawBytes, value4.RawBytes) { - t.Errorf("unexpected value: %v", kvs) + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey2) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value4.RawBytes) { + t.Errorf("unexpected value: %v", res.KVs) } // The first key we encounter is newer than our read timestamp and we need to // back up to the previous key. - kvs, _, _, err = unwrapMVCCScan(ctx, engine, testKey4, testKey6, 1, hlc.Timestamp{WallTime: 1}, + res, err = MVCCScan(ctx, engine, testKey4, testKey6, 1, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey4) || - !bytes.Equal(kvs[0].Value.RawBytes, value2.RawBytes) { - t.Fatalf("unexpected value: %v", kvs) + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey4) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value2.RawBytes) { + t.Fatalf("unexpected value: %v", res.KVs) } // Scan only the first key in the key space. - kvs, _, _, err = unwrapMVCCScan(ctx, engine, testKey1, testKey1.Next(), 1, hlc.Timestamp{WallTime: 1}, + res, err = MVCCScan(ctx, engine, testKey1, testKey1.Next(), 1, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey1) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) { - t.Fatalf("unexpected value: %v", kvs) + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey1) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) { + t.Fatalf("unexpected value: %v", res.KVs) } }) } @@ -2976,15 +2973,15 @@ func TestMVCCReverseScanFirstKeyInFuture(t *testing.T) { t.Fatal(err) } - kvs, _, _, err := unwrapMVCCScan(ctx, engine, testKey1, testKey4, math.MaxInt64, + res, err := MVCCScan(ctx, engine, testKey1, testKey4, math.MaxInt64, hlc.Timestamp{WallTime: 2}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey2) || - !bytes.Equal(kvs[0].Value.RawBytes, value2.RawBytes) { - t.Errorf("unexpected value: %v", kvs) + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey2) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value2.RawBytes) { + t.Errorf("unexpected value: %v", res.KVs) } }) } @@ -3017,14 +3014,14 @@ func TestMVCCReverseScanSeeksOverRepeatedKeys(t *testing.T) { t.Fatal(err) } - kvs, _, _, err := unwrapMVCCScan(ctx, engine, testKey1, testKey3, math.MaxInt64, + res, err := MVCCScan(ctx, engine, testKey1, testKey3, math.MaxInt64, hlc.Timestamp{WallTime: 1}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey2) || - !bytes.Equal(kvs[0].Value.RawBytes, value2.RawBytes) { + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey2) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value2.RawBytes) { t.Fatal("unexpected scan results") } }) @@ -3064,14 +3061,14 @@ func TestMVCCReverseScanStopAtSmallestKey(t *testing.T) { } } - kvs, _, _, err := unwrapMVCCScan(ctx, engine, testKey1, testKey3, math.MaxInt64, + res, err := MVCCScan(ctx, engine, testKey1, testKey3, math.MaxInt64, hlc.Timestamp{WallTime: ts}, MVCCScanOptions{Reverse: true}) if err != nil { t.Fatal(err) } - if len(kvs) != 1 || - !bytes.Equal(kvs[0].Key, testKey1) || - !bytes.Equal(kvs[0].Value.RawBytes, value1.RawBytes) { + if len(res.KVs) != 1 || + !bytes.Equal(res.KVs[0].Key, testKey1) || + !bytes.Equal(res.KVs[0].Value.RawBytes, value1.RawBytes) { t.Fatal("unexpected scan results") } }