Skip to content

Commit b4147ec

Browse files
LiuRuoyu01yuhaijun999
authored andcommitted
[feat][client] Add enable or disable balance command
1 parent 36eaac0 commit b4147ec

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/client_v2/coordinator.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ void SetUpCoordinatorSubCommands(CLI::App &app) {
5757
// br
5858
SetUpGetBackUpStatus(app);
5959
SetUpGetRestoreStatus(app);
60+
61+
// balance
62+
SetUpEnableOrDisableBalance(app);
63+
6064
}
6165

6266
bool GetBrpcChannel(const std::string &location, brpc::Channel &channel) {
@@ -2783,5 +2787,48 @@ void RunGetRestoreStatus(GetRestoreStatusOptions const &opt) {
27832787
}
27842788
}
27852789

2790+
void SetUpEnableOrDisableBalance(CLI::App &app) {
2791+
auto opt = std::make_shared<EnableOrDisableBalanceOptions>();
2792+
auto *cmd = app.add_subcommand("DisableBalance", "DisableBalance ")->group("Coordinator Command");
2793+
cmd->add_option("--coor_url", opt->coor_url, "Coordinator url, default:file://./coor_list");
2794+
cmd->add_option("--balance_leader", opt->enable_balance_leader, "Request parameter enable_balance_leader true or false")
2795+
->required();
2796+
cmd->add_option("--balance_region", opt->enable_balance_region, "Request parameter enable_balance_region true or false")
2797+
->required();
2798+
cmd->callback([opt]() { RunEnableOrDisableBalance(*opt); });
2799+
}
2800+
2801+
void RunEnableOrDisableBalance(EnableOrDisableBalanceOptions const &opt) {
2802+
if (Helper::SetUp(opt.coor_url) < 0) {
2803+
exit(-1);
2804+
}
2805+
dingodb::pb::coordinator::ControlConfigRequest request;
2806+
dingodb::pb::coordinator::ControlConfigResponse response;
2807+
2808+
request.mutable_request_info()->set_request_id(0);
2809+
2810+
dingodb::pb::common::ControlConfigVariable config_balance_leader;
2811+
config_balance_leader.set_name("FLAGS_enable_balance_leader");
2812+
config_balance_leader.set_value(opt.enable_balance_leader);
2813+
request.mutable_control_config_variable()->Add(std::move(config_balance_leader));
2814+
2815+
dingodb::pb::common::ControlConfigVariable config_balance_region;
2816+
config_balance_region.set_name("FLAGS_enable_balance_region");
2817+
config_balance_region.set_value(opt.enable_balance_region);
2818+
request.mutable_control_config_variable()->Add(std::move(config_balance_region));
2819+
2820+
butil::Status status =
2821+
CoordinatorInteraction::GetInstance().GetCoorinatorInteraction()->SendRequest("ControlConfig", request, response);
2822+
if (!status.ok()) {
2823+
std::cout << status.error_cstr();
2824+
}
2825+
2826+
for (const auto &config : response.control_config_variable()) {
2827+
if (config.is_error_occurred()) {
2828+
std::cout << "ControlConfig not support variable: " << config.name() << " skip.";
2829+
}
2830+
}
2831+
}
2832+
27862833
// refactor
27872834
} // namespace client_v2

src/client_v2/coordinator.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,14 @@ struct GetRestoreStatusOptions {
569569
void SetUpGetRestoreStatus(CLI::App &app);
570570
void RunGetRestoreStatus(GetRestoreStatusOptions const &opt);
571571

572+
struct EnableOrDisableBalanceOptions {
573+
std::string coor_url;
574+
std::string enable_balance_leader;
575+
std::string enable_balance_region;
576+
};
577+
void SetUpEnableOrDisableBalance(CLI::App &app);
578+
void RunEnableOrDisableBalance(EnableOrDisableBalanceOptions const &opt);
579+
572580
} // namespace client_v2
573581

574582
#endif // DINGODB_CLIENT_COORDINATOR_H_

0 commit comments

Comments
 (0)