Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
54e05aee
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
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看板
提交
54e05aee
编写于
11月 12, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: adjust sync append entry reply
上级
437daf8c
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
205 addition
and
185 deletion
+205
-185
source/libs/sync/inc/syncAppendEntriesReply.h
source/libs/sync/inc/syncAppendEntriesReply.h
+1
-1
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+2
-19
source/libs/sync/src/syncAppendEntries.c
source/libs/sync/src/syncAppendEntries.c
+10
-7
source/libs/sync/src/syncAppendEntriesReply.c
source/libs/sync/src/syncAppendEntriesReply.c
+3
-2
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
+14
-153
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
+156
-0
未找到文件。
source/libs/sync/inc/syncAppendEntriesReply.h
浏览文件 @
54e05aee
...
...
@@ -35,7 +35,7 @@ extern "C" {
// /\ Discard(m)
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
//
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncMessage.h
浏览文件 @
54e05aee
...
...
@@ -112,24 +112,6 @@ typedef struct SyncAppendEntriesReply {
int64_t
startTime
;
}
SyncAppendEntriesReply
;
SyncAppendEntriesReply
*
syncAppendEntriesReplyBuild
(
int32_t
vgId
);
void
syncAppendEntriesReplyDestroy
(
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplySerialize
(
const
SyncAppendEntriesReply
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncAppendEntriesReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesReply
*
pMsg
);
char
*
syncAppendEntriesReplySerialize2
(
const
SyncAppendEntriesReply
*
pMsg
,
uint32_t
*
len
);
SyncAppendEntriesReply
*
syncAppendEntriesReplyDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncAppendEntriesReply2RpcMsg
(
const
SyncAppendEntriesReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncAppendEntriesReplyFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncAppendEntriesReply
*
pMsg
);
SyncAppendEntriesReply
*
syncAppendEntriesReplyFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncAppendEntriesReply2Json
(
const
SyncAppendEntriesReply
*
pMsg
);
char
*
syncAppendEntriesReply2Str
(
const
SyncAppendEntriesReply
*
pMsg
);
// for debug ----------------------
void
syncAppendEntriesReplyPrint
(
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyPrint2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyLog
(
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyLog2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncHeartbeat
{
uint32_t
bytes
;
...
...
@@ -430,7 +412,7 @@ void syncLocalCmdLog2(char* s, const SyncLocalCmd* pMsg);
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
,
SyncAppendEntriesReply
*
pMsg
);
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pMsg
);
int32_t
syncNodeOnPreSnapshot
(
SSyncNode
*
ths
,
SyncPreSnapshot
*
pMsg
);
int32_t
syncNodeOnPreSnapshotReply
(
SSyncNode
*
ths
,
SyncPreSnapshotReply
*
pMsg
);
...
...
@@ -460,6 +442,7 @@ int32_t syncClientRequestBuildFromNoopEntry(SRpcMsg* pClientRequestRpcMsg, const
int32_t
syncBuildRequestVote
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildRequestVoteReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
int32_t
syncBuildAppendEntries
(
SRpcMsg
*
pMsg
,
int32_t
dataLen
,
int32_t
vgId
);
int32_t
syncBuildAppendEntriesReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncAppendEntries.c
浏览文件 @
54e05aee
...
...
@@ -138,6 +138,7 @@ void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMs
int32_t
syncNodeOnAppendEntries
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pRpcMsg
)
{
SyncAppendEntries
*
pMsg
=
pRpcMsg
->
pCont
;
SRpcMsg
rpcRsp
=
{
0
};
// if already drop replica, do not process
if
(
!
syncNodeInRaftGroup
(
ths
,
&
(
pMsg
->
srcId
)))
{
...
...
@@ -146,7 +147,13 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
}
// prepare response msg
SyncAppendEntriesReply
*
pReply
=
syncAppendEntriesReplyBuild
(
ths
->
vgId
);
int32_t
code
=
syncBuildRequestVoteReply
(
&
rpcRsp
,
ths
->
vgId
);
if
(
code
!=
0
)
{
syncLogRecvAppendEntries
(
ths
,
pMsg
,
"build rsp error"
);
goto
_IGNORE
;
}
SyncAppendEntriesReply
*
pReply
=
rpcRsp
.
pCont
;
pReply
->
srcId
=
ths
->
myRaftId
;
pReply
->
destId
=
pMsg
->
srcId
;
pReply
->
term
=
ths
->
pRaftStore
->
currentTerm
;
...
...
@@ -288,7 +295,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, const SRpcMsg* pRpcMsg) {
goto
_SEND_RESPONSE
;
_IGNORE:
syncAppendEntriesReplyDestroy
(
pReply
);
rpcFreeCont
(
rpcRsp
.
pCont
);
return
0
;
_SEND_RESPONSE:
...
...
@@ -296,10 +303,6 @@ _SEND_RESPONSE:
syncLogSendAppendEntriesReply
(
ths
,
pReply
,
""
);
// send response
SRpcMsg
rpcMsg
;
syncAppendEntriesReply2RpcMsg
(
pReply
,
&
rpcMsg
);
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcMsg
);
syncAppendEntriesReplyDestroy
(
pReply
);
syncNodeSendMsgById
(
&
pReply
->
destId
,
ths
,
&
rpcRsp
);
return
0
;
}
\ No newline at end of file
source/libs/sync/src/syncAppendEntriesReply.c
浏览文件 @
54e05aee
...
...
@@ -73,8 +73,9 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
#endif
}
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
SyncAppendEntriesReply
*
pMsg
)
{
int32_t
ret
=
0
;
int32_t
syncNodeOnAppendEntriesReply
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pRpcMsg
)
{
int32_t
ret
=
0
;
SyncAppendEntriesReply
*
pMsg
=
pRpcMsg
->
pCont
;
// if already drop replica, do not process
if
(
!
syncNodeInRaftGroup
(
ths
,
&
(
pMsg
->
srcId
)))
{
...
...
source/libs/sync/src/syncMain.c
浏览文件 @
54e05aee
...
...
@@ -152,9 +152,7 @@ int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) {
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES
)
{
syncNodeOnAppendEntries
(
pSyncNode
,
pMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_APPEND_ENTRIES_REPLY
)
{
SyncAppendEntriesReply
*
pSyncMsg
=
syncAppendEntriesReplyFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnAppendEntriesReply
(
pSyncNode
,
pSyncMsg
);
syncAppendEntriesReplyDestroy
(
pSyncMsg
);
syncNodeOnAppendEntriesReply
(
pSyncNode
,
pMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_SNAPSHOT_SEND
)
{
SyncSnapshotSend
*
pSyncMsg
=
syncSnapshotSendFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnSnapshot
(
pSyncNode
,
pSyncMsg
);
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
54e05aee
...
...
@@ -93,7 +93,7 @@ int32_t syncBuildRequestVote(SRpcMsg* pMsg, int32_t vgId) {
pMsg
->
msgType
=
TDMT_SYNC_REQUEST_VOTE
;
pMsg
->
contLen
=
bytes
;
if
(
pMsg
->
pCont
==
NULL
)
{
terrno
=
T
DMT_SYNC_REQUEST_VOTE
;
terrno
=
T
SDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
@@ -110,7 +110,7 @@ int32_t syncBuildRequestVoteReply(SRpcMsg* pMsg, int32_t vgId) {
pMsg
->
msgType
=
TDMT_SYNC_REQUEST_VOTE_REPLY
;
pMsg
->
contLen
=
bytes
;
if
(
pMsg
->
pCont
==
NULL
)
{
terrno
=
T
DMT_SYNC_REQUEST_VOTE
;
terrno
=
T
SDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
...
...
@@ -139,160 +139,21 @@ int32_t syncBuildAppendEntries(SRpcMsg* pMsg, int32_t dataLen, int32_t vgId) {
return
0
;
}
// ---- message process SyncAppendEntriesReply----
SyncAppendEntriesReply
*
syncAppendEntriesReplyBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncAppendEntriesReply
);
SyncAppendEntriesReply
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
int32_t
syncBuildAppendEntriesReply
(
SRpcMsg
*
pMsg
,
int32_t
vgId
)
{
int32_t
bytes
=
sizeof
(
SyncRequestVoteReply
);
pMsg
->
pCont
=
rpcMallocCont
(
bytes
);
pMsg
->
msgType
=
TDMT_SYNC_APPEND_ENTRIES_REPLY
;
return
pMsg
;
}
void
syncAppendEntriesReplyDestroy
(
SyncAppendEntriesReply
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncAppendEntriesReplySerialize
(
const
SyncAppendEntriesReply
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncAppendEntriesReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesReply
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncAppendEntriesReplySerialize2
(
const
SyncAppendEntriesReply
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncAppendEntriesReplySerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncAppendEntriesReply
*
syncAppendEntriesReplyDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncAppendEntriesReply
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncAppendEntriesReplyDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncAppendEntriesReply2RpcMsg
(
const
SyncAppendEntriesReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncAppendEntriesReplySerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncAppendEntriesReplyFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncAppendEntriesReply
*
pMsg
)
{
syncAppendEntriesReplyDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncAppendEntriesReply
*
syncAppendEntriesReplyFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncAppendEntriesReply
*
pMsg
=
syncAppendEntriesReplyDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncAppendEntriesReply2Json
(
const
SyncAppendEntriesReply
*
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
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
cJSON
*
pTmp
=
pSrcId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pSrcId
,
"vgId"
,
pMsg
->
srcId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
destId
.
addr
);
cJSON_AddStringToObject
(
pDestId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
destId
.
addr
;
cJSON
*
pTmp
=
pDestId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pMsg
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"destId"
,
pDestId
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
privateTerm
);
cJSON_AddStringToObject
(
pRoot
,
"privateTerm"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"success"
,
pMsg
->
success
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
matchIndex
);
cJSON_AddStringToObject
(
pRoot
,
"matchIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
startTime
);
cJSON_AddStringToObject
(
pRoot
,
"startTime"
,
u64buf
);
pMsg
->
contLen
=
bytes
;
if
(
pMsg
->
pCont
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
-
1
;
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncAppendEntriesReply"
,
pRoot
);
return
pJson
;
}
char
*
syncAppendEntriesReply2Str
(
const
SyncAppendEntriesReply
*
pMsg
)
{
cJSON
*
pJson
=
syncAppendEntriesReply2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncAppendEntriesReplyPrint
(
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
printf
(
"syncAppendEntriesReplyPrint | len:%d | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesReplyPrint2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
printf
(
"syncAppendEntriesReplyPrint2 | len:%d | %s | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesReplyLog
(
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesReplyLog | len:%d| %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesReplyLog2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesReplyLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
SyncAppendEntriesReply
*
pAppendEntriesReply
=
pMsg
->
pCont
;
pAppendEntriesReply
->
bytes
=
bytes
;
pAppendEntriesReply
->
msgType
=
TDMT_SYNC_APPEND_ENTRIES_REPLY
;
pAppendEntriesReply
->
vgId
=
vgId
;
return
0
;
}
// ---- message process SyncHeartbeat----
...
...
source/libs/sync/test/sync_test_lib/inc/syncTest.h
浏览文件 @
54e05aee
...
...
@@ -295,6 +295,24 @@ void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg);
void
syncAppendEntriesLog
(
const
SyncAppendEntries
*
pMsg
);
void
syncAppendEntriesLog2
(
char
*
s
,
const
SyncAppendEntries
*
pMsg
);
SyncAppendEntriesReply
*
syncAppendEntriesReplyBuild
(
int32_t
vgId
);
void
syncAppendEntriesReplyDestroy
(
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplySerialize
(
const
SyncAppendEntriesReply
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncAppendEntriesReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesReply
*
pMsg
);
char
*
syncAppendEntriesReplySerialize2
(
const
SyncAppendEntriesReply
*
pMsg
,
uint32_t
*
len
);
SyncAppendEntriesReply
*
syncAppendEntriesReplyDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncAppendEntriesReply2RpcMsg
(
const
SyncAppendEntriesReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncAppendEntriesReplyFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncAppendEntriesReply
*
pMsg
);
SyncAppendEntriesReply
*
syncAppendEntriesReplyFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncAppendEntriesReply2Json
(
const
SyncAppendEntriesReply
*
pMsg
);
char
*
syncAppendEntriesReply2Str
(
const
SyncAppendEntriesReply
*
pMsg
);
// for debug ----------------------
void
syncAppendEntriesReplyPrint
(
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyPrint2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyLog
(
const
SyncAppendEntriesReply
*
pMsg
);
void
syncAppendEntriesReplyLog2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
浏览文件 @
54e05aee
...
...
@@ -1479,3 +1479,159 @@ void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
taosMemoryFree
(
serialized
);
}
}
// ---- message process SyncAppendEntriesReply----
SyncAppendEntriesReply
*
syncAppendEntriesReplyBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncAppendEntriesReply
);
SyncAppendEntriesReply
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_APPEND_ENTRIES_REPLY
;
return
pMsg
;
}
void
syncAppendEntriesReplyDestroy
(
SyncAppendEntriesReply
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncAppendEntriesReplySerialize
(
const
SyncAppendEntriesReply
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncAppendEntriesReplyDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncAppendEntriesReply
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncAppendEntriesReplySerialize2
(
const
SyncAppendEntriesReply
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncAppendEntriesReplySerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncAppendEntriesReply
*
syncAppendEntriesReplyDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncAppendEntriesReply
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncAppendEntriesReplyDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncAppendEntriesReply2RpcMsg
(
const
SyncAppendEntriesReply
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncAppendEntriesReplySerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncAppendEntriesReplyFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncAppendEntriesReply
*
pMsg
)
{
syncAppendEntriesReplyDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncAppendEntriesReply
*
syncAppendEntriesReplyFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncAppendEntriesReply
*
pMsg
=
syncAppendEntriesReplyDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncAppendEntriesReply2Json
(
const
SyncAppendEntriesReply
*
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
*
pSrcId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
srcId
.
addr
);
cJSON_AddStringToObject
(
pSrcId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
srcId
.
addr
;
cJSON
*
pTmp
=
pSrcId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pSrcId
,
"vgId"
,
pMsg
->
srcId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"srcId"
,
pSrcId
);
cJSON
*
pDestId
=
cJSON_CreateObject
();
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
destId
.
addr
);
cJSON_AddStringToObject
(
pDestId
,
"addr"
,
u64buf
);
{
uint64_t
u64
=
pMsg
->
destId
.
addr
;
cJSON
*
pTmp
=
pDestId
;
char
host
[
128
]
=
{
0
};
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
cJSON_AddNumberToObject
(
pDestId
,
"vgId"
,
pMsg
->
destId
.
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"destId"
,
pDestId
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
privateTerm
);
cJSON_AddStringToObject
(
pRoot
,
"privateTerm"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"success"
,
pMsg
->
success
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
matchIndex
);
cJSON_AddStringToObject
(
pRoot
,
"matchIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
startTime
);
cJSON_AddStringToObject
(
pRoot
,
"startTime"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncAppendEntriesReply"
,
pRoot
);
return
pJson
;
}
char
*
syncAppendEntriesReply2Str
(
const
SyncAppendEntriesReply
*
pMsg
)
{
cJSON
*
pJson
=
syncAppendEntriesReply2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncAppendEntriesReplyPrint
(
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
printf
(
"syncAppendEntriesReplyPrint | len:%d | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesReplyPrint2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
printf
(
"syncAppendEntriesReplyPrint2 | len:%d | %s | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesReplyLog
(
const
SyncAppendEntriesReply
*
pMsg
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesReplyLog | len:%d| %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncAppendEntriesReplyLog2
(
char
*
s
,
const
SyncAppendEntriesReply
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncAppendEntriesReply2Str
(
pMsg
);
sTrace
(
"syncAppendEntriesReplyLog2 | 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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录