|
@ -2,12 +2,17 @@ package weed_server |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"context" |
|
|
"context" |
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog" |
|
|
"github.com/chrislusf/seaweedfs/weed/glog" |
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" |
|
|
"github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb" |
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle" |
|
|
"github.com/chrislusf/seaweedfs/weed/storage/needle" |
|
|
|
|
|
"github.com/prometheus/procfs" |
|
|
|
|
|
"github.com/prometheus/procfs/blockdevice" |
|
|
|
|
|
"math" |
|
|
|
|
|
"runtime" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
var numCPU = runtime.NumCPU() |
|
|
|
|
|
|
|
|
func (vs *VolumeServer) VacuumVolumeCheck(ctx context.Context, req *volume_server_pb.VacuumVolumeCheckRequest) (*volume_server_pb.VacuumVolumeCheckResponse, error) { |
|
|
func (vs *VolumeServer) VacuumVolumeCheck(ctx context.Context, req *volume_server_pb.VacuumVolumeCheckRequest) (*volume_server_pb.VacuumVolumeCheckResponse, error) { |
|
|
|
|
|
|
|
|
resp := &volume_server_pb.VacuumVolumeCheckResponse{} |
|
|
resp := &volume_server_pb.VacuumVolumeCheckResponse{} |
|
@ -29,11 +34,24 @@ func (vs *VolumeServer) VacuumVolumeCompact(req *volume_server_pb.VacuumVolumeCo |
|
|
resp := &volume_server_pb.VacuumVolumeCompactResponse{} |
|
|
resp := &volume_server_pb.VacuumVolumeCompactResponse{} |
|
|
reportInterval := int64(1024 * 1024 * 128) |
|
|
reportInterval := int64(1024 * 1024 * 128) |
|
|
nextReportTarget := reportInterval |
|
|
nextReportTarget := reportInterval |
|
|
|
|
|
|
|
|
|
|
|
fs, fsErr := procfs.NewDefaultFS() |
|
|
|
|
|
bd, bdErr := blockdevice.NewDefaultFS() |
|
|
var sendErr error |
|
|
var sendErr error |
|
|
err := vs.store.CompactVolume(needle.VolumeId(req.VolumeId), req.Preallocate, vs.compactionBytePerSecond, func(processed int64) bool { |
|
|
err := vs.store.CompactVolume(needle.VolumeId(req.VolumeId), req.Preallocate, vs.compactionBytePerSecond, func(processed int64) bool { |
|
|
if processed > nextReportTarget { |
|
|
if processed > nextReportTarget { |
|
|
resp.ProcessedBytes = processed |
|
|
resp.ProcessedBytes = processed |
|
|
|
|
|
if fsErr == nil && numCPU > 0 { |
|
|
|
|
|
if fsLa, err := fs.LoadAvg(); err == nil { |
|
|
|
|
|
resp.PercentLoadAvg_1M = uint32(math.Round(fsLa.Load1 * 100 / float64(numCPU))) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if bdErr == nil { |
|
|
|
|
|
if bdStats, err := bd.ProcDiskstats(); err == nil { |
|
|
|
|
|
for _, stat := range bdStats { |
|
|
|
|
|
glog.V(0).Infof("vacuum id: processed ProcDiskstats: %+v", req.VolumeId, stat) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
if sendErr = stream.Send(resp); sendErr != nil { |
|
|
if sendErr = stream.Send(resp); sendErr != nil { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|