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:
parent
4b52dea172
commit
904f6b19a0
19
bitcask.go
19
bitcask.go
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user