Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d04c1271
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看板
提交
d04c1271
编写于
6月 02, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: send snapshot
上级
48a331fd
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
40 addition
and
18 deletion
+40
-18
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+8
-7
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+6
-0
source/libs/sync/src/syncIO.c
source/libs/sync/src/syncIO.c
+2
-1
source/libs/sync/src/syncReplication.c
source/libs/sync/src/syncReplication.c
+19
-8
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+4
-1
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
+1
-1
未找到文件。
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
d04c1271
...
@@ -39,14 +39,15 @@ typedef struct SSyncSnapshotSender {
...
@@ -39,14 +39,15 @@ typedef struct SSyncSnapshotSender {
bool
start
;
bool
start
;
int32_t
seq
;
int32_t
seq
;
int32_t
ack
;
int32_t
ack
;
void
*
pReader
;
void
*
pReader
;
void
*
pCurrentBlock
;
void
*
pCurrentBlock
;
int32_t
blockLen
;
int32_t
blockLen
;
SSnapshot
snapshot
;
SSnapshot
snapshot
;
int64_t
sendingMS
;
int64_t
sendingMS
;
SSyncNode
*
pSyncNode
;
SSyncNode
*
pSyncNode
;
int32_t
replicaIndex
;
int32_t
replicaIndex
;
SyncTerm
term
;
SyncTerm
term
;
bool
finish
;
}
SSyncSnapshotSender
;
}
SSyncSnapshotSender
;
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
);
SSyncSnapshotSender
*
snapshotSenderCreate
(
SSyncNode
*
pSyncNode
,
int32_t
replicaIndex
);
...
@@ -55,14 +56,14 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender);
...
@@ -55,14 +56,14 @@ void snapshotSenderStart(SSyncSnapshotSender *pSender);
void
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
);
void
snapshotSenderStop
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
int32_t
snapshotReSend
(
SSyncSnapshotSender
*
pSender
);
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
cJSON
*
snapshotSender2Json
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
char
*
snapshotSender2Str
(
SSyncSnapshotSender
*
pSender
);
typedef
struct
SSyncSnapshotReceiver
{
typedef
struct
SSyncSnapshotReceiver
{
bool
start
;
bool
start
;
int32_t
ack
;
int32_t
ack
;
void
*
pWriter
;
void
*
pWriter
;
SyncTerm
term
;
SyncTerm
term
;
SSyncNode
*
pSyncNode
;
SSyncNode
*
pSyncNode
;
...
@@ -73,8 +74,8 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, int32_t repl
...
@@ -73,8 +74,8 @@ SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, int32_t repl
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverDestroy
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStart
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
);
void
snapshotReceiverStop
(
SSyncSnapshotReceiver
*
pReceiver
);
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
);
cJSON
*
snapshotReceiver2Json
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
char
*
snapshotReceiver2Str
(
SSyncSnapshotReceiver
*
pReceiver
);
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
d04c1271
...
@@ -471,12 +471,18 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
...
@@ -471,12 +471,18 @@ int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMs
ASSERT
(
pMsg
->
prevLogIndex
==
snapshot
.
lastApplyIndex
);
ASSERT
(
pMsg
->
prevLogIndex
==
snapshot
.
lastApplyIndex
);
logOK
=
(
pMsg
->
prevLogIndex
==
snapshot
.
lastApplyIndex
)
&&
(
pMsg
->
prevLogTerm
==
snapshot
.
lastApplyTerm
);
logOK
=
(
pMsg
->
prevLogIndex
==
snapshot
.
lastApplyIndex
)
&&
(
pMsg
->
prevLogTerm
==
snapshot
.
lastApplyTerm
);
sTrace
(
"1 - logOK:%d, pMsg->prevLogIndex:%ld, snapshot.lastApplyIndex:%ld, pMsg->prevLogTerm:%lu, "
"snapshot.lastApplyTerm:%lu"
,
logOK
,
pMsg
->
prevLogIndex
,
snapshot
.
lastApplyIndex
,
pMsg
->
prevLogTerm
,
snapshot
.
lastApplyTerm
);
}
else
{
}
else
{
logOK
=
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
||
logOK
=
(
pMsg
->
prevLogIndex
==
SYNC_INDEX_INVALID
)
||
((
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
)
&&
((
pMsg
->
prevLogIndex
>=
SYNC_INDEX_BEGIN
)
&&
(
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
&&
(
pMsg
->
prevLogIndex
<=
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
))
&&
(
pMsg
->
prevLogTerm
==
localPreLogTerm
));
(
pMsg
->
prevLogTerm
==
localPreLogTerm
));
sTrace
(
"2 - logOK:%d, pMsg->prevLogIndex:%ld, getLastIndex:%ld, pMsg->prevLogTerm:%lu, localPreLogTerm:%lu"
,
logOK
,
pMsg
->
prevLogIndex
,
ths
->
pLogStore
->
getLastIndex
(
ths
->
pLogStore
),
pMsg
->
prevLogTerm
,
localPreLogTerm
);
}
}
// reject request
// reject request
...
...
source/libs/sync/src/syncIO.c
浏览文件 @
d04c1271
...
@@ -75,7 +75,8 @@ int32_t syncIOSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
...
@@ -75,7 +75,8 @@ int32_t syncIOSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
syncUtilMsgNtoH
(
pMsg
->
pCont
);
syncUtilMsgNtoH
(
pMsg
->
pCont
);
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==syncIOSendMsg== %s:%d msgType:%d"
,
pEpSet
->
eps
[
0
].
fqdn
,
pEpSet
->
eps
[
0
].
port
,
pMsg
->
msgType
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==syncIOSendMsg== %s:%d msgType:%d"
,
pEpSet
->
eps
[
0
].
fqdn
,
pEpSet
->
eps
[
0
].
port
,
pMsg
->
msgType
);
syncRpcMsgLog2
(
logBuf
,
pMsg
);
syncRpcMsgLog2
(
logBuf
,
pMsg
);
syncUtilMsgHtoN
(
pMsg
->
pCont
);
syncUtilMsgHtoN
(
pMsg
->
pCont
);
...
...
source/libs/sync/src/syncReplication.c
浏览文件 @
d04c1271
...
@@ -134,7 +134,22 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
...
@@ -134,7 +134,22 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
// batch optimized
// batch optimized
// SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex);
// SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex);
if
(
syncNodeIsIndexInSnapshot
(
pSyncNode
,
nextIndex
))
{
// sending snapshot finish?
bool
snapshotSendingFinish
=
false
;
SSyncSnapshotSender
*
pSender
=
NULL
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
if
(
syncUtilSameId
(
pDestId
,
&
((
pSyncNode
->
replicasId
)[
i
])))
{
pSender
=
(
pSyncNode
->
senders
)[
i
];
}
}
ASSERT
(
pSender
!=
NULL
);
snapshotSendingFinish
=
(
pSender
->
finish
)
&&
(
pSender
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
);
if
(
snapshotSendingFinish
)
{
sInfo
(
"snapshotSendingFinish! term:%lu"
,
pSender
->
term
);
}
if
((
syncNodeIsIndexInSnapshot
(
pSyncNode
,
nextIndex
-
1
)
&&
!
snapshotSendingFinish
)
||
syncNodeIsIndexInSnapshot
(
pSyncNode
,
nextIndex
))
{
// will send this msg until snapshot receive finish!
// will send this msg until snapshot receive finish!
SSnapshot
snapshot
;
SSnapshot
snapshot
;
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
pSyncNode
->
pFsm
->
FpGetSnapshot
(
pSyncNode
->
pFsm
,
&
snapshot
);
...
@@ -142,14 +157,10 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
...
@@ -142,14 +157,10 @@ int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
);
snapshot
.
lastApplyIndex
,
snapshot
.
lastApplyTerm
);
// do not use next index
// do not use next index
// always send from new last index + 1
// always send from snapshot.lastApplyIndex + 1, and wait for snapshot transfer finish
SyncIndex
lastIndex
;
SyncTerm
lastTerm
;
ret
=
syncNodeGetLastIndexTerm
(
pSyncNode
,
&
lastIndex
,
&
lastTerm
);
ASSERT
(
ret
==
0
);
ret
=
syncNodeGetPreIndexTerm
(
pSyncNode
,
lastIndex
+
1
,
&
preLogIndex
,
&
preLogTerm
)
;
preLogIndex
=
snapshot
.
lastApplyIndex
;
ASSERT
(
ret
==
0
)
;
preLogTerm
=
snapshot
.
lastApplyTerm
;
// to claim leader
// to claim leader
SyncAppendEntries
*
pMsg
=
syncAppendEntriesBuild
(
0
,
pSyncNode
->
vgId
);
SyncAppendEntries
*
pMsg
=
syncAppendEntriesBuild
(
0
,
pSyncNode
->
vgId
);
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
d04c1271
...
@@ -40,6 +40,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
...
@@ -40,6 +40,7 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
pSender
->
pSyncNode
=
pSyncNode
;
pSender
->
pSyncNode
=
pSyncNode
;
pSender
->
replicaIndex
=
replicaIndex
;
pSender
->
replicaIndex
=
replicaIndex
;
pSender
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pSender
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pSender
->
finish
=
false
;
}
else
{
}
else
{
sInfo
(
"snapshotSenderCreate cannot create sender"
);
sInfo
(
"snapshotSenderCreate cannot create sender"
);
}
}
...
@@ -270,6 +271,7 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
...
@@ -270,6 +271,7 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender) {
cJSON_AddNumberToObject
(
pRoot
,
"replicaIndex"
,
pSender
->
replicaIndex
);
cJSON_AddNumberToObject
(
pRoot
,
"replicaIndex"
,
pSender
->
replicaIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSender
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%lu"
,
pSender
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"finish"
,
pSender
->
finish
);
}
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON
*
pJson
=
cJSON_CreateObject
();
...
@@ -435,7 +437,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
...
@@ -435,7 +437,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
pReceiver
->
pWriter
=
NULL
;
pReceiver
->
pWriter
=
NULL
;
snapshotReceiverStop
(
pReceiver
);
snapshotReceiverStop
(
pReceiver
);
pReceiver
->
ack
=
pMsg
->
seq
;
pReceiver
->
ack
=
pMsg
->
seq
;
needRsp
=
fals
e
;
needRsp
=
tru
e
;
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
char
*
msgStr
=
syncSnapshotSend2Str
(
pMsg
);
sTrace
(
"snapshot recv end ack:%d recv msg:%s"
,
pReceiver
->
ack
,
msgStr
);
sTrace
(
"snapshot recv end ack:%d recv msg:%s"
,
pReceiver
->
ack
,
msgStr
);
...
@@ -506,6 +508,7 @@ int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
...
@@ -506,6 +508,7 @@ int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
// receiver ack is finish, close sender
// receiver ack is finish, close sender
if
(
pMsg
->
ack
==
SYNC_SNAPSHOT_SEQ_END
)
{
if
(
pMsg
->
ack
==
SYNC_SNAPSHOT_SEQ_END
)
{
pSender
->
finish
=
true
;
snapshotSenderStop
(
pSender
);
snapshotSenderStop
(
pSender
);
return
0
;
return
0
;
}
}
...
...
source/libs/sync/test/syncConfigChangeSnapshotTest.cpp
浏览文件 @
d04c1271
...
@@ -129,7 +129,7 @@ int32_t SnapshotStopWrite(struct SSyncFSM* pFsm, void* pWriter, bool isApply) {
...
@@ -129,7 +129,7 @@ int32_t SnapshotStopWrite(struct SSyncFSM* pFsm, void* pWriter, bool isApply) {
sTrace
(
"%s"
,
logBuf
);
sTrace
(
"%s"
,
logBuf
);
if
(
isApply
)
{
if
(
isApply
)
{
gSnapshotLastApplyIndex
=
7
;
gSnapshotLastApplyIndex
=
10
;
gSnapshotLastApplyTerm
=
1
;
gSnapshotLastApplyTerm
=
1
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录