Cluster: master node must clear its hash slots when turning into a slave.

When a master turns into a slave after a failover event, make sure to
clear the assigned slots before setting up the replication, as a slave
should never claim slots in an explicit way, but just take over the
master slots when replacing its master.
This commit is contained in:
antirez 2013-03-20 11:32:35 +01:00
parent 506f9a42b0
commit e006407fd0

View File

@ -907,6 +907,7 @@ int clusterProcessPacket(clusterLink *link) {
oldmaster == server.cluster->myself)
{
redisLog(REDIS_WARNING,"One of my slaves took my place. Reconfiguring myself as a replica of %.40s", sender->name);
clusterDelNodeSlots(server.cluster->myself);
clusterSetMaster(sender);
}
@ -1836,11 +1837,13 @@ int verifyClusterConfigWithData(void) {
* SLAVE nodes handling
* -------------------------------------------------------------------------- */
/* Set the specified node 'n' as master. */
/* Set the specified node 'n' as master. Setup the node as a slave if
* needed. */
void clusterSetMaster(clusterNode *n) {
clusterNode *myself = server.cluster->myself;
redisAssert(n != myself);
redisAssert(myself->numslots == 0);
if (myself->flags & REDIS_NODE_MASTER) {
myself->flags &= ~REDIS_NODE_MASTER;