filer_grpc_server_kv.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package weed_server
  2. import (
  3. "context"
  4. "github.com/seaweedfs/seaweedfs/weed/filer"
  5. "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
  6. )
  7. func (fs *FilerServer) KvGet(ctx context.Context, req *filer_pb.KvGetRequest) (*filer_pb.KvGetResponse, error) {
  8. value, err := fs.filer.Store.KvGet(ctx, req.Key)
  9. if err == filer.ErrKvNotFound {
  10. return &filer_pb.KvGetResponse{}, nil
  11. }
  12. if err != nil {
  13. return &filer_pb.KvGetResponse{Error: err.Error()}, nil
  14. }
  15. return &filer_pb.KvGetResponse{
  16. Value: value,
  17. }, nil
  18. }
  19. // KvPut sets the key~value. if empty value, delete the kv entry
  20. func (fs *FilerServer) KvPut(ctx context.Context, req *filer_pb.KvPutRequest) (*filer_pb.KvPutResponse, error) {
  21. if len(req.Value) == 0 {
  22. if err := fs.filer.Store.KvDelete(ctx, req.Key); err != nil {
  23. return &filer_pb.KvPutResponse{Error: err.Error()}, nil
  24. }
  25. }
  26. err := fs.filer.Store.KvPut(ctx, req.Key, req.Value)
  27. if err != nil {
  28. return &filer_pb.KvPutResponse{Error: err.Error()}, nil
  29. }
  30. return &filer_pb.KvPutResponse{}, nil
  31. }