1
0
mirror of https://github.com/taigrr/bitcask synced 2025-01-18 04:03:17 -08:00

Improve read performance by ~6x for active Datafile by not reopening it each time

This commit is contained in:
James Mills 2019-03-13 07:41:00 +10:00
parent 4b52dea172
commit 904f6b19a0
No known key found for this signature in database
GPG Key ID: AC4C014F1440EBD6

View File

@ -43,11 +43,22 @@ func (b *Bitcask) Get(key string) ([]byte, error) {
return nil, ErrKeyNotFound
}
df, err := NewDatafile(b.path, item.FileID, true)
if err != nil {
return nil, err
var (
df *Datafile
err error
)
// Optimization
if item.FileID == b.curr.id {
df = b.curr
} else {
// TODO: Pre-open non-active Datafiles and cache the file pointers?
df, err = NewDatafile(b.path, item.FileID, true)
if err != nil {
return nil, err
}
defer df.Close()
}
defer df.Close()
e, err := df.ReadAt(item.Index)
if err != nil {