Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
603e480f
R
redis
项目概览
Turbo码先生
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
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,发现更多精彩内容 >>
提交
603e480f
编写于
1月 22, 2014
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cluster: clusterGenNodesDescription() refactored into two functions.
上级
1cf532dc
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
80 addition
and
68 deletion
+80
-68
src/cluster.c
src/cluster.c
+80
-68
未找到文件。
src/cluster.c
浏览文件 @
603e480f
...
...
@@ -2510,6 +2510,82 @@ void clusterSetMaster(clusterNode *n) {
* CLUSTER command
* -------------------------------------------------------------------------- */
/* 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
)
{
int
j
,
start
;
sds
ci
;
/* Node coordinates */
ci
=
sdscatprintf
(
sdsempty
(),
"%.40s %s:%d "
,
node
->
name
,
node
->
ip
,
node
->
port
);
/* Flags */
if
(
node
->
flags
==
0
)
ci
=
sdscat
(
ci
,
"noflags,"
);
if
(
node
->
flags
&
REDIS_NODE_MYSELF
)
ci
=
sdscat
(
ci
,
"myself,"
);
if
(
node
->
flags
&
REDIS_NODE_MASTER
)
ci
=
sdscat
(
ci
,
"master,"
);
if
(
node
->
flags
&
REDIS_NODE_SLAVE
)
ci
=
sdscat
(
ci
,
"slave,"
);
if
(
node
->
flags
&
REDIS_NODE_PFAIL
)
ci
=
sdscat
(
ci
,
"fail?,"
);
if
(
node
->
flags
&
REDIS_NODE_FAIL
)
ci
=
sdscat
(
ci
,
"fail,"
);
if
(
node
->
flags
&
REDIS_NODE_HANDSHAKE
)
ci
=
sdscat
(
ci
,
"handshake,"
);
if
(
node
->
flags
&
REDIS_NODE_NOADDR
)
ci
=
sdscat
(
ci
,
"noaddr,"
);
if
(
ci
[
sdslen
(
ci
)
-
1
]
==
','
)
ci
[
sdslen
(
ci
)
-
1
]
=
' '
;
/* Slave of... or just "-" */
if
(
node
->
slaveof
)
ci
=
sdscatprintf
(
ci
,
"%.40s "
,
node
->
slaveof
->
name
);
else
ci
=
sdscatprintf
(
ci
,
"- "
);
/* Latency from the POV of this node, link status */
ci
=
sdscatprintf
(
ci
,
"%lld %lld %llu %s"
,
(
long
long
)
node
->
ping_sent
,
(
long
long
)
node
->
pong_received
,
(
unsigned
long
long
)
node
->
configEpoch
,
(
node
->
link
||
node
->
flags
&
REDIS_NODE_MYSELF
)
?
"connected"
:
"disconnected"
);
/* Slots served by this instance */
start
=
-
1
;
for
(
j
=
0
;
j
<
REDIS_CLUSTER_SLOTS
;
j
++
)
{
int
bit
;
if
((
bit
=
clusterNodeGetSlotBit
(
node
,
j
))
!=
0
)
{
if
(
start
==
-
1
)
start
=
j
;
}
if
(
start
!=
-
1
&&
(
!
bit
||
j
==
REDIS_CLUSTER_SLOTS
-
1
))
{
if
(
j
==
REDIS_CLUSTER_SLOTS
-
1
)
j
++
;
if
(
start
==
j
-
1
)
{
ci
=
sdscatprintf
(
ci
,
" %d"
,
start
);
}
else
{
ci
=
sdscatprintf
(
ci
,
" %d-%d"
,
start
,
j
-
1
);
}
start
=
-
1
;
}
}
/* Just for MYSELF node we also dump info about slots that
* we are migrating to other instances or importing from other
* instances. */
if
(
node
->
flags
&
REDIS_NODE_MYSELF
)
{
for
(
j
=
0
;
j
<
REDIS_CLUSTER_SLOTS
;
j
++
)
{
if
(
server
.
cluster
->
migrating_slots_to
[
j
])
{
ci
=
sdscatprintf
(
ci
,
" [%d->-%.40s]"
,
j
,
server
.
cluster
->
migrating_slots_to
[
j
]
->
name
);
}
else
if
(
server
.
cluster
->
importing_slots_from
[
j
])
{
ci
=
sdscatprintf
(
ci
,
" [%d-<-%.40s]"
,
j
,
server
.
cluster
->
importing_slots_from
[
j
]
->
name
);
}
}
}
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).
...
...
@@ -2523,82 +2599,18 @@ void clusterSetMaster(clusterNode *n) {
* 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
();
sds
ci
=
sdsempty
()
,
ni
;
dictIterator
*
di
;
dictEntry
*
de
;
int
j
,
start
;
di
=
dictGetSafeIterator
(
server
.
cluster
->
nodes
);
while
((
de
=
dictNext
(
di
))
!=
NULL
)
{
clusterNode
*
node
=
dictGetVal
(
de
);
if
(
node
->
flags
&
filter
)
continue
;
/* Node coordinates */
ci
=
sdscatprintf
(
ci
,
"%.40s %s:%d "
,
node
->
name
,
node
->
ip
,
node
->
port
);
/* Flags */
if
(
node
->
flags
==
0
)
ci
=
sdscat
(
ci
,
"noflags,"
);
if
(
node
->
flags
&
REDIS_NODE_MYSELF
)
ci
=
sdscat
(
ci
,
"myself,"
);
if
(
node
->
flags
&
REDIS_NODE_MASTER
)
ci
=
sdscat
(
ci
,
"master,"
);
if
(
node
->
flags
&
REDIS_NODE_SLAVE
)
ci
=
sdscat
(
ci
,
"slave,"
);
if
(
node
->
flags
&
REDIS_NODE_PFAIL
)
ci
=
sdscat
(
ci
,
"fail?,"
);
if
(
node
->
flags
&
REDIS_NODE_FAIL
)
ci
=
sdscat
(
ci
,
"fail,"
);
if
(
node
->
flags
&
REDIS_NODE_HANDSHAKE
)
ci
=
sdscat
(
ci
,
"handshake,"
);
if
(
node
->
flags
&
REDIS_NODE_NOADDR
)
ci
=
sdscat
(
ci
,
"noaddr,"
);
if
(
ci
[
sdslen
(
ci
)
-
1
]
==
','
)
ci
[
sdslen
(
ci
)
-
1
]
=
' '
;
/* Slave of... or just "-" */
if
(
node
->
slaveof
)
ci
=
sdscatprintf
(
ci
,
"%.40s "
,
node
->
slaveof
->
name
);
else
ci
=
sdscatprintf
(
ci
,
"- "
);
/* Latency from the POV of this node, link status */
ci
=
sdscatprintf
(
ci
,
"%lld %lld %llu %s"
,
(
long
long
)
node
->
ping_sent
,
(
long
long
)
node
->
pong_received
,
(
unsigned
long
long
)
node
->
configEpoch
,
(
node
->
link
||
node
->
flags
&
REDIS_NODE_MYSELF
)
?
"connected"
:
"disconnected"
);
/* Slots served by this instance */
start
=
-
1
;
for
(
j
=
0
;
j
<
REDIS_CLUSTER_SLOTS
;
j
++
)
{
int
bit
;
if
((
bit
=
clusterNodeGetSlotBit
(
node
,
j
))
!=
0
)
{
if
(
start
==
-
1
)
start
=
j
;
}
if
(
start
!=
-
1
&&
(
!
bit
||
j
==
REDIS_CLUSTER_SLOTS
-
1
))
{
if
(
j
==
REDIS_CLUSTER_SLOTS
-
1
)
j
++
;
if
(
start
==
j
-
1
)
{
ci
=
sdscatprintf
(
ci
,
" %d"
,
start
);
}
else
{
ci
=
sdscatprintf
(
ci
,
" %d-%d"
,
start
,
j
-
1
);
}
start
=
-
1
;
}
}
/* Just for MYSELF node we also dump info about slots that
* we are migrating to other instances or importing from other
* instances. */
if
(
node
->
flags
&
REDIS_NODE_MYSELF
)
{
for
(
j
=
0
;
j
<
REDIS_CLUSTER_SLOTS
;
j
++
)
{
if
(
server
.
cluster
->
migrating_slots_to
[
j
])
{
ci
=
sdscatprintf
(
ci
,
" [%d->-%.40s]"
,
j
,
server
.
cluster
->
migrating_slots_to
[
j
]
->
name
);
}
else
if
(
server
.
cluster
->
importing_slots_from
[
j
])
{
ci
=
sdscatprintf
(
ci
,
" [%d-<-%.40s]"
,
j
,
server
.
cluster
->
importing_slots_from
[
j
]
->
name
);
}
}
}
ni
=
clusterGenNodeDescription
(
node
);
ci
=
sdscatsds
(
ci
,
ni
);
sdsfree
(
ni
);
ci
=
sdscatlen
(
ci
,
"
\n
"
,
1
);
}
dictReleaseIterator
(
di
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录