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.

78 lines
2.1 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) VacuumVolumeCheck(ctx context.Context, req *volume_server_pb.VacuumVolumeCheckRequest) (*volume_server_pb.VacuumVolumeCheckResponse, error) {
  9. resp := &volume_server_pb.VacuumVolumeCheckResponse{}
  10. garbageRatio, err := vs.store.CheckCompactVolume(needle.VolumeId(req.VolumeId))
  11. resp.GarbageRatio = garbageRatio
  12. if err != nil {
  13. glog.V(3).Infof("check volume %d: %v", req.VolumeId, err)
  14. }
  15. return resp, err
  16. }
  17. func (vs *VolumeServer) VacuumVolumeCompact(ctx context.Context, req *volume_server_pb.VacuumVolumeCompactRequest) (*volume_server_pb.VacuumVolumeCompactResponse, error) {
  18. resp := &volume_server_pb.VacuumVolumeCompactResponse{}
  19. err := vs.store.CompactVolume(needle.VolumeId(req.VolumeId), req.Preallocate, vs.compactionBytePerSecond)
  20. if err != nil {
  21. glog.Errorf("compact volume %d: %v", req.VolumeId, err)
  22. } else {
  23. glog.V(1).Infof("compact volume %d", req.VolumeId)
  24. }
  25. return resp, err
  26. }
  27. func (vs *VolumeServer) VacuumVolumeCommit(ctx context.Context, req *volume_server_pb.VacuumVolumeCommitRequest) (*volume_server_pb.VacuumVolumeCommitResponse, error) {
  28. resp := &volume_server_pb.VacuumVolumeCommitResponse{}
  29. err := vs.store.CommitCompactVolume(needle.VolumeId(req.VolumeId))
  30. if err != nil {
  31. glog.Errorf("commit volume %d: %v", req.VolumeId, err)
  32. } else {
  33. glog.V(1).Infof("commit volume %d", req.VolumeId)
  34. }
  35. if err == nil {
  36. if vs.store.GetVolume(needle.VolumeId(req.VolumeId)).IsReadOnly() {
  37. resp.IsReadOnly = true
  38. }
  39. }
  40. return resp, err
  41. }
  42. func (vs *VolumeServer) VacuumVolumeCleanup(ctx context.Context, req *volume_server_pb.VacuumVolumeCleanupRequest) (*volume_server_pb.VacuumVolumeCleanupResponse, error) {
  43. resp := &volume_server_pb.VacuumVolumeCleanupResponse{}
  44. err := vs.store.CommitCleanupVolume(needle.VolumeId(req.VolumeId))
  45. if err != nil {
  46. glog.Errorf("cleanup volume %d: %v", req.VolumeId, err)
  47. } else {
  48. glog.V(1).Infof("cleanup volume %d", req.VolumeId)
  49. }
  50. return resp, err
  51. }