Commit fc3ca8ff authored by antirez's avatar antirez
Browse files

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.
parent a411d557
...@@ -806,12 +806,6 @@ int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) { ...@@ -806,12 +806,6 @@ int clusterNodeAddSlave(clusterNode *master, clusterNode *slave) {
return C_OK; return C_OK;
} }
void clusterNodeResetSlaves(clusterNode *n) {
zfree(n->slaves);
n->numslaves = 0;
n->slaves = NULL;
}
int clusterCountNonFailingSlaves(clusterNode *n) { int clusterCountNonFailingSlaves(clusterNode *n) {
int j, okslaves = 0; int j, okslaves = 0;
...@@ -825,12 +819,10 @@ void freeClusterNode(clusterNode *n) { ...@@ -825,12 +819,10 @@ void freeClusterNode(clusterNode *n) {
sds nodename; sds nodename;
int j; 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). */ * all the slaves->slaveof fields to NULL (unknown). */
if (nodeIsMaster(n)) { for (j = 0; j < n->numslaves; j++)
for (j = 0; j < n->numslaves; j++) n->slaves[j]->slaveof = NULL;
n->slaves[j]->slaveof = NULL;
}
/* Remove this node from the list of slaves of its master. */ /* Remove this node from the list of slaves of its master. */
if (nodeIsSlave(n) && n->slaveof) clusterNodeRemoveSlave(n->slaveof,n); if (nodeIsSlave(n) && n->slaveof) clusterNodeRemoveSlave(n->slaveof,n);
...@@ -1775,9 +1767,6 @@ int clusterProcessPacket(clusterLink *link) { ...@@ -1775,9 +1767,6 @@ int clusterProcessPacket(clusterLink *link) {
CLUSTER_NODE_MIGRATE_TO); CLUSTER_NODE_MIGRATE_TO);
sender->flags |= CLUSTER_NODE_SLAVE; sender->flags |= CLUSTER_NODE_SLAVE;
/* Remove the list of slaves from the node. */
if (sender->numslaves) clusterNodeResetSlaves(sender);
/* Update config and state. */ /* Update config and state. */
clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG| clusterDoBeforeSleep(CLUSTER_TODO_SAVE_CONFIG|
CLUSTER_TODO_UPDATE_STATE); CLUSTER_TODO_UPDATE_STATE);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment