You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.0 KiB

3 months ago
  1. package shell
  2. import (
  3. "flag"
  4. "fmt"
  5. "io"
  6. )
  7. func init() {
  8. Commands = append(Commands, &commandEcBalance{})
  9. }
  10. type commandEcBalance struct {
  11. }
  12. func (c *commandEcBalance) Name() string {
  13. return "ec.balance"
  14. }
  15. func (c *commandEcBalance) Help() string {
  16. return `balance all ec shards among all racks and volume servers
  17. ec.balance [-c EACH_COLLECTION|<collection_name>] [-force] [-dataCenter <data_center>] [-shardReplicaPlacement <replica_placement>]
  18. Algorithm:
  19. ` + ecBalanceAlgorithmDescription
  20. }
  21. func (c *commandEcBalance) HasTag(CommandTag) bool {
  22. return false
  23. }
  24. func (c *commandEcBalance) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  25. balanceCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  26. collection := balanceCommand.String("collection", "EACH_COLLECTION", "collection name, or \"EACH_COLLECTION\" for each collection")
  27. dc := balanceCommand.String("dataCenter", "", "only apply the balancing for this dataCenter")
  28. shardReplicaPlacement := balanceCommand.String("shardReplicaPlacement", "", "replica placement for EC shards, or master default if empty")
  29. maxParallelization := balanceCommand.Int("maxParallelization", 10, "run up to X tasks in parallel, whenever possible")
  30. applyBalancing := balanceCommand.Bool("force", false, "apply the balancing plan")
  31. if err = balanceCommand.Parse(args); err != nil {
  32. return nil
  33. }
  34. infoAboutSimulationMode(writer, *applyBalancing, "-force")
  35. if err = commandEnv.confirmIsLocked(args); err != nil {
  36. return
  37. }
  38. var collections []string
  39. if *collection == "EACH_COLLECTION" {
  40. collections, err = ListCollectionNames(commandEnv, false, true)
  41. if err != nil {
  42. return err
  43. }
  44. } else {
  45. collections = append(collections, *collection)
  46. }
  47. fmt.Printf("balanceEcVolumes collections %+v\n", len(collections))
  48. rp, err := parseReplicaPlacementArg(commandEnv, *shardReplicaPlacement)
  49. if err != nil {
  50. return err
  51. }
  52. return EcBalance(commandEnv, collections, *dc, rp, *maxParallelization, *applyBalancing)
  53. }