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

Function clusterSetMaster

src/cluster.cpp:4172–4188  ·  view source on GitHub ↗

Set the specified node 'n' as master for this node. * If this node is currently a master, it is turned into a slave. */

Source from the content-addressed store, hash-verified

4170/* Set the specified node 'n' as master for this node.
4171 * If this node is currently a master, it is turned into a slave. */
4172void clusterSetMaster(clusterNode *n) {
4173 serverAssert(n != myself);
4174 serverAssert(myself->numslots == 0);
4175
4176 if (nodeIsMaster(myself)) {
4177 myself->flags &= ~(CLUSTER_NODE_MASTER|CLUSTER_NODE_MIGRATE_TO);
4178 myself->flags |= CLUSTER_NODE_SLAVE;
4179 clusterCloseAllSlots();
4180 } else {
4181 if (myself->slaveof)
4182 clusterNodeRemoveSlave(myself->slaveof,myself);
4183 }
4184 myself->slaveof = n;
4185 clusterNodeAddSlave(n,myself);
4186 replicationAddMaster(n->ip, n->port);
4187 resetManualFailover();
4188}
4189
4190/* -----------------------------------------------------------------------------
4191 * Nodes to string representation functions.

Callers 3

clusterCommandFunction · 0.85

Calls 5

clusterCloseAllSlotsFunction · 0.85
clusterNodeRemoveSlaveFunction · 0.85
clusterNodeAddSlaveFunction · 0.85
replicationAddMasterFunction · 0.85
resetManualFailoverFunction · 0.85

Tested by

no test coverage detected