command_mq_balance.go 999 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package shell
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/seaweedfs/seaweedfs/weed/pb"
  6. "github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
  7. "io"
  8. )
  9. func init() {
  10. Commands = append(Commands, &commandMqBalanceTopics{})
  11. }
  12. type commandMqBalanceTopics struct {
  13. }
  14. func (c *commandMqBalanceTopics) Name() string {
  15. return "mq.balance"
  16. }
  17. func (c *commandMqBalanceTopics) Help() string {
  18. return `balance topic partitions
  19. `
  20. }
  21. func (c *commandMqBalanceTopics) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
  22. // find the broker balancer
  23. brokerBalancer, err := findBrokerBalancer(commandEnv)
  24. if err != nil {
  25. return err
  26. }
  27. fmt.Fprintf(writer, "current balancer: %s\n", brokerBalancer)
  28. // balance topics
  29. return pb.WithBrokerGrpcClient(false, brokerBalancer, commandEnv.option.GrpcDialOption, func(client mq_pb.SeaweedMessagingClient) error {
  30. _, err := client.BalanceTopics(context.Background(), &mq_pb.BalanceTopicsRequest{})
  31. if err != nil {
  32. return err
  33. }
  34. return nil
  35. })
  36. }