MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / HandleClientChangeRole

Function HandleClientChangeRole

src/cmd/fedb.cc:4042–4077  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4040}
4041
4042void HandleClientChangeRole(const std::vector<std::string> parts,
4043 ::fedb::client::TabletClient* client) {
4044 if (parts.size() < 4) {
4045 std::cout << "Bad changerole format" << std::endl;
4046 return;
4047 }
4048 try {
4049 uint64_t termid = 0;
4050 if (parts.size() > 4) {
4051 termid = boost::lexical_cast<uint64_t>(parts[4]);
4052 }
4053 if (parts[3].compare("leader") == 0) {
4054 bool ok = client->ChangeRole(
4055 boost::lexical_cast<uint32_t>(parts[1]),
4056 boost::lexical_cast<uint32_t>(parts[2]), true, termid);
4057 if (ok) {
4058 std::cout << "ChangeRole ok" << std::endl;
4059 } else {
4060 std::cout << "Fail to change leader" << std::endl;
4061 }
4062 } else if (parts[3].compare("follower") == 0) {
4063 bool ok = client->ChangeRole(
4064 boost::lexical_cast<uint32_t>(parts[1]),
4065 boost::lexical_cast<uint32_t>(parts[2]), false, termid);
4066 if (ok) {
4067 std::cout << "ChangeRole ok" << std::endl;
4068 } else {
4069 std::cout << "Fail to change follower" << std::endl;
4070 }
4071 } else {
4072 std::cout << "role must be leader or follower" << std::endl;
4073 }
4074 } catch (boost::bad_lexical_cast& e) {
4075 std::cout << "Bad changerole format" << std::endl;
4076 }
4077}
4078
4079void HandleClientPreview(const std::vector<std::string>& parts,
4080 ::fedb::client::TabletClient* client) {

Callers 1

StartClientFunction · 0.85

Calls 3

compareMethod · 0.80
sizeMethod · 0.45
ChangeRoleMethod · 0.45

Tested by

no test coverage detected