Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9c5b5e93
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
9c5b5e93
编写于
1月 10, 2023
作者:
S
Shengliang Guan
提交者:
GitHub
1月 10, 2023
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #19408 from taosdata/FIX/TD-21428-main
enh: vote for higher lastLogTerm despite commitIndex
上级
e194d87e
63965231
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
37 addition
and
41 deletion
+37
-41
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+2
-2
source/libs/sync/inc/syncPipeline.h
source/libs/sync/inc/syncPipeline.h
+6
-6
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+2
-2
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+2
-2
source/libs/sync/src/syncPipeline.c
source/libs/sync/src/syncPipeline.c
+17
-19
source/libs/sync/src/syncRequestVote.c
source/libs/sync/src/syncRequestVote.c
+8
-10
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
9c5b5e93
...
...
@@ -258,8 +258,8 @@ int32_t syncBuildRequestVote(SRpcMsg* pMsg, int32_t vgId);
int32_t
syncBuildRequestVoteReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildAppendEntries
(
SRpcMsg
*
pMsg
,
int32_t
dataLen
,
int32_t
vgId
);
int32_t
syncBuildAppendEntriesReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildAppendEntriesFromRaft
Log
(
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
,
SyncTerm
prevLogTerm
,
SRpcMsg
*
pRpcMsg
);
int32_t
syncBuildAppendEntriesFromRaft
Entry
(
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
,
SyncTerm
prevLogTerm
,
SRpcMsg
*
pRpcMsg
);
int32_t
syncBuildHeartbeat
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildHeartbeatReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildPreSnapshot
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
...
...
source/libs/sync/inc/syncPipeline.h
浏览文件 @
9c5b5e93
...
...
@@ -78,14 +78,14 @@ static FORCE_INLINE int32_t syncLogGetNextRetryBackoff(SSyncLogReplMgr* pMgr) {
SyncTerm
syncLogReplMgrGetPrevLogTerm
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
);
int32_t
syncLogReplMgrReplicateOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLog
Buffe
rReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
);
int32_t
syncLogReplMgrReplicateAttempt
edOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogReplMgrReplicateProbe
Once
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
);
int32_t
syncLog
ReplMg
rReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
);
int32_t
syncLogReplMgrReplicateAttempt
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
int32_t
syncLogReplMgrReplicateProbe
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
);
int32_t
syncLogReplMgrProcessReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgrProcessReplyInRecoveryMode
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgrProcessReply
InNormalMode
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgrProcessReplyAsRecovery
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgrProcessReply
AsNormal
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncLogReplMgrProcessHeartbeatReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncHeartbeatReply
*
pMsg
);
int32_t
syncLogReplMgrRetryOnNeed
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
9c5b5e93
...
...
@@ -128,7 +128,7 @@ int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
return
0
;
}
SSyncRaftEntry
*
sync
LogAppendEntriesToRaftEntry
(
const
SyncAppendEntries
*
pMsg
)
{
SSyncRaftEntry
*
sync
BuildRaftEntryFromAppendEntries
(
const
SyncAppendEntries
*
pMsg
)
{
SSyncRaftEntry
*
pEntry
=
taosMemoryMalloc
(
pMsg
->
dataLen
);
if
(
pEntry
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
...
...
@@ -182,7 +182,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
goto
_IGNORE
;
}
SSyncRaftEntry
*
pEntry
=
sync
LogAppendEntriesToRaftEntry
(
pMsg
);
SSyncRaftEntry
*
pEntry
=
sync
BuildRaftEntryFromAppendEntries
(
pMsg
);
if
(
pEntry
==
NULL
)
{
sError
(
"vgId:%d, failed to get raft entry from append entries since %s"
,
ths
->
vgId
,
terrstr
());
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
9c5b5e93
...
...
@@ -154,8 +154,8 @@ int32_t syncBuildAppendEntriesReply(SRpcMsg* pMsg, int32_t vgId) {
return
0
;
}
int32_t
syncBuildAppendEntriesFromRaft
Log
(
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
,
SyncTerm
prevLogTerm
,
SRpcMsg
*
pRpcMsg
)
{
int32_t
syncBuildAppendEntriesFromRaft
Entry
(
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
,
SyncTerm
prevLogTerm
,
SRpcMsg
*
pRpcMsg
)
{
uint32_t
dataLen
=
pEntry
->
bytes
;
uint32_t
bytes
=
sizeof
(
SyncAppendEntries
)
+
dataLen
;
pRpcMsg
->
contLen
=
bytes
;
...
...
source/libs/sync/src/syncPipeline.c
浏览文件 @
9c5b5e93
...
...
@@ -642,7 +642,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) {
}
bool
barrier
=
false
;
if
(
syncLog
Buffe
rReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
if
(
syncLog
ReplMg
rReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
sError
(
"vgId:%d, failed to replicate sync log entry since %s. index: %"
PRId64
", dest: %"
PRIx64
""
,
pNode
->
vgId
,
terrstr
(),
index
,
pDestId
->
addr
);
goto
_out
;
...
...
@@ -674,8 +674,7 @@ _out:
return
ret
;
}
int32_t
syncLogReplMgrProcessReplyInRecoveryMode
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
syncLogReplMgrProcessReplyAsRecovery
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
SRaftId
destId
=
pMsg
->
srcId
;
ASSERT
(
pMgr
->
restored
==
false
);
...
...
@@ -750,7 +749,7 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
// attempt to replicate the raft log at index
(
void
)
syncLogReplMgrReset
(
pMgr
);
return
syncLogReplMgrReplicateProbe
Once
(
pMgr
,
pNode
,
index
);
return
syncLogReplMgrReplicateProbe
(
pMgr
,
pNode
,
index
);
}
int32_t
syncLogReplMgrProcessHeartbeatReply
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncHeartbeatReply
*
pMsg
)
{
...
...
@@ -778,9 +777,9 @@ int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sync
}
if
(
pMgr
->
restored
)
{
(
void
)
syncLogReplMgrProcessReply
InNormalMode
(
pMgr
,
pNode
,
pMsg
);
(
void
)
syncLogReplMgrProcessReply
AsNormal
(
pMgr
,
pNode
,
pMsg
);
}
else
{
(
void
)
syncLogReplMgrProcessReply
InRecoveryMode
(
pMgr
,
pNode
,
pMsg
);
(
void
)
syncLogReplMgrProcessReply
AsRecovery
(
pMgr
,
pNode
,
pMsg
);
}
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
return
0
;
...
...
@@ -788,14 +787,14 @@ int32_t syncLogReplMgrProcessReply(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Sync
int32_t
syncLogReplMgrReplicateOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
if
(
pMgr
->
restored
)
{
(
void
)
syncLogReplMgrReplicateAttempt
edOnce
(
pMgr
,
pNode
);
(
void
)
syncLogReplMgrReplicateAttempt
(
pMgr
,
pNode
);
}
else
{
(
void
)
syncLogReplMgrReplicateProbe
Once
(
pMgr
,
pNode
,
pNode
->
pLogBuf
->
matchIndex
);
(
void
)
syncLogReplMgrReplicateProbe
(
pMgr
,
pNode
,
pNode
->
pLogBuf
->
matchIndex
);
}
return
0
;
}
int32_t
syncLogReplMgrReplicateProbe
Once
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
)
{
int32_t
syncLogReplMgrReplicateProbe
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
)
{
ASSERT
(
!
pMgr
->
restored
);
ASSERT
(
pMgr
->
startIndex
>=
0
);
int64_t
retryMaxWaitMs
=
syncGetRetryMaxWaitMs
();
...
...
@@ -810,7 +809,7 @@ int32_t syncLogReplMgrReplicateProbeOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode
SRaftId
*
pDestId
=
&
pNode
->
replicasId
[
pMgr
->
peerId
];
bool
barrier
=
false
;
SyncTerm
term
=
-
1
;
if
(
syncLog
Buffe
rReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
if
(
syncLog
ReplMg
rReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
sError
(
"vgId:%d, failed to replicate log entry since %s. index: %"
PRId64
", dest: 0x%016"
PRIx64
""
,
pNode
->
vgId
,
terrstr
(),
index
,
pDestId
->
addr
);
return
-
1
;
...
...
@@ -833,7 +832,7 @@ int32_t syncLogReplMgrReplicateProbeOnce(SSyncLogReplMgr* pMgr, SSyncNode* pNode
return
0
;
}
int32_t
syncLogReplMgrReplicateAttempt
edOnce
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
int32_t
syncLogReplMgrReplicateAttempt
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
)
{
ASSERT
(
pMgr
->
restored
);
SRaftId
*
pDestId
=
&
pNode
->
replicasId
[
pMgr
->
peerId
];
...
...
@@ -854,7 +853,8 @@ int32_t syncLogReplMgrReplicateAttemptedOnce(SSyncLogReplMgr* pMgr, SSyncNode* p
int64_t
pos
=
index
%
pMgr
->
size
;
SRaftId
*
pDestId
=
&
pNode
->
replicasId
[
pMgr
->
peerId
];
bool
barrier
=
false
;
if
(
syncLogBufferReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
SyncTerm
term
=
-
1
;
if
(
syncLogReplMgrReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
pDestId
,
&
barrier
)
<
0
)
{
sError
(
"vgId:%d, failed to replicate log entry since %s. index: %"
PRId64
", dest: 0x%016"
PRIx64
""
,
pNode
->
vgId
,
terrstr
(),
index
,
pDestId
->
addr
);
return
-
1
;
...
...
@@ -888,7 +888,7 @@ int32_t syncLogReplMgrReplicateAttemptedOnce(SSyncLogReplMgr* pMgr, SSyncNode* p
return
0
;
}
int32_t
syncLogReplMgrProcessReply
InNormalMode
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
syncLogReplMgrProcessReply
AsNormal
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncAppendEntriesReply
*
pMsg
)
{
ASSERT
(
pMgr
->
restored
==
true
);
if
(
pMgr
->
startIndex
<=
pMsg
->
lastSendIndex
&&
pMsg
->
lastSendIndex
<
pMgr
->
endIndex
)
{
if
(
pMgr
->
startIndex
<
pMgr
->
matchIndex
&&
pMgr
->
retryBackoff
>
0
)
{
...
...
@@ -907,7 +907,7 @@ int32_t syncLogReplMgrProcessReplyInNormalMode(SSyncLogReplMgr* pMgr, SSyncNode*
pMgr
->
startIndex
=
pMgr
->
matchIndex
;
}
return
syncLogReplMgrReplicateAttempt
edOnce
(
pMgr
,
pNode
);
return
syncLogReplMgrReplicateAttempt
(
pMgr
,
pNode
);
}
SSyncLogReplMgr
*
syncLogReplMgrCreate
()
{
...
...
@@ -1101,12 +1101,11 @@ SSyncRaftEntry* syncLogBufferGetOneEntry(SSyncLogBuffer* pBuf, SSyncNode* pNode,
return
pEntry
;
}
int32_t
syncLog
Buffe
rReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
)
{
int32_t
syncLog
ReplMg
rReplicateOneTo
(
SSyncLogReplMgr
*
pMgr
,
SSyncNode
*
pNode
,
SyncIndex
index
,
SyncTerm
*
pTerm
,
SRaftId
*
pDestId
,
bool
*
pBarrier
)
{
SSyncRaftEntry
*
pEntry
=
NULL
;
SRpcMsg
msgOut
=
{
0
};
bool
inBuf
=
false
;
int32_t
ret
=
-
1
;
SyncTerm
prevLogTerm
=
-
1
;
SSyncLogBuffer
*
pBuf
=
pNode
->
pLogBuf
;
...
...
@@ -1132,14 +1131,13 @@ int32_t syncLogBufferReplicateOneTo(SSyncLogReplMgr* pMgr, SSyncNode* pNode, Syn
}
if
(
pTerm
)
*
pTerm
=
pEntry
->
term
;
int32_t
code
=
syncBuildAppendEntriesFromRaft
Log
(
pNode
,
pEntry
,
prevLogTerm
,
&
msgOut
);
int32_t
code
=
syncBuildAppendEntriesFromRaft
Entry
(
pNode
,
pEntry
,
prevLogTerm
,
&
msgOut
);
if
(
code
<
0
)
{
sError
(
"vgId:%d, failed to get append entries for index:%"
PRId64
""
,
pNode
->
vgId
,
index
);
goto
_err
;
}
(
void
)
syncNodeSendAppendEntries
(
pNode
,
pDestId
,
&
msgOut
);
ret
=
0
;
sTrace
(
"vgId:%d, replicate one msg index: %"
PRId64
" term: %"
PRId64
" prevterm: %"
PRId64
" to dest: 0x%016"
PRIx64
,
pNode
->
vgId
,
pEntry
->
index
,
pEntry
->
term
,
prevLogTerm
,
pDestId
->
addr
);
...
...
source/libs/sync/src/syncRequestVote.c
浏览文件 @
9c5b5e93
...
...
@@ -48,15 +48,6 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* ths, SyncRequestVote* pMsg) {
SyncTerm
myLastTerm
=
syncNodeGetLastTerm
(
ths
);
SyncIndex
myLastIndex
=
syncNodeGetLastIndex
(
ths
);
if
(
pMsg
->
lastLogIndex
<
ths
->
commitIndex
)
{
sNTrace
(
ths
,
"logok:0, {my-lterm:%"
PRIu64
", my-lindex:%"
PRId64
", recv-lterm:%"
PRIu64
", recv-lindex:%"
PRId64
", recv-term:%"
PRIu64
"}"
,
myLastTerm
,
myLastIndex
,
pMsg
->
lastLogTerm
,
pMsg
->
lastLogIndex
,
pMsg
->
term
);
return
false
;
}
if
(
myLastTerm
==
SYNC_TERM_INVALID
)
{
sNTrace
(
ths
,
"logok:0, {my-lterm:%"
PRIu64
", my-lindex:%"
PRId64
", recv-lterm:%"
PRIu64
", recv-lindex:%"
PRId64
...
...
@@ -70,6 +61,13 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* ths, SyncRequestVote* pMsg) {
"logok:1, {my-lterm:%"
PRIu64
", my-lindex:%"
PRId64
", recv-lterm:%"
PRIu64
", recv-lindex:%"
PRId64
", recv-term:%"
PRIu64
"}"
,
myLastTerm
,
myLastIndex
,
pMsg
->
lastLogTerm
,
pMsg
->
lastLogIndex
,
pMsg
->
term
);
if
(
pMsg
->
lastLogIndex
<
ths
->
commitIndex
)
{
sNWarn
(
ths
,
"logok:1, commit rollback required. {my-lterm:%"
PRIu64
", my-lindex:%"
PRId64
", recv-lterm:%"
PRIu64
", recv-lindex:%"
PRId64
", recv-term:%"
PRIu64
"}"
,
myLastTerm
,
myLastIndex
,
pMsg
->
lastLogTerm
,
pMsg
->
lastLogIndex
,
pMsg
->
term
);
}
return
true
;
}
...
...
@@ -137,4 +135,4 @@ int32_t syncNodeOnRequestVote(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
syncLogSendRequestVoteReply
(
ths
,
pReply
,
""
);
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
return
0
;
}
\ No newline at end of file
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录