Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d5f7f8c3
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d5f7f8c3
编写于
11月 13, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact: remove sync apply msg
上级
7bcda46c
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
175 addition
and
175 deletion
+175
-175
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+2
-22
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+0
-153
source/libs/sync/test/sync_test_lib/inc/syncTest.h
source/libs/sync/test/sync_test_lib/inc/syncTest.h
+20
-0
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
+153
-0
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
d5f7f8c3
...
...
@@ -172,27 +172,6 @@ typedef struct SyncApplyMsg {
char
data
[];
// user RpcMsg.pCont
}
SyncApplyMsg
;
SyncApplyMsg
*
syncApplyMsgBuild
(
uint32_t
dataLen
);
SyncApplyMsg
*
syncApplyMsgBuild2
(
const
SRpcMsg
*
pOriginalRpcMsg
,
int32_t
vgId
,
SFsmCbMeta
*
pMeta
);
void
syncApplyMsgDestroy
(
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgSerialize
(
const
SyncApplyMsg
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncApplyMsgDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncApplyMsg
*
pMsg
);
char
*
syncApplyMsgSerialize2
(
const
SyncApplyMsg
*
pMsg
,
uint32_t
*
len
);
SyncApplyMsg
*
syncApplyMsgDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncApplyMsg2RpcMsg
(
const
SyncApplyMsg
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
// SyncApplyMsg to SRpcMsg, put it into ApplyQ
void
syncApplyMsgFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncApplyMsg
*
pMsg
);
// get SRpcMsg from ApplyQ, to SyncApplyMsg
SyncApplyMsg
*
syncApplyMsgFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
void
syncApplyMsg2OriginalRpcMsg
(
const
SyncApplyMsg
*
pMsg
,
SRpcMsg
*
pOriginalRpcMsg
);
// SyncApplyMsg to OriginalRpcMsg
cJSON
*
syncApplyMsg2Json
(
const
SyncApplyMsg
*
pMsg
);
char
*
syncApplyMsg2Str
(
const
SyncApplyMsg
*
pMsg
);
// for debug ----------------------
void
syncApplyMsgPrint
(
const
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgPrint2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgLog
(
const
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgLog2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncSnapshotSend
{
uint32_t
bytes
;
int32_t
vgId
;
...
...
@@ -352,7 +331,7 @@ ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode);
const
char
*
syncTimerTypeStr
(
enum
ESyncTimeoutType
timerType
);
int32_t
syncBuildTimeout
(
SRpcMsg
*
pMsg
,
ESyncTimeoutType
ttype
,
uint64_t
logicClock
,
int32_t
ms
,
SSyncNode
*
pNode
);
int32_t
syncBuildClientRequest
(
SRpcMsg
*
pMsg
,
const
SRpcMsg
*
pOriginal
Rpc
,
uint64_t
seq
,
bool
isWeak
,
int32_t
vgId
);
int32_t
syncBuildClientRequest
(
SRpcMsg
*
pMsg
,
const
SRpcMsg
*
pOriginal
,
uint64_t
seq
,
bool
isWeak
,
int32_t
vgId
);
int32_t
syncBuildClientRequestFromNoopEntry
(
SRpcMsg
*
pMsg
,
const
SSyncRaftEntry
*
pEntry
,
int32_t
vgId
);
int32_t
syncBuildRequestVote
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildRequestVoteReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
...
...
@@ -362,6 +341,7 @@ int32_t syncBuildHeartbeat(SRpcMsg* pMsg, int32_t vgId);
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
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
d5f7f8c3
...
...
@@ -223,159 +223,6 @@ int32_t syncBuildPreSnapshotReply(SRpcMsg* pMsg, int32_t vgId) {
return
0
;
}
// ---- message process SyncApplyMsg----
SyncApplyMsg
*
syncApplyMsgBuild
(
uint32_t
dataLen
)
{
uint32_t
bytes
=
sizeof
(
SyncApplyMsg
)
+
dataLen
;
SyncApplyMsg
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
msgType
=
TDMT_SYNC_APPLY_MSG
;
pMsg
->
dataLen
=
dataLen
;
return
pMsg
;
}
SyncApplyMsg
*
syncApplyMsgBuild2
(
const
SRpcMsg
*
pOriginalRpcMsg
,
int32_t
vgId
,
SFsmCbMeta
*
pMeta
)
{
SyncApplyMsg
*
pMsg
=
syncApplyMsgBuild
(
pOriginalRpcMsg
->
contLen
);
pMsg
->
vgId
=
vgId
;
pMsg
->
originalRpcType
=
pOriginalRpcMsg
->
msgType
;
pMsg
->
fsmMeta
=
*
pMeta
;
memcpy
(
pMsg
->
data
,
pOriginalRpcMsg
->
pCont
,
pOriginalRpcMsg
->
contLen
);
return
pMsg
;
}
void
syncApplyMsgDestroy
(
SyncApplyMsg
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncApplyMsgSerialize
(
const
SyncApplyMsg
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncApplyMsgDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncApplyMsg
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncApplyMsgSerialize2
(
const
SyncApplyMsg
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncApplyMsgSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncApplyMsg
*
syncApplyMsgDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncApplyMsg
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncApplyMsgDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
// SyncApplyMsg to SRpcMsg, put it into ApplyQ
void
syncApplyMsg2RpcMsg
(
const
SyncApplyMsg
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncApplyMsgSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
// get SRpcMsg from ApplyQ, to SyncApplyMsg
void
syncApplyMsgFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncApplyMsg
*
pMsg
)
{
syncApplyMsgDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncApplyMsg
*
syncApplyMsgFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncApplyMsg
*
pMsg
=
syncApplyMsgDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
return
pMsg
;
}
// SyncApplyMsg to OriginalRpcMsg
void
syncApplyMsg2OriginalRpcMsg
(
const
SyncApplyMsg
*
pMsg
,
SRpcMsg
*
pOriginalRpcMsg
)
{
memset
(
pOriginalRpcMsg
,
0
,
sizeof
(
*
pOriginalRpcMsg
));
pOriginalRpcMsg
->
msgType
=
pMsg
->
originalRpcType
;
pOriginalRpcMsg
->
contLen
=
pMsg
->
dataLen
;
pOriginalRpcMsg
->
pCont
=
rpcMallocCont
(
pOriginalRpcMsg
->
contLen
);
memcpy
(
pOriginalRpcMsg
->
pCont
,
pMsg
->
data
,
pOriginalRpcMsg
->
contLen
);
}
cJSON
*
syncApplyMsg2Json
(
const
SyncApplyMsg
*
pMsg
)
{
char
u64buf
[
128
]
=
{
0
};
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pMsg
->
vgId
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON_AddNumberToObject
(
pRoot
,
"originalRpcType"
,
pMsg
->
originalRpcType
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
fsmMeta
.
index
);
cJSON_AddStringToObject
(
pRoot
,
"fsmMeta.index"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"fsmMeta.isWeak"
,
pMsg
->
fsmMeta
.
isWeak
);
cJSON_AddNumberToObject
(
pRoot
,
"fsmMeta.code"
,
pMsg
->
fsmMeta
.
code
);
cJSON_AddNumberToObject
(
pRoot
,
"fsmMeta.state"
,
pMsg
->
fsmMeta
.
state
);
cJSON_AddStringToObject
(
pRoot
,
"fsmMeta.state.str"
,
syncStr
(
pMsg
->
fsmMeta
.
state
));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
fsmMeta
.
seqNum
);
cJSON_AddStringToObject
(
pRoot
,
"fsmMeta.seqNum"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pMsg
->
dataLen
);
char
*
s
;
s
=
syncUtilPrintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
s
=
syncUtilPrintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
taosMemoryFree
(
s
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncApplyMsg"
,
pRoot
);
return
pJson
;
}
char
*
syncApplyMsg2Str
(
const
SyncApplyMsg
*
pMsg
)
{
cJSON
*
pJson
=
syncApplyMsg2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncApplyMsgPrint
(
const
SyncApplyMsg
*
pMsg
)
{
char
*
serialized
=
syncApplyMsg2Str
(
pMsg
);
printf
(
"syncApplyMsgPrint | len:%d | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncApplyMsgPrint2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
)
{
char
*
serialized
=
syncApplyMsg2Str
(
pMsg
);
printf
(
"syncApplyMsgPrint2 | len:%d | %s | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncApplyMsgLog
(
const
SyncApplyMsg
*
pMsg
)
{
char
*
serialized
=
syncApplyMsg2Str
(
pMsg
);
sTrace
(
"ssyncApplyMsgLog | len:%d | %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncApplyMsgLog2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncApplyMsg2Str
(
pMsg
);
sTrace
(
"syncApplyMsgLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
// ---------------------------------------------
SyncSnapshotSend
*
syncSnapshotSendBuild
(
uint32_t
dataLen
,
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncSnapshotSend
)
+
dataLen
;
...
...
source/libs/sync/test/sync_test_lib/inc/syncTest.h
浏览文件 @
d5f7f8c3
...
...
@@ -389,6 +389,26 @@ void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg);
int32_t
syncNodeOnPreSnapshot
(
SSyncNode
*
ths
,
SyncPreSnapshot
*
pMsg
);
int32_t
syncNodeOnPreSnapshotReply
(
SSyncNode
*
ths
,
SyncPreSnapshotReply
*
pMsg
);
SyncApplyMsg
*
syncApplyMsgBuild
(
uint32_t
dataLen
);
SyncApplyMsg
*
syncApplyMsgBuild2
(
const
SRpcMsg
*
pOriginalRpcMsg
,
int32_t
vgId
,
SFsmCbMeta
*
pMeta
);
void
syncApplyMsgDestroy
(
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgSerialize
(
const
SyncApplyMsg
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncApplyMsgDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncApplyMsg
*
pMsg
);
char
*
syncApplyMsgSerialize2
(
const
SyncApplyMsg
*
pMsg
,
uint32_t
*
len
);
SyncApplyMsg
*
syncApplyMsgDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncApplyMsg2RpcMsg
(
const
SyncApplyMsg
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
// SyncApplyMsg to SRpcMsg, put it into ApplyQ
void
syncApplyMsgFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncApplyMsg
*
pMsg
);
// get SRpcMsg from ApplyQ, to SyncApplyMsg
SyncApplyMsg
*
syncApplyMsgFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
void
syncApplyMsg2OriginalRpcMsg
(
const
SyncApplyMsg
*
pMsg
,
SRpcMsg
*
pOriginalRpcMsg
);
// SyncApplyMsg to OriginalRpcMsg
cJSON
*
syncApplyMsg2Json
(
const
SyncApplyMsg
*
pMsg
);
char
*
syncApplyMsg2Str
(
const
SyncApplyMsg
*
pMsg
);
// for debug ----------------------
void
syncApplyMsgPrint
(
const
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgPrint2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgLog
(
const
SyncApplyMsg
*
pMsg
);
void
syncApplyMsgLog2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
浏览文件 @
d5f7f8c3
...
...
@@ -2239,3 +2239,156 @@ void syncPreSnapshotReplyLog2(char* s, const SyncPreSnapshotReply* pMsg) {
taosMemoryFree
(
serialized
);
}
}
// ---- message process SyncApplyMsg----
SyncApplyMsg
*
syncApplyMsgBuild
(
uint32_t
dataLen
)
{
uint32_t
bytes
=
sizeof
(
SyncApplyMsg
)
+
dataLen
;
SyncApplyMsg
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
msgType
=
TDMT_SYNC_APPLY_MSG
;
pMsg
->
dataLen
=
dataLen
;
return
pMsg
;
}
SyncApplyMsg
*
syncApplyMsgBuild2
(
const
SRpcMsg
*
pOriginalRpcMsg
,
int32_t
vgId
,
SFsmCbMeta
*
pMeta
)
{
SyncApplyMsg
*
pMsg
=
syncApplyMsgBuild
(
pOriginalRpcMsg
->
contLen
);
pMsg
->
vgId
=
vgId
;
pMsg
->
originalRpcType
=
pOriginalRpcMsg
->
msgType
;
pMsg
->
fsmMeta
=
*
pMeta
;
memcpy
(
pMsg
->
data
,
pOriginalRpcMsg
->
pCont
,
pOriginalRpcMsg
->
contLen
);
return
pMsg
;
}
void
syncApplyMsgDestroy
(
SyncApplyMsg
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncApplyMsgSerialize
(
const
SyncApplyMsg
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncApplyMsgDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncApplyMsg
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncApplyMsgSerialize2
(
const
SyncApplyMsg
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncApplyMsgSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncApplyMsg
*
syncApplyMsgDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncApplyMsg
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncApplyMsgDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
// SyncApplyMsg to SRpcMsg, put it into ApplyQ
void
syncApplyMsg2RpcMsg
(
const
SyncApplyMsg
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncApplyMsgSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
// get SRpcMsg from ApplyQ, to SyncApplyMsg
void
syncApplyMsgFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncApplyMsg
*
pMsg
)
{
syncApplyMsgDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncApplyMsg
*
syncApplyMsgFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncApplyMsg
*
pMsg
=
syncApplyMsgDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
return
pMsg
;
}
// SyncApplyMsg to OriginalRpcMsg
void
syncApplyMsg2OriginalRpcMsg
(
const
SyncApplyMsg
*
pMsg
,
SRpcMsg
*
pOriginalRpcMsg
)
{
memset
(
pOriginalRpcMsg
,
0
,
sizeof
(
*
pOriginalRpcMsg
));
pOriginalRpcMsg
->
msgType
=
pMsg
->
originalRpcType
;
pOriginalRpcMsg
->
contLen
=
pMsg
->
dataLen
;
pOriginalRpcMsg
->
pCont
=
rpcMallocCont
(
pOriginalRpcMsg
->
contLen
);
memcpy
(
pOriginalRpcMsg
->
pCont
,
pMsg
->
data
,
pOriginalRpcMsg
->
contLen
);
}
cJSON
*
syncApplyMsg2Json
(
const
SyncApplyMsg
*
pMsg
)
{
char
u64buf
[
128
]
=
{
0
};
cJSON
*
pRoot
=
cJSON_CreateObject
();
if
(
pMsg
!=
NULL
)
{
cJSON_AddNumberToObject
(
pRoot
,
"bytes"
,
pMsg
->
bytes
);
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pMsg
->
vgId
);
cJSON_AddNumberToObject
(
pRoot
,
"msgType"
,
pMsg
->
msgType
);
cJSON_AddNumberToObject
(
pRoot
,
"originalRpcType"
,
pMsg
->
originalRpcType
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
fsmMeta
.
index
);
cJSON_AddStringToObject
(
pRoot
,
"fsmMeta.index"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"fsmMeta.isWeak"
,
pMsg
->
fsmMeta
.
isWeak
);
cJSON_AddNumberToObject
(
pRoot
,
"fsmMeta.code"
,
pMsg
->
fsmMeta
.
code
);
cJSON_AddNumberToObject
(
pRoot
,
"fsmMeta.state"
,
pMsg
->
fsmMeta
.
state
);
cJSON_AddStringToObject
(
pRoot
,
"fsmMeta.state.str"
,
syncStr
(
pMsg
->
fsmMeta
.
state
));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
fsmMeta
.
seqNum
);
cJSON_AddStringToObject
(
pRoot
,
"fsmMeta.seqNum"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"dataLen"
,
pMsg
->
dataLen
);
char
*
s
;
s
=
syncUtilPrintBin
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data"
,
s
);
taosMemoryFree
(
s
);
s
=
syncUtilPrintBin2
((
char
*
)(
pMsg
->
data
),
pMsg
->
dataLen
);
cJSON_AddStringToObject
(
pRoot
,
"data2"
,
s
);
taosMemoryFree
(
s
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncApplyMsg"
,
pRoot
);
return
pJson
;
}
char
*
syncApplyMsg2Str
(
const
SyncApplyMsg
*
pMsg
)
{
cJSON
*
pJson
=
syncApplyMsg2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncApplyMsgPrint
(
const
SyncApplyMsg
*
pMsg
)
{
char
*
serialized
=
syncApplyMsg2Str
(
pMsg
);
printf
(
"syncApplyMsgPrint | len:%d | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncApplyMsgPrint2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
)
{
char
*
serialized
=
syncApplyMsg2Str
(
pMsg
);
printf
(
"syncApplyMsgPrint2 | len:%d | %s | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncApplyMsgLog
(
const
SyncApplyMsg
*
pMsg
)
{
char
*
serialized
=
syncApplyMsg2Str
(
pMsg
);
sTrace
(
"ssyncApplyMsgLog | len:%d | %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncApplyMsgLog2
(
char
*
s
,
const
SyncApplyMsg
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncApplyMsg2Str
(
pMsg
);
sTrace
(
"syncApplyMsgLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录