volume_grpc_vacuum.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. return resp, err
  36. }
  37. func (vs *VolumeServer) VacuumVolumeCleanup(ctx context.Context, req *volume_server_pb.VacuumVolumeCleanupRequest) (*volume_server_pb.VacuumVolumeCleanupResponse, error) {
  38. resp := &volume_server_pb.VacuumVolumeCleanupResponse{}
  39. err := vs.store.CommitCleanupVolume(needle.VolumeId(req.VolumeId))
  40. if err != nil {
  41. glog.Errorf("cleanup volume %d: %v", req.VolumeId, err)
  42. } else {
  43. glog.V(1).Infof("cleanup volume %d", req.VolumeId)
  44. }
  45. return resp, err
  46. }