Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
98a2451c
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,发现更多精彩内容 >>
提交
98a2451c
编写于
6月 08, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): sync snapshot
上级
29b97fa0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
29 addition
and
10 deletion
+29
-10
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+14
-9
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+1
-1
source/libs/sync/test/syncTestTool.cpp
source/libs/sync/test/syncTestTool.cpp
+14
-0
未找到文件。
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
98a2451c
...
...
@@ -469,7 +469,7 @@ static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
// delete confict entries
code
=
ths
->
pLogStore
->
syncLogTruncate
(
ths
->
pLogStore
,
delBegin
);
ASSERT
(
code
==
0
);
sInfo
(
"sync
NodeMakeLogSam
e, from %ld to %ld"
,
delBegin
,
delEnd
);
sInfo
(
"sync
event log truncat
e, from %ld to %ld"
,
delBegin
,
delEnd
);
logStoreSimpleLog2
(
"after syncNodeMakeLogSame"
,
ths
->
pLogStore
);
return
code
;
...
...
@@ -556,8 +556,6 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
}
ASSERT
(
pMsg
->
dataLen
>=
0
);
bool
logOK
=
syncNodeOnAppendEntriesLogOK
(
ths
,
pMsg
);
// candidate to follower
//
// operation:
...
...
@@ -582,7 +580,10 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
// I have snapshot, have log, log <= snapshot, preIndex > myLastIndex
//
// condition3:
// I have snapshot, preIndex <= snapshot.lastApplyIndex
// I have snapshot, preIndex < snapshot.lastApplyIndex
//
// condition4:
// I have snapshot, preIndex == snapshot.lastApplyIndex, no data
//
// operation:
// match snapshot.lastApplyIndex - 1;
...
...
@@ -598,15 +599,16 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
condition0
&&
(
ths
->
pLogStore
->
syncLogEntryCount
(
ths
->
pLogStore
)
==
0
)
&&
(
pMsg
->
prevLogIndex
>
myLastIndex
);
bool
condition2
=
condition0
&&
(
ths
->
pLogStore
->
syncLogLastIndex
(
ths
->
pLogStore
)
<=
snapshot
.
lastApplyIndex
)
&&
(
pMsg
->
prevLogIndex
>
myLastIndex
);
bool
condition3
=
condition0
&&
(
pMsg
->
prevLogIndex
<=
snapshot
.
lastApplyIndex
);
bool
condition
=
condition1
||
condition2
||
condition3
;
bool
condition3
=
condition0
&&
(
pMsg
->
prevLogIndex
<
snapshot
.
lastApplyIndex
);
bool
condition4
=
condition0
&&
(
pMsg
->
prevLogIndex
==
snapshot
.
lastApplyIndex
)
&&
(
pMsg
->
dataLen
==
0
);
bool
condition
=
condition1
||
condition2
||
condition3
||
condition4
;
if
(
condition
)
{
sTrace
(
"recv SyncAppendEntries, fake match, myLastIndex:%ld, syncLogBeginIndex:%ld, syncLogEndIndex:%ld, "
"condition1:%d, condition2:%d, condition3:%d"
,
"condition1:%d, condition2:%d, condition3:%d
, condition4:%d
"
,
myLastIndex
,
ths
->
pLogStore
->
syncLogBeginIndex
(
ths
->
pLogStore
),
ths
->
pLogStore
->
syncLogEndIndex
(
ths
->
pLogStore
),
condition1
,
condition2
,
condition3
);
ths
->
pLogStore
->
syncLogEndIndex
(
ths
->
pLogStore
),
condition1
,
condition2
,
condition3
,
condition4
);
// prepare response msg
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
(
ths
->
vgId
);
...
...
@@ -615,7 +617,7 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
pReply
->
privateTerm
=
ths
->
pNewNodeReceiver
->
privateTerm
;
pReply
->
success
=
true
;
pReply
->
matchIndex
=
snapshot
.
lastApplyIndex
-
1
;
pReply
->
matchIndex
=
snapshot
.
lastApplyIndex
;
// send response
SRpcMsg
rpcMsg
;
...
...
@@ -627,6 +629,9 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
}
}
while
(
0
);
// calculate logOK here, before will coredump, due to fake match
bool
logOK
=
syncNodeOnAppendEntriesLogOK
(
ths
,
pMsg
);
// not match
//
// condition1:
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
98a2451c
...
...
@@ -178,7 +178,7 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
snapshotSenderStart
(
pSender
);
char
*
s
=
snapshotSender2Str
(
pSender
);
sInfo
(
"snapshot send
,
start sender first time, sender:%s"
,
s
);
sInfo
(
"snapshot send start sender first time, sender:%s"
,
s
);
taosMemoryFree
(
s
);
}
...
...
source/libs/sync/test/syncTestTool.cpp
浏览文件 @
98a2451c
...
...
@@ -205,6 +205,19 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
#if 0
{
pCfg->myIndex = myIndex;
pCfg->replicaNum = replicaNum;
for (int i = 0; i < replicaNum; ++i) {
pCfg->nodeInfo[i].nodePort = gPorts[i];
taosGetFqdn(pCfg->nodeInfo[i].nodeFqdn);
// snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1");
}
}
#endif
if
(
isStandBy
)
{
pCfg
->
myIndex
=
0
;
pCfg
->
replicaNum
=
1
;
...
...
@@ -222,6 +235,7 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
}
}
int64_t
rid
=
syncOpen
(
&
syncInfo
);
assert
(
rid
>
0
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录