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
2601e3e4
Commit
2601e3e4
authored
Jan 21, 2015
by
antirez
Browse files
Cluster: node deletion cleanup / centralization.
parent
59ad6ac5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
2601e3e4
...
...
@@ -819,6 +819,7 @@ int clusterCountNonFailingSlaves(clusterNode *n) {
return
okslaves
;
}
/* Low level cleanup of the node structure. Only called by clusterDelNode(). */
void
freeClusterNode
(
clusterNode
*
n
)
{
sds
nodename
;
int
j
;
...
...
@@ -830,10 +831,15 @@ void freeClusterNode(clusterNode *n) {
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
);
redisAssert
(
dictDelete
(
server
.
cluster
->
nodes
,
nodename
)
==
DICT_OK
);
sdsfree
(
nodename
);
if
(
n
->
slaveof
)
clusterNodeRemoveSlave
(
n
->
slaveof
,
n
);
/* Release link and associated data structures. */
if
(
n
->
link
)
freeClusterLink
(
n
->
link
);
listRelease
(
n
->
fail_reports
);
zfree
(
n
);
...
...
@@ -848,11 +854,16 @@ int clusterAddNode(clusterNode *node) {
return
(
retval
==
DICT_OK
)
?
REDIS_OK
:
REDIS_ERR
;
}
/* Remove a node from the cluster:
* 1) Mark all the nodes handled by it as unassigned.
* 2) Remove all the failure reports sent by this node.
* 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.
/* Remove a node from the cluster. The functio performs the high level
* cleanup, calling freeClusterNode() for the low level cleanup.
* Here we do the following:
*
* 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
)
{
int
j
;
...
...
@@ -879,11 +890,7 @@ void clusterDelNode(clusterNode *delnode) {
}
dictReleaseIterator
(
di
);
/* 3) Remove this node from its master's slaves if needed. */
if
(
nodeIsSlave
(
delnode
)
&&
delnode
->
slaveof
)
clusterNodeRemoveSlave
(
delnode
->
slaveof
,
delnode
);
/* 4) Free the node, unlinking it from the cluster. */
/* 3) Free the node, unlinking it from the cluster. */
freeClusterNode
(
delnode
);
}
...
...
@@ -1619,7 +1626,7 @@ int clusterProcessPacket(clusterLink *link) {
}
/* Free this node as we already have it. This will
* cause the link to be freed as well. */
freeC
lusterNode
(
link
->
node
);
c
luster
Del
Node
(
link
->
node
);
return
0
;
}
...
...
@@ -2913,7 +2920,7 @@ void clusterCron(void) {
/* A Node in HANDSHAKE state has a limited lifespan equal to the
* configured node timeout. */
if
(
nodeInHandshake
(
node
)
&&
now
-
node
->
ctime
>
handshake_timeout
)
{
freeC
lusterNode
(
node
);
c
luster
Del
Node
(
node
);
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