MCPcopy Create free account
hub / github.com/F-Stack/f-stack / clusterUpdateSlotsConfigWith

Function clusterUpdateSlotsConfigWith

app/redis-6.2.6/src/cluster.c:1635–1741  ·  view source on GitHub ↗

This function is called when we receive a master configuration via a * PING, PONG or UPDATE packet. What we receive is a node, a configEpoch of the * node, and the set of slots claimed under this configEpoch. * * What we do is to rebind the slots with newer configuration compared to our * local configuration, and if needed, we turn ourself into a replica of the * node (see the function comme

Source from the content-addressed store, hash-verified

1633 * Sometimes it is not actually the "Sender" of the information, like in the
1634 * case we receive the info via an UPDATE packet. */
1635void clusterUpdateSlotsConfigWith(clusterNode *sender, uint64_t senderConfigEpoch, unsigned char *slots) {
1636 int j;
1637 clusterNode *curmaster = NULL, *newmaster = NULL;
1638 /* The dirty slots list is a list of slots for which we lose the ownership
1639 * while having still keys inside. This usually happens after a failover
1640 * or after a manual cluster reconfiguration operated by the admin.
1641 *
1642 * If the update message is not able to demote a master to slave (in this
1643 * case we'll resync with the master updating the whole key space), we
1644 * need to delete all the keys in the slots we lost ownership. */
1645 uint16_t dirty_slots[CLUSTER_SLOTS];
1646 int dirty_slots_count = 0;
1647
1648 /* We should detect if sender is new master of our shard.
1649 * We will know it if all our slots were migrated to sender, and sender
1650 * has no slots except ours */
1651 int sender_slots = 0;
1652 int migrated_our_slots = 0;
1653
1654 /* Here we set curmaster to this node or the node this node
1655 * replicates to if it's a slave. In the for loop we are
1656 * interested to check if slots are taken away from curmaster. */
1657 curmaster = nodeIsMaster(myself) ? myself : myself->slaveof;
1658
1659 if (sender == myself) {
1660 serverLog(LL_WARNING,"Discarding UPDATE message about myself.");
1661 return;
1662 }
1663
1664 for (j = 0; j < CLUSTER_SLOTS; j++) {
1665 if (bitmapTestBit(slots,j)) {
1666 sender_slots++;
1667
1668 /* The slot is already bound to the sender of this message. */
1669 if (server.cluster->slots[j] == sender) continue;
1670
1671 /* The slot is in importing state, it should be modified only
1672 * manually via redis-trib (example: a resharding is in progress
1673 * and the migrating side slot was already closed and is advertising
1674 * a new config. We still want the slot to be closed manually). */
1675 if (server.cluster->importing_slots_from[j]) continue;
1676
1677 /* We rebind the slot to the new node claiming it if:
1678 * 1) The slot was unassigned or the new node claims it with a
1679 * greater configEpoch.
1680 * 2) We are not currently importing the slot. */
1681 if (server.cluster->slots[j] == NULL ||
1682 server.cluster->slots[j]->configEpoch < senderConfigEpoch)
1683 {
1684 /* Was this slot mine, and still contains keys? Mark it as
1685 * a dirty slot. */
1686 if (server.cluster->slots[j] == myself &&
1687 countKeysInSlot(j) &&
1688 sender != myself)
1689 {
1690 dirty_slots[dirty_slots_count] = j;
1691 dirty_slots_count++;
1692 }

Callers 1

clusterProcessPacketFunction · 0.85

Calls 7

bitmapTestBitFunction · 0.85
countKeysInSlotFunction · 0.85
clusterDelSlotFunction · 0.85
clusterAddSlotFunction · 0.85
clusterDoBeforeSleepFunction · 0.85
clusterSetMasterFunction · 0.85
delKeysInSlotFunction · 0.85

Tested by

no test coverage detected