@@ -151,6 +151,10 @@ void SlaveofCmd::Do(std::shared_ptr<Slot> slot) {
151151 return ;
152152 }
153153
154+ /* The return value of the slaveof command OK does not really represent whether
155+ * the data synchronization was successful, but only changes the status of the
156+ * slaveof executor to slave */
157+
154158 bool sm_ret = g_pika_server->SetMaster (master_ip_, static_cast <int32_t >(master_port_));
155159
156160 if (sm_ret) {
@@ -1038,7 +1042,7 @@ void InfoCmd::InfoReplication(std::string& info) {
10381042 info.append (" ERR: server role is error\r\n " );
10391043 return ;
10401044 }
1041-
1045+ tmp_stream << " ReplicationID: " << g_pika_conf-> replication_id () << " \r\n " ;
10421046 std::string slaves_list_str;
10431047 switch (host_role) {
10441048 case PIKA_ROLE_SLAVE :
@@ -1324,6 +1328,8 @@ void ConfigCmd::Do(std::shared_ptr<Slot> slot) {
13241328 ConfigRewrite (config_ret);
13251329 } else if (strcasecmp (config_args_v_[0 ].data (), " resetstat" ) == 0 ) {
13261330 ConfigResetstat (config_ret);
1331+ } else if (strcasecmp (config_args_v_[0 ].data (), " rewritereplicationid" ) == 0 ) {
1332+ ConfigRewriteReplicationID (config_ret);
13271333 }
13281334 res_.AppendStringRaw (config_ret);
13291335}
@@ -1849,6 +1855,12 @@ void ConfigCmd::ConfigGet(std::string& ret) {
18491855 EncodeNumber (&config_body, g_pika_conf->max_rsync_parallel_num ());
18501856 }
18511857
1858+ if (pstd::stringmatch (pattern.data (), " replication-id" , 1 ) != 0 ) {
1859+ elements += 2 ;
1860+ EncodeString (&config_body, " replication-id" );
1861+ EncodeString (&config_body, g_pika_conf->replication_id ());
1862+ }
1863+
18521864 std::stringstream resp;
18531865 resp << " *" << std::to_string (elements) << " \r\n " << config_body;
18541866 ret = resp.str ();
@@ -2183,12 +2195,12 @@ void ConfigCmd::ConfigSet(std::string& ret) {
21832195 g_pika_conf->SetThrottleBytesPerSecond (static_cast <int >(ival));
21842196 ret = " +OK\r\n " ;
21852197 } else if (set_item == " max-rsync-parallel-num" ) {
2186- if ((pstd::string2int (value.data (), value.size (), &ival) == 0 ) || ival > kMaxRsyncParallelNum ) {
2187- ret = " -ERR Invalid argument \' " + value + " \' for CONFIG SET 'max-rsync-parallel-num'\r\n " ;
2188- return ;
2189- }
2190- g_pika_conf->SetMaxRsyncParallelNum (static_cast <int >(ival));
2191- ret = " +OK\r\n " ;
2198+ if ((pstd::string2int (value.data (), value.size (), &ival) == 0 ) || ival > kMaxRsyncParallelNum ) {
2199+ ret = " -ERR Invalid argument \' " + value + " \' for CONFIG SET 'max-rsync-parallel-num'\r\n " ;
2200+ return ;
2201+ }
2202+ g_pika_conf->SetMaxRsyncParallelNum (static_cast <int >(ival));
2203+ ret = " +OK\r\n " ;
21922204 } else {
21932205 ret = " -ERR Unsupported CONFIG parameter: " + set_item + " \r\n " ;
21942206 }
@@ -2202,6 +2214,14 @@ void ConfigCmd::ConfigRewrite(std::string& ret) {
22022214 }
22032215}
22042216
2217+ void ConfigCmd::ConfigRewriteReplicationID (std::string &ret) {
2218+ if (g_pika_conf->ConfigRewriteReplicationID () != 0 ) {
2219+ ret = " +OK\r\n " ;
2220+ } else {
2221+ ret = " -ERR Rewire ReplicationID CONFIG fail\r\n " ;
2222+ }
2223+ }
2224+
22052225void ConfigCmd::ConfigResetstat (std::string& ret) {
22062226 g_pika_server->ResetStat ();
22072227 ret = " +OK\r\n " ;
@@ -2627,6 +2647,19 @@ void DiskRecoveryCmd::Do(std::shared_ptr<Slot> slot) {
26272647 res_.SetRes (CmdRes::kOk , " The disk error has been recovered" );
26282648}
26292649
2650+ void ClearReplicationIDCmd::DoInitial () {
2651+ if (!CheckArg (argv_.size ())) {
2652+ res_.SetRes (CmdRes::kWrongNum , kCmdNameClearReplicationID );
2653+ return ;
2654+ }
2655+ }
2656+
2657+ void ClearReplicationIDCmd::Do (std::shared_ptr<Slot> slot) {
2658+ g_pika_conf->SetReplicationID (" " );
2659+ g_pika_conf->ConfigRewriteReplicationID ();
2660+ res_.SetRes (CmdRes::kOk , " ReplicationID is cleared" );
2661+ }
2662+
26302663#ifdef WITH_COMMAND_DOCS
26312664
26322665bool CommandCmd::CommandFieldCompare::operator ()(const std::string& a, const std::string& b) const {
0 commit comments