Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
59448cd1
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
59448cd1
编写于
11月 01, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): pre snapshot on message
上级
21d60cb5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
60 addition
and
8 deletion
+60
-8
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+1
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+6
-4
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+2
-2
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+50
-0
source/libs/sync/test/syncPreSnapshotReplyTest.cpp
source/libs/sync/test/syncPreSnapshotReplyTest.cpp
+1
-1
未找到文件。
include/libs/sync/syncTools.h
浏览文件 @
59448cd1
...
...
@@ -550,7 +550,7 @@ typedef struct SyncPreSnapshotReply {
// private data
SyncTerm
term
;
SyncIndex
matchIndex
;
SyncIndex
snapStart
;
}
SyncPreSnapshotReply
;
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
59448cd1
...
...
@@ -3702,8 +3702,9 @@ void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshot
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"send sync-pre-snapshot-reply to %s:%d {term:%"
PRIu64
", match:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
matchIndex
,
s
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"send sync-pre-snapshot-reply to %s:%d {term:%"
PRIu64
", snap-start:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
snapStart
,
s
);
syncNodeEventLog
(
pSyncNode
,
logBuf
);
}
...
...
@@ -3712,7 +3713,8 @@ void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshot
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
srcId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
char
logBuf
[
256
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-pre-snapshot-reply from %s:%d {term:%"
PRIu64
", match:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
matchIndex
,
s
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"recv sync-pre-snapshot-reply from %s:%d {term:%"
PRIu64
", snap-start:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
snapStart
,
s
);
syncNodeEventLog
(
pSyncNode
,
logBuf
);
}
source/libs/sync/src/syncMessage.c
浏览文件 @
59448cd1
...
...
@@ -2568,8 +2568,8 @@ cJSON* syncPreSnapshotReply2Json(const SyncPreSnapshotReply* pMsg) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
matchIndex
);
cJSON_AddStringToObject
(
pRoot
,
"
match-index
"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
snapStart
);
cJSON_AddStringToObject
(
pRoot
,
"
snap-start
"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
59448cd1
...
...
@@ -925,10 +925,60 @@ int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
int32_t
syncNodeOnPreSnapshot
(
SSyncNode
*
ths
,
SyncPreSnapshot
*
pMsg
)
{
syncLogRecvSyncPreSnapshot
(
ths
,
pMsg
,
""
);
SyncPreSnapshotReply
*
pMsgReply
=
syncPreSnapshotReplyBuild
(
ths
->
vgId
);
pMsgReply
->
srcId
=
ths
->
myRaftId
;
pMsgReply
->
destId
=
pMsg
->
srcId
;
pMsgReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
SSyncLogStoreData
*
pData
=
ths
->
pLogStore
->
data
;
SWal
*
pWal
=
pData
->
pWal
;
if
(
syncNodeIsMnode
(
ths
))
{
pMsgReply
->
snapStart
=
SYNC_INDEX_BEGIN
;
}
else
{
bool
isEmpty
=
ths
->
pLogStore
->
syncLogIsEmpty
(
ths
->
pLogStore
);
int64_t
walCommitVer
=
walGetCommittedVer
(
pWal
);
if
(
!
isEmpty
&&
ths
->
commitIndex
!=
walCommitVer
)
{
char
logBuf
[
128
];
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"commit not same, wal-commit:%"
PRId64
", commit:%"
PRId64
", ignore"
,
walCommitVer
,
ths
->
commitIndex
);
syncNodeErrorLog
(
ths
,
logBuf
);
goto
_IGNORE
;
}
pMsgReply
->
snapStart
=
ths
->
commitIndex
+
1
;
// make local log clean
int32_t
code
=
ths
->
pLogStore
->
syncLogTruncate
(
ths
->
pLogStore
,
pMsgReply
->
snapStart
);
if
(
code
!=
0
)
{
syncNodeErrorLog
(
ths
,
"truncate wal error"
);
goto
_IGNORE
;
}
}
// can not write behind _RESPONSE
SRpcMsg
rpcMsg
;
_RESPONSE:
syncPreSnapshotReply2RpcMsg
(
pMsgReply
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pMsgReply
->
destId
,
ths
,
&
rpcMsg
);
syncPreSnapshotReplyDestroy
(
pMsgReply
);
return
0
;
_IGNORE:
syncPreSnapshotReplyDestroy
(
pMsgReply
);
return
0
;
}
int32_t
syncNodeOnPreSnapshotReply
(
SSyncNode
*
ths
,
SyncPreSnapshotReply
*
pMsg
)
{
syncLogRecvSyncPreSnapshotReply
(
ths
,
pMsg
,
""
);
// start snapshot
return
0
;
}
\ No newline at end of file
source/libs/sync/test/syncPreSnapshotReplyTest.cpp
浏览文件 @
59448cd1
...
...
@@ -22,7 +22,7 @@ SyncPreSnapshotReply *createMsg() {
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
term
=
9527
;
pMsg
->
matchIndex
=
12306
;
pMsg
->
snapStart
=
12306
;
return
pMsg
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录