seaweedfs/weed/filer/tikv/tikv_store_kv.go

50 lines
991 B
Go
Raw Normal View History

2021-08-30 07:59:25 +00:00
// +build tikv
2021-08-26 07:20:18 +00:00
package tikv
import (
"context"
"github.com/chrislusf/seaweedfs/weed/filer"
"github.com/tikv/client-go/v2/txnkv"
)
func (store *TikvStore) KvPut(ctx context.Context, key []byte, value []byte) error {
tw, err := store.getTxn(ctx)
if err != nil {
return err
}
return tw.RunInTxn(func(txn *txnkv.KVTxn) error {
return txn.Set(key, value)
})
}
func (store *TikvStore) KvGet(ctx context.Context, key []byte) ([]byte, error) {
tw, err := store.getTxn(ctx)
if err != nil {
return nil, err
}
var data []byte = nil
err = tw.RunInTxn(func(txn *txnkv.KVTxn) error {
val, err := txn.Get(context.TODO(), key)
if err == nil {
data = val
}
return err
})
2021-08-26 08:20:35 +00:00
if isNotExists(err) {
return data, filer.ErrKvNotFound
}
2021-08-26 07:20:18 +00:00
return data, err
}
func (store *TikvStore) KvDelete(ctx context.Context, key []byte) error {
tw, err := store.getTxn(ctx)
if err != nil {
return err
}
return tw.RunInTxn(func(txn *txnkv.KVTxn) error {
return txn.Delete(key)
})
}