This function implements the final part of automatic and manual failovers, * where the slave grabs its master's hash slots, and propagates the new * configuration. * * Note that it's up to the caller to be sure that the node got a new * configuration epoch already. */
| 3152 | * Note that it's up to the caller to be sure that the node got a new |
| 3153 | * configuration epoch already. */ |
| 3154 | void clusterFailoverReplaceYourMaster(void) { |
| 3155 | int j; |
| 3156 | clusterNode *oldmaster = myself->slaveof; |
| 3157 | |
| 3158 | if (nodeIsMaster(myself) || oldmaster == NULL) return; |
| 3159 | |
| 3160 | /* 1) Turn this node into a master. */ |
| 3161 | clusterSetNodeAsMaster(myself); |
| 3162 | replicationUnsetMaster(getFirstMaster()); |
| 3163 | |
| 3164 | /* 2) Claim all the slots assigned to our master. */ |
| 3165 | for (j = 0; j < CLUSTER_SLOTS; j++) { |
| 3166 | if (clusterNodeGetSlotBit(oldmaster,j)) { |
| 3167 | clusterDelSlot(j); |
| 3168 | clusterAddSlot(myself,j); |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | /* 3) Update state and save config. */ |
| 3173 | clusterUpdateState(); |
| 3174 | clusterSaveConfigOrDie(1); |
| 3175 | |
| 3176 | /* 4) Pong all the other nodes so that they can update the state |
| 3177 | * accordingly and detect that we switched to master role. */ |
| 3178 | clusterBroadcastPong(CLUSTER_BROADCAST_ALL); |
| 3179 | |
| 3180 | /* 5) If there was a manual failover in progress, clear the state. */ |
| 3181 | resetManualFailover(); |
| 3182 | } |
| 3183 | |
| 3184 | /* This function is called if we are a slave node and our master serving |
| 3185 | * a non-zero amount of hash slots is in FAIL state. |
no test coverage detected