diff options
author | antirez <antirez@gmail.com> | 2016-01-14 17:34:49 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2016-01-25 15:21:49 +0100 |
commit | 515392c2167c045ba38ad6c57fdb5a761bc77108 (patch) | |
tree | 942c9f80041a615080ad1110160965aac33585b6 | |
parent | d5872e8e3190ce2e86d350666f03a6e361f9d2c2 (diff) | |
download | redis-515392c2167c045ba38ad6c57fdb5a761bc77108.tar.gz |
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.
-rw-r--r-- | src/cluster.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/src/cluster.c b/src/cluster.c index 7a1e48981..345dc5ffa 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -806,12 +806,6 @@ int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) { return REDIS_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); @@ -1780,9 +1772,6 @@ int clusterProcessPacket(clusterLink *link) { REDIS_NODE_MIGRATE_TO); sender->flags |= REDIS_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); |