Browse Source

ec.encode: add -fullPercent option

pull/991/head
Chris Lu 6 years ago
parent
commit
b9e138713c
  1. 10
      weed/shell/command_ec_encode.go

10
weed/shell/command_ec_encode.go

@ -31,6 +31,9 @@ func (c *commandEcEncode) Name() string {
func (c *commandEcEncode) Help() string { func (c *commandEcEncode) Help() string {
return `apply erasure coding to a volume return `apply erasure coding to a volume
ec.encode [-collection=""] [-fullPercent=95] [-quietFor=1h]
ec.encode [-collection=""] [-volumeId=<volume_id>]
This command will: This command will:
1. freeze one volume 1. freeze one volume
2. apply erasure coding to the volume 2. apply erasure coding to the volume
@ -53,6 +56,7 @@ func (c *commandEcEncode) Do(args []string, commandEnv *commandEnv, writer io.Wr
encodeCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) encodeCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
volumeId := encodeCommand.Int("volumeId", 0, "the volume id") volumeId := encodeCommand.Int("volumeId", 0, "the volume id")
collection := encodeCommand.String("collection", "", "the collection name") collection := encodeCommand.String("collection", "", "the collection name")
fullPercentage := encodeCommand.Float64("fullPercent", 95, "the volume reaches the percentage of max volume size")
quietPeriod := encodeCommand.Duration("quietFor", time.Hour, "select volumes without no writes for this period") quietPeriod := encodeCommand.Duration("quietFor", time.Hour, "select volumes without no writes for this period")
if err = encodeCommand.Parse(args); err != nil { if err = encodeCommand.Parse(args); err != nil {
return nil return nil
@ -67,7 +71,7 @@ func (c *commandEcEncode) Do(args []string, commandEnv *commandEnv, writer io.Wr
} }
// apply to all volumes in the collection // apply to all volumes in the collection
volumeIds, err := collectVolumeIdsForEcEncode(ctx, commandEnv, *collection, *quietPeriod)
volumeIds, err := collectVolumeIdsForEcEncode(ctx, commandEnv, *collection, *fullPercentage, *quietPeriod)
if err != nil { if err != nil {
return err return err
} }
@ -224,7 +228,7 @@ func balancedEcDistribution(servers []*EcNode) (allocated []int) {
return allocated return allocated
} }
func collectVolumeIdsForEcEncode(ctx context.Context, commandEnv *commandEnv, selectedCollection string, quietPeriod time.Duration) (vids []needle.VolumeId, err error) {
func collectVolumeIdsForEcEncode(ctx context.Context, commandEnv *commandEnv, selectedCollection string, fullPercentage float64, quietPeriod time.Duration) (vids []needle.VolumeId, err error) {
var resp *master_pb.VolumeListResponse var resp *master_pb.VolumeListResponse
err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error {
@ -246,12 +250,14 @@ func collectVolumeIdsForEcEncode(ctx context.Context, commandEnv *commandEnv, se
for _, dn := range r.DataNodeInfos { for _, dn := range r.DataNodeInfos {
for _, v := range dn.VolumeInfos { for _, v := range dn.VolumeInfos {
if v.Collection == selectedCollection && v.ModifiedAtSecond+quietSeconds < nowUnixSeconds { if v.Collection == selectedCollection && v.ModifiedAtSecond+quietSeconds < nowUnixSeconds {
if float64(v.Size) > fullPercentage/100*float64(resp.VolumeSizeLimitMb)*1024*1024 {
vidMap[v.Id] = true vidMap[v.Id] = true
} }
} }
} }
} }
} }
}
for vid, _ := range vidMap { for vid, _ := range vidMap {
vids = append(vids, needle.VolumeId(vid)) vids = append(vids, needle.VolumeId(vid))

Loading…
Cancel
Save