Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
44994201
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看板
提交
44994201
编写于
6月 02, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(sync): sending snapshot
上级
ac90f61b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
10 deletion
+41
-10
source/libs/sync/inc/syncRaftLog.h
source/libs/sync/inc/syncRaftLog.h
+2
-0
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+26
-8
source/libs/sync/src/syncRaftLog.c
source/libs/sync/src/syncRaftLog.c
+6
-0
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+5
-2
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+2
-0
未找到文件。
source/libs/sync/inc/syncRaftLog.h
浏览文件 @
44994201
...
...
@@ -39,6 +39,8 @@ char* logStore2Str(SSyncLogStore* pLogStore);
cJSON
*
logStoreSimple2Json
(
SSyncLogStore
*
pLogStore
);
char
*
logStoreSimple2Str
(
SSyncLogStore
*
pLogStore
);
SyncIndex
logStoreFirstIndex
(
SSyncLogStore
*
pLogStore
);
// SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore);
// SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore);
// SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
44994201
...
...
@@ -454,16 +454,16 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
SyncIndex
localPreLogIndex
;
SyncTerm
localPreLogTerm
;
ret
=
syncNodeGetPreIndexTerm
(
ths
,
pMsg
->
prevLogIndex
+
1
,
&
localPreLogIndex
,
&
localPreLogTerm
);
ASSERT
(
ret
==
0
);
SyncIndex
localLastIndex
;
SyncTerm
localLastTerm
;
ret
=
syncNodeGetLastIndexTerm
(
ths
,
&
localLastIndex
,
&
localLastTerm
);
ASSERT
(
ret
==
0
);
bool
logOK
;
if
(
syncNodeIsIndexInSnapshot
(
ths
,
pMsg
->
prevLogIndex
))
{
SyncIndex
logFirstIndex
=
logStoreFirstIndex
(
ths
->
pLogStore
);
SSnapshot
snapshot
;
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
if
(
logFirstIndex
>
snapshot
.
lastApplyIndex
)
{
logOK
=
false
;
}
else
if
(
syncNodeIsIndexInSnapshot
(
ths
,
pMsg
->
prevLogIndex
))
{
SSnapshot
snapshot
;
ths
->
pFsm
->
FpGetSnapshot
(
ths
->
pFsm
,
&
snapshot
);
...
...
@@ -478,6 +478,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
logOK
,
pMsg
->
prevLogIndex
,
snapshot
.
lastApplyIndex
,
pMsg
->
prevLogTerm
,
snapshot
.
lastApplyTerm
);
}
else
{
ret
=
syncNodeGetPreIndexTerm
(
ths
,
pMsg
->
prevLogIndex
+
1
,
&
localPreLogIndex
,
&
localPreLogTerm
);
ASSERT
(
ret
==
0
);
logOK
=
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
||
((
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
)
&&
(
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
&&
...
...
@@ -510,6 +513,21 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
return
ret
;
}
SyncIndex
localLastIndex
;
SyncTerm
localLastTerm
;
if
(
logFirstIndex
==
SYNC_INDEX_INVALID
)
{
localLastIndex
=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
);
localLastTerm
=
ths
->
pLogStore
->
getLastTerm
(
ths
->
pLogStore
);
}
else
if
(
logFirstIndex
>
snapshot
.
lastApplyIndex
)
{
localLastIndex
=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
);
localLastTerm
=
ths
->
pLogStore
->
getLastTerm
(
ths
->
pLogStore
);
}
else
{
ret
=
syncNodeGetLastIndexTerm
(
ths
,
&
localLastIndex
,
&
localLastTerm
);
ASSERT
(
ret
==
0
);
}
// return to follower state
if
(
pMsg
->
term
==
ths
->
pRaftStore
->
currentTerm
&&
ths
->
state
==
TAOS_SYNC_STATE_CANDIDATE
)
{
sTrace
(
...
...
source/libs/sync/src/syncRaftLog.c
浏览文件 @
44994201
...
...
@@ -258,6 +258,12 @@ char* logStoreSimple2Str(SSyncLogStore* pLogStore) {
return
serialized
;
}
SyncIndex
logStoreFirstIndex
(
SSyncLogStore
*
pLogStore
)
{
SSyncLogStoreData
*
pData
=
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
return
walGetFirstVer
(
pWal
);
}
// for debug -----------------
void
logStorePrint
(
SSyncLogStore
*
pLogStore
)
{
char
*
serialized
=
logStore2Str
(
pLogStore
);
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
44994201
...
...
@@ -151,8 +151,8 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
if
((
syncNodeIsIndexInSnapshot
(
pSyncNode
,
nextIndex
-
1
)
&&
!
snapshotSendingFinish
)
||
syncNodeIsIndexInSnapshot
(
pSyncNode
,
nextIndex
))
{
// will send this msg until snapshot receive finish!
SSnapshot
snapshot
;
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
)
;
SSnapshot
snapshot
=
pSender
->
snapshot
;
sInfo
(
"nextIndex:%ld in snapshot: <lastApplyIndex:%ld, lastApplyTerm:%lu>, begin snapshot"
,
nextIndex
,
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
);
...
...
@@ -162,6 +162,9 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
preLogIndex
=
snapshot
.
lastApplyIndex
;
preLogTerm
=
snapshot
.
lastApplyTerm
;
// update next index!
syncIndexMgrSetIndex
(
pSyncNode
->
pNextIndex
,
pDestId
,
snapshot
.
lastApplyIndex
+
1
);
// to claim leader
SyncAppendEntries
*
pMsg
=
syncAppendEntriesBuild
(
0
,
pSyncNode
->
vgId
);
assert
(
pMsg
!=
NULL
);
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
44994201
...
...
@@ -41,6 +41,8 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
pSender
->
pSyncNode
=
pSyncNode
;
pSender
->
replicaIndex
=
replicaIndex
;
pSender
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pSender
->
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSender
->
pSyncNode
->
pFsm
,
&
(
pSender
->
snapshot
));
pSender
->
finish
=
false
;
}
else
{
sInfo
(
"snapshotSenderCreate cannot create sender"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录