command_mq_balance.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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) HasTag(CommandTag) bool {
  22. return false
  23. }
  24. func (c *commandMqBalanceTopics) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
  25. // find the broker balancer
  26. brokerBalancer, err := findBrokerBalancer(commandEnv)
  27. if err != nil {
  28. return err
  29. }
  30. fmt.Fprintf(writer, "current balancer: %s\n", brokerBalancer)
  31. // balance topics
  32. return pb.WithBrokerGrpcClient(false, brokerBalancer, commandEnv.option.GrpcDialOption, func(client mq_pb.SeaweedMessagingClient) error {
  33. _, err := client.BalanceTopics(context.Background(), &mq_pb.BalanceTopicsRequest{})
  34. if err != nil {
  35. return err
  36. }
  37. return nil
  38. })
  39. }