From 50d3971e86184ae117d0e33e57105cd89f5e1e3d Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Mon, 2 Sep 2019 19:44:11 +1000 Subject: [PATCH] Fixed a bug with incorrect offsets populating the trie (#82) --- bitcask.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bitcask.go b/bitcask.go index aedccce..30f7cb9 100644 --- a/bitcask.go +++ b/bitcask.go @@ -356,6 +356,7 @@ func (b *Bitcask) reopen() error { } } else { for i, df := range datafiles { + var offset int64 for { e, n, err := df.Read() if err != nil { @@ -368,11 +369,13 @@ func (b *Bitcask) reopen() error { // Tombstone value (deleted key) if len(e.Value) == 0 { t.Delete(e.Key) + offset += n 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) + offset += n } } }