Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
28a5a9d7
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看板
提交
28a5a9d7
编写于
10月 19, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): add log, update quorum first when reconfig
上级
1df2703c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
60 addition
and
66 deletion
+60
-66
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+3
-1
source/dnode/mnode/impl/src/mndMain.c
source/dnode/mnode/impl/src/mndMain.c
+1
-1
source/dnode/vnode/src/vnd/vnodeSync.c
source/dnode/vnode/src/vnd/vnodeSync.c
+1
-1
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+2
-4
source/libs/sync/inc/syncTimeout.h
source/libs/sync/inc/syncTimeout.h
+1
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+39
-46
source/libs/sync/src/syncTimeout.c
source/libs/sync/src/syncTimeout.c
+11
-10
source/libs/sync/src/syncVoteMgr.c
source/libs/sync/src/syncVoteMgr.c
+2
-2
未找到文件。
include/libs/sync/syncTools.h
浏览文件 @
28a5a9d7
...
...
@@ -157,6 +157,8 @@ typedef enum ESyncTimeoutType {
SYNC_TIMEOUT_HEARTBEAT
,
}
ESyncTimeoutType
;
const
char
*
syncTimerTypeStr
(
enum
ESyncTimeoutType
timerType
);
typedef
struct
SyncTimeout
{
uint32_t
bytes
;
int32_t
vgId
;
...
...
@@ -677,7 +679,7 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg);
// on message ----------------------
int32_t
syncNodeOnPingCb
(
SSyncNode
*
ths
,
SyncPing
*
pMsg
);
int32_t
syncNodeOnPingReplyCb
(
SSyncNode
*
ths
,
SyncPingReply
*
pMsg
);
int32_t
syncNodeOnTime
outCb
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
int32_t
syncNodeOnTime
r
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
int32_t
syncNodeOnHeartbeat
(
SSyncNode
*
ths
,
SyncHeartbeat
*
pMsg
);
int32_t
syncNodeOnHeartbeatReply
(
SSyncNode
*
ths
,
SyncHeartbeatReply
*
pMsg
);
...
...
source/dnode/mnode/impl/src/mndMain.c
浏览文件 @
28a5a9d7
...
...
@@ -503,7 +503,7 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
if
(
pMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnTime
outCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnTime
r
(
pSyncNode
,
pSyncMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING
)
{
...
...
source/dnode/vnode/src/vnd/vnodeSync.c
浏览文件 @
28a5a9d7
...
...
@@ -388,7 +388,7 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
if
(
pMsg
->
msgType
==
TDMT_SYNC_TIMEOUT
)
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pMsg
);
ASSERT
(
pSyncMsg
!=
NULL
);
code
=
syncNodeOnTime
outCb
(
pSyncNode
,
pSyncMsg
);
code
=
syncNodeOnTime
r
(
pSyncNode
,
pSyncMsg
);
syncTimeoutDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_PING
)
{
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
28a5a9d7
...
...
@@ -232,12 +232,8 @@ int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms);
int32_t
syncNodeResetElectTimer
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeStartHeartbeatTimer
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeStartHeartbeatTimerNow
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeStartHeartbeatTimerMS
(
SSyncNode
*
pSyncNode
,
int32_t
ms
);
int32_t
syncNodeStopHeartbeatTimer
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeRestartHeartbeatTimer
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeRestartHeartbeatTimerNow
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeRestartNowHeartbeatTimerMS
(
SSyncNode
*
pSyncNode
,
int32_t
ms
);
// utils --------------
int32_t
syncNodeSendMsgById
(
const
SRaftId
*
destRaftId
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
);
...
...
@@ -313,6 +309,8 @@ int32_t syncNodePeerStateInit(SSyncNode* pSyncNode);
void
syncNodeStepDown
(
SSyncNode
*
pSyncNode
,
SyncTerm
newTerm
);
// trace log
void
syncLogRecvTimer
(
SSyncNode
*
pSyncNode
,
const
SyncTimeout
*
pMsg
,
const
char
*
s
);
void
syncLogSendRequestVote
(
SSyncNode
*
pSyncNode
,
const
SyncRequestVote
*
pMsg
,
const
char
*
s
);
void
syncLogRecvRequestVote
(
SSyncNode
*
pSyncNode
,
const
SyncRequestVote
*
pMsg
,
const
char
*
s
);
...
...
source/libs/sync/inc/syncTimeout.h
浏览文件 @
28a5a9d7
...
...
@@ -39,7 +39,7 @@ extern "C" {
// /\ voterLog' = [voterLog EXCEPT ![i] = [j \in {} |-> <<>>]]
// /\ UNCHANGED <<messages, leaderVars, logVars>>
//
int32_t
syncNodeOnTime
outCb
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
int32_t
syncNodeOnTime
r
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
28a5a9d7
...
...
@@ -1174,7 +1174,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) {
pSyncNode
->
FpOnPing
=
syncNodeOnPingCb
;
pSyncNode
->
FpOnPingReply
=
syncNodeOnPingReplyCb
;
pSyncNode
->
FpOnClientRequest
=
syncNodeOnClientRequest
;
pSyncNode
->
FpOnTimeout
=
syncNodeOnTime
outCb
;
pSyncNode
->
FpOnTimeout
=
syncNodeOnTime
r
;
pSyncNode
->
FpOnSnapshot
=
syncNodeOnSnapshot
;
pSyncNode
->
FpOnSnapshotReply
=
syncNodeOnSnapshotReply
;
pSyncNode
->
FpOnRequestVote
=
syncNodeOnRequestVote
;
...
...
@@ -1259,7 +1259,7 @@ void syncNodeStart(SSyncNode* pSyncNode) {
syncNodeBecomeFollower
(
pSyncNode
,
"first start"
);
}
if
(
pSyncNode
->
vgId
==
1
)
{
if
(
syncNodeIsMnode
(
pSyncNode
)
)
{
int32_t
ret
=
0
;
ret
=
syncNodeStartPingTimer
(
pSyncNode
);
ASSERT
(
ret
==
0
);
...
...
@@ -1486,47 +1486,32 @@ static int32_t syncNodeDoStartHeartbeatTimer(SSyncNode* pSyncNode) {
int32_t
syncNodeStartHeartbeatTimer
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
if
(
syncNodeIsMnode
(
pSyncNode
))
{
pSyncNode
->
heartbeatTimerMS
=
pSyncNode
->
hbBaseLine
;
ret
=
syncNodeDoStartHeartbeatTimer
(
pSyncNode
);
}
else
{
do
{
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SSyncTimer
*
pSyncTimer
=
syncNodeGetHbTimer
(
pSyncNode
,
&
(
pSyncNode
->
peersId
[
i
]));
syncHbTimerStart
(
pSyncNode
,
pSyncTimer
);
}
}
while
(
0
);
}
return
ret
;
}
#if 0
pSyncNode->heartbeatTimerMS = pSyncNode->hbBaseLine;
ret = syncNodeDoStartHeartbeatTimer(pSyncNode);
#endif
int32_t
syncNodeStartHeartbeatTimerMS
(
SSyncNode
*
pSyncNode
,
int32_t
ms
)
{
pSyncNode
->
heartbeatTimerMS
=
ms
;
int32_t
ret
=
syncNodeDoStartHeartbeatTimer
(
pSyncNode
);
return
ret
;
}
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SSyncTimer
*
pSyncTimer
=
syncNodeGetHbTimer
(
pSyncNode
,
&
(
pSyncNode
->
peersId
[
i
]));
syncHbTimerStart
(
pSyncNode
,
pSyncTimer
);
}
int32_t
syncNodeStartHeartbeatTimerNow
(
SSyncNode
*
pSyncNode
)
{
pSyncNode
->
heartbeatTimerMS
=
1
;
int32_t
ret
=
syncNodeDoStartHeartbeatTimer
(
pSyncNode
);
return
ret
;
}
int32_t
syncNodeStopHeartbeatTimer
(
SSyncNode
*
pSyncNode
)
{
int32_t
ret
=
0
;
#if 0
atomic_add_fetch_64(&pSyncNode->heartbeatTimerLogicClockUser, 1);
taosTmrStop(pSyncNode->pHeartbeatTimer);
pSyncNode->pHeartbeatTimer = NULL;
#endif
sTrace
(
"vgId:%d, sync %s stop heartbeat timer"
,
pSyncNode
->
vgId
,
syncUtilState2String
(
pSyncNode
->
state
));
do
{
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SSyncTimer
*
pSyncTimer
=
syncNodeGetHbTimer
(
pSyncNode
,
&
(
pSyncNode
->
peersId
[
i
]));
syncHbTimerStop
(
pSyncNode
,
pSyncTimer
);
}
}
while
(
0
);
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SSyncTimer
*
pSyncTimer
=
syncNodeGetHbTimer
(
pSyncNode
,
&
(
pSyncNode
->
peersId
[
i
]));
syncHbTimerStop
(
pSyncNode
,
pSyncTimer
);
}
return
ret
;
}
...
...
@@ -1537,18 +1522,6 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode) {
return
0
;
}
int32_t
syncNodeRestartHeartbeatTimerNow
(
SSyncNode
*
pSyncNode
)
{
syncNodeStopHeartbeatTimer
(
pSyncNode
);
syncNodeStartHeartbeatTimerNow
(
pSyncNode
);
return
0
;
}
int32_t
syncNodeRestartNowHeartbeatTimerMS
(
SSyncNode
*
pSyncNode
,
int32_t
ms
)
{
syncNodeStopHeartbeatTimer
(
pSyncNode
);
syncNodeStartHeartbeatTimerMS
(
pSyncNode
,
ms
);
return
0
;
}
// utils --------------
int32_t
syncNodeSendMsgById
(
const
SRaftId
*
destRaftId
,
SSyncNode
*
pSyncNode
,
SRpcMsg
*
pMsg
)
{
SEpSet
epSet
;
...
...
@@ -2025,13 +1998,14 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
syncUtilnodeInfo2raftId
(
&
pSyncNode
->
pRaftCfg
->
cfg
.
nodeInfo
[
i
],
pSyncNode
->
vgId
,
&
pSyncNode
->
replicasId
[
i
]);
}
// update quorum first
pSyncNode
->
quorum
=
syncUtilQuorum
(
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
);
syncIndexMgrUpdate
(
pSyncNode
->
pNextIndex
,
pSyncNode
);
syncIndexMgrUpdate
(
pSyncNode
->
pMatchIndex
,
pSyncNode
);
voteGrantedUpdate
(
pSyncNode
->
pVotesGranted
,
pSyncNode
);
votesRespondUpdate
(
pSyncNode
->
pVotesRespond
,
pSyncNode
);
pSyncNode
->
quorum
=
syncUtilQuorum
(
pSyncNode
->
pRaftCfg
->
cfg
.
replicaNum
);
// reset snapshot senders
// clear new
...
...
@@ -3355,6 +3329,25 @@ bool syncNodeCanChange(SSyncNode* pSyncNode) {
return
true
;
}
const
char
*
syncTimerTypeStr
(
enum
ESyncTimeoutType
timerType
)
{
if
(
timerType
==
SYNC_TIMEOUT_PING
)
{
return
"ping"
;
}
else
if
(
timerType
==
SYNC_TIMEOUT_ELECTION
)
{
return
"elect"
;
}
else
if
(
timerType
==
SYNC_TIMEOUT_HEARTBEAT
)
{
return
"heartbeat"
;
}
else
{
return
"unknown"
;
}
}
void
syncLogRecvTimer
(
SSyncNode
*
pSyncNode
,
const
SyncTimeout
*
pMsg
,
const
char
*
s
)
{
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-timer {type:%s, lc:%lu, ms:%d, data:%p}, %s"
,
syncTimerTypeStr
(
pMsg
->
timeoutType
),
s
,
pMsg
->
logicClock
,
pMsg
->
timerMS
,
pMsg
->
data
);
syncNodeEventLog
(
pSyncNode
,
logBuf
);
}
void
syncLogSendRequestVote
(
SSyncNode
*
pSyncNode
,
const
SyncRequestVote
*
pMsg
,
const
char
*
s
)
{
char
host
[
64
];
uint16_t
port
;
...
...
source/libs/sync/src/syncTimeout.c
浏览文件 @
28a5a9d7
...
...
@@ -60,12 +60,12 @@ static void syncNodeCleanConfigIndex(SSyncNode* ths) {
int32_t
syncNodeTimerRoutine
(
SSyncNode
*
ths
)
{
syncNodeEventLog
(
ths
,
"timer routines"
);
if
(
ths
->
vgId
==
1
)
{
if
(
syncNodeIsMnode
(
ths
)
)
{
syncNodeCleanConfigIndex
(
ths
);
}
#if 0
if (
ths->vgId != 1
) {
if (
!syncNodeIsMnode(ths)
) {
syncRespClean(ths->pSyncRespMgr);
}
#endif
...
...
@@ -73,9 +73,9 @@ int32_t syncNodeTimerRoutine(SSyncNode* ths) {
return
0
;
}
int32_t
syncNodeOnTime
outCb
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
)
{
int32_t
syncNodeOnTime
r
(
SSyncNode
*
ths
,
SyncTimeout
*
pMsg
)
{
int32_t
ret
=
0
;
sync
TimeoutLog2
(
"==syncNodeOnTimeoutCb=="
,
pMsg
);
sync
LogRecvTimer
(
ths
,
pMsg
,
""
);
if
(
pMsg
->
timeoutType
==
SYNC_TIMEOUT_PING
)
{
if
(
atomic_load_64
(
&
ths
->
pingTimerLogicClockUser
)
<=
pMsg
->
logicClock
)
{
...
...
@@ -84,28 +84,29 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) {
// syncNodePingAll(ths);
// syncNodePingPeers(ths);
// sTrace("vgId:%d, sync timeout, type:ping count:%d", ths->vgId, ths->pingTimerCounter);
syncNodeTimerRoutine
(
ths
);
}
}
else
if
(
pMsg
->
timeoutType
==
SYNC_TIMEOUT_ELECTION
)
{
if
(
atomic_load_64
(
&
ths
->
electTimerLogicClockUser
)
<=
pMsg
->
logicClock
)
{
++
(
ths
->
electTimerCounter
);
sTrace
(
"vgId:%d, sync timer, type:election count:%d, electTimerLogicClockUser:%ld"
,
ths
->
vgId
,
ths
->
electTimerCounter
,
ths
->
electTimerLogicClockUser
);
sTrace
(
"vgId:%d, sync timer, type:election count:%d, lc-user:%ld"
,
ths
->
vgId
,
ths
->
electTimerCounter
,
ths
->
electTimerLogicClockUser
);
syncNodeElect
(
ths
);
}
}
else
if
(
pMsg
->
timeoutType
==
SYNC_TIMEOUT_HEARTBEAT
)
{
if
(
atomic_load_64
(
&
ths
->
heartbeatTimerLogicClockUser
)
<=
pMsg
->
logicClock
)
{
++
(
ths
->
heartbeatTimerCounter
);
sTrace
(
"vgId:%d, sync timer, type:replicate count:%d, heartbeatTimerLogicClockUser:%ld"
,
ths
->
vgId
,
ths
->
heartbeatTimerCounter
,
ths
->
heartbeatTimerLogicClockUser
);
sTrace
(
"vgId:%d, sync timer, type:replicate count:%d, lc-user:%ld"
,
ths
->
vgId
,
ths
->
heartbeatTimerCounter
,
ths
->
heartbeatTimerLogicClockUser
);
// syncNodeReplicate(ths, true);
}
}
else
{
sError
(
"vgId:%d,
unknown timeout
-type:%d"
,
ths
->
vgId
,
pMsg
->
timeoutType
);
sError
(
"vgId:%d,
recv unknown timer
-type:%d"
,
ths
->
vgId
,
pMsg
->
timeoutType
);
}
return
ret
;
...
...
source/libs/sync/src/syncVoteMgr.c
浏览文件 @
28a5a9d7
...
...
@@ -130,7 +130,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
char
*
voteGranted2Str
(
SVotesGranted
*
pVotesGranted
)
{
cJSON
*
pJson
=
voteGranted2Json
(
pVotesGranted
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
...
...
@@ -259,7 +259,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
char
*
votesRespond2Str
(
SVotesRespond
*
pVotesRespond
)
{
cJSON
*
pJson
=
votesRespond2Json
(
pVotesRespond
);
char
*
serialized
=
cJSON_Print
(
pJson
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录