aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_mq_balance.go
blob: af79bba2d618bc99036da4ab4b1ee8af4a05f219 (plain)
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
47
48
49
50
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) IsResourceHeavy() bool {
	return false
}

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
	})

}