Skip to content

Commit

Permalink
Optimize-slaveof (OpenAtomFoundation#2027)
Browse files Browse the repository at this point in the history
Co-authored-by: wuxianrong <wuxianrong@360.cn>
  • Loading branch information
Mixficsol and wuxianrong authored Sep 25, 2023
1 parent 86d88d1 commit f7df2fc
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pika_admin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void SlaveofCmd::DoInitial() {
return;
}

// self is master of A , want to slavof B
// self is master of A , want to slaveof B
if ((g_pika_server->role() & PIKA_ROLE_MASTER) != 0) {
res_.SetRes(CmdRes::kErrOther, "already master of others, invalid usage");
return;
Expand All @@ -122,7 +122,7 @@ void SlaveofCmd::DoInitial() {
}

if ((master_ip_ == "127.0.0.1" || master_ip_ == g_pika_server->host()) && master_port_ == g_pika_server->port()) {
res_.SetRes(CmdRes::kErrOther, "you fucked up");
res_.SetRes(CmdRes::kErrOther, "The ip and port of the connection are themselves");
return;
}

Expand All @@ -148,6 +148,7 @@ void SlaveofCmd::Do(std::shared_ptr<Slot> slot) {
if (is_none_) {
res_.SetRes(CmdRes::kOk);
g_pika_conf->SetSlaveof(std::string());
g_pika_conf->ConfigRewrite();
return;
}

Expand All @@ -161,6 +162,7 @@ void SlaveofCmd::Do(std::shared_ptr<Slot> slot) {
res_.SetRes(CmdRes::kOk);
g_pika_conf->SetSlaveof(master_ip_ + ":" + std::to_string(master_port_));
g_pika_conf->SetMasterRunID("");
g_pika_conf->ConfigRewrite();
g_pika_server->SetFirstMetaSync(true);
} else {
res_.SetRes(CmdRes::kErrOther, "Server is not in correct state for slaveof");
Expand Down

0 comments on commit f7df2fc

Please sign in to comment.