Skip to content

Commit

Permalink
manifest: cleaner implementation of assertNotL0Cmp
Browse files Browse the repository at this point in the history
I verified that the assertion works (by undoing the TestExcise fix in
the previous PR).
  • Loading branch information
RaduBerinde committed Apr 1, 2024
1 parent 1c7bcd1 commit d3f89bf
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions internal/manifest/level_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package manifest
import (
"bytes"
"fmt"
"reflect"

"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/invariants"
Expand Down Expand Up @@ -558,7 +559,7 @@ func (i *LevelIterator) SeekGE(cmp Compare, userKey []byte) *FileMetadata {
return nil
}
if invariants.Enabled {
i.assertNotL0Cmp(userKey)
i.assertNotL0Cmp()
}
m := i.seek(func(m *FileMetadata) bool {
return cmp(m.Largest.UserKey, userKey) >= 0
Expand All @@ -579,14 +580,9 @@ func (i *LevelIterator) SeekGE(cmp Compare, userKey []byte) *FileMetadata {
// assertNotL0Cmp verifies that the btree associated with the iterator is
// ordered by Smallest key (i.e. L1+ or L0 sublevel) and not by LargestSeqNum
// (L0).
//
// userKey is an arbitrary valid key.
func (i *LevelIterator) assertNotL0Cmp(userKey []byte) {
k := base.MakeInternalKey(userKey, 1, base.InternalKeyKindSet)
a := FileMetadata{Smallest: k, LargestSeqNum: 10}
b := FileMetadata{Smallest: k, LargestSeqNum: 100}
if i.iter.cmp(&a, &b) != 0 {
panic("SeekGE used with btreeCmpSeqNum")
func (i *LevelIterator) assertNotL0Cmp() {
if reflect.ValueOf(i.iter.cmp).Pointer() == reflect.ValueOf(btreeCmpSeqNum).Pointer() {
panic("Seek used with btreeCmpSeqNum")
}
}

Expand All @@ -599,7 +595,7 @@ func (i *LevelIterator) SeekLT(cmp Compare, userKey []byte) *FileMetadata {
return nil
}
if invariants.Enabled {
i.assertNotL0Cmp(userKey)
i.assertNotL0Cmp()
}
i.seek(func(m *FileMetadata) bool {
return cmp(m.Smallest.UserKey, userKey) >= 0
Expand Down

0 comments on commit d3f89bf

Please sign in to comment.