MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / clusterManagerFixMultipleSlotOwners

Function clusterManagerFixMultipleSlotOwners

src/redis-cli.c:4476–4511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4474}
4475
4476int clusterManagerFixMultipleSlotOwners(int slot, list *owners) {
4477 clusterManagerLogInfo(">>> Fixing multiple owners for slot %d...\n", slot);
4478 int success = 0;
4479 assert(listLength(owners) > 1);
4480 clusterManagerNode *owner = clusterManagerGetNodeWithMostKeysInSlot(owners,
4481 slot,
4482 NULL);
4483 if (!owner) owner = listFirst(owners)->value;
4484 clusterManagerLogInfo(">>> Setting slot %d owner: %s:%d\n",
4485 slot, owner->ip, owner->port);
4486 /* Set the slot owner. */
4487 if (!clusterManagerSetSlotOwner(owner, slot, 0)) return 0;
4488 listIter li;
4489 listNode *ln;
4490 listRewind(cluster_manager.nodes, &li);
4491 /* Update configuration in all the other master nodes by assigning the slot
4492 * itself to the new owner, and by eventually migrating keys if the node
4493 * has keys for the slot. */
4494 while ((ln = listNext(&li)) != NULL) {
4495 clusterManagerNode *n = ln->value;
4496 if (n == owner) continue;
4497 if (n->flags & CLUSTER_MANAGER_FLAG_SLAVE) continue;
4498 int count = clusterManagerCountKeysInSlot(n, slot);
4499 success = (count >= 0);
4500 if (!success) break;
4501 clusterManagerDelSlot(n, slot, 1);
4502 if (!clusterManagerSetSlot(n, owner, slot, "node", NULL)) return 0;
4503 if (count > 0) {
4504 int opts = CLUSTER_MANAGER_OPT_VERBOSE |
4505 CLUSTER_MANAGER_OPT_COLD;
4506 success = clusterManagerMoveSlot(n, owner, slot, opts, NULL);
4507 if (!success) break;
4508 }
4509 }
4510 return success;
4511}
4512
4513static clusterManagerNode *clusterNodeForResharding(char *id,
4514 clusterManagerNode *target,

Callers 1

Calls 8

listRewindFunction · 0.85
listNextFunction · 0.85
clusterManagerDelSlotFunction · 0.85
clusterManagerSetSlotFunction · 0.85
clusterManagerMoveSlotFunction · 0.85

Tested by

no test coverage detected