Fixed a bug with incorrect offsets populating the trie (#82)

This commit is contained in:
James Mills 2019-09-02 19:44:11 +10:00 committed by GitHub
parent 0338755f8c
commit 50d3971e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -356,6 +356,7 @@ func (b *Bitcask) reopen() error {
} }
} else { } else {
for i, df := range datafiles { for i, df := range datafiles {
var offset int64
for { for {
e, n, err := df.Read() e, n, err := df.Read()
if err != nil { if err != nil {
@ -368,11 +369,13 @@ func (b *Bitcask) reopen() error {
// Tombstone value (deleted key) // Tombstone value (deleted key)
if len(e.Value) == 0 { if len(e.Value) == 0 {
t.Delete(e.Key) t.Delete(e.Key)
offset += n
continue continue
} }
item := internal.Item{FileID: ids[i], Offset: e.Offset, Size: n} item := internal.Item{FileID: ids[i], Offset: offset, Size: n}
t.Insert(e.Key, item) t.Insert(e.Key, item)
offset += n
} }
} }
} }