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.

54 lines
1.4 KiB

  1. package arangodb
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/arangodb/go-driver"
  6. "github.com/chrislusf/seaweedfs/weed/filer"
  7. "github.com/chrislusf/seaweedfs/weed/glog"
  8. )
  9. func (store *ArangodbStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
  10. model := &Model{
  11. Key: hashString(".kvstore." + string(key)),
  12. Directory: ".kvstore." + string(key),
  13. Meta: bytesToArray(value),
  14. }
  15. exists, err := store.kvCollection.DocumentExists(ctx, model.Key)
  16. if err != nil {
  17. return fmt.Errorf("kv put: %v", err)
  18. }
  19. if exists {
  20. _, err = store.kvCollection.UpdateDocument(ctx, model.Key, model)
  21. } else {
  22. _, err = store.kvCollection.CreateDocument(ctx, model)
  23. }
  24. if err != nil {
  25. return fmt.Errorf("kv put: %v", err)
  26. }
  27. return nil
  28. }
  29. func (store *ArangodbStore) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
  30. var model Model
  31. _, err = store.kvCollection.ReadDocument(ctx, hashString(".kvstore."+string(key)), &model)
  32. if driver.IsNotFound(err) {
  33. return nil, filer.ErrKvNotFound
  34. }
  35. if err != nil {
  36. glog.Errorf("kv get: %s %v", string(key), err)
  37. return nil, filer.ErrKvNotFound
  38. }
  39. return arrayToBytes(model.Meta), nil
  40. }
  41. func (store *ArangodbStore) KvDelete(ctx context.Context, key []byte) (err error) {
  42. _, err = store.kvCollection.RemoveDocument(ctx, hashString(".kvstore."+string(key)))
  43. if err != nil {
  44. glog.Errorf("kv del: %v", err)
  45. return filer.ErrKvNotFound
  46. }
  47. return nil
  48. }