Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f7191d2f
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
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看板
提交
f7191d2f
编写于
11月 02, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(sync): add pre snapshot
上级
59448cd1
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
358 addition
and
197 deletion
+358
-197
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+7
-2
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+14
-11
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+0
-1
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+2
-0
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+10
-0
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+7
-4
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+2
-2
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+313
-173
source/libs/sync/test/syncSnapshotReceiverTest.cpp
source/libs/sync/test/syncSnapshotReceiverTest.cpp
+0
-1
source/libs/sync/test/syncSnapshotRspTest.cpp
source/libs/sync/test/syncSnapshotRspTest.cpp
+1
-1
source/libs/sync/test/syncSnapshotSendTest.cpp
source/libs/sync/test/syncSnapshotSendTest.cpp
+0
-1
source/libs/sync/test/syncSnapshotSenderTest.cpp
source/libs/sync/test/syncSnapshotSenderTest.cpp
+2
-1
未找到文件。
source/libs/sync/inc/syncInt.h
浏览文件 @
f7191d2f
...
@@ -22,9 +22,8 @@ extern "C" {
...
@@ -22,9 +22,8 @@ extern "C" {
#include "sync.h"
#include "sync.h"
#include "syncTools.h"
#include "syncTools.h"
#include "tlog.h"
#include "ttimer.h"
#include "taosdef.h"
#include "taosdef.h"
#include "tlog.h"
#include "ttimer.h"
#include "ttimer.h"
// clang-format off
// clang-format off
...
@@ -344,6 +343,12 @@ void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMs
...
@@ -344,6 +343,12 @@ void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMs
void
syncLogSendSyncPreSnapshotReply
(
SSyncNode
*
pSyncNode
,
const
SyncPreSnapshotReply
*
pMsg
,
const
char
*
s
);
void
syncLogSendSyncPreSnapshotReply
(
SSyncNode
*
pSyncNode
,
const
SyncPreSnapshotReply
*
pMsg
,
const
char
*
s
);
void
syncLogRecvSyncPreSnapshotReply
(
SSyncNode
*
pSyncNode
,
const
SyncPreSnapshotReply
*
pMsg
,
const
char
*
s
);
void
syncLogRecvSyncPreSnapshotReply
(
SSyncNode
*
pSyncNode
,
const
SyncPreSnapshotReply
*
pMsg
,
const
char
*
s
);
void
syncLogSendSyncSnapshotSend
(
SSyncNode
*
pSyncNode
,
const
SyncSnapshotSend
*
pMsg
,
const
char
*
s
);
void
syncLogRecvSyncSnapshotSend
(
SSyncNode
*
pSyncNode
,
const
SyncSnapshotSend
*
pMsg
,
const
char
*
s
);
void
syncLogSendSyncSnapshotRsp
(
SSyncNode
*
pSyncNode
,
const
SyncSnapshotRsp
*
pMsg
,
const
char
*
s
);
void
syncLogRecvSyncSnapshotRsp
(
SSyncNode
*
pSyncNode
,
const
SyncSnapshotRsp
*
pMsg
,
const
char
*
s
);
// for debug --------------
// for debug --------------
void
syncNodePrint
(
SSyncNode
*
pObj
);
void
syncNodePrint
(
SSyncNode
*
pObj
);
void
syncNodePrint2
(
char
*
s
,
SSyncNode
*
pObj
);
void
syncNodePrint2
(
char
*
s
,
SSyncNode
*
pObj
);
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
f7191d2f
...
@@ -28,10 +28,11 @@ extern "C" {
...
@@ -28,10 +28,11 @@ extern "C" {
#include "syncMessage.h"
#include "syncMessage.h"
#include "taosdef.h"
#include "taosdef.h"
#define SYNC_SNAPSHOT_SEQ_INVALID -1
#define SYNC_SNAPSHOT_SEQ_INVALID -2
#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -2
#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -3
#define SYNC_SNAPSHOT_SEQ_BEGIN 0
#define SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT -1
#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF
#define SYNC_SNAPSHOT_SEQ_BEGIN 0
#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF
#define SYNC_SNAPSHOT_RETRY_MS 5000
#define SYNC_SNAPSHOT_RETRY_MS 5000
...
@@ -47,19 +48,19 @@ typedef struct SSyncSnapshotSender {
...
@@ -47,19 +48,19 @@ typedef struct SSyncSnapshotSender {
SSnapshot
snapshot
;
SSnapshot
snapshot
;
SSyncCfg
lastConfig
;
SSyncCfg
lastConfig
;
int64_t
sendingMS
;
int64_t
sendingMS
;
SSyncNode
*
pSyncNode
;
int32_t
replicaIndex
;
SyncTerm
term
;
SyncTerm
term
;
SyncTerm
privateTerm
;
int64_t
startTime
;
int64_t
startTime
;
bool
finish
;
bool
finish
;
// init when create
SSyncNode
*
pSyncNode
;
int32_t
replicaIndex
;
}
SSyncSnapshotSender
;
}
SSyncSnapshotSender
;
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
);
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
);
void
snapshotSenderDestroy
(
SSyncSnapshotSender
*
pSender
);
void
snapshotSenderDestroy
(
SSyncSnapshotSender
*
pSender
);
bool
snapshotSenderIsStart
(
SSyncSnapshotSender
*
pSender
);
bool
snapshotSenderIsStart
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSenderStart
(
SSyncSnapshotSender
*
pSender
,
SSnapshotParam
snapshotParam
,
SSnapshot
snapshot
,
int32_t
snapshotSenderStart
(
SSyncSnapshotSender
*
pSender
);
void
*
pReader
);
int32_t
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
,
bool
finish
);
int32_t
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
,
bool
finish
);
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
...
@@ -76,11 +77,13 @@ typedef struct SSyncSnapshotReceiver {
...
@@ -76,11 +77,13 @@ typedef struct SSyncSnapshotReceiver {
int32_t
ack
;
int32_t
ack
;
void
*
pWriter
;
void
*
pWriter
;
SyncTerm
term
;
SyncTerm
term
;
SyncTerm
privateTerm
;
SSnapshotParam
snapshotParam
;
SSnapshotParam
snapshotParam
;
SSnapshot
snapshot
;
SSnapshot
snapshot
;
SRaftId
fromId
;
SRaftId
fromId
;
SSyncNode
*
pSyncNode
;
int64_t
startTime
;
// init when create
SSyncNode
*
pSyncNode
;
}
SSyncSnapshotReceiver
;
}
SSyncSnapshotReceiver
;
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
f7191d2f
...
@@ -142,7 +142,6 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
...
@@ -142,7 +142,6 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
// pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
// pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
pReply
->
matchIndex
=
SYNC_INDEX_INVALID
;
pReply
->
matchIndex
=
SYNC_INDEX_INVALID
;
pReply
->
lastSendIndex
=
pMsg
->
prevLogIndex
+
1
;
pReply
->
lastSendIndex
=
pMsg
->
prevLogIndex
+
1
;
pReply
->
privateTerm
=
ths
->
pNewNodeReceiver
->
privateTerm
;
pReply
->
startTime
=
ths
->
startTime
;
pReply
->
startTime
=
ths
->
startTime
;
if
(
pMsg
->
term
<
ths
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
term
<
ths
->
pRaftStore
->
currentTerm
)
{
...
...
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
f7191d2f
...
@@ -73,6 +73,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
...
@@ -73,6 +73,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
int32_t
code
=
ths
->
pFsm
->
FpSnapshotStartRead
(
ths
->
pFsm
,
&
readerParam
,
&
pReader
);
int32_t
code
=
ths
->
pFsm
->
FpSnapshotStartRead
(
ths
->
pFsm
,
&
readerParam
,
&
pReader
);
ASSERT
(
code
==
0
);
ASSERT
(
code
==
0
);
#if 0
if (pMsg->privateTerm < pSender->privateTerm) {
if (pMsg->privateTerm < pSender->privateTerm) {
ASSERT(pReader != NULL);
ASSERT(pReader != NULL);
snapshotSenderStart(pSender, readerParam, snapshot, pReader);
snapshotSenderStart(pSender, readerParam, snapshot, pReader);
...
@@ -82,6 +83,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
...
@@ -82,6 +83,7 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader);
ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader);
}
}
}
}
#endif
}
}
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
f7191d2f
...
@@ -2355,6 +2355,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
...
@@ -2355,6 +2355,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
// init peer mgr
// init peer mgr
syncNodePeerStateInit
(
pSyncNode
);
syncNodePeerStateInit
(
pSyncNode
);
#if 0
// update sender private term
// update sender private term
SSyncSnapshotSender* pMySender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->myRaftId));
SSyncSnapshotSender* pMySender = syncNodeGetSnapshotSender(pSyncNode, &(pSyncNode->myRaftId));
if (pMySender != NULL) {
if (pMySender != NULL) {
...
@@ -2365,6 +2366,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
...
@@ -2365,6 +2366,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
}
}
(pMySender->privateTerm) += 100;
(pMySender->privateTerm) += 100;
}
}
#endif
// close receiver
// close receiver
if
(
snapshotReceiverIsStart
(
pSyncNode
->
pNewNodeReceiver
))
{
if
(
snapshotReceiverIsStart
(
pSyncNode
->
pNewNodeReceiver
))
{
...
@@ -3718,3 +3720,11 @@ void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshot
...
@@ -3718,3 +3720,11 @@ void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshot
pMsg
->
term
,
pMsg
->
snapStart
,
s
);
pMsg
->
term
,
pMsg
->
snapStart
,
s
);
syncNodeEventLog
(
pSyncNode
,
logBuf
);
syncNodeEventLog
(
pSyncNode
,
logBuf
);
}
}
void
syncLogSendSyncSnapshotSend
(
SSyncNode
*
pSyncNode
,
const
SyncSnapshotSend
*
pMsg
,
const
char
*
s
)
{}
void
syncLogRecvSyncSnapshotSend
(
SSyncNode
*
pSyncNode
,
const
SyncSnapshotSend
*
pMsg
,
const
char
*
s
)
{}
void
syncLogSendSyncSnapshotRsp
(
SSyncNode
*
pSyncNode
,
const
SyncSnapshotRsp
*
pMsg
,
const
char
*
s
)
{}
void
syncLogRecvSyncSnapshotRsp
(
SSyncNode
*
pSyncNode
,
const
SyncSnapshotRsp
*
pMsg
,
const
char
*
s
)
{}
source/libs/sync/src/syncMessage.c
浏览文件 @
f7191d2f
...
@@ -2873,8 +2873,8 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
...
@@ -2873,8 +2873,8 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u64
,
pMsg
->
privateTerm
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d64
,
pMsg
->
startTime
);
cJSON_AddStringToObject
(
pRoot
,
"
privateTerm
"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"
startTime
"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
beginIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
beginIndex
);
cJSON_AddStringToObject
(
pRoot
,
"beginIndex"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"beginIndex"
,
u64buf
);
...
@@ -3048,8 +3048,8 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) {
...
@@ -3048,8 +3048,8 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
u64
,
pMsg
->
privateTerm
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRI
d64
,
pMsg
->
startTime
);
cJSON_AddStringToObject
(
pRoot
,
"
privateTerm
"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"
startTime
"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
lastIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
lastIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastIndex"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"lastIndex"
,
u64buf
);
...
@@ -3059,6 +3059,9 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) {
...
@@ -3059,6 +3059,9 @@ cJSON* syncSnapshotRsp2Json(const SyncSnapshotRsp* pMsg) {
cJSON_AddNumberToObject
(
pRoot
,
"ack"
,
pMsg
->
ack
);
cJSON_AddNumberToObject
(
pRoot
,
"ack"
,
pMsg
->
ack
);
cJSON_AddNumberToObject
(
pRoot
,
"code"
,
pMsg
->
code
);
cJSON_AddNumberToObject
(
pRoot
,
"code"
,
pMsg
->
code
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
snapBeginIndex
);
cJSON_AddStringToObject
(
pRoot
,
"snap-begin"
,
u64buf
);
}
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON
*
pJson
=
cJSON_CreateObject
();
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
f7191d2f
...
@@ -62,8 +62,8 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
...
@@ -62,8 +62,8 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
syncNodeEventLog
(
pSyncNode
,
logBuf
);
syncNodeEventLog
(
pSyncNode
,
logBuf
);
// start snapshot
// start snapshot
int32_t
code
=
syncNodeStartSnapshot
(
pSyncNode
,
pDestId
);
//
int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId);
ASSERT
(
code
==
0
);
return
0
;
return
0
;
}
}
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
f7191d2f
此差异已折叠。
点击以展开。
source/libs/sync/test/syncSnapshotReceiverTest.cpp
浏览文件 @
f7191d2f
...
@@ -50,7 +50,6 @@ SSyncSnapshotReceiver* createReceiver() {
...
@@ -50,7 +50,6 @@ SSyncSnapshotReceiver* createReceiver() {
pReceiver
->
ack
=
20
;
pReceiver
->
ack
=
20
;
pReceiver
->
pWriter
=
(
void
*
)
0x11
;
pReceiver
->
pWriter
=
(
void
*
)
0x11
;
pReceiver
->
term
=
66
;
pReceiver
->
term
=
66
;
pReceiver
->
privateTerm
=
99
;
return
pReceiver
;
return
pReceiver
;
}
}
...
...
source/libs/sync/test/syncSnapshotRspTest.cpp
浏览文件 @
f7191d2f
...
@@ -21,7 +21,7 @@ SyncSnapshotRsp *createMsg() {
...
@@ -21,7 +21,7 @@ SyncSnapshotRsp *createMsg() {
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
term
=
11
;
pMsg
->
term
=
11
;
pMsg
->
privateTerm
=
99
;
pMsg
->
startTime
=
99
;
pMsg
->
lastIndex
=
22
;
pMsg
->
lastIndex
=
22
;
pMsg
->
lastTerm
=
33
;
pMsg
->
lastTerm
=
33
;
pMsg
->
ack
=
44
;
pMsg
->
ack
=
44
;
...
...
source/libs/sync/test/syncSnapshotSendTest.cpp
浏览文件 @
f7191d2f
...
@@ -21,7 +21,6 @@ SyncSnapshotSend *createMsg() {
...
@@ -21,7 +21,6 @@ SyncSnapshotSend *createMsg() {
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
term
=
11
;
pMsg
->
term
=
11
;
pMsg
->
privateTerm
=
99
;
pMsg
->
lastIndex
=
22
;
pMsg
->
lastIndex
=
22
;
pMsg
->
lastTerm
=
33
;
pMsg
->
lastTerm
=
33
;
...
...
source/libs/sync/test/syncSnapshotSenderTest.cpp
浏览文件 @
f7191d2f
...
@@ -55,7 +55,8 @@ SSyncSnapshotSender* createSender() {
...
@@ -55,7 +55,8 @@ SSyncSnapshotSender* createSender() {
pSender
->
snapshot
.
lastApplyTerm
=
88
;
pSender
->
snapshot
.
lastApplyTerm
=
88
;
pSender
->
sendingMS
=
77
;
pSender
->
sendingMS
=
77
;
pSender
->
term
=
66
;
pSender
->
term
=
66
;
pSender
->
privateTerm
=
99
;
//pSender->privateTerm = 99;
return
pSender
;
return
pSender
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录