Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Turbo码先生
redis
提交
ae717310
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,发现更多精彩内容 >>
提交
ae717310
编写于
4月 11, 2013
作者:
A
antirez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cluster: PING/PONG handling redesigned.
上级
a120560f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
61 addition
and
40 deletion
+61
-40
src/cluster.c
src/cluster.c
+61
-40
未找到文件。
src/cluster.c
浏览文件 @
ae717310
...
...
@@ -888,7 +888,23 @@ int clusterProcessPacket(clusterLink *link) {
}
/* Update our info about the node */
if
(
link
->
node
)
link
->
node
->
pong_received
=
time
(
NULL
);
if
(
link
->
node
&&
type
==
CLUSTERMSG_TYPE_PONG
)
{
link
->
node
->
pong_received
=
time
(
NULL
);
link
->
node
->
ping_sent
=
0
;
/* The PFAIL condition can be reversed without external
* help if it is not transitive (that is, if it does not
* turn into a FAIL state).
*
* The FAIL condition is also reversible under specific
* conditions detected by clearNodeFailureIfNeeded(). */
if
(
link
->
node
->
flags
&
REDIS_NODE_PFAIL
)
{
link
->
node
->
flags
&=
~
REDIS_NODE_PFAIL
;
update_state
=
1
;
}
else
if
(
link
->
node
->
flags
&
REDIS_NODE_FAIL
)
{
clearNodeFailureIfNeeded
(
link
->
node
);
}
}
/* Update master/slave state */
if
(
sender
)
{
...
...
@@ -1502,8 +1518,8 @@ void clusterCron(void) {
dictIterator
*
di
;
dictEntry
*
de
;
int
j
,
update_state
=
0
;
time_t
min_p
ing_sent
=
0
;
clusterNode
*
min_p
i
ng_node
=
NULL
;
time_t
min_p
ong
=
0
;
clusterNode
*
min_p
o
ng_node
=
NULL
;
/* Check if we have disconnected nodes and re-establish the connection. */
di
=
dictGetIterator
(
server
.
cluster
->
nodes
);
...
...
@@ -1522,7 +1538,10 @@ void clusterCron(void) {
link
->
fd
=
fd
;
node
->
link
=
link
;
aeCreateFileEvent
(
server
.
el
,
link
->
fd
,
AE_READABLE
,
clusterReadHandler
,
link
);
/* If the node is flagged as MEET, we send a MEET message instead
/* Queue a PING in the new connection ASAP: this is crucial
* to avoid false positives in failure detection.
*
* If the node is flagged as MEET, we send a MEET message instead
* of a PING one, to force the receiver to add us in its node
* table. */
clusterSendPing
(
link
,
node
->
flags
&
REDIS_NODE_MEET
?
...
...
@@ -1540,21 +1559,22 @@ void clusterCron(void) {
dictReleaseIterator
(
di
);
/* Ping some random node. Check a few random nodes and ping the one with
* the oldest p
ing_sent
time */
* the oldest p
ong_received
time */
for
(
j
=
0
;
j
<
5
;
j
++
)
{
de
=
dictGetRandomKey
(
server
.
cluster
->
nodes
);
clusterNode
*
this
=
dictGetVal
(
de
);
if
(
this
->
link
==
NULL
)
continue
;
/* Don't ping nodes disconnected or with a ping currently active. */
if
(
this
->
link
==
NULL
||
this
->
ping_sent
!=
0
)
continue
;
if
(
this
->
flags
&
(
REDIS_NODE_MYSELF
|
REDIS_NODE_HANDSHAKE
))
continue
;
if
(
min_p
ing_node
==
NULL
||
min_ping_sent
>
this
->
ping_sent
)
{
min_p
i
ng_node
=
this
;
min_p
ing_sent
=
this
->
ping_sent
;
if
(
min_p
ong_node
==
NULL
||
min_pong
>
this
->
pong_received
)
{
min_p
o
ng_node
=
this
;
min_p
ong
=
this
->
pong_received
;
}
}
if
(
min_p
i
ng_node
)
{
redisLog
(
REDIS_DEBUG
,
"Pinging node %.40s"
,
min_p
i
ng_node
->
name
);
clusterSendPing
(
min_p
i
ng_node
->
link
,
CLUSTERMSG_TYPE_PING
);
if
(
min_p
o
ng_node
)
{
redisLog
(
REDIS_DEBUG
,
"Pinging node %.40s"
,
min_p
o
ng_node
->
name
);
clusterSendPing
(
min_p
o
ng_node
->
link
,
CLUSTERMSG_TYPE_PING
);
}
/* Iterate nodes to check if we need to flag something as failing */
...
...
@@ -1568,42 +1588,43 @@ void clusterCron(void) {
(
REDIS_NODE_MYSELF
|
REDIS_NODE_NOADDR
|
REDIS_NODE_HANDSHAKE
))
continue
;
/* If our ping is older than half the cluster timeout (may happen
* in a cluster with many nodes), send a new ping. */
#if 0
/* If we are waiting for the PONG more than half the cluster
* timeout, reconnect the link: maybe there is a connection
* issue even if the node is alive. */
if (node->link && /* is connected */
node->ping_sent && /* we already sent a ping */
node->pong_received < node->ping_sent && /* still waiting pong */
/* and we are waiting for the pong more than timeout/2 */
now - node->ping_sent > server.cluster_node_timeout/2)
{
/* Disconnect the link, it will be reconnected automatically. */
printf("DISCONNECT!\n");
freeClusterLink(node->link);
}
#endif
/* If we have currently no active ping in this instance, and the
* received PONG is older than half the cluster timeout, send
* a new ping now, to ensure all the nodes are pinged without
* a too big delay. */
if
(
node
->
link
&&
(
now
-
node
->
ping_sent
)
>
server
.
cluster_node_timeout
/
2
)
node
->
ping_sent
==
0
&&
(
now
-
node
->
pong_received
)
>
server
.
cluster_node_timeout
/
2
)
{
clusterSendPing
(
node
->
link
,
CLUSTERMSG_TYPE_PING
);
continue
;
}
/* Check only if we already sent a ping and did not received
* a reply yet. */
if
(
node
->
ping_sent
==
0
||
node
->
ping_sent
<=
node
->
pong_received
)
continue
;
/* Check only if we have an active ping for this instance. */
if
(
node
->
ping_sent
==
0
)
continue
;
/* If we never received a pong, use the ping time to compute
* the delay. */
if
(
node
->
pong_received
)
{
delay
=
now
-
node
->
pong_received
;
}
else
{
delay
=
now
-
node
->
ping_sent
;
}
/* Compute the delay of the PONG. Note that if we already received
* the PONG, then node->ping_sent is zero, so can't reach this
* code at all. */
delay
=
now
-
node
->
ping_sent
;
if
(
delay
<
server
.
cluster_node_timeout
)
{
/* The PFAIL condition can be reversed without external
* help if it is not transitive (that is, if it does not
* turn into a FAIL state).
*
* The FAIL condition is also reversible under specific
* conditions detected by clearNodeFailureIfNeeded(). */
if
(
node
->
flags
&
REDIS_NODE_PFAIL
)
{
node
->
flags
&=
~
REDIS_NODE_PFAIL
;
update_state
=
1
;
}
else
if
(
node
->
flags
&
REDIS_NODE_FAIL
)
{
clearNodeFailureIfNeeded
(
node
);
}
}
else
{
if
(
delay
>
server
.
cluster_node_timeout
)
{
/* Timeout reached. Set the node as possibly failing if it is
* not already in this state. */
if
(
!
(
node
->
flags
&
(
REDIS_NODE_PFAIL
|
REDIS_NODE_FAIL
)))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录