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.

40 lines
1.4 KiB

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