diff options
| author | Chris Lu <chris.lu@gmail.com> | 2019-05-31 23:41:17 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2019-05-31 23:41:17 -0700 |
| commit | f919d0235cff244941e4e9f8c51bf89224d3d0ab (patch) | |
| tree | 6be136609bee776020f80150540378d3b1d158cb /weed/shell/command_ec_encode.go | |
| parent | a72cef3c429202aff5c04ed2c7b9296b2351174f (diff) | |
| download | seaweedfs-f919d0235cff244941e4e9f8c51bf89224d3d0ab.tar.xz seaweedfs-f919d0235cff244941e4e9f8c51bf89224d3d0ab.zip | |
ec encode volumes quiet for a period of time
Diffstat (limited to 'weed/shell/command_ec_encode.go')
| -rw-r--r-- | weed/shell/command_ec_encode.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/weed/shell/command_ec_encode.go b/weed/shell/command_ec_encode.go index e69d1bfc7..7ecd7bb8c 100644 --- a/weed/shell/command_ec_encode.go +++ b/weed/shell/command_ec_encode.go @@ -7,6 +7,7 @@ import ( "io" "sort" "sync" + "time" "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/operation" @@ -54,6 +55,7 @@ func (c *commandEcEncode) Do(args []string, commandEnv *commandEnv, writer io.Wr encodeCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError) volumeId := encodeCommand.Int("volumeId", 0, "the volume id") collection := encodeCommand.String("collection", "", "the collection name") + quietPeriod := encodeCommand.Duration("quietFor", time.Hour, "select volumes without no writes for this period") if err = encodeCommand.Parse(args); err != nil { return nil } @@ -67,7 +69,7 @@ func (c *commandEcEncode) Do(args []string, commandEnv *commandEnv, writer io.Wr } // apply to all volumes in the collection - volumeIds, err := collectVolumeByCollection(ctx, commandEnv, *collection) + volumeIds, err := collectVolumeForEcEncode(ctx, commandEnv, *collection, *quietPeriod) if err != nil { return err } @@ -347,7 +349,7 @@ func collectEcNodes(ctx context.Context, commandEnv *commandEnv) (ecNodes []*EcN return } -func collectVolumeByCollection(ctx context.Context, commandEnv *commandEnv, selectedCollection string) (vids []needle.VolumeId, err error) { +func collectVolumeForEcEncode(ctx context.Context, commandEnv *commandEnv, selectedCollection string, quietPeriod time.Duration) (vids []needle.VolumeId, err error) { var resp *master_pb.VolumeListResponse err = commandEnv.masterClient.WithClient(ctx, func(client master_pb.SeaweedClient) error { @@ -358,12 +360,15 @@ func collectVolumeByCollection(ctx context.Context, commandEnv *commandEnv, sele return } + quietSeconds := int64((quietPeriod * time.Second).Seconds()) + nowUnixSeconds := time.Now().Unix() + vidMap := make(map[uint32]bool) for _, dc := range resp.TopologyInfo.DataCenterInfos { for _, r := range dc.RackInfos { for _, dn := range r.DataNodeInfos { for _, v := range dn.VolumeInfos { - if v.Collection == selectedCollection { + if v.Collection == selectedCollection && v.ModifiedAtSecond+quietSeconds < nowUnixSeconds { vidMap[v.Id] = true } } |
