mirror of
https://github.com/chaisql/chai.git
synced 2025-12-24 11:30:53 +08:00
Fix successor with empty keys
This commit is contained in:
@@ -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",
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user