Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: amend BenchmarkRangeDelIterate #1071

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 79 additions & 59 deletions range_del_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,70 +452,90 @@ func BenchmarkRangeDelIterate(b *testing.B) {
b.Run(fmt.Sprintf("entries=%d", entries), func(b *testing.B) {
for _, deleted := range []int{entries, entries - 1} {
b.Run(fmt.Sprintf("deleted=%d", deleted), func(b *testing.B) {
mem := vfs.NewMem()
cache := NewCache(128 << 20) // 128 MB
defer cache.Unref()

d, err := Open("", &Options{
Cache: cache,
FS: mem,
DebugCheck: DebugCheckLevels,
})
if err != nil {
b.Fatal(err)
for _, snapshotCompact := range []bool{false, true} {
b.Run(fmt.Sprintf("snapshotAndCompact=%t", snapshotCompact), func(b *testing.B) {
benchmarkRangeDelIterate(b, entries, deleted, snapshotCompact)
})
}
defer d.Close()
})
}
})
}
}

makeKey := func(i int) []byte {
return []byte(fmt.Sprintf("%09d", i))
}
func benchmarkRangeDelIterate(b *testing.B, entries, deleted int, snapshotCompact bool) {
mem := vfs.NewMem()
cache := NewCache(128 << 20) // 128 MB
defer cache.Unref()

// Create an sstable with N entries and ingest it. This is a fast way
// to get a lot of entries into pebble.
f, err := mem.Create("ext")
if err != nil {
b.Fatal(err)
}
w := sstable.NewWriter(f, sstable.WriterOptions{
BlockSize: 32 << 10, // 32 KB
})
for i := 0; i < entries; i++ {
key := base.MakeInternalKey(makeKey(i), 0, InternalKeyKindSet)
if err := w.Add(key, nil); err != nil {
b.Fatal(err)
}
}
if err := w.Close(); err != nil {
b.Fatal(err)
}
if err := d.Ingest([]string{"ext"}); err != nil {
b.Fatal(err)
}
d, err := Open("", &Options{
Cache: cache,
FS: mem,
DebugCheck: DebugCheckLevels,
})
if err != nil {
b.Fatal(err)
}
defer d.Close()

// Create a range tombstone that deletes most (or all) of those entries.
from := makeKey(0)
to := makeKey(deleted)
if err := d.DeleteRange(from, to, nil); err != nil {
b.Fatal(err)
}
makeKey := func(i int) []byte {
return []byte(fmt.Sprintf("%09d", i))
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
iter := d.NewIter(nil)
iter.SeekGE(from)
if deleted < entries {
if !iter.Valid() {
b.Fatal("key not found")
}
} else if iter.Valid() {
b.Fatal("unexpected key found")
}
if err := iter.Close(); err != nil {
b.Fatal(err)
}
}
})
// Create an sstable with N entries and ingest it. This is a fast way
// to get a lot of entries into pebble.
f, err := mem.Create("ext")
if err != nil {
b.Fatal(err)
}
w := sstable.NewWriter(f, sstable.WriterOptions{
BlockSize: 32 << 10, // 32 KB
})
for i := 0; i < entries; i++ {
key := base.MakeInternalKey(makeKey(i), 0, InternalKeyKindSet)
if err := w.Add(key, nil); err != nil {
b.Fatal(err)
}
}
if err := w.Close(); err != nil {
b.Fatal(err)
}
if err := d.Ingest([]string{"ext"}); err != nil {
b.Fatal(err)
}

// Some benchmarks test snapshots that force the range tombstone into the
// same level as the covered data.
// See https://github.com/cockroachdb/pebble/issues/1070.
if snapshotCompact {
s := d.NewSnapshot()
defer func() { require.NoError(b, s.Close()) }()
}

// Create a range tombstone that deletes most (or all) of those entries.
from := makeKey(0)
to := makeKey(deleted)
if err := d.DeleteRange(from, to, nil); err != nil {
b.Fatal(err)
}

if snapshotCompact {
require.NoError(b, d.Compact(makeKey(0), makeKey(entries)))
}

b.ResetTimer()
for i := 0; i < b.N; i++ {
iter := d.NewIter(nil)
iter.SeekGE(from)
if deleted < entries {
if !iter.Valid() {
b.Fatal("key not found")
}
})
} else if iter.Valid() {
b.Fatal("unexpected key found")
}
if err := iter.Close(); err != nil {
b.Fatal(err)
}
}
}