Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
eec0ab8c
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看板
提交
eec0ab8c
编写于
11月 13, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact: adjust sync snapshotsend msg
上级
d5f7f8c3
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
125 addition
and
109 deletion
+125
-109
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+2
-21
source/libs/sync/inc/syncSnapshot.h
source/libs/sync/inc/syncSnapshot.h
+1
-1
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+1
-3
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+13
-61
source/libs/sync/src/syncSnapshot.c
source/libs/sync/src/syncSnapshot.c
+24
-23
source/libs/sync/test/sync_test_lib/inc/syncTest.h
source/libs/sync/test/sync_test_lib/inc/syncTest.h
+18
-0
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
+66
-0
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
eec0ab8c
...
...
@@ -191,25 +191,6 @@ typedef struct SyncSnapshotSend {
char
data
[];
}
SyncSnapshotSend
;
SyncSnapshotSend
*
syncSnapshotSendBuild
(
uint32_t
dataLen
,
int32_t
vgId
);
void
syncSnapshotSendDestroy
(
SyncSnapshotSend
*
pMsg
);
void
syncSnapshotSendSerialize
(
const
SyncSnapshotSend
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncSnapshotSendDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncSnapshotSend
*
pMsg
);
char
*
syncSnapshotSendSerialize2
(
const
SyncSnapshotSend
*
pMsg
,
uint32_t
*
len
);
SyncSnapshotSend
*
syncSnapshotSendDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncSnapshotSend2RpcMsg
(
const
SyncSnapshotSend
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncSnapshotSendFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncSnapshotSend
*
pMsg
);
SyncSnapshotSend
*
syncSnapshotSendFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncSnapshotSend2Json
(
const
SyncSnapshotSend
*
pMsg
);
char
*
syncSnapshotSend2Str
(
const
SyncSnapshotSend
*
pMsg
);
// for debug ----------------------
void
syncSnapshotSendPrint
(
const
SyncSnapshotSend
*
pMsg
);
void
syncSnapshotSendPrint2
(
char
*
s
,
const
SyncSnapshotSend
*
pMsg
);
void
syncSnapshotSendLog
(
const
SyncSnapshotSend
*
pMsg
);
void
syncSnapshotSendLog2
(
char
*
s
,
const
SyncSnapshotSend
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncSnapshotRsp
{
uint32_t
bytes
;
int32_t
vgId
;
...
...
@@ -312,8 +293,7 @@ int32_t syncNodeOnRequestVote(SSyncNode* pNode, const SRpcMsg* pMsg);
int32_t
syncNodeOnRequestVoteReply
(
SSyncNode
*
pNode
,
const
SRpcMsg
*
pMsg
);
int32_t
syncNodeOnAppendEntries
(
SSyncNode
*
pNode
,
const
SRpcMsg
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
int32_t
syncNodeOnSnapshot
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshot
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
int32_t
syncNodeOnSnapshotReply
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
int32_t
syncNodeOnHeartbeat
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
...
...
@@ -342,6 +322,7 @@ int32_t syncBuildHeartbeatReply(SRpcMsg* pMsg, int32_t vgId);
int32_t
syncBuildPreSnapshot
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildPreSnapshotReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildApplyMsg
(
SRpcMsg
*
pMsg
,
const
SRpcMsg
*
pOriginal
,
int32_t
vgId
,
SFsmCbMeta
*
pMeta
);
int32_t
syncBuildSnapshotSend
(
SRpcMsg
*
pMsg
,
int32_t
dataLen
,
int32_t
vgId
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncSnapshot.h
浏览文件 @
eec0ab8c
...
...
@@ -84,7 +84,7 @@ bool snapshotReceiverIsStart(SSyncSnapshotReceiver *pReceiver)
void
snapshotReceiverForceStop
(
SSyncSnapshotReceiver
*
pReceiver
);
// on message
int32_t
syncNodeOnSnapshot
(
SSyncNode
*
ths
,
SyncSnapshotSend
*
pMsg
);
int32_t
syncNodeOnSnapshot
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
int32_t
syncNodeOnSnapshotReply
(
SSyncNode
*
ths
,
SyncSnapshotRsp
*
pMsg
);
// start
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
eec0ab8c
...
...
@@ -150,9 +150,7 @@ int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) {
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
code
=
syncNodeOnAppendEntriesReply
(
pSyncNode
,
pMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_SNAPSHOT_SEND
)
{
SyncSnapshotSend
*
pSyncMsg
=
syncSnapshotSendFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnSnapshot
(
pSyncNode
,
pSyncMsg
);
syncSnapshotSendDestroy
(
pSyncMsg
);
code
=
syncNodeOnSnapshot
(
pSyncNode
,
pMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_SNAPSHOT_RSP
)
{
SyncSnapshotRsp
*
pSyncMsg
=
syncSnapshotRspFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnSnapshotReply
(
pSyncNode
,
pSyncMsg
);
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
eec0ab8c
...
...
@@ -223,70 +223,22 @@ int32_t syncBuildPreSnapshotReply(SRpcMsg* pMsg, int32_t vgId) {
return
0
;
}
// ---------------------------------------------
SyncSnapshotSend
*
syncSnapshotSendBuild
(
uint32_t
dataLen
,
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncSnapshotSend
)
+
dataLen
;
SyncSnapshotSend
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
int32_t
syncBuildSnapshotSend
(
SRpcMsg
*
pMsg
,
int32_t
dataLen
,
int32_t
vgId
)
{
int32_t
bytes
=
sizeof
(
SyncSnapshotSend
)
+
dataLen
;
pMsg
->
pCont
=
rpcMallocCont
(
bytes
);
pMsg
->
msgType
=
TDMT_SYNC_SNAPSHOT_SEND
;
pMsg
->
dataLen
=
dataLen
;
return
pMsg
;
}
void
syncSnapshotSendDestroy
(
SyncSnapshotSend
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncSnapshotSendSerialize
(
const
SyncSnapshotSend
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncSnapshotSendDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncSnapshotSend
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
ASSERT
(
pMsg
->
bytes
==
sizeof
(
SyncSnapshotSend
)
+
pMsg
->
dataLen
);
}
char
*
syncSnapshotSendSerialize2
(
const
SyncSnapshotSend
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncSnapshotSendSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
pMsg
->
contLen
=
bytes
;
if
(
pMsg
->
pCont
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
return
buf
;
}
SyncSnapshotSend
*
syncSnapshotSendDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncSnapshotSend
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncSnapshotSendDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncSnapshotSend2RpcMsg
(
const
SyncSnapshotSend
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncSnapshotSendSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncSnapshotSendFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncSnapshotSend
*
pMsg
)
{
syncSnapshotSendDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncSnapshotSend
*
syncSnapshotSendFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncSnapshotSend
*
pMsg
=
syncSnapshotSendDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
SyncSnapshotSend
*
pSnapshotSend
=
pMsg
->
pCont
;
pSnapshotSend
->
bytes
=
bytes
;
pSnapshotSend
->
vgId
=
vgId
;
pSnapshotSend
->
msgType
=
TDMT_SYNC_SNAPSHOT_SEND
;
pSnapshotSend
->
dataLen
=
dataLen
;
return
0
;
}
SyncSnapshotRsp
*
syncSnapshotRspBuild
(
int32_t
vgId
)
{
...
...
source/libs/sync/src/syncSnapshot.c
浏览文件 @
eec0ab8c
...
...
@@ -105,7 +105,10 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
pSender
->
finish
=
false
;
// build begin msg
SyncSnapshotSend
*
pMsg
=
syncSnapshotSendBuild
(
0
,
pSender
->
pSyncNode
->
vgId
);
SRpcMsg
rpcMsg
=
{
0
};
(
void
)
syncBuildSnapshotSend
(
&
rpcMsg
,
0
,
pSender
->
pSyncNode
->
vgId
);
SyncSnapshotSend
*
pMsg
=
rpcMsg
.
pCont
;
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
...
...
@@ -118,11 +121,8 @@ int32_t snapshotSenderStart(SSyncSnapshotSender *pSender) {
pMsg
->
seq
=
SYNC_SNAPSHOT_SEQ_PRE_SNAPSHOT
;
// send msg
SRpcMsg
rpcMsg
;
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pMsg
->
destId
,
pSender
->
pSyncNode
,
&
rpcMsg
);
syncLogSendSyncSnapshotSend
(
pSender
->
pSyncNode
,
pMsg
,
""
);
syncSnapshotSendDestroy
(
pMsg
);
// event log
sSTrace
(
pSender
,
"snapshot sender start"
);
...
...
@@ -176,7 +176,10 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
}
// build msg
SyncSnapshotSend
*
pMsg
=
syncSnapshotSendBuild
(
pSender
->
blockLen
,
pSender
->
pSyncNode
->
vgId
);
SRpcMsg
rpcMsg
=
{
0
};
(
void
)
syncBuildSnapshotSend
(
&
rpcMsg
,
pSender
->
blockLen
,
pSender
->
pSyncNode
->
vgId
);
SyncSnapshotSend
*
pMsg
=
rpcMsg
.
pCont
;
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
...
...
@@ -192,11 +195,8 @@ int32_t snapshotSend(SSyncSnapshotSender *pSender) {
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
// send msg
SRpcMsg
rpcMsg
;
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pMsg
->
destId
,
pSender
->
pSyncNode
,
&
rpcMsg
);
syncLogSendSyncSnapshotSend
(
pSender
->
pSyncNode
,
pMsg
,
""
);
syncSnapshotSendDestroy
(
pMsg
);
// event log
if
(
pSender
->
seq
==
SYNC_SNAPSHOT_SEQ_END
)
{
...
...
@@ -212,7 +212,10 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
// send current block data
if
(
pSender
->
pCurrentBlock
!=
NULL
&&
pSender
->
blockLen
>
0
)
{
// build msg
SyncSnapshotSend
*
pMsg
=
syncSnapshotSendBuild
(
pSender
->
blockLen
,
pSender
->
pSyncNode
->
vgId
);
SRpcMsg
rpcMsg
=
{
0
};
(
void
)
syncBuildSnapshotSend
(
&
rpcMsg
,
pSender
->
blockLen
,
pSender
->
pSyncNode
->
vgId
);
SyncSnapshotSend
*
pMsg
=
rpcMsg
.
pCont
;
pMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
pMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
...
...
@@ -224,15 +227,11 @@ int32_t snapshotReSend(SSyncSnapshotSender *pSender) {
pMsg
->
seq
=
pSender
->
seq
;
// pMsg->privateTerm = pSender->privateTerm;
memcpy
(
pMsg
->
data
,
pSender
->
pCurrentBlock
,
pSender
->
blockLen
);
// send msg
SRpcMsg
rpcMsg
;
syncSnapshotSend2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pMsg
->
destId
,
pSender
->
pSyncNode
,
&
rpcMsg
);
syncLogSendSyncSnapshotSend
(
pSender
->
pSyncNode
,
pMsg
,
""
);
syncSnapshotSendDestroy
(
pMsg
);
// event log
sSTrace
(
pSender
,
"snapshot sender resend"
);
...
...
@@ -705,7 +704,9 @@ static int32_t syncNodeOnSnapshotEnd(SSyncNode *pSyncNode, SyncSnapshotSend *pMs
//
// condition 5, got data, update ack
//
int32_t
syncNodeOnSnapshot
(
SSyncNode
*
pSyncNode
,
SyncSnapshotSend
*
pMsg
)
{
int32_t
syncNodeOnSnapshot
(
SSyncNode
*
pSyncNode
,
const
SRpcMsg
*
pRpcMsg
)
{
SyncSnapshotSend
*
pMsg
=
pRpcMsg
->
pCont
;
// if already drop replica, do not process
if
(
!
syncNodeInRaftGroup
(
pSyncNode
,
&
(
pMsg
->
srcId
)))
{
syncLogRecvSyncSnapshotSend
(
pSyncNode
,
pMsg
,
"not in my config"
);
...
...
@@ -797,13 +798,16 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
}
// update next index
syncIndexMgrSetIndex
(
pSyncNode
->
pNextIndex
,
&
(
pMsg
->
srcId
)
,
snapshot
.
lastApplyIndex
+
1
);
syncIndexMgrSetIndex
(
pSyncNode
->
pNextIndex
,
&
pMsg
->
srcId
,
snapshot
.
lastApplyIndex
+
1
);
// update seq
pSender
->
seq
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
// build begin msg
SyncSnapshotSend
*
pSendMsg
=
syncSnapshotSendBuild
(
0
,
pSender
->
pSyncNode
->
vgId
);
SRpcMsg
rpcMsg
=
{
0
};
(
void
)
syncBuildSnapshotSend
(
&
rpcMsg
,
0
,
pSender
->
pSyncNode
->
vgId
);
SyncSnapshotSend
*
pSendMsg
=
rpcMsg
.
pCont
;
pSendMsg
->
srcId
=
pSender
->
pSyncNode
->
myRaftId
;
pSendMsg
->
destId
=
(
pSender
->
pSyncNode
->
replicasId
)[
pSender
->
replicaIndex
];
pSendMsg
->
term
=
pSender
->
pSyncNode
->
pRaftStore
->
currentTerm
;
...
...
@@ -816,11 +820,8 @@ int32_t syncNodeOnSnapshotReplyPre(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg)
pSendMsg
->
seq
=
SYNC_SNAPSHOT_SEQ_BEGIN
;
// send msg
SRpcMsg
rpcMsg
;
syncSnapshotSend2RpcMsg
(
pSendMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
(
pSendMsg
->
destId
),
pSender
->
pSyncNode
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pSendMsg
->
destId
,
pSender
->
pSyncNode
,
&
rpcMsg
);
syncLogSendSyncSnapshotSend
(
pSyncNode
,
pSendMsg
,
""
);
syncSnapshotSendDestroy
(
pSendMsg
);
return
0
;
}
...
...
source/libs/sync/test/sync_test_lib/inc/syncTest.h
浏览文件 @
eec0ab8c
...
...
@@ -409,6 +409,24 @@ void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg);
void
syncApplyMsgLog
(
const
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgLog2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
);
SyncSnapshotSend
*
syncSnapshotSendBuild
(
uint32_t
dataLen
,
int32_t
vgId
);
void
syncSnapshotSendDestroy
(
SyncSnapshotSend
*
pMsg
);
void
syncSnapshotSendSerialize
(
const
SyncSnapshotSend
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncSnapshotSendDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncSnapshotSend
*
pMsg
);
char
*
syncSnapshotSendSerialize2
(
const
SyncSnapshotSend
*
pMsg
,
uint32_t
*
len
);
SyncSnapshotSend
*
syncSnapshotSendDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncSnapshotSend2RpcMsg
(
const
SyncSnapshotSend
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncSnapshotSendFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncSnapshotSend
*
pMsg
);
SyncSnapshotSend
*
syncSnapshotSendFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncSnapshotSend2Json
(
const
SyncSnapshotSend
*
pMsg
);
char
*
syncSnapshotSend2Str
(
const
SyncSnapshotSend
*
pMsg
);
// for debug ----------------------
void
syncSnapshotSendPrint
(
const
SyncSnapshotSend
*
pMsg
);
void
syncSnapshotSendPrint2
(
char
*
s
,
const
SyncSnapshotSend
*
pMsg
);
void
syncSnapshotSendLog
(
const
SyncSnapshotSend
*
pMsg
);
void
syncSnapshotSendLog2
(
char
*
s
,
const
SyncSnapshotSend
*
pMsg
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
浏览文件 @
eec0ab8c
...
...
@@ -2392,3 +2392,69 @@ void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) {
taosMemoryFree
(
serialized
);
}
}
// ---------------------------------------------
SyncSnapshotSend
*
syncSnapshotSendBuild
(
uint32_t
dataLen
,
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncSnapshotSend
)
+
dataLen
;
SyncSnapshotSend
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_SNAPSHOT_SEND
;
pMsg
->
dataLen
=
dataLen
;
return
pMsg
;
}
void
syncSnapshotSendDestroy
(
SyncSnapshotSend
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncSnapshotSendSerialize
(
const
SyncSnapshotSend
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncSnapshotSendDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncSnapshotSend
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
ASSERT
(
pMsg
->
bytes
==
sizeof
(
SyncSnapshotSend
)
+
pMsg
->
dataLen
);
}
char
*
syncSnapshotSendSerialize2
(
const
SyncSnapshotSend
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncSnapshotSendSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncSnapshotSend
*
syncSnapshotSendDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncSnapshotSend
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncSnapshotSendDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncSnapshotSend2RpcMsg
(
const
SyncSnapshotSend
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncSnapshotSendSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncSnapshotSendFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncSnapshotSend
*
pMsg
)
{
syncSnapshotSendDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncSnapshotSend
*
syncSnapshotSendFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncSnapshotSend
*
pMsg
=
syncSnapshotSendDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录