Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ee9cdb29
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22017
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看板
提交
ee9cdb29
编写于
5月 31, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(sync): syncNodeOnSnapshotSendCb, syncNodeOnSnapshotRspCb
上级
21191ae2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
34 deletion
+66
-34
source/dnode/mnode/impl/src/mndMain.c
source/dnode/mnode/impl/src/mndMain.c
+10
-11
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+56
-23
未找到文件。
source/dnode/mnode/impl/src/mndMain.c
浏览文件 @
ee9cdb29
...
...
@@ -369,15 +369,14 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
mError
(
"failed to process sync msg:%p type:%s since %s"
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
),
terrstr
());
return
TAOS_SYNC_PROPOSE_OTHER_ERROR
;
}
char
logBuf
[
512
]
=
{
0
};
char
*
syncNodeStr
=
sync2SimpleStr
(
pMgmt
->
sync
);
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==vnodeProcessSyncReq== msgType:%d, syncNode: %s"
,
pMsg
->
msgType
,
syncNodeStr
);
syncRpcMsgLog2
(
logBuf
,
pMsg
);
taosMemoryFree
(
syncNodeStr
);
// ugly! use function pointer
// ToDo: ugly! use function pointer
if
(
syncNodeSnapshotEnable
(
pSyncNode
))
{
if
(
pMsg
->
msgType
==
TDMT_VND_SYNC_TIMEOUT
)
{
SyncTimeout
*
pSyncMsg
=
syncTimeoutFromRpcMsg2
(
pMsg
);
...
...
@@ -413,14 +412,14 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
code
=
syncNodeOnAppendEntriesReplySnapshotCb
(
pSyncNode
,
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_VND_SYNC_SNAPSHOT_SEND
)
{
SyncSnapshotSend
*
pSyncMsg
=
syncSnapshotSendFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnSnapshotSendCb
(
pSyncNode
,
pSyncMsg
);
syncSnapshotSendDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_VND_SYNC_SNAPSHOT_RSP
)
{
SyncSnapshotRsp
*
pSyncMsg
=
syncSnapshotRspFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnSnapshotRspCb
(
pSyncNode
,
pSyncMsg
);
syncSnapshotRspDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_VND_SYNC_SNAPSHOT_SEND
)
{
SyncSnapshotSend
*
pSyncMsg
=
syncSnapshotSendFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnSnapshotSendCb
(
pSyncNode
,
pSyncMsg
);
syncSnapshotSendDestroy
(
pSyncMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_VND_SYNC_SNAPSHOT_RSP
)
{
SyncSnapshotRsp
*
pSyncMsg
=
syncSnapshotRspFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnSnapshotRspCb
(
pSyncNode
,
pSyncMsg
);
syncSnapshotRspDestroy
(
pSyncMsg
);
}
else
{
mError
(
"failed to process msg:%p since invalid type:%s"
,
pMsg
,
TMSG_INFO
(
pMsg
->
msgType
));
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
ee9cdb29
...
...
@@ -299,6 +299,7 @@ char *snapshotReceiver2Str(SSyncSnapshotReceiver *pReceiver) {
return
serialized
;
}
// receiver do something
int32_t
syncNodeOnSnapshotSendCb
(
SSyncNode
*
pSyncNode
,
SyncSnapshotSend
*
pMsg
)
{
SSyncSnapshotReceiver
*
pReceiver
=
NULL
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
...
...
@@ -308,32 +309,64 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
}
ASSERT
(
pReceiver
!=
NULL
);
SyncSnapshotRsp
*
pRspMsg
=
syncSnapshotRspBuild
(
pSyncNode
->
vgId
);
pRspMsg
->
srcId
=
pSyncNode
->
myRaftId
;
pRspMsg
->
destId
=
pMsg
->
srcId
;
pRspMsg
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pRspMsg
->
lastIndex
=
pMsg
->
lastIndex
;
pRspMsg
->
lastTerm
=
pMsg
->
lastTerm
;
pRspMsg
->
ack
=
pMsg
->
seq
;
// state, term, seq/ack
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_FOLLOWER
)
{
SyncSnapshotRsp
*
pRspMsg
=
syncSnapshotRspBuild
(
pSyncNode
->
vgId
);
pRspMsg
->
srcId
=
pSyncNode
->
myRaftId
;
pRspMsg
->
destId
=
pMsg
->
srcId
;
pRspMsg
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
pRspMsg
->
lastIndex
=
pMsg
->
lastIndex
;
pRspMsg
->
lastTerm
=
pMsg
->
lastTerm
;
pRspMsg
->
ack
=
pMsg
->
seq
;
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_BEGIN
)
{
// begin
snapshotReceiverStart
(
pReceiver
);
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
// end
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
pMsg
->
data
,
pMsg
->
dataLen
);
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
true
);
snapshotReceiverStop
(
pReceiver
);
}
else
if
(
pMsg
->
seq
==
SYNC_SNAPSHOT_SEQ_FORCE_CLOSE
)
{
pSyncNode
->
pFsm
->
FpSnapshotStopWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
false
);
snapshotReceiverStop
(
pReceiver
);
if
(
pMsg
->
seq
==
0
)
{
// begin
snapshotReceiverStart
(
pReceiver
);
}
else
if
(
pMsg
->
seq
==
-
1
)
{
// end
snapshotReceiverStop
(
pReceiver
);
// apply msg finish
}
else
{
// transfering
if
(
pMsg
->
seq
==
pReceiver
->
ack
+
1
)
{
pSyncNode
->
pFsm
->
FpSnapshotDoWrite
(
pSyncNode
->
pFsm
,
pReceiver
->
pWriter
,
pMsg
->
data
,
pMsg
->
dataLen
);
}
}
}
else
{
// transfering
// apply msg
SRpcMsg
rpcMsg
;
syncSnapshotRsp2RpcMsg
(
pRspMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pRspMsg
->
destId
),
pSyncNode
,
&
rpcMsg
);
}
SRpcMsg
rpcMsg
;
syncSnapshotRsp2RpcMsg
(
pRspMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pRspMsg
->
destId
),
pSyncNode
,
&
rpcMsg
);
return
0
;
}
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
)
{
return
0
;
}
\ No newline at end of file
// sender do something
int32_t
syncNodeOnSnapshotRspCb
(
SSyncNode
*
pSyncNode
,
SyncSnapshotRsp
*
pMsg
)
{
SSyncSnapshotSender
*
pSender
=
NULL
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
if
(
syncUtilSameId
(
&
(
pMsg
->
srcId
),
&
((
pSyncNode
->
replicasId
)[
i
])))
{
pSender
=
(
pSyncNode
->
senders
)[
i
];
}
}
ASSERT
(
pSender
!=
NULL
);
// state, term, seq/ack
if
(
pSyncNode
->
state
==
TAOS_SYNC_STATE_LEADER
)
{
if
(
pMsg
->
term
==
pSyncNode
->
pRaftStore
->
currentTerm
)
{
if
(
pMsg
->
ack
==
pSender
->
seq
)
{
pSender
->
ack
=
pMsg
->
ack
;
snapshotSend
(
pSender
);
(
pSender
->
seq
)
++
;
}
}
}
return
0
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录