Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
dbf270a0
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
dbf270a0
编写于
11月 23, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
11月 23, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18403 from taosdata/feature/3.0_mhli
refactor(sync): can not propose when heartbeat timeout
上级
906d3fb2
2b411912
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
43 addition
and
7 deletion
+43
-7
include/libs/sync/sync.h
include/libs/sync/sync.h
+1
-0
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
+1
-1
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
+1
-1
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+1
-0
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+1
-0
source/libs/sync/src/syncIndexMgr.c
source/libs/sync/src/syncIndexMgr.c
+3
-2
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+33
-1
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+2
-2
未找到文件。
include/libs/sync/sync.h
浏览文件 @
dbf270a0
...
...
@@ -41,6 +41,7 @@ extern "C" {
#define SNAPSHOT_WAIT_MS 1000 * 30
#define SYNC_APPEND_ENTRIES_TIMEOUT_MS 10000
#define SYNC_HEART_TIMEOUT_MS 1000 * 8
#define SYNC_MAX_BATCH_SIZE 1
#define SYNC_INDEX_BEGIN 0
...
...
source/dnode/mgmt/mgmt_mnode/src/mmHandle.c
浏览文件 @
dbf270a0
...
...
@@ -196,7 +196,7 @@ SArray *mmGetMsgHandles() {
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_PRE_SNAPSHOT
,
mmPutMsgToSyncQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_PRE_SNAPSHOT_REPLY
,
mmPutMsgToSyncQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_HEARTBEAT
,
mmPutMsgToSyncCtrlQueue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_HEARTBEAT_REPLY
,
mmPutMsgToSync
Ctrl
Queue
,
1
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_HEARTBEAT_REPLY
,
mmPutMsgToSyncQueue
,
1
)
==
NULL
)
goto
_OVER
;
code
=
0
;
...
...
source/dnode/mgmt/mgmt_vnode/src/vmHandle.c
浏览文件 @
dbf270a0
...
...
@@ -464,7 +464,7 @@ SArray *vmGetMsgHandles() {
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_PRE_SNAPSHOT_REPLY
,
vmPutMsgToSyncQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_HEARTBEAT
,
vmPutMsgToSyncCtrlQueue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_HEARTBEAT_REPLY
,
vmPutMsgToSync
Ctrl
Queue
,
0
)
==
NULL
)
goto
_OVER
;
if
(
dmSetMgmtHandle
(
pArray
,
TDMT_SYNC_HEARTBEAT_REPLY
,
vmPutMsgToSyncQueue
,
0
)
==
NULL
)
goto
_OVER
;
code
=
0
;
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
dbf270a0
...
...
@@ -232,6 +232,7 @@ int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, S
int32_t
syncNodeSendMsgByInfo
(
const
SNodeInfo
*
nodeInfo
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
);
SyncIndex
syncMinMatchIndex
(
SSyncNode
*
pSyncNode
);
int32_t
syncCacheEntry
(
SSyncLogStore
*
pLogStore
,
SSyncRaftEntry
*
pEntry
,
LRUHandle
**
h
);
bool
syncNodeHeartbeatTimeout
(
SSyncNode
*
pSyncNode
);
// raft state change --------------
void
syncNodeUpdateTerm
(
SSyncNode
*
pSyncNode
,
SyncTerm
term
);
...
...
source/libs/sync/inc/syncMessage.h
浏览文件 @
dbf270a0
...
...
@@ -137,6 +137,7 @@ typedef struct SyncHeartbeatReply {
SyncTerm
term
;
SyncTerm
privateTerm
;
int64_t
startTime
;
int64_t
timeStamp
;
}
SyncHeartbeatReply
;
typedef
struct
SyncPreSnapshot
{
...
...
source/libs/sync/src/syncIndexMgr.c
浏览文件 @
dbf270a0
...
...
@@ -50,9 +50,10 @@ void syncIndexMgrClear(SSyncIndexMgr *pSyncIndexMgr) {
memset
(
pSyncIndexMgr
->
privateTerm
,
0
,
sizeof
(
pSyncIndexMgr
->
privateTerm
));
// int64_t timeNow = taosGetMonotonicMs();
int64_t
timeNow
=
taosGetTimestampMs
();
for
(
int
i
=
0
;
i
<
pSyncIndexMgr
->
replicaNum
;
++
i
)
{
pSyncIndexMgr
->
startTimeArr
[
i
]
=
0
;
pSyncIndexMgr
->
recvTimeArr
[
i
]
=
0
;
pSyncIndexMgr
->
recvTimeArr
[
i
]
=
timeNow
;
}
/*
...
...
@@ -147,7 +148,7 @@ int64_t syncIndexMgrGetRecvTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRa
return
recvTime
;
}
}
ASSERT
(
0
);
return
-
1
;
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
dbf270a0
...
...
@@ -639,6 +639,14 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
return
-
1
;
}
// heartbeat timeout
if
(
syncNodeHeartbeatTimeout
(
pSyncNode
))
{
terrno
=
TSDB_CODE_SYN_PROPOSE_NOT_READY
;
sNError
(
pSyncNode
,
"failed to sync propose since hearbeat timeout, type:%s, last:%"
PRId64
", cmt:%"
PRId64
,
TMSG_INFO
(
pMsg
->
msgType
),
syncNodeGetLastIndex
(
pSyncNode
),
pSyncNode
->
commitIndex
);
return
-
1
;
}
// optimized one replica
if
(
syncNodeIsOptimizedOneReplica
(
pSyncNode
,
pMsg
))
{
SyncIndex
retIndex
;
...
...
@@ -2086,6 +2094,29 @@ int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHand
return
code
;
}
bool
syncNodeHeartbeatTimeout
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
->
replicaNum
==
1
)
{
return
false
;
}
int32_t
toCount
=
0
;
int64_t
tsNow
=
taosGetTimestampMs
();
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
int64_t
recvTime
=
syncIndexMgrGetRecvTime
(
pSyncNode
->
pMatchIndex
,
&
(
pSyncNode
->
peersId
[
i
]));
if
(
recvTime
==
0
||
recvTime
==
-
1
)
{
continue
;
}
if
(
tsNow
-
recvTime
>
SYNC_HEART_TIMEOUT_MS
)
{
toCount
++
;
}
}
bool
b
=
(
toCount
>=
pSyncNode
->
quorum
?
true
:
false
);
return
b
;
}
static
int32_t
syncNodeAppendNoop
(
SSyncNode
*
ths
)
{
int32_t
ret
=
0
;
...
...
@@ -2127,6 +2158,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
pMsgReply
->
srcId
=
ths
->
myRaftId
;
pMsgReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pMsgReply
->
privateTerm
=
8864
;
// magic number
pMsgReply
->
timeStamp
=
taosGetTimestampMs
();
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
!=
TAOS_SYNC_STATE_LEADER
)
{
syncNodeResetElectTimer
(
ths
);
...
...
@@ -2191,7 +2223,7 @@ int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
syncLogRecvHeartbeatReply
(
ths
,
pMsg
,
""
);
// update last reply time, make decision whether the other node is alive or not
syncIndexMgrSetRecvTime
(
ths
->
pMatchIndex
,
&
pMsg
->
destId
,
pMsg
->
startTime
);
syncIndexMgrSetRecvTime
(
ths
->
pMatchIndex
,
&
pMsg
->
srcId
,
pMsg
->
timeStamp
);
return
0
;
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
dbf270a0
...
...
@@ -424,8 +424,8 @@ void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* p
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"recv sync-heartbeat-reply from %s:%d {term:%"
PRId64
",
pterm
:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
privateTerm
,
s
);
sNTrace
(
pSyncNode
,
"recv sync-heartbeat-reply from %s:%d {term:%"
PRId64
",
ts
:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
timeStamp
,
s
);
}
void
syncLogSendSyncPreSnapshot
(
SSyncNode
*
pSyncNode
,
const
SyncPreSnapshot
*
pMsg
,
const
char
*
s
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录