Skip to content

Commit

Permalink
storage: respect new Pebble iterator visibility
Browse files Browse the repository at this point in the history
Pebble recently tightened its iterator semantics such that it has a
static view of the underlying reader as of the time of its creation.
Previously, a batch iterator could see batch writes that occurred after
the iterator was created.

This patch prepares CRDB for this change.

Release note: None
  • Loading branch information
erikgrinaker committed May 23, 2022
1 parent 9ac8818 commit 4c35637
Showing 1 changed file with 0 additions and 67 deletions.
67 changes: 0 additions & 67 deletions pkg/storage/mvcc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,73 +951,6 @@ func TestMVCCInvalidateIterator(t *testing.T) {
}
}

func TestMVCCPutAfterBatchIterCreate(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

for _, engineImpl := range mvccEngineImpls {
t.Run(engineImpl.name, func(t *testing.T) {
engine := engineImpl.create()
defer engine.Close()

value := MVCCValue{Value: roachpb.MakeValueFromString("foobar")}
err := engine.PutMVCC(MVCCKey{Key: testKey1, Timestamp: hlc.Timestamp{WallTime: 5}}, value)
if err != nil {
t.Fatal(err)
}
err = engine.PutMVCC(MVCCKey{Key: testKey2, Timestamp: hlc.Timestamp{WallTime: 5}}, value)
if err != nil {
t.Fatal(err)
}
err = engine.PutMVCC(MVCCKey{Key: testKey2, Timestamp: hlc.Timestamp{WallTime: 3}}, value)
if err != nil {
t.Fatal(err)
}
err = engine.PutMVCC(MVCCKey{Key: testKey3, Timestamp: hlc.Timestamp{WallTime: 5}}, value)
if err != nil {
t.Fatal(err)
}
err = engine.PutMVCC(MVCCKey{Key: testKey4, Timestamp: hlc.Timestamp{WallTime: 5}}, value)
if err != nil {
t.Fatal(err)
}

batch := engine.NewBatch()
defer batch.Close()
txn := &roachpb.Transaction{
TxnMeta: enginepb.TxnMeta{
WriteTimestamp: hlc.Timestamp{WallTime: 10},
},
Name: "test",
Status: roachpb.PENDING,
ReadTimestamp: hlc.Timestamp{WallTime: 10},
GlobalUncertaintyLimit: hlc.Timestamp{WallTime: 10},
}
iter := batch.NewMVCCIterator(MVCCKeyAndIntentsIterKind, IterOptions{
LowerBound: testKey1,
UpperBound: testKey5,
})
defer iter.Close()
iter.SeekGE(MVCCKey{Key: testKey1, Timestamp: hlc.Timestamp{WallTime: 5}})
iter.Next() // key2/5

// Lay down an intent on key3, which will go at key3/0 and sort before key3/5.
err = MVCCDelete(context.Background(), batch, nil, testKey3, txn.WriteTimestamp, hlc.ClockTimestamp{}, txn)
if err != nil {
t.Fatal(err)
}
iter.SeekGE(MVCCKey{Key: testKey3})
if ok, err := iter.Valid(); !ok || err != nil {
t.Fatalf("expected valid iter: ok %t, err %s", ok, err.Error())
}
// Should see the intent.
if iter.UnsafeKey().IsValue() {
t.Fatalf("expected iterator to land on an intent, got a value: %v", iter.UnsafeKey())
}
})
}
}

func mvccScanTest(ctx context.Context, t *testing.T, engine Engine) {
if err := MVCCPut(ctx, engine, nil, testKey1, hlc.Timestamp{WallTime: 1}, hlc.ClockTimestamp{}, value1, nil); err != nil {
t.Fatal(err)
Expand Down

0 comments on commit 4c35637

Please sign in to comment.