2020-09-02 12:58:57 +08:00
|
|
|
package leveldb
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-07-29 15:17:28 +08:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
2020-09-02 13:48:23 +08:00
|
|
|
"github.com/syndtr/goleveldb/leveldb"
|
2020-09-02 12:58:57 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (store *LevelDBStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
|
|
|
|
|
|
|
|
err = store.db.Put(key, value, nil)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("kv put: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *LevelDBStore) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
|
|
|
|
|
|
|
|
value, err = store.db.Get(key, nil)
|
|
|
|
|
2020-09-02 13:48:23 +08:00
|
|
|
if err == leveldb.ErrNotFound {
|
|
|
|
return nil, filer.ErrKvNotFound
|
|
|
|
}
|
|
|
|
|
2020-09-02 12:58:57 +08:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("kv get: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (store *LevelDBStore) KvDelete(ctx context.Context, key []byte) (err error) {
|
|
|
|
|
|
|
|
err = store.db.Delete(key, nil)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("kv delete: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|