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.

113 lines
2.8 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. package weed_server
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  6. "github.com/chrislusf/seaweedfs/weed/storage/needle"
  7. )
  8. func (vs *VolumeServer) DeleteCollection(ctx context.Context, req *volume_server_pb.DeleteCollectionRequest) (*volume_server_pb.DeleteCollectionResponse, error) {
  9. resp := &volume_server_pb.DeleteCollectionResponse{}
  10. err := vs.store.DeleteCollection(req.Collection)
  11. if err != nil {
  12. glog.Errorf("delete collection %s: %v", req.Collection, err)
  13. } else {
  14. glog.V(2).Infof("delete collection %v", req)
  15. }
  16. return resp, err
  17. }
  18. func (vs *VolumeServer) AllocateVolume(ctx context.Context, req *volume_server_pb.AllocateVolumeRequest) (*volume_server_pb.AllocateVolumeResponse, error) {
  19. resp := &volume_server_pb.AllocateVolumeResponse{}
  20. err := vs.store.AddVolume(
  21. needle.VolumeId(req.VolumeId),
  22. req.Collection,
  23. vs.needleMapKind,
  24. req.Replication,
  25. req.Ttl,
  26. req.Preallocate,
  27. req.MemoryMapMaxSizeMb,
  28. )
  29. if err != nil {
  30. glog.Errorf("assign volume %v: %v", req, err)
  31. } else {
  32. glog.V(2).Infof("assign volume %v", req)
  33. }
  34. return resp, err
  35. }
  36. func (vs *VolumeServer) VolumeMount(ctx context.Context, req *volume_server_pb.VolumeMountRequest) (*volume_server_pb.VolumeMountResponse, error) {
  37. resp := &volume_server_pb.VolumeMountResponse{}
  38. err := vs.store.MountVolume(needle.VolumeId(req.VolumeId))
  39. if err != nil {
  40. glog.Errorf("volume mount %v: %v", req, err)
  41. } else {
  42. glog.V(2).Infof("volume mount %v", req)
  43. }
  44. return resp, err
  45. }
  46. func (vs *VolumeServer) VolumeUnmount(ctx context.Context, req *volume_server_pb.VolumeUnmountRequest) (*volume_server_pb.VolumeUnmountResponse, error) {
  47. resp := &volume_server_pb.VolumeUnmountResponse{}
  48. err := vs.store.UnmountVolume(needle.VolumeId(req.VolumeId))
  49. if err != nil {
  50. glog.Errorf("volume unmount %v: %v", req, err)
  51. } else {
  52. glog.V(2).Infof("volume unmount %v", req)
  53. }
  54. return resp, err
  55. }
  56. func (vs *VolumeServer) VolumeDelete(ctx context.Context, req *volume_server_pb.VolumeDeleteRequest) (*volume_server_pb.VolumeDeleteResponse, error) {
  57. resp := &volume_server_pb.VolumeDeleteResponse{}
  58. err := vs.store.DeleteVolume(needle.VolumeId(req.VolumeId))
  59. if err != nil {
  60. glog.Errorf("volume delete %v: %v", req, err)
  61. } else {
  62. glog.V(2).Infof("volume delete %v", req)
  63. }
  64. return resp, err
  65. }
  66. func (vs *VolumeServer) VolumeMarkReadonly(ctx context.Context, req *volume_server_pb.VolumeMarkReadonlyRequest) (*volume_server_pb.VolumeMarkReadonlyResponse, error) {
  67. resp := &volume_server_pb.VolumeMarkReadonlyResponse{}
  68. err := vs.store.MarkVolumeReadonly(needle.VolumeId(req.VolumeId))
  69. if err != nil {
  70. glog.Errorf("volume mark readonly %v: %v", req, err)
  71. } else {
  72. glog.V(2).Infof("volume mark readonly %v", req)
  73. }
  74. return resp, err
  75. }