volume_grpc_read_write.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package weed_server
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  6. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  7. "github.com/chrislusf/seaweedfs/weed/storage/types"
  8. )
  9. func (vs *VolumeServer) ReadNeedleBlob(ctx context.Context, req *volume_server_pb.ReadNeedleBlobRequest) (resp *volume_server_pb.ReadNeedleBlobResponse, err error) {
  10. resp = &volume_server_pb.ReadNeedleBlobResponse{}
  11. v := vs.store.GetVolume(needle.VolumeId(req.VolumeId))
  12. if v == nil {
  13. return nil, fmt.Errorf("not found volume id %d", req.VolumeId)
  14. }
  15. resp.NeedleBlob, err = v.ReadNeedleBlob(req.Offset, types.Size(req.Size))
  16. if err != nil {
  17. return nil, fmt.Errorf("read needle blob offset %d size %d: %v", req.Offset, req.Size, err)
  18. }
  19. return resp, nil
  20. }
  21. func (vs *VolumeServer) WriteNeedleBlob(ctx context.Context, req *volume_server_pb.WriteNeedleBlobRequest) (resp *volume_server_pb.WriteNeedleBlobResponse, err error) {
  22. resp = &volume_server_pb.WriteNeedleBlobResponse{}
  23. v := vs.store.GetVolume(needle.VolumeId(req.VolumeId))
  24. if v == nil {
  25. return nil, fmt.Errorf("not found volume id %d", req.VolumeId)
  26. }
  27. if err = v.WriteNeedleBlob(types.NeedleId(req.NeedleId), req.NeedleBlob, types.Size(req.Size)); err != nil {
  28. return nil, fmt.Errorf("write blob needle %d size %d: %v", req.NeedleId, req.Size, err)
  29. }
  30. return resp, nil
  31. }