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.

51 lines
939 B

  1. // +build rocksdb
  2. package rocksdb
  3. import (
  4. "context"
  5. "fmt"
  6. "github.com/tecbot/gorocksdb"
  7. "github.com/chrislusf/seaweedfs/weed/filer"
  8. )
  9. func (store *RocksDBStore) KvPut(ctx context.Context, key []byte, value []byte) (err error) {
  10. wo := gorocksdb.NewDefaultWriteOptions()
  11. err = store.db.Put(wo, key, value)
  12. if err != nil {
  13. return fmt.Errorf("kv put: %v", err)
  14. }
  15. return nil
  16. }
  17. func (store *RocksDBStore) KvGet(ctx context.Context, key []byte) (value []byte, err error) {
  18. ro := gorocksdb.NewDefaultReadOptions()
  19. value, err = store.db.GetBytes(ro, key)
  20. if value == nil {
  21. return nil, filer.ErrKvNotFound
  22. }
  23. if err != nil {
  24. return nil, fmt.Errorf("kv get: %v", err)
  25. }
  26. return
  27. }
  28. func (store *RocksDBStore) KvDelete(ctx context.Context, key []byte) (err error) {
  29. wo := gorocksdb.NewDefaultWriteOptions()
  30. err = store.db.Delete(wo, key)
  31. if err != nil {
  32. return fmt.Errorf("kv delete: %v", err)
  33. }
  34. return nil
  35. }