Skip to content

Commit

Permalink
fix: level handler - key with zero version can never be found
Browse files Browse the repository at this point in the history
  • Loading branch information
agfn committed Nov 8, 2023
1 parent fb1b009 commit 3a299d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion level_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func (s *levelHandler) get(key []byte) (y.ValueStruct, error) {
continue
}
if y.SameKey(key, it.Key()) {
if version := y.ParseTs(it.Key()); maxVs.Version < version {
if version := y.ParseTs(it.Key()); maxVs.Version < version || maxVs.Value == nil {
maxVs = it.ValueCopy()
maxVs.Version = version
}
Expand Down
15 changes: 15 additions & 0 deletions levels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,21 @@ func TestLevelGet(t *testing.T) {
{"foo", "bar10", 11, 0}, // Should return biggest version.
},
},
{
"zero version",
map[int][][]keyValVersion{
0: { // Level 1 has 1 table with a single key.
{{"fool0", "barl0", 0, 0}},
},
1: { // Level 1 has 1 table with a single key.
{{"foo", "bar", 0, 0}},
},
},
[]keyValVersion{
{"fool0", "barl0", 0, 0},
{"foo", "bar", 0, 0},
},
},
}
for _, ti := range tt {
t.Run(ti.name, func(t *testing.T) {
Expand Down

0 comments on commit 3a299d3

Please sign in to comment.