Fix successor with empty keys

This commit is contained in:
Asdine El Hrychy
2022-06-17 19:01:04 +04:00
parent c0c9567029
commit e6002cc22b
3 changed files with 5 additions and 45 deletions

View File

@@ -1,8 +1,6 @@
package pebble
import (
"fmt"
"github.com/cockroachdb/pebble"
"github.com/genjidb/genji/internal/encoding"
)
@@ -31,45 +29,3 @@ var DefaultComparer = &pebble.Comparer{
// format, and should not be changed.
Name: "leveldb.BytewiseComparator",
}
var stats = struct {
SuccessorCount int
SeparatorCount int
CompareCount int
EqualCount int
AbbrevCount int
FormatKeyCount int
}{}
// DefaultComparer is the default implementation of the Comparer interface for Genji.
func WithStats(cmp *pebble.Comparer) *pebble.Comparer {
return &pebble.Comparer{
Compare: func(a, b []byte) int {
stats.CompareCount++
return cmp.Compare(a, b)
},
Equal: func(a, b []byte) bool {
stats.EqualCount++
return cmp.Equal(a, b)
},
AbbreviatedKey: func(key []byte) uint64 {
stats.AbbrevCount++
return cmp.AbbreviatedKey(key)
},
FormatKey: func(key []byte) fmt.Formatter {
stats.FormatKeyCount++
return cmp.FormatKey(key)
},
Separator: func(dst, a, b []byte) []byte {
stats.SeparatorCount++
return cmp.Separator(dst, a, b)
},
Successor: func(dst, a []byte) []byte {
stats.SuccessorCount++
return cmp.Successor(dst, a)
},
// This name is part of the C++ Level-DB implementation's default file
// format, and should not be changed.
Name: "leveldb.BytewiseComparator",
}
}

View File

@@ -79,7 +79,7 @@ func TestPebbleBatchSet(t *testing.T) {
var opts pebble.Options
opts.FS = vfs.NewMem()
opts.Comparer = WithStats(DefaultComparer)
opts.Comparer = DefaultComparer
db, err := Open("", &opts)
require.NoError(t, err)

View File

@@ -240,6 +240,10 @@ func compareNextValue(a, b []byte) (cmp int, n int) {
}
func Successor(dst, a []byte) []byte {
if len(a) == 0 {
return a
}
namespace, _ := DecodeInt(a)
if namespace == math.MaxInt64 {
return a