Skip to content

Commit

Permalink
Fix Get to handle bitcask.ErrKeyNotFound errors for non-existent keys
Browse files Browse the repository at this point in the history
  • Loading branch information
prologic committed Oct 23, 2023
1 parent 297eb96 commit ab35bdd
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions store/bitcask/bitcask.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
package bitcask

import (
"path/filepath"

"git.mills.io/prologic/bitcask"
"github.com/ostafen/clover/v2/store"
)
Expand All @@ -12,13 +10,9 @@ type bitcaskStore struct {
db *bitcask.Bitcask
}

const (
dbFileName = "data.db"
)

// Open ...
func Open(dir string) (store.Store, error) {
db, err := bitcask.Open(filepath.Join(dir, dbFileName))
db, err := bitcask.Open(dir)
if err != nil {
return nil, err
}
Expand All @@ -42,7 +36,12 @@ func (tx *bitcaskTx) Set(key, value []byte) error {
}

func (tx *bitcaskTx) Get(key []byte) ([]byte, error) {
return tx.Bitcask.Get(key)
value, err := tx.Bitcask.Get(key)
// XXX: Clover assumes non-nil errors even for "Key Not Found" (which Bitcask considers an error)
if err == bitcask.ErrKeyExpired {
return nil, nil
}
return value, nil
}

func (tx *bitcaskTx) Delete(key []byte) error {
Expand Down

0 comments on commit ab35bdd

Please sign in to comment.