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
603e480f
Commit
603e480f
authored
Jan 22, 2014
by
antirez
Browse files
Cluster: clusterGenNodesDescription() refactored into two functions.
parent
1cf532dc
Changes
1
Show whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
603e480f
...
...
@@ -2510,32 +2510,16 @@ void clusterSetMaster(clusterNode *n) {
* CLUSTER command
* -------------------------------------------------------------------------- */
/* Generate a csv-alike representation of the nodes we are aware of,
* including the "myself" node, and return an SDS string containing the
* representation (it is up to the caller to free it).
*
* All the nodes matching at least one of the node flags specified in
* "filter" are excluded from the output, so using zero as a filter will
* include all the known nodes in the representation, including nodes in
* the HANDSHAKE state.
/* Generate a csv-alike representation of the specified cluster node.
* See clusterGenNodesDescription() top comment for more information.
*
* The representation obtained using this function is used for the output
* of the CLUSTER NODES function, and as format for the cluster
* configuration file (nodes.conf) for a given node. */
sds
clusterGenNodesDescription
(
int
filter
)
{
sds
ci
=
sdsempty
();
dictIterator
*
di
;
dictEntry
*
de
;
* The function returns the string representation as an SDS string. */
sds clusterGenNodeDescription(clusterNode *node) {
int j, start;
di
=
dictGetSafeIterator
(
server
.
cluster
->
nodes
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
clusterNode
*
node
=
dictGetVal
(
de
);
if
(
node
->
flags
&
filter
)
continue
;
sds ci;
/* Node coordinates */
ci
=
sdscatprintf
(
ci
,
"%.40s %s:%d "
,
ci = sdscatprintf(
sdsempty()
,"%.40s %s:%d ",
node->name,
node->ip,
node->port);
...
...
@@ -2599,6 +2583,34 @@ sds clusterGenNodesDescription(int filter) {
}
}
}
return ci;
}
/* Generate a csv-alike representation of the nodes we are aware of,
* including the "myself" node, and return an SDS string containing the
* representation (it is up to the caller to free it).
*
* All the nodes matching at least one of the node flags specified in
* "filter" are excluded from the output, so using zero as a filter will
* include all the known nodes in the representation, including nodes in
* the HANDSHAKE state.
*
* The representation obtained using this function is used for the output
* of the CLUSTER NODES function, and as format for the cluster
* configuration file (nodes.conf) for a given node. */
sds clusterGenNodesDescription(int filter) {
sds ci = sdsempty(), ni;
dictIterator *di;
dictEntry *de;
di = dictGetSafeIterator(server.cluster->nodes);
while((de = dictNext(di)) != NULL) {
clusterNode *node = dictGetVal(de);
if (node->flags & filter) continue;
ni = clusterGenNodeDescription(node);
ci = sdscatsds(ci,ni);
sdsfree(ni);
ci = sdscatlen(ci,"\n",1);
}
dictReleaseIterator(di);
...
...
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