Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ func (opt *IteratorOptions) pickTable(t table.TableInterface) bool {
}
return key
}
if bytes.Compare(trim(t.Smallest()), opt.Prefix) > 0 {
if bytes.Compare(trim(y.ParseKey(t.Smallest())), opt.Prefix) > 0 {
return false
}
if bytes.Compare(trim(t.Biggest()), opt.Prefix) < 0 {
if bytes.Compare(trim(y.ParseKey(t.Biggest())), opt.Prefix) < 0 {
return false
}
// Bloom filter lookup would only work if opt.Prefix does NOT have the read
Expand Down
26 changes: 15 additions & 11 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,25 @@ func (tm *tableMock) DoesNotHave(key []byte) bool { return false }
func TestPickTables(t *testing.T) {
opt := DefaultIteratorOptions

within := func(prefix, left, right string) {
opt.Prefix = []byte(prefix)
tm := &tableMock{left: []byte(left), right: []byte(right)}
require.True(t, opt.pickTable(tm))
within := func(prefix, left, right []byte) {
opt.Prefix = prefix
// PickTable expects smallest and biggest to contain timestamps.
tm := &tableMock{left: y.KeyWithTs(left, 1), right: y.KeyWithTs(right, 1)}
require.True(t, opt.pickTable(tm), "within failed for %b %b %b\n", prefix, left, right)
}
outside := func(prefix, left, right string) {
opt.Prefix = []byte(prefix)
tm := &tableMock{left: []byte(left), right: []byte(right)}
require.False(t, opt.pickTable(tm))
// PickTable expects smallest and biggest to contain timestamps.
tm := &tableMock{left: y.KeyWithTs([]byte(left), 1), right: y.KeyWithTs([]byte(right), 1)}
require.False(t, opt.pickTable(tm), "outside failed for %b %b %b", prefix, left, right)
}
within("abc", "ab", "ad")
within("abc", "abc", "ad")
within("abc", "abb123", "ad")
within("abc", "abc123", "abd234")
within("abc", "abc123", "abc456")
within([]byte("abc"), []byte("ab"), []byte("ad"))
within([]byte("abc"), []byte("abc"), []byte("ad"))
within([]byte("abc"), []byte("abb123"), []byte("ad"))
within([]byte("abc"), []byte("abc123"), []byte("abd234"))
within([]byte("abc"), []byte("abc123"), []byte("abc456"))
// Regression test for https://github.com/dgraph-io/badger/issues/992
within([]byte{0, 0, 1}, []byte{0}, []byte{0, 0, 1})

outside("abd", "abe", "ad")
outside("abd", "ac", "ad")
Expand Down
5 changes: 3 additions & 2 deletions table/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type blockIterator struct {
entryOffsets []uint32

// prevOverlap stores the overlap of the previous key with the base key.
// This avoids unnecssary copy of base key when the overlap is same for multiple keys.
// This avoids unnecessary copy of base key when the overlap is same for multiple keys.
prevOverlap uint16
}

Expand Down Expand Up @@ -341,7 +341,8 @@ func (itr *Iterator) prev() {
}
}

// Key follows the y.Iterator interface
// Key follows the y.Iterator interface.
// Returns the key with timestamp.
func (itr *Iterator) Key() []byte {
return itr.bi.key
}
Expand Down
2 changes: 1 addition & 1 deletion table/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type Table struct {
mmap []byte // Memory mapped.

// The following are initialized once and const.
smallest, biggest []byte // Smallest and largest keys.
smallest, biggest []byte // Smallest and largest keys (with timestamps).
id uint64 // file id, part of filename

bf *z.Bloom
Expand Down