Skip to content

Instantly share code, notes, and snippets.

@petermattis
Created April 19, 2019 15:10
Show Gist options
  • Save petermattis/ea649419688e70ffda0b181e90493dec to your computer and use it in GitHub Desktop.
Save petermattis/ea649419688e70ffda0b181e90493dec to your computer and use it in GitHub Desktop.
func TestBadStats(t *testing.T) {
defer leaktest.AfterTest(t)()
stopper := stop.NewStopper()
defer stopper.Stop(context.TODO())
e := NewInMem(roachpb.Attributes{}, 1<<20)
stopper.AddCloser(e)
func() {
b := e.NewBatch()
defer b.Close()
ctx := context.Background()
// Add an intent and a deletion tombstone.
if err := MVCCDelete(ctx, b, nil, roachpb.Key("foo"), txn1.Timestamp, txn1); err != nil {
t.Fatal(err)
}
// Whack in an additional versioned key that is newer than the deletion
// tombstone. The use of blind put disables the normal MVCC checks that
// would prohibit this situation.
ts := hlc.Timestamp{Logical: 2}
if err := MVCCBlindPut(ctx, b, nil, roachpb.Key("foo"), ts, roachpb.MakeValueFromBytes(nil), nil); err != nil {
t.Fatal(err)
}
if err := b.Commit(false); err != nil {
t.Fatal(err)
}
}()
func() {
iter := e.NewIterator(IterOptions{LowerBound: roachpb.KeyMin, UpperBound: roachpb.KeyMax})
defer iter.Close()
for iter.Seek(NilKey); ; iter.Next() {
if valid, err := iter.Valid(); err != nil {
t.Fatal(err)
} else if !valid {
break
}
fmt.Printf("%s %d\n", iter.UnsafeKey(), len(iter.UnsafeValue()))
}
// "foo" 41
// "foo"/0.000000000,2 5
// "foo"/0.000000000,1 0
// Boom!
ms, err := iter.ComputeStats(NilKey, MVCCKeyMax, 0)
if err != nil {
t.Fatal(err)
}
fmt.Printf("%+v\n", ms)
}()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment