| 4117 | } |
| 4118 | |
| 4119 | void replicaofCommand(client *c) { |
| 4120 | /* SLAVEOF is not allowed in cluster mode as replication is automatically |
| 4121 | * configured using the current address of the master node. */ |
| 4122 | if (g_pserver->cluster_enabled) { |
| 4123 | addReplyError(c,"REPLICAOF not allowed in cluster mode."); |
| 4124 | return; |
| 4125 | } |
| 4126 | |
| 4127 | if (g_pserver->failover_state != NO_FAILOVER) { |
| 4128 | addReplyError(c,"REPLICAOF not allowed while failing over."); |
| 4129 | return; |
| 4130 | } |
| 4131 | |
| 4132 | if (c->argc > 3) { |
| 4133 | if (c->argc != 4) { |
| 4134 | addReplyError(c, "Invalid arguments"); |
| 4135 | return; |
| 4136 | } |
| 4137 | if (!strcasecmp((const char*)ptrFromObj(c->argv[1]),"remove")) { |
| 4138 | listIter li; |
| 4139 | listNode *ln; |
| 4140 | bool fRemoved = false; |
| 4141 | long port; |
| 4142 | string2l(szFromObj(c->argv[3]), sdslen(szFromObj(c->argv[3])), &port); |
| 4143 | LRestart: |
| 4144 | listRewind(g_pserver->masters, &li); |
| 4145 | while ((ln = listNext(&li))) { |
| 4146 | redisMaster *mi = (redisMaster*)listNodeValue(ln); |
| 4147 | if (mi->masterport != port) |
| 4148 | continue; |
| 4149 | if (sdscmp(szFromObj(c->argv[2]), mi->masterhost) == 0) { |
| 4150 | replicationUnsetMaster(mi); |
| 4151 | fRemoved = true; |
| 4152 | goto LRestart; |
| 4153 | } |
| 4154 | } |
| 4155 | if (!fRemoved) { |
| 4156 | addReplyError(c, "Master not found"); |
| 4157 | return; |
| 4158 | } else if (listLength(g_pserver->masters) == 0) { |
| 4159 | goto LLogNoMaster; |
| 4160 | } |
| 4161 | } |
| 4162 | } else if (!strcasecmp((const char*)ptrFromObj(c->argv[1]),"no") && |
| 4163 | !strcasecmp((const char*)ptrFromObj(c->argv[2]),"one")) { |
| 4164 | /* The special host/port combination "NO" "ONE" turns the instance |
| 4165 | * into a master. Otherwise the new master address is set. */ |
| 4166 | if (listLength(g_pserver->masters)) { |
| 4167 | while (listLength(g_pserver->masters)) |
| 4168 | { |
| 4169 | replicationUnsetMaster((redisMaster*)listNodeValue(listFirst(g_pserver->masters))); |
| 4170 | } |
| 4171 | LLogNoMaster: |
| 4172 | sds client = catClientInfoString(sdsempty(),c); |
| 4173 | serverLog(LL_NOTICE,"MASTER MODE enabled (user request from '%s')", |
| 4174 | client); |
| 4175 | sdsfree(client); |
| 4176 | } |
nothing calls this directly
no test coverage detected