Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
0a3edcbe
Commit
0a3edcbe
authored
Jan 21, 2015
by
antirez
Browse files
Cluster: node deletion cleanup / centralization.
parent
5130c253
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
0a3edcbe
...
@@ -819,6 +819,7 @@ int clusterCountNonFailingSlaves(clusterNode *n) {
...
@@ -819,6 +819,7 @@ int clusterCountNonFailingSlaves(clusterNode *n) {
return okslaves;
return okslaves;
}
}
/* Low level cleanup of the node structure. Only called by clusterDelNode(). */
void freeClusterNode(clusterNode *n) {
void freeClusterNode(clusterNode *n) {
sds nodename;
sds nodename;
int j;
int j;
...
@@ -830,10 +831,15 @@ void freeClusterNode(clusterNode *n) {
...
@@ -830,10 +831,15 @@ void freeClusterNode(clusterNode *n) {
n->slaves[j]->slaveof = NULL;
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);
/* Unlink from the set of nodes. */
nodename = sdsnewlen(n->name, REDIS_CLUSTER_NAMELEN);
nodename = sdsnewlen(n->name, REDIS_CLUSTER_NAMELEN);
redisAssert(dictDelete(server.cluster->nodes,nodename) == DICT_OK);
redisAssert(dictDelete(server.cluster->nodes,nodename) == DICT_OK);
sdsfree(nodename);
sdsfree(nodename);
if (n->slaveof) clusterNodeRemoveSlave(n->slaveof, n);
/* Release link and associated data structures. */
if (n->link) freeClusterLink(n->link);
if (n->link) freeClusterLink(n->link);
listRelease(n->fail_reports);
listRelease(n->fail_reports);
zfree(n);
zfree(n);
...
@@ -848,11 +854,16 @@ int clusterAddNode(clusterNode *node) {
...
@@ -848,11 +854,16 @@ int clusterAddNode(clusterNode *node) {
return (retval == DICT_OK) ? REDIS_OK : REDIS_ERR;
return (retval == DICT_OK) ? REDIS_OK : REDIS_ERR;
}
}
/* Remove a node from the cluster:
/* Remove a node from the cluster. The functio performs the high level
* 1) Mark all the nodes handled by it as unassigned.
* cleanup, calling freeClusterNode() for the low level cleanup.
* 2) Remove all the failure reports sent by this node.
* Here we do the following:
* 3) Free the node, that will in turn remove it from the hash table
*
* and from the list of slaves of its master, if it is a slave node.
* 1) Mark all the slots handled by it as unassigned.
* 2) Remove all the failure reports sent by this node and referenced by
* other nodes.
* 3) Free the node with freeClusterNode() that will in turn remove it
* from the hash table and from the list of slaves of its master, if
* it is a slave node.
*/
*/
void clusterDelNode(clusterNode *delnode) {
void clusterDelNode(clusterNode *delnode) {
int j;
int j;
...
@@ -879,11 +890,7 @@ void clusterDelNode(clusterNode *delnode) {
...
@@ -879,11 +890,7 @@ void clusterDelNode(clusterNode *delnode) {
}
}
dictReleaseIterator(di);
dictReleaseIterator(di);
/* 3) Remove this node from its master's slaves if needed. */
/* 3) Free the node, unlinking it from the cluster. */
if (nodeIsSlave(delnode) && delnode->slaveof)
clusterNodeRemoveSlave(delnode->slaveof,delnode);
/* 4) Free the node, unlinking it from the cluster. */
freeClusterNode(delnode);
freeClusterNode(delnode);
}
}
...
@@ -1619,7 +1626,7 @@ int clusterProcessPacket(clusterLink *link) {
...
@@ -1619,7 +1626,7 @@ int clusterProcessPacket(clusterLink *link) {
}
}
/* Free this node as we already have it. This will
/* Free this node as we already have it. This will
* cause the link to be freed as well. */
* cause the link to be freed as well. */
freeC
lusterNode(link->node);
c
luster
Del
Node(link->node);
return 0;
return 0;
}
}
...
@@ -2913,7 +2920,7 @@ void clusterCron(void) {
...
@@ -2913,7 +2920,7 @@ void clusterCron(void) {
/* A Node in HANDSHAKE state has a limited lifespan equal to the
/* A Node in HANDSHAKE state has a limited lifespan equal to the
* configured node timeout. */
* configured node timeout. */
if (nodeInHandshake(node) && now - node->ctime > handshake_timeout) {
if (nodeInHandshake(node) && now - node->ctime > handshake_timeout) {
freeC
lusterNode(node);
c
luster
Del
Node(node);
continue;
continue;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment