Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0c4ade93
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0c4ade93
编写于
12月 28, 2022
作者:
B
Benguang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: update sync node commitIndex only if matchTerm equals currentTerm upon heartbeat
上级
c4fad84c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
34 addition
and
15 deletion
+34
-15
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
+1
-0
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+1
-0
source/libs/sync/src/syncCommit.c
source/libs/sync/src/syncCommit.c
+1
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+18
-10
source/libs/sync/src/syncPipeline.c
source/libs/sync/src/syncPipeline.c
+9
-2
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+1
-1
source/libs/wal/src/walMeta.c
source/libs/wal/src/walMeta.c
+1
-0
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
0c4ade93
...
...
@@ -247,8 +247,8 @@ typedef struct SyncLocalCmd {
SRaftId
destId
;
int32_t
cmd
;
SyncTerm
sdNew
Term
;
// step down new term
SyncIndex
fcIndex
;
// follower commit index
SyncTerm
current
Term
;
// step down new term
SyncIndex
commitIndex
;
// follower commit index
}
SyncLocalCmd
;
int32_t
syncBuildTimeout
(
SRpcMsg
*
pMsg
,
ESyncTimeoutType
ttype
,
uint64_t
logicClock
,
int32_t
ms
,
SSyncNode
*
pNode
);
...
...
source/libs/sync/inc/syncPipeline.h
浏览文件 @
0c4ade93
...
...
@@ -98,6 +98,7 @@ int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode);
// access
int64_t
syncLogBufferGetEndIndex
(
SSyncLogBuffer
*
pBuf
);
SyncTerm
syncLogBufferGetLastMatchTerm
(
SSyncLogBuffer
*
pBuf
);
int32_t
syncLogBufferAppend
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
);
int32_t
syncLogBufferAccept
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
,
SyncTerm
prevTerm
);
int64_t
syncLogBufferProceed
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
SyncTerm
*
pMatchTerm
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
0c4ade93
...
...
@@ -90,6 +90,7 @@
//
int32_t
syncNodeFollowerCommit
(
SSyncNode
*
ths
,
SyncIndex
newCommitIndex
)
{
ASSERT
(
false
&&
"deprecated"
);
if
(
ths
->
state
!=
TAOS_SYNC_STATE_FOLLOWER
)
{
sNTrace
(
ths
,
"can not do follower commit"
);
return
-
1
;
...
...
source/libs/sync/src/syncCommit.c
浏览文件 @
0c4ade93
...
...
@@ -44,6 +44,7 @@
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
//
void
syncOneReplicaAdvance
(
SSyncNode
*
pSyncNode
)
{
ASSERT
(
false
&&
"deprecated"
);
if
(
pSyncNode
==
NULL
)
{
sError
(
"pSyncNode is NULL"
);
return
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
0c4ade93
...
...
@@ -1036,6 +1036,7 @@ SSyncNode* syncNodeOpen(SSyncInfo* pSyncInfo) {
}
}
pSyncNode
->
commitIndex
=
commitIndex
;
sInfo
(
"vgId:%d, sync node commitIndex initialized as %"
PRId64
,
pSyncNode
->
vgId
,
pSyncNode
->
commitIndex
);
if
(
syncNodeLogStoreRestoreOnNeed
(
pSyncNode
)
<
0
)
{
goto
_error
;
...
...
@@ -1176,9 +1177,10 @@ int32_t syncNodeRestore(SSyncNode* pSyncNode) {
}
ASSERT
(
endIndex
==
lastVer
+
1
);
commitIndex
=
TMAX
(
pSyncNode
->
commitIndex
,
commitIndex
);
pSyncNode
->
commitIndex
=
TMAX
(
pSyncNode
->
commitIndex
,
commitIndex
);
sInfo
(
"vgId:%d, restore sync until commitIndex:%"
PRId64
,
pSyncNode
->
vgId
,
pSyncNode
->
commitIndex
);
if
(
syncLogBufferCommit
(
pSyncNode
->
pLogBuf
,
pSyncNode
,
commitIndex
)
<
0
)
{
if
(
syncLogBufferCommit
(
pSyncNode
->
pLogBuf
,
pSyncNode
,
pSyncNode
->
commitIndex
)
<
0
)
{
return
-
1
;
}
...
...
@@ -2545,8 +2547,9 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
SyncLocalCmd
*
pSyncMsg
=
rpcMsgLocalCmd
.
pCont
;
pSyncMsg
->
cmd
=
SYNC_LOCAL_CMD_FOLLOWER_CMT
;
pSyncMsg
->
fcIndex
=
pMsg
->
commitIndex
;
SyncIndex
fcIndex
=
pSyncMsg
->
fcIndex
;
pSyncMsg
->
commitIndex
=
pMsg
->
commitIndex
;
pSyncMsg
->
currentTerm
=
pMsg
->
term
;
SyncIndex
fcIndex
=
pSyncMsg
->
commitIndex
;
if
(
ths
->
syncEqMsg
!=
NULL
&&
ths
->
msgcb
!=
NULL
)
{
int32_t
code
=
ths
->
syncEqMsg
(
ths
->
msgcb
,
&
rpcMsgLocalCmd
);
...
...
@@ -2567,7 +2570,8 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
SyncLocalCmd
*
pSyncMsg
=
rpcMsgLocalCmd
.
pCont
;
pSyncMsg
->
cmd
=
SYNC_LOCAL_CMD_STEP_DOWN
;
pSyncMsg
->
sdNewTerm
=
pMsg
->
term
;
pSyncMsg
->
currentTerm
=
pMsg
->
term
;
pSyncMsg
->
commitIndex
=
pMsg
->
commitIndex
;
if
(
ths
->
syncEqMsg
!=
NULL
&&
ths
->
msgcb
!=
NULL
)
{
int32_t
code
=
ths
->
syncEqMsg
(
ths
->
msgcb
,
&
rpcMsgLocalCmd
);
...
...
@@ -2575,7 +2579,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
sError
(
"vgId:%d, sync enqueue step-down msg error, code:%d"
,
ths
->
vgId
,
code
);
rpcFreeCont
(
rpcMsgLocalCmd
.
pCont
);
}
else
{
sTrace
(
"vgId:%d, sync enqueue step-down msg, new-term: %"
PRId64
,
ths
->
vgId
,
pSyncMsg
->
sdNew
Term
);
sTrace
(
"vgId:%d, sync enqueue step-down msg, new-term: %"
PRId64
,
ths
->
vgId
,
pSyncMsg
->
current
Term
);
}
}
}
...
...
@@ -2633,10 +2637,13 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
syncLogRecvLocalCmd
(
ths
,
pMsg
,
""
);
if
(
pMsg
->
cmd
==
SYNC_LOCAL_CMD_STEP_DOWN
)
{
syncNodeStepDown
(
ths
,
pMsg
->
sdNew
Term
);
syncNodeStepDown
(
ths
,
pMsg
->
current
Term
);
}
else
if
(
pMsg
->
cmd
==
SYNC_LOCAL_CMD_FOLLOWER_CMT
)
{
(
void
)
syncNodeUpdateCommitIndex
(
ths
,
pMsg
->
fcIndex
);
SyncTerm
matchTerm
=
syncLogBufferGetLastMatchTerm
(
ths
->
pLogBuf
);
if
(
pMsg
->
currentTerm
==
matchTerm
)
{
(
void
)
syncNodeUpdateCommitIndex
(
ths
,
pMsg
->
commitIndex
);
}
if
(
syncLogBufferCommit
(
ths
->
pLogBuf
,
ths
,
ths
->
commitIndex
)
<
0
)
{
sError
(
"vgId:%d, failed to commit raft log since %s. commit index: %"
PRId64
""
,
ths
->
vgId
,
terrstr
(),
ths
->
commitIndex
);
...
...
@@ -2649,14 +2656,15 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
}
int32_t
syncNodeOnLocalCmdOld
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pRpcMsg
)
{
ASSERT
(
false
&&
"deprecated"
);
SyncLocalCmd
*
pMsg
=
pRpcMsg
->
pCont
;
syncLogRecvLocalCmd
(
ths
,
pMsg
,
""
);
if
(
pMsg
->
cmd
==
SYNC_LOCAL_CMD_STEP_DOWN
)
{
syncNodeStepDown
(
ths
,
pMsg
->
sdNew
Term
);
syncNodeStepDown
(
ths
,
pMsg
->
current
Term
);
}
else
if
(
pMsg
->
cmd
==
SYNC_LOCAL_CMD_FOLLOWER_CMT
)
{
syncNodeFollowerCommit
(
ths
,
pMsg
->
fc
Index
);
syncNodeFollowerCommit
(
ths
,
pMsg
->
commit
Index
);
}
else
{
sError
(
"error local cmd"
);
...
...
source/libs/sync/src/syncPipeline.c
浏览文件 @
0c4ade93
...
...
@@ -265,20 +265,27 @@ int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
return
ret
;
}
FORCE_INLINE
SyncTerm
syncLogBufferGetLastMatchTerm
(
SSyncLogBuffer
*
pBuf
)
{
FORCE_INLINE
SyncTerm
syncLogBufferGetLastMatchTerm
WithoutLock
(
SSyncLogBuffer
*
pBuf
)
{
SyncIndex
index
=
pBuf
->
matchIndex
;
SSyncRaftEntry
*
pEntry
=
pBuf
->
entries
[(
index
+
pBuf
->
size
)
%
pBuf
->
size
].
pItem
;
ASSERT
(
pEntry
!=
NULL
);
return
pEntry
->
term
;
}
SyncTerm
syncLogBufferGetLastMatchTerm
(
SSyncLogBuffer
*
pBuf
)
{
taosThreadMutexLock
(
&
pBuf
->
mutex
);
SyncTerm
term
=
syncLogBufferGetLastMatchTermWithoutLock
(
pBuf
);
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
return
term
;
}
int32_t
syncLogBufferAccept
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
SSyncRaftEntry
*
pEntry
,
SyncTerm
prevTerm
)
{
taosThreadMutexLock
(
&
pBuf
->
mutex
);
syncLogBufferValidate
(
pBuf
);
int32_t
ret
=
-
1
;
SyncIndex
index
=
pEntry
->
index
;
SyncIndex
prevIndex
=
pEntry
->
index
-
1
;
SyncTerm
lastMatchTerm
=
syncLogBufferGetLastMatchTerm
(
pBuf
);
SyncTerm
lastMatchTerm
=
syncLogBufferGetLastMatchTermWithoutLock
(
pBuf
);
SSyncRaftEntry
*
pExist
=
NULL
;
bool
inBuf
=
true
;
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
0c4ade93
...
...
@@ -411,7 +411,7 @@ void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const c
if
(
!
(
sDebugFlag
&
DEBUG_TRACE
))
return
;
sNTrace
(
pSyncNode
,
"recv sync-local-cmd {cmd:%d-%s, sd-new-term:%"
PRId64
", fc-index:%"
PRId64
"}, %s"
,
pMsg
->
cmd
,
syncLocalCmdGetStr
(
pMsg
->
cmd
),
pMsg
->
sdNewTerm
,
pMsg
->
fc
Index
,
s
);
syncLocalCmdGetStr
(
pMsg
->
cmd
),
pMsg
->
currentTerm
,
pMsg
->
commit
Index
,
s
);
}
void
syncLogSendAppendEntriesReply
(
SSyncNode
*
pSyncNode
,
const
SyncAppendEntriesReply
*
pMsg
,
const
char
*
s
)
{
...
...
source/libs/wal/src/walMeta.c
浏览文件 @
0c4ade93
...
...
@@ -295,6 +295,7 @@ void walAlignVersions(SWal* pWal) {
// reset commitVer and appliedVer
pWal
->
vers
.
commitVer
=
pWal
->
vers
.
snapshotVer
;
pWal
->
vers
.
appliedVer
=
pWal
->
vers
.
snapshotVer
;
wInfo
(
"vgId:%d, reset commitVer to %"
PRId64
,
pWal
->
cfg
.
vgId
,
pWal
->
vers
.
commitVer
);
}
bool
walLogEntriesComplete
(
const
SWal
*
pWal
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录