| 5223 | } |
| 5224 | |
| 5225 | static int clusterManagerFixMultipleSlotOwners(int slot, list *owners) { |
| 5226 | clusterManagerLogInfo(">>> Fixing multiple owners for slot %d...\n", slot); |
| 5227 | int success = 0; |
| 5228 | assert(listLength(owners) > 1); |
| 5229 | clusterManagerNode *owner = clusterManagerGetNodeWithMostKeysInSlot(owners, |
| 5230 | slot, |
| 5231 | NULL); |
| 5232 | if (!owner) owner = listFirst(owners)->value; |
| 5233 | clusterManagerLogInfo(">>> Setting slot %d owner: %s:%d\n", |
| 5234 | slot, owner->ip, owner->port); |
| 5235 | /* Set the slot owner. */ |
| 5236 | if (!clusterManagerSetSlotOwner(owner, slot, 0)) return 0; |
| 5237 | listIter li; |
| 5238 | listNode *ln; |
| 5239 | listRewind(cluster_manager.nodes, &li); |
| 5240 | /* Update configuration in all the other master nodes by assigning the slot |
| 5241 | * itself to the new owner, and by eventually migrating keys if the node |
| 5242 | * has keys for the slot. */ |
| 5243 | while ((ln = listNext(&li)) != NULL) { |
| 5244 | clusterManagerNode *n = ln->value; |
| 5245 | if (n == owner) continue; |
| 5246 | if (n->flags & CLUSTER_MANAGER_FLAG_SLAVE) continue; |
| 5247 | int count = clusterManagerCountKeysInSlot(n, slot); |
| 5248 | success = (count >= 0); |
| 5249 | if (!success) break; |
| 5250 | clusterManagerDelSlot(n, slot, 1); |
| 5251 | if (!clusterManagerSetSlot(n, owner, slot, "node", NULL)) return 0; |
| 5252 | if (count > 0) { |
| 5253 | int opts = CLUSTER_MANAGER_OPT_VERBOSE | |
| 5254 | CLUSTER_MANAGER_OPT_COLD; |
| 5255 | success = clusterManagerMoveSlot(n, owner, slot, opts, NULL); |
| 5256 | if (!success) break; |
| 5257 | } |
| 5258 | } |
| 5259 | return success; |
| 5260 | } |
| 5261 | |
| 5262 | static int clusterManagerCheckCluster(int quiet) { |
| 5263 | listNode *ln = listFirst(cluster_manager.nodes); |
no test coverage detected