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.

89 lines
2.5 KiB

6 years ago
6 years ago
3 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(req *volume_server_pb.VacuumVolumeCompactRequest, stream volume_server_pb.VolumeServer_VacuumVolumeCompactServer) error {
  18. resp := &volume_server_pb.VacuumVolumeCompactResponse{}
  19. reportInterval := int64(1024 * 1024 * 128)
  20. nextReportTarget := reportInterval
  21. var sendErr error
  22. err := vs.store.CompactVolume(needle.VolumeId(req.VolumeId), req.Preallocate, vs.compactionBytePerSecond, func(processed int64) bool {
  23. if processed > nextReportTarget {
  24. resp.ProcessedBytes = processed
  25. if sendErr = stream.Send(resp); sendErr != nil {
  26. return false
  27. }
  28. nextReportTarget = processed + reportInterval
  29. }
  30. return true
  31. })
  32. if err != nil {
  33. glog.Errorf("compact volume %d: %v", req.VolumeId, err)
  34. return err
  35. }
  36. if sendErr != nil {
  37. glog.Errorf("compact volume %d report progress: %v", req.VolumeId, sendErr)
  38. return sendErr
  39. }
  40. glog.V(1).Infof("compact volume %d", req.VolumeId)
  41. return nil
  42. }
  43. func (vs *VolumeServer) VacuumVolumeCommit(ctx context.Context, req *volume_server_pb.VacuumVolumeCommitRequest) (*volume_server_pb.VacuumVolumeCommitResponse, error) {
  44. resp := &volume_server_pb.VacuumVolumeCommitResponse{}
  45. readOnly, err := vs.store.CommitCompactVolume(needle.VolumeId(req.VolumeId))
  46. if err != nil {
  47. glog.Errorf("commit volume %d: %v", req.VolumeId, err)
  48. } else {
  49. glog.V(1).Infof("commit volume %d", req.VolumeId)
  50. }
  51. resp.IsReadOnly = readOnly
  52. return resp, err
  53. }
  54. func (vs *VolumeServer) VacuumVolumeCleanup(ctx context.Context, req *volume_server_pb.VacuumVolumeCleanupRequest) (*volume_server_pb.VacuumVolumeCleanupResponse, error) {
  55. resp := &volume_server_pb.VacuumVolumeCleanupResponse{}
  56. err := vs.store.CommitCleanupVolume(needle.VolumeId(req.VolumeId))
  57. if err != nil {
  58. glog.Errorf("cleanup volume %d: %v", req.VolumeId, err)
  59. } else {
  60. glog.V(1).Infof("cleanup volume %d", req.VolumeId)
  61. }
  62. return resp, err
  63. }