seaweedfs/weed/filer/leveldb2/leveldb2_store_kv.go
Chris Lu 37234bf3f8 filer store adds kv support
can compile now, need to implement those unimplemented
2020-09-01 21:59:00 -07:00

57 lines
1.2 KiB
Go

package leveldb
import (
"context"
"fmt"
"github.com/chrislusf/seaweedfs/weed/filer"
"github.com/syndtr/goleveldb/leveldb"
)
func (store *LevelDB2Store) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
partitionId := bucketKvKey(key, store.dbCount)
err = store.dbs[partitionId].Put(key, value, nil)
if err != nil {
return fmt.Errorf("kv bucket %d put: %v", partitionId, err)
}
return nil
}
func (store *LevelDB2Store) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
partitionId := bucketKvKey(key, store.dbCount)
value, err = store.dbs[partitionId].Get(key, nil)
if err == leveldb.ErrNotFound {
return nil, filer.ErrKvNotFound
}
if err != nil {
return nil, fmt.Errorf("kv bucket %d get: %v", partitionId, err)
}
return
}
func (store *LevelDB2Store) KvDelete(ctx context.Context, key []byte) (err error) {
partitionId := bucketKvKey(key, store.dbCount)
err = store.dbs[partitionId].Delete(key, nil)
if err != nil {
return fmt.Errorf("kv bucket %d delete: %v", partitionId, err)
}
return nil
}
func bucketKvKey(key []byte, dbCount int) (partitionId int) {
return int(key[len(key)-1]) % dbCount
}