Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xindoo
redis
提交
e1b6c9dd
R
redis
项目概览
xindoo
/
redis
通知
2
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e1b6c9dd
编写于
3月 13, 2015
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cluster: CLUSTER NODES speedup.
上级
b2e8eca7
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
32 addition
and
16 deletion
+32
-16
src/cluster.c
src/cluster.c
+32
-16
未找到文件。
src/cluster.c
浏览文件 @
e1b6c9dd
...
...
@@ -3547,28 +3547,30 @@ sds representRedisNodeFlags(sds ci, uint16_t flags) {
/* Generate a csv-alike representation of the specified cluster node.
* See clusterGenNodesDescription() top comment for more information.
*
* The function returns the string representation as an SDS string. */
sds
clusterGenNodeDescription
(
clusterNode
*
node
)
{
* The function appends the node representation to the SDS string 'ci' and
* 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
;
sds
ci
;
/* Node coordinates */
ci
=
sdscatprintf
(
sdsempty
(),
"%.40s %s:%d "
,
node
->
name
,
node
->
ip
,
node
->
port
);
ci
=
sdscatlen
(
ci
,
node
->
name
,
40
);
ci
=
sdscatfmt
(
ci
,
" %s:%i "
,
node
->
ip
,
node
->
port
);
/* Flags */
ci
=
representRedisNodeFlags
(
ci
,
node
->
flags
);
/* Slave of... or just "-" */
if
(
node
->
slaveof
)
ci
=
sdscatprintf
(
ci
,
" %.40s "
,
node
->
slaveof
->
name
);
else
if
(
node
->
slaveof
)
{
ci
=
sdscatlen
(
ci
,
" "
,
1
);
ci
=
sdscatlen
(
ci
,
node
->
slaveof
->
name
,
40
);
ci
=
sdscatlen
(
ci
,
" "
,
1
);
}
else
{
ci
=
sdscatlen
(
ci
,
" - "
,
3
);
}
/* 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
->
pong_received
,
(
unsigned
long
long
)
node
->
configEpoch
,
...
...
@@ -3580,6 +3582,19 @@ sds clusterGenNodeDescription(clusterNode *node) {
for
(
j
=
0
;
j
<
REDIS_CLUSTER_SLOTS
;
j
++
)
{
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
(
start
==
-
1
)
start
=
j
;
}
...
...
@@ -3625,18 +3640,19 @@ sds clusterGenNodeDescription(clusterNode *node) {
* 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
;
sds
ci
=
sdsempty
();
dictIterator
*
di
;
dictEntry
*
de
;
/* Make room to avoid multiple resizes of the buffer. */
ci
=
sdsMakeRoomFor
(
ci
,
256
*
dictSize
(
server
.
cluster
->
nodes
));
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
=
clusterGenNodeDescription
(
ci
,
node
);
ci
=
sdscatlen
(
ci
,
"
\n
"
,
1
);
}
dictReleaseIterator
(
di
);
...
...
@@ -4093,7 +4109,7 @@ void clusterCommand(redisClient *c) {
addReplyMultiBulkLen
(
c
,
n
->
numslaves
);
for
(
j
=
0
;
j
<
n
->
numslaves
;
j
++
)
{
sds
ni
=
clusterGenNodeDescription
(
n
->
slaves
[
j
]);
sds
ni
=
clusterGenNodeDescription
(
sdsempty
(),
n
->
slaves
[
j
]);
addReplyBulkCString
(
c
,
ni
);
sdsfree
(
ni
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录