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.

50 lines
1007 B

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