-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
command_mq_balance.go
46 lines (36 loc) · 999 Bytes
/
command_mq_balance.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package shell
import (
"context"
"fmt"
"github.com/seaweedfs/seaweedfs/weed/pb"
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
"io"
)
func init() {
Commands = append(Commands, &commandMqBalanceTopics{})
}
type commandMqBalanceTopics struct {
}
func (c *commandMqBalanceTopics) Name() string {
return "mq.balance"
}
func (c *commandMqBalanceTopics) Help() string {
return `balance topic partitions
`
}
func (c *commandMqBalanceTopics) Do(args []string, commandEnv *CommandEnv, writer io.Writer) error {
// find the broker balancer
brokerBalancer, err := findBrokerBalancer(commandEnv)
if err != nil {
return err
}
fmt.Fprintf(writer, "current balancer: %s\n", brokerBalancer)
// balance topics
return pb.WithBrokerGrpcClient(false, brokerBalancer, commandEnv.option.GrpcDialOption, func(client mq_pb.SeaweedMessagingClient) error {
_, err := client.BalanceTopics(context.Background(), &mq_pb.BalanceTopicsRequest{})
if err != nil {
return err
}
return nil
})
}