From e006407fd08bb2b0a7f0aac703e367786ae85168 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 20 Mar 2013 11:32:35 +0100 Subject: [PATCH] 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. --- src/cluster.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cluster.c b/src/cluster.c index f26cc98c..34c5627f 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -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;