Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
2e640e8e
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2e640e8e
编写于
11月 24, 2022
作者:
B
Benguang Zhao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: start snapshot in recovery mode of sync repl mgr with lastMatchTerm in reply msg
上级
f68e41a4
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
45 addition
and
27 deletion
+45
-27
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+1
-1
source/libs/sync/inc/syncPipeline.h
source/libs/sync/inc/syncPipeline.h
+1
-1
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+1
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+1
-1
source/libs/sync/src/syncPipeline.c
source/libs/sync/src/syncPipeline.c
+39
-21
source/libs/sync/src/syncUtil.c
source/libs/sync/src/syncUtil.c
+2
-2
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
2e640e8e
...
...
@@ -105,7 +105,7 @@ typedef struct SyncAppendEntriesReply {
SRaftId
destId
;
// private data
SyncTerm
term
;
SyncTerm
private
Term
;
SyncTerm
lastMatch
Term
;
bool
success
;
SyncIndex
matchIndex
;
SyncIndex
lastSendIndex
;
...
...
source/libs/sync/inc/syncPipeline.h
浏览文件 @
2e640e8e
...
...
@@ -103,7 +103,7 @@ int32_t syncLogBufferReInit(SSyncLogBuffer* pBuf, SSyncNode* pNode);
int64_t
syncLogBufferGetEndIndex
(
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
);
int64_t
syncLogBufferProceed
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
SyncTerm
*
pMatchTerm
);
int32_t
syncLogBufferCommit
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
int64_t
commitIndex
);
int32_t
syncLogBufferReset
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
2e640e8e
...
...
@@ -206,7 +206,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
accepted
=
true
;
_SEND_RESPONSE:
pReply
->
matchIndex
=
syncLogBufferProceed
(
ths
->
pLogBuf
,
ths
);
pReply
->
matchIndex
=
syncLogBufferProceed
(
ths
->
pLogBuf
,
ths
,
&
pReply
->
lastMatchTerm
);
bool
matched
=
(
pReply
->
matchIndex
>=
pReply
->
lastSendIndex
);
if
(
accepted
&&
matched
)
{
pReply
->
success
=
true
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
2e640e8e
...
...
@@ -2170,7 +2170,7 @@ int32_t syncNodeAppend(SSyncNode* ths, SSyncRaftEntry* pEntry) {
}
// proceed match index, with replicating on needed
SyncIndex
matchIndex
=
syncLogBufferProceed
(
ths
->
pLogBuf
,
ths
);
SyncIndex
matchIndex
=
syncLogBufferProceed
(
ths
->
pLogBuf
,
ths
,
NULL
);
sDebug
(
"vgId:%d, append raft entry. index: %"
PRId64
", term: %"
PRId64
" pBuf: [%"
PRId64
" %"
PRId64
" %"
PRId64
", %"
PRId64
")"
,
...
...
source/libs/sync/src/syncPipeline.c
浏览文件 @
2e640e8e
...
...
@@ -76,17 +76,17 @@ SyncTerm syncLogReplMgrGetPrevLogTerm(SSyncLogReplMgr* pMgr, SSyncNode* pNode, S
if
(
prevIndex
==
-
1
)
return
0
;
if
(
index
-
1
>
pBuf
->
matchIndex
)
{
if
(
prevIndex
>
pBuf
->
matchIndex
)
{
terrno
=
TSDB_CODE_WAL_LOG_NOT_EXIST
;
return
-
1
;
}
ASSERT
(
index
-
1
==
prevIndex
);
if
(
index
-
1
>=
pBuf
->
startIndex
)
{
pEntry
=
pBuf
->
entries
[(
i
ndex
+
pBuf
->
size
)
%
pBuf
->
size
].
pItem
;
if
(
prevIndex
>=
pBuf
->
startIndex
)
{
pEntry
=
pBuf
->
entries
[(
prevI
ndex
+
pBuf
->
size
)
%
pBuf
->
size
].
pItem
;
ASSERT
(
pEntry
!=
NULL
&&
"no log entry found"
);
prevLogTerm
=
p
Buf
->
entries
[(
index
+
pBuf
->
size
)
%
pBuf
->
size
].
prevLogT
erm
;
prevLogTerm
=
p
Entry
->
t
erm
;
return
prevLogTerm
;
}
...
...
@@ -354,7 +354,7 @@ int32_t syncLogStorePersist(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
return
0
;
}
int64_t
syncLogBufferProceed
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
)
{
int64_t
syncLogBufferProceed
(
SSyncLogBuffer
*
pBuf
,
SSyncNode
*
pNode
,
SyncTerm
*
pMatchTerm
)
{
taosThreadMutexLock
(
&
pBuf
->
mutex
);
syncLogBufferValidate
(
pBuf
);
...
...
@@ -419,6 +419,9 @@ int64_t syncLogBufferProceed(SSyncLogBuffer* pBuf, SSyncNode* pNode) {
_out:
pBuf
->
matchIndex
=
matchIndex
;
if
(
pMatchTerm
)
{
*
pMatchTerm
=
pBuf
->
entries
[(
matchIndex
+
pBuf
->
size
)
%
pBuf
->
size
].
pItem
->
term
;
}
syncLogBufferValidate
(
pBuf
);
taosThreadMutexUnlock
(
&
pBuf
->
mutex
);
return
matchIndex
;
...
...
@@ -615,16 +618,16 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
ASSERT
(
pMgr
->
restored
==
false
);
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
src
Id
.
addr
,
host
,
sizeof
(
host
),
&
port
);
syncUtilU642Addr
(
dest
Id
.
addr
,
host
,
sizeof
(
host
),
&
port
);
if
(
pMgr
->
endIndex
==
0
)
{
ASSERT
(
pMgr
->
startIndex
==
0
);
ASSERT
(
pMgr
->
matchIndex
==
0
);
if
(
pMsg
->
matchIndex
<
0
)
{
pMgr
->
restored
=
true
;
sInfo
(
"vgId:%d, sync log repl mgr of peer %s:%d restored. pMgr(rs:%d): [%"
PRId64
" %"
PRId64
", %"
PRId64
sInfo
(
"vgId:%d, sync log repl mgr of peer %s:%d
(%"
PRIx64
")
restored. pMgr(rs:%d): [%"
PRId64
" %"
PRId64
", %"
PRId64
"), pBuf: [%"
PRId64
" %"
PRId64
" %"
PRId64
", %"
PRId64
")"
,
pNode
->
vgId
,
host
,
port
,
pMgr
->
restored
,
pMgr
->
startIndex
,
pMgr
->
matchIndex
,
pMgr
->
endIndex
,
pNode
->
vgId
,
host
,
port
,
destId
.
addr
,
pMgr
->
restored
,
pMgr
->
startIndex
,
pMgr
->
matchIndex
,
pMgr
->
endIndex
,
pBuf
->
startIndex
,
pBuf
->
commitIndex
,
pBuf
->
matchIndex
,
pBuf
->
endIndex
);
return
0
;
}
...
...
@@ -638,9 +641,9 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
if
(
pMsg
->
matchIndex
==
pMsg
->
lastSendIndex
)
{
pMgr
->
restored
=
true
;
sInfo
(
"vgId:%d, sync log repl mgr of peer %s:%d restored. pMgr(rs:%d): [%"
PRId64
" %"
PRId64
", %"
PRId64
sInfo
(
"vgId:%d, sync log repl mgr of peer %s:%d
(%"
PRIx64
")
restored. pMgr(rs:%d): [%"
PRId64
" %"
PRId64
", %"
PRId64
"), pBuf: [%"
PRId64
" %"
PRId64
" %"
PRId64
", %"
PRId64
")"
,
pNode
->
vgId
,
host
,
port
,
pMgr
->
restored
,
pMgr
->
startIndex
,
pMgr
->
matchIndex
,
pMgr
->
endIndex
,
pNode
->
vgId
,
host
,
port
,
destId
.
addr
,
pMgr
->
restored
,
pMgr
->
startIndex
,
pMgr
->
matchIndex
,
pMgr
->
endIndex
,
pBuf
->
startIndex
,
pBuf
->
commitIndex
,
pBuf
->
matchIndex
,
pBuf
->
endIndex
);
return
0
;
}
...
...
@@ -648,23 +651,38 @@ int32_t syncLogReplMgrProcessReplyInRecoveryMode(SSyncLogReplMgr* pMgr, SSyncNod
(
void
)
syncLogReplMgrReset
(
pMgr
);
}
// check existence of WAl log
// check last match term
SyncTerm
term
=
-
1
;
SyncIndex
firstVer
=
pNode
->
pLogStore
->
syncLogBeginIndex
(
pNode
->
pLogStore
);
if
(
pMsg
->
matchIndex
+
1
<
firstVer
)
{
SyncIndex
index
=
TMIN
(
pMsg
->
matchIndex
,
pNode
->
pLogBuf
->
matchIndex
);
if
(
pMsg
->
matchIndex
<
pNode
->
pLogBuf
->
matchIndex
)
{
term
=
syncLogReplMgrGetPrevLogTerm
(
pMgr
,
pNode
,
index
+
1
);
if
(
term
<
0
||
(
term
!=
pMsg
->
lastMatchTerm
&&
(
index
+
1
==
firstVer
||
index
==
firstVer
)))
{
ASSERT
(
term
>=
0
||
terrno
==
TSDB_CODE_WAL_LOG_NOT_EXIST
);
if
(
syncNodeStartSnapshot
(
pNode
,
&
destId
)
<
0
)
{
sError
(
"vgId:%d, failed to start snapshot for dest: 0x%016"
PRIx64
,
pNode
->
vgId
,
destId
.
addr
);
sError
(
"vgId:%d, failed to start snapshot for peer %s:%d"
,
pNode
->
vgId
,
host
,
port
);
}
return
0
;
}
// send match index
SyncIndex
index
=
TMIN
(
pMsg
->
matchIndex
,
pNode
->
pLogBuf
->
matchIndex
);
ASSERT
(
index
+
1
>=
firstVer
);
if
(
term
==
pMsg
->
lastMatchTerm
)
{
index
=
index
+
1
;
ASSERT
(
index
<=
pNode
->
pLogBuf
->
matchIndex
);
}
else
{
ASSERT
(
index
>
firstVer
);
}
}
// attempt to replicate the raft log at index
bool
barrier
=
false
;
SyncTerm
term
=
-
1
;
ASSERT
(
index
>=
0
);
if
(
syncLogBufferReplicateOneTo
(
pMgr
,
pNode
,
index
,
&
term
,
&
destId
,
&
barrier
)
<
0
)
{
sError
(
"vgId:%d, failed to replicate log entry since %s. index: %"
PRId64
",
dest: 0x%016"
PRIx64
"
"
,
pNode
->
vgId
,
terrstr
(),
index
,
destId
.
addr
);
sError
(
"vgId:%d, failed to replicate log entry since %s. index: %"
PRId64
",
peer %s:%d
"
,
pNode
->
vgId
,
terrstr
(),
index
,
host
,
port
);
return
-
1
;
}
...
...
source/libs/sync/src/syncUtil.c
浏览文件 @
2e640e8e
...
...
@@ -373,7 +373,7 @@ void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries
sNTrace
(
pSyncNode
,
"send sync-append-entries-reply to %s:%d, {term:%"
PRId64
", pterm:%"
PRId64
", success:%d, lsend-index:%"
PRId64
", match:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
private
Term
,
pMsg
->
success
,
pMsg
->
lastSendIndex
,
pMsg
->
matchIndex
,
s
);
host
,
port
,
pMsg
->
term
,
pMsg
->
lastMatch
Term
,
pMsg
->
success
,
pMsg
->
lastSendIndex
,
pMsg
->
matchIndex
,
s
);
}
void
syncLogRecvAppendEntriesReply
(
SSyncNode
*
pSyncNode
,
const
SyncAppendEntriesReply
*
pMsg
,
const
char
*
s
)
{
...
...
@@ -384,7 +384,7 @@ void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries
sNTrace
(
pSyncNode
,
"recv sync-append-entries-reply from %s:%d {term:%"
PRId64
", pterm:%"
PRId64
", success:%d, lsend-index:%"
PRId64
", match:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
private
Term
,
pMsg
->
success
,
pMsg
->
lastSendIndex
,
pMsg
->
matchIndex
,
s
);
host
,
port
,
pMsg
->
term
,
pMsg
->
lastMatch
Term
,
pMsg
->
success
,
pMsg
->
lastSendIndex
,
pMsg
->
matchIndex
,
s
);
}
void
syncLogSendHeartbeat
(
SSyncNode
*
pSyncNode
,
const
SyncHeartbeat
*
pMsg
,
const
char
*
s
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录