You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
975 B

3 years ago
3 years ago
3 years ago
  1. package tikv
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/filer"
  5. "github.com/tikv/client-go/v2/txnkv"
  6. )
  7. func (store *TikvStore) KvPut(ctx context.Context, key []byte, value []byte) error {
  8. tw, err := store.getTxn(ctx)
  9. if err != nil {
  10. return err
  11. }
  12. return tw.RunInTxn(func(txn *txnkv.KVTxn) error {
  13. return txn.Set(key, value)
  14. })
  15. }
  16. func (store *TikvStore) KvGet(ctx context.Context, key []byte) ([]byte, error) {
  17. tw, err := store.getTxn(ctx)
  18. if err != nil {
  19. return nil, err
  20. }
  21. var data []byte = nil
  22. err = tw.RunInTxn(func(txn *txnkv.KVTxn) error {
  23. val, err := txn.Get(context.TODO(), key)
  24. if err == nil {
  25. data = val
  26. }
  27. return err
  28. })
  29. if isNotExists(err) {
  30. return data, filer.ErrKvNotFound
  31. }
  32. return data, err
  33. }
  34. func (store *TikvStore) KvDelete(ctx context.Context, key []byte) error {
  35. tw, err := store.getTxn(ctx)
  36. if err != nil {
  37. return err
  38. }
  39. return tw.RunInTxn(func(txn *txnkv.KVTxn) error {
  40. return txn.Delete(key)
  41. })
  42. }