seaweedfs/weed/shell/command_ec_balance.go

67 lines
1.9 KiB
Go
Raw Normal View History

2019-05-30 16:38:59 +08:00
package shell
import (
"flag"
"fmt"
"io"
2019-05-30 16:38:59 +08:00
)
func init() {
Commands = append(Commands, &commandEcBalance{})
2019-05-30 16:38:59 +08:00
}
type commandEcBalance struct {
}
func (c *commandEcBalance) Name() string {
return "ec.balance"
}
func (c *commandEcBalance) Help() string {
2019-06-11 12:32:56 +08:00
return `balance all ec shards among all racks and volume servers
2019-05-30 16:38:59 +08:00
ec.balance [-c EACH_COLLECTION|<collection_name>] [-force] [-dataCenter <data_center>] [-shardReplicaPlacement <replica_placement>]
2019-05-30 16:38:59 +08:00
Algorithm:
` + ecBalanceAlgorithmDescription
2019-05-30 16:38:59 +08:00
}
2024-09-30 01:38:22 +08:00
func (c *commandEcBalance) HasTag(CommandTag) bool {
return false
}
func (c *commandEcBalance) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
2019-05-30 16:38:59 +08:00
balanceCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
2019-06-03 17:26:31 +08:00
collection := balanceCommand.String("collection", "EACH_COLLECTION", "collection name, or \"EACH_COLLECTION\" for each collection")
2019-05-30 16:38:59 +08:00
dc := balanceCommand.String("dataCenter", "", "only apply the balancing for this dataCenter")
shardReplicaPlacement := balanceCommand.String("shardReplicaPlacement", "", "replica placement for EC shards, or master default if empty")
parallelize := balanceCommand.Bool("parallelize", true, "parallelize operations whenever possible")
2019-06-03 17:26:31 +08:00
applyBalancing := balanceCommand.Bool("force", false, "apply the balancing plan")
2019-05-30 16:38:59 +08:00
if err = balanceCommand.Parse(args); err != nil {
return nil
}
2022-06-01 05:48:46 +08:00
infoAboutSimulationMode(writer, *applyBalancing, "-force")
2019-05-30 16:38:59 +08:00
2021-12-11 05:24:38 +08:00
if err = commandEnv.confirmIsLocked(args); err != nil {
return
}
var collections []string
2019-06-11 12:32:56 +08:00
if *collection == "EACH_COLLECTION" {
collections, err = ListCollectionNames(commandEnv, false, true)
2019-06-11 12:32:56 +08:00
if err != nil {
return err
2019-05-30 16:38:59 +08:00
}
2019-06-11 12:32:56 +08:00
} else {
collections = append(collections, *collection)
2019-05-30 16:38:59 +08:00
}
fmt.Printf("balanceEcVolumes collections %+v\n", len(collections))
2019-06-11 12:32:56 +08:00
rp, err := parseReplicaPlacementArg(commandEnv, *shardReplicaPlacement)
if err != nil {
return err
}
return EcBalance(commandEnv, collections, *dc, rp, *parallelize, *applyBalancing)
2019-06-06 14:20:26 +08:00
}