From fc3ca8ff8714124901a438cd7277d9e4e1cdae46 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 14 Jan 2016 17:34:49 +0100 Subject: [PATCH] Cluster: fix setting nodes slaveof pointer to NULL on node release. With this commit we preserve the list of nodes that have .slaveof set to the node, even when the node is turned into a slave, and make sure to fix the .slaveof pointers to NULL when a node is freed from memory, regardless of the fact it's a slave or a master. Basically we try to remember the logical master in the current configuration even if the logical master advertised it as a slave already. However we still remember the associations, so that when a node is freed we can fix them. This should fix issue #3002. --- src/cluster.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/src/cluster.c b/src/cluster.c index 18ae0ab0b..f7c942585 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -806,12 +806,6 @@ int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) { return C_OK; } -void clusterNodeResetSlaves(clusterNode *n) { - zfree(n->slaves); - n->numslaves = 0; - n->slaves = NULL; -} - int clusterCountNonFailingSlaves(clusterNode *n) { int j, okslaves = 0; @@ -825,12 +819,10 @@ void freeClusterNode(clusterNode *n) { sds nodename; int j; - /* If the node is a master with associated slaves, we have to set + /* If the node has associated slaves, we have to set * all the slaves->slaveof fields to NULL (unknown). */ - if (nodeIsMaster(n)) { - for (j = 0; j < n->numslaves; j++) - n->slaves[j]->slaveof = NULL; - } + for (j = 0; j < n->numslaves; j++) + n->slaves[j]->slaveof = NULL; /* Remove this node from the list of slaves of its master. */ if (nodeIsSlave(n) && n->slaveof) clusterNodeRemoveSlave(n->slaveof,n); @@ -1775,9 +1767,6 @@ int clusterProcessPacket(clusterLink *link) { CLUSTER_NODE_MIGRATE_TO); sender->flags |= CLUSTER_NODE_SLAVE; - /* Remove the list of slaves from the node. */ - if (sender->numslaves) clusterNodeResetSlaves(sender); - /* Update config and state. */ clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG| CLUSTER_TODO_UPDATE_STATE);