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
e1b6c9dd
Commit
e1b6c9dd
authored
Mar 13, 2015
by
antirez
Browse files
Cluster: CLUSTER NODES speedup.
parent
b2e8eca7
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/cluster.c
View file @
e1b6c9dd
...
@@ -3547,28 +3547,30 @@ sds representRedisNodeFlags(sds ci, uint16_t flags) {
...
@@ -3547,28 +3547,30 @@ sds representRedisNodeFlags(sds ci, uint16_t flags) {
/* Generate a csv-alike representation of the specified cluster node.
/* Generate a csv-alike representation of the specified cluster node.
* See clusterGenNodesDescription() top comment for more information.
* See clusterGenNodesDescription() top comment for more information.
*
*
* The function returns the string representation as an SDS string. */
* The function appends the node representation to the SDS string 'ci' and
sds
clusterGenNodeDescription
(
clusterNode
*
node
)
{
* returns it (that may point to a different string as usually with the
* SDS-style API). */
sds
clusterGenNodeDescription
(
sds
ci
,
clusterNode
*
node
)
{
int
j
,
start
;
int
j
,
start
;
sds
ci
;
/* Node coordinates */
/* Node coordinates */
ci
=
sdscatprintf
(
sdsempty
(),
"%.40s %s:%d "
,
ci
=
sdscatlen
(
ci
,
node
->
name
,
40
);
node
->
name
,
ci
=
sdscatfmt
(
ci
,
" %s:%i "
,
node
->
ip
,
node
->
port
);
node
->
ip
,
node
->
port
);
/* Flags */
/* Flags */
ci
=
representRedisNodeFlags
(
ci
,
node
->
flags
);
ci
=
representRedisNodeFlags
(
ci
,
node
->
flags
);
/* Slave of... or just "-" */
/* Slave of... or just "-" */
if
(
node
->
slaveof
)
if
(
node
->
slaveof
)
{
ci
=
sdscatprintf
(
ci
,
" %.40s "
,
node
->
slaveof
->
name
);
ci
=
sdscatlen
(
ci
,
" "
,
1
);
else
ci
=
sdscatlen
(
ci
,
node
->
slaveof
->
name
,
40
);
ci
=
sdscatlen
(
ci
,
" "
,
1
);
}
else
{
ci
=
sdscatlen
(
ci
,
" - "
,
3
);
ci
=
sdscatlen
(
ci
,
" - "
,
3
);
}
/* Latency from the POV of this node, link status */
/* Latency from the POV of this node, link status */
ci
=
sdscat
printf
(
ci
,
"%lld %lld %llu
%s"
,
ci
=
sdscat
fmt
(
ci
,
"%I %I %U
%s"
,
(
long
long
)
node
->
ping_sent
,
(
long
long
)
node
->
ping_sent
,
(
long
long
)
node
->
pong_received
,
(
long
long
)
node
->
pong_received
,
(
unsigned
long
long
)
node
->
configEpoch
,
(
unsigned
long
long
)
node
->
configEpoch
,
...
@@ -3580,6 +3582,19 @@ sds clusterGenNodeDescription(clusterNode *node) {
...
@@ -3580,6 +3582,19 @@ sds clusterGenNodeDescription(clusterNode *node) {
for
(
j
=
0
;
j
<
REDIS_CLUSTER_SLOTS
;
j
++
)
{
for
(
j
=
0
;
j
<
REDIS_CLUSTER_SLOTS
;
j
++
)
{
int
bit
;
int
bit
;
/* It is common for a node to have pretty contiguous slots, so
* optimize this loop by skipping whole 32bit words if they have
* no set bits. We stop to the penultimate word because last word
* has special handling when start != -1 (later in the loop). */
if
((
j
&
31
)
==
0
&&
j
<
REDIS_CLUSTER_SLOTS
-
32
)
{
uint32_t
*
slotword
=
((
uint32_t
*
)
node
->
slots
)
+
(
j
/
32
);
if
((
start
==
-
1
&&
*
slotword
==
0
)
||
(
start
!=
-
1
&&
*
slotword
==
UINT32_MAX
))
{
j
+=
32
;
continue
;
}
}
if
((
bit
=
clusterNodeGetSlotBit
(
node
,
j
))
!=
0
)
{
if
((
bit
=
clusterNodeGetSlotBit
(
node
,
j
))
!=
0
)
{
if
(
start
==
-
1
)
start
=
j
;
if
(
start
==
-
1
)
start
=
j
;
}
}
...
@@ -3625,18 +3640,19 @@ sds clusterGenNodeDescription(clusterNode *node) {
...
@@ -3625,18 +3640,19 @@ sds clusterGenNodeDescription(clusterNode *node) {
* of the CLUSTER NODES function, and as format for the cluster
* of the CLUSTER NODES function, and as format for the cluster
* configuration file (nodes.conf) for a given node. */
* configuration file (nodes.conf) for a given node. */
sds
clusterGenNodesDescription
(
int
filter
)
{
sds
clusterGenNodesDescription
(
int
filter
)
{
sds
ci
=
sdsempty
()
,
ni
;
sds
ci
=
sdsempty
();
dictIterator
*
di
;
dictIterator
*
di
;
dictEntry
*
de
;
dictEntry
*
de
;
/* Make room to avoid multiple resizes of the buffer. */
ci
=
sdsMakeRoomFor
(
ci
,
256
*
dictSize
(
server
.
cluster
->
nodes
));
di
=
dictGetSafeIterator
(
server
.
cluster
->
nodes
);
di
=
dictGetSafeIterator
(
server
.
cluster
->
nodes
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
clusterNode
*
node
=
dictGetVal
(
de
);
clusterNode
*
node
=
dictGetVal
(
de
);
if
(
node
->
flags
&
filter
)
continue
;
if
(
node
->
flags
&
filter
)
continue
;
ni
=
clusterGenNodeDescription
(
node
);
ci
=
clusterGenNodeDescription
(
ci
,
node
);
ci
=
sdscatsds
(
ci
,
ni
);
sdsfree
(
ni
);
ci
=
sdscatlen
(
ci
,
"
\n
"
,
1
);
ci
=
sdscatlen
(
ci
,
"
\n
"
,
1
);
}
}
dictReleaseIterator
(
di
);
dictReleaseIterator
(
di
);
...
@@ -4093,7 +4109,7 @@ void clusterCommand(redisClient *c) {
...
@@ -4093,7 +4109,7 @@ void clusterCommand(redisClient *c) {
addReplyMultiBulkLen
(
c
,
n
->
numslaves
);
addReplyMultiBulkLen
(
c
,
n
->
numslaves
);
for
(
j
=
0
;
j
<
n
->
numslaves
;
j
++
)
{
for
(
j
=
0
;
j
<
n
->
numslaves
;
j
++
)
{
sds
ni
=
clusterGenNodeDescription
(
n
->
slaves
[
j
]);
sds
ni
=
clusterGenNodeDescription
(
sdsempty
(),
n
->
slaves
[
j
]);
addReplyBulkCString
(
c
,
ni
);
addReplyBulkCString
(
c
,
ni
);
sdsfree
(
ni
);
sdsfree
(
ni
);
}
}
...
...
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