2018-10-15 14:12:43 +08:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
|
2019-04-19 12:43:36 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle"
|
2018-10-15 14:12:43 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCheck(ctx context.Context, req *volume_server_pb.VacuumVolumeCheckRequest) (*volume_server_pb.VacuumVolumeCheckResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCheckResponse{}
|
|
|
|
|
2019-04-19 12:43:36 +08:00
|
|
|
garbageRatio, err := vs.store.CheckCompactVolume(needle.VolumeId(req.VolumeId))
|
2018-10-15 14:12:43 +08:00
|
|
|
|
|
|
|
resp.GarbageRatio = garbageRatio
|
|
|
|
|
|
|
|
if err != nil {
|
2019-03-24 02:33:34 +08:00
|
|
|
glog.V(3).Infof("check volume %d: %v", req.VolumeId, err)
|
2018-10-15 14:12:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCompact(ctx context.Context, req *volume_server_pb.VacuumVolumeCompactRequest) (*volume_server_pb.VacuumVolumeCompactResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCompactResponse{}
|
|
|
|
|
2019-05-04 08:22:39 +08:00
|
|
|
err := vs.store.CompactVolume(needle.VolumeId(req.VolumeId), req.Preallocate, vs.compactionBytePerSecond)
|
2018-10-15 14:12:43 +08:00
|
|
|
|
|
|
|
if err != nil {
|
2019-03-24 02:33:34 +08:00
|
|
|
glog.Errorf("compact volume %d: %v", req.VolumeId, err)
|
2018-10-15 14:12:43 +08:00
|
|
|
} else {
|
2019-03-24 02:33:34 +08:00
|
|
|
glog.V(1).Infof("compact volume %d", req.VolumeId)
|
2018-10-15 14:12:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCommit(ctx context.Context, req *volume_server_pb.VacuumVolumeCommitRequest) (*volume_server_pb.VacuumVolumeCommitResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCommitResponse{}
|
|
|
|
|
2019-04-19 12:43:36 +08:00
|
|
|
err := vs.store.CommitCompactVolume(needle.VolumeId(req.VolumeId))
|
2018-10-15 14:12:43 +08:00
|
|
|
|
|
|
|
if err != nil {
|
2019-03-24 02:33:34 +08:00
|
|
|
glog.Errorf("commit volume %d: %v", req.VolumeId, err)
|
2018-10-15 14:12:43 +08:00
|
|
|
} else {
|
2019-03-24 02:33:34 +08:00
|
|
|
glog.V(1).Infof("commit volume %d", req.VolumeId)
|
2018-10-15 14:12:43 +08:00
|
|
|
}
|
2020-03-18 00:43:57 +08:00
|
|
|
if err == nil {
|
|
|
|
if vs.store.GetVolume(needle.VolumeId(req.VolumeId)).IsReadOnly() {
|
|
|
|
resp.IsReadOnly = true
|
|
|
|
}
|
|
|
|
}
|
2018-10-15 14:12:43 +08:00
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCleanup(ctx context.Context, req *volume_server_pb.VacuumVolumeCleanupRequest) (*volume_server_pb.VacuumVolumeCleanupResponse, error) {
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCleanupResponse{}
|
|
|
|
|
2019-04-19 12:43:36 +08:00
|
|
|
err := vs.store.CommitCleanupVolume(needle.VolumeId(req.VolumeId))
|
2018-10-15 14:12:43 +08:00
|
|
|
|
|
|
|
if err != nil {
|
2019-03-24 02:33:34 +08:00
|
|
|
glog.Errorf("cleanup volume %d: %v", req.VolumeId, err)
|
2018-10-15 14:12:43 +08:00
|
|
|
} else {
|
2019-03-24 02:33:34 +08:00
|
|
|
glog.V(1).Infof("cleanup volume %d", req.VolumeId)
|
2018-10-15 14:12:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return resp, err
|
|
|
|
|
|
|
|
}
|