Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8cca68f2
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看板
提交
8cca68f2
编写于
11月 12, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: adjust request vote msg
上级
26cb3c38
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
232 addition
and
227 deletion
+232
-227
source/libs/sync/inc/syncElection.h
source/libs/sync/inc/syncElection.h
+1
-3
source/libs/sync/inc/syncInt.h
source/libs/sync/inc/syncInt.h
+0
-1
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+10
-30
source/libs/sync/inc/syncRequestVote.h
source/libs/sync/inc/syncRequestVote.h
+1
-1
source/libs/sync/src/syncElection.c
source/libs/sync/src/syncElection.c
+35
-33
source/libs/sync/src/syncMain.c
source/libs/sync/src/syncMain.c
+1
-11
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+12
-146
source/libs/sync/src/syncRequestVote.c
source/libs/sync/src/syncRequestVote.c
+3
-2
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
+151
-0
未找到文件。
source/libs/sync/inc/syncElection.h
浏览文件 @
8cca68f2
...
...
@@ -34,9 +34,7 @@ extern "C" {
// mdest |-> j])
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
int32_t
syncNodeElect
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeRequestVotePeers
(
SSyncNode
*
pSyncNode
);
int32_t
syncNodeSendRequestVote
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncRequestVote
*
pMsg
);
int32_t
syncNodeElect
(
SSyncNode
*
pNode
);
#ifdef __cplusplus
}
...
...
source/libs/sync/inc/syncInt.h
浏览文件 @
8cca68f2
...
...
@@ -324,7 +324,6 @@ int32_t syncNodePeerStateInit(SSyncNode* pSyncNode);
void
syncLogRecvTimer
(
SSyncNode
*
pSyncNode
,
const
SyncTimeout
*
pMsg
,
const
char
*
s
);
void
syncLogRecvLocalCmd
(
SSyncNode
*
pSyncNode
,
const
SyncLocalCmd
*
pMsg
,
const
char
*
s
);
void
syncLogSendRequestVote
(
SSyncNode
*
pSyncNode
,
const
SyncRequestVote
*
pMsg
,
const
char
*
s
);
void
syncLogRecvRequestVote
(
SSyncNode
*
pSyncNode
,
const
SyncRequestVote
*
pMsg
,
const
char
*
s
);
void
syncLogSendRequestVoteReply
(
SSyncNode
*
pSyncNode
,
const
SyncRequestVoteReply
*
pMsg
,
const
char
*
s
);
...
...
source/libs/sync/inc/syncMessage.h
浏览文件 @
8cca68f2
...
...
@@ -28,8 +28,6 @@ typedef enum ESyncTimeoutType {
SYNC_TIMEOUT_HEARTBEAT
,
}
ESyncTimeoutType
;
const
char
*
syncTimerTypeStr
(
enum
ESyncTimeoutType
timerType
);
typedef
struct
SyncTimeout
{
uint32_t
bytes
;
int32_t
vgId
;
...
...
@@ -40,9 +38,6 @@ typedef struct SyncTimeout {
void
*
data
;
// need optimized
}
SyncTimeout
;
int32_t
syncTimeoutBuild
(
SRpcMsg
*
pTimeoutRpcMsg
,
ESyncTimeoutType
timeoutType
,
uint64_t
logicClock
,
int32_t
timerMS
,
SSyncNode
*
pNode
);
typedef
struct
SyncClientRequest
{
uint32_t
bytes
;
int32_t
vgId
;
...
...
@@ -54,10 +49,6 @@ typedef struct SyncClientRequest {
char
data
[];
// origin RpcMsg.pCont
}
SyncClientRequest
;
int32_t
syncClientRequestBuildFromRpcMsg
(
SRpcMsg
*
pClientRequestRpcMsg
,
const
SRpcMsg
*
pOriginalRpcMsg
,
uint64_t
seqNum
,
bool
isWeak
,
int32_t
vgId
);
int32_t
syncClientRequestBuildFromNoopEntry
(
SRpcMsg
*
pClientRequestRpcMsg
,
const
SSyncRaftEntry
*
pEntry
,
int32_t
vgId
);
typedef
struct
SyncClientRequestReply
{
uint32_t
bytes
;
int32_t
vgId
;
...
...
@@ -78,25 +69,6 @@ typedef struct SyncRequestVote {
SyncTerm
lastLogTerm
;
}
SyncRequestVote
;
SyncRequestVote
*
syncRequestVoteBuild
(
int32_t
vgId
);
void
syncRequestVoteDestroy
(
SyncRequestVote
*
pMsg
);
void
syncRequestVoteSerialize
(
const
SyncRequestVote
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncRequestVoteDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncRequestVote
*
pMsg
);
char
*
syncRequestVoteSerialize2
(
const
SyncRequestVote
*
pMsg
,
uint32_t
*
len
);
SyncRequestVote
*
syncRequestVoteDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncRequestVote2RpcMsg
(
const
SyncRequestVote
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncRequestVoteFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncRequestVote
*
pMsg
);
SyncRequestVote
*
syncRequestVoteFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncRequestVote2Json
(
const
SyncRequestVote
*
pMsg
);
char
*
syncRequestVote2Str
(
const
SyncRequestVote
*
pMsg
);
// for debug ----------------------
void
syncRequestVotePrint
(
const
SyncRequestVote
*
pMsg
);
void
syncRequestVotePrint2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
);
void
syncRequestVoteLog
(
const
SyncRequestVote
*
pMsg
);
void
syncRequestVoteLog2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
);
// ---------------------------------------------
typedef
struct
SyncRequestVoteReply
{
uint32_t
bytes
;
int32_t
vgId
;
...
...
@@ -505,8 +477,7 @@ void syncLocalCmdLog(const SyncLocalCmd* pMsg);
void
syncLocalCmdLog2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
);
// on message ----------------------
int32_t
syncNodeOnRequestVote
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
int32_t
syncNodeOnRequestVote
(
SSyncNode
*
pNode
,
const
SRpcMsg
*
pMsg
);
int32_t
syncNodeOnRequestVoteReply
(
SSyncNode
*
ths
,
SyncRequestVoteReply
*
pMsg
);
int32_t
syncNodeOnAppendEntries
(
SSyncNode
*
ths
,
SyncAppendEntries
*
pMsg
);
...
...
@@ -530,6 +501,15 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg);
bool
syncNodeSnapshotEnable
(
SSyncNode
*
pSyncNode
);
ESyncStrategy
syncNodeStrategy
(
SSyncNode
*
pSyncNode
);
const
char
*
syncTimerTypeStr
(
enum
ESyncTimeoutType
timerType
);
int32_t
syncTimeoutBuild
(
SRpcMsg
*
pTimeoutRpcMsg
,
ESyncTimeoutType
timeoutType
,
uint64_t
logicClock
,
int32_t
timerMS
,
SSyncNode
*
pNode
);
int32_t
syncClientRequestBuildFromRpcMsg
(
SRpcMsg
*
pClientRequestRpcMsg
,
const
SRpcMsg
*
pOriginalRpcMsg
,
uint64_t
seqNum
,
bool
isWeak
,
int32_t
vgId
);
int32_t
syncClientRequestBuildFromNoopEntry
(
SRpcMsg
*
pClientRequestRpcMsg
,
const
SSyncRaftEntry
*
pEntry
,
int32_t
vgId
);
int32_t
syncBuildRequestVote
(
SRpcMsg
*
pMsg
,
int32_t
vgId
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/inc/syncRequestVote.h
浏览文件 @
8cca68f2
...
...
@@ -44,7 +44,7 @@ extern "C" {
// m)
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
//
int32_t
syncNodeOnRequestVote
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
);
int32_t
syncNodeOnRequestVote
(
SSyncNode
*
pNode
,
const
SRpcMsg
*
pMsg
);
#ifdef __cplusplus
}
...
...
source/libs/sync/src/syncElection.c
浏览文件 @
8cca68f2
...
...
@@ -33,6 +33,41 @@
// mdest |-> j])
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
static
void
syncLogSendRequestVote
(
SSyncNode
*
pNode
,
const
SyncRequestVote
*
pMsg
,
const
char
*
s
)
{
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pNode
,
"send sync-request-vote to %s:%d {term:%"
PRId64
", lindex:%"
PRId64
", lterm:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
lastLogIndex
,
pMsg
->
lastLogTerm
,
s
);
}
static
int32_t
syncNodeRequestVotePeers
(
SSyncNode
*
pNode
)
{
if
(
pNode
->
state
!=
TAOS_SYNC_STATE_CANDIDATE
)
{
sNTrace
(
pNode
,
"not candidate, stop elect"
);
return
0
;
}
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pNode
->
peersNum
;
++
i
)
{
SRpcMsg
rpcMsg
=
{
0
};
ret
=
syncBuildRequestVote
(
&
rpcMsg
,
pNode
->
vgId
);
ASSERT
(
ret
==
0
);
SyncRequestVote
*
pMsg
=
rpcMsg
.
pCont
;
pMsg
->
srcId
=
pNode
->
myRaftId
;
pMsg
->
destId
=
pNode
->
peersId
[
i
];
pMsg
->
term
=
pNode
->
pRaftStore
->
currentTerm
;
ret
=
syncNodeGetLastIndexTerm
(
pNode
,
&
pMsg
->
lastLogIndex
,
&
pMsg
->
lastLogTerm
);
ASSERT
(
ret
==
0
);
ret
=
syncNodeSendMsgById
(
&
pNode
->
peersId
[
i
],
pNode
,
&
rpcMsg
);
ASSERT
(
ret
==
0
);
}
return
ret
;
}
int32_t
syncNodeElect
(
SSyncNode
*
pSyncNode
)
{
sNTrace
(
pSyncNode
,
"begin election"
);
...
...
@@ -81,36 +116,3 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
return
ret
;
}
int32_t
syncNodeRequestVotePeers
(
SSyncNode
*
pSyncNode
)
{
if
(
pSyncNode
->
state
!=
TAOS_SYNC_STATE_CANDIDATE
)
{
sNTrace
(
pSyncNode
,
"not candidate, stop elect"
);
return
0
;
}
int32_t
ret
=
0
;
for
(
int
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
SyncRequestVote
*
pMsg
=
syncRequestVoteBuild
(
pSyncNode
->
vgId
);
pMsg
->
srcId
=
pSyncNode
->
myRaftId
;
pMsg
->
destId
=
pSyncNode
->
peersId
[
i
];
pMsg
->
term
=
pSyncNode
->
pRaftStore
->
currentTerm
;
ret
=
syncNodeGetLastIndexTerm
(
pSyncNode
,
&
(
pMsg
->
lastLogIndex
),
&
(
pMsg
->
lastLogTerm
));
ASSERT
(
ret
==
0
);
ret
=
syncNodeSendRequestVote
(
pSyncNode
,
&
pSyncNode
->
peersId
[
i
],
pMsg
);
ASSERT
(
ret
==
0
);
syncRequestVoteDestroy
(
pMsg
);
}
return
ret
;
}
int32_t
syncNodeSendRequestVote
(
SSyncNode
*
pSyncNode
,
const
SRaftId
*
destRaftId
,
const
SyncRequestVote
*
pMsg
)
{
int32_t
ret
=
0
;
syncLogSendRequestVote
(
pSyncNode
,
pMsg
,
""
);
SRpcMsg
rpcMsg
;
syncRequestVote2RpcMsg
(
pMsg
,
&
rpcMsg
);
syncNodeSendMsgById
(
destRaftId
,
pSyncNode
,
&
rpcMsg
);
return
ret
;
}
\ No newline at end of file
source/libs/sync/src/syncMain.c
浏览文件 @
8cca68f2
...
...
@@ -146,9 +146,7 @@ int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) {
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_CLIENT_REQUEST
)
{
code
=
syncNodeOnClientRequest
(
pSyncNode
,
pMsg
,
NULL
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE
)
{
SyncRequestVote
*
pSyncMsg
=
syncRequestVoteFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnRequestVote
(
pSyncNode
,
pSyncMsg
);
syncRequestVoteDestroy
(
pSyncMsg
);
syncNodeOnRequestVote
(
pSyncNode
,
pMsg
);
}
else
if
(
pMsg
->
msgType
==
TDMT_SYNC_REQUEST_VOTE_REPLY
)
{
SyncRequestVoteReply
*
pSyncMsg
=
syncRequestVoteReplyFromRpcMsg2
(
pMsg
);
code
=
syncNodeOnRequestVoteReply
(
pSyncNode
,
pSyncMsg
);
...
...
@@ -2535,14 +2533,6 @@ void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char*
syncTimerTypeStr
(
pMsg
->
timeoutType
),
pMsg
->
logicClock
,
pMsg
->
timerMS
,
pMsg
->
data
,
s
);
}
void
syncLogSendRequestVote
(
SSyncNode
*
pSyncNode
,
const
SyncRequestVote
*
pMsg
,
const
char
*
s
)
{
char
host
[
64
];
uint16_t
port
;
syncUtilU642Addr
(
pMsg
->
destId
.
addr
,
host
,
sizeof
(
host
),
&
port
);
sNTrace
(
pSyncNode
,
"send sync-request-vote to %s:%d {term:%"
PRId64
", lindex:%"
PRId64
", lterm:%"
PRId64
"}, %s"
,
host
,
port
,
pMsg
->
term
,
pMsg
->
lastLogIndex
,
pMsg
->
lastLogTerm
,
s
);
}
void
syncLogRecvRequestVote
(
SSyncNode
*
pSyncNode
,
const
SyncRequestVote
*
pMsg
,
const
char
*
s
)
{
char
logBuf
[
256
];
char
host
[
64
];
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
8cca68f2
...
...
@@ -88,155 +88,21 @@ int32_t syncClientRequestBuildFromNoopEntry(SRpcMsg* pClientRequestRpcMsg, const
return
0
;
}
// ---- message process SyncRequestVote----
SyncRequestVote
*
syncRequestVoteBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncRequestVote
);
SyncRequestVote
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
int32_t
syncBuildRequestVote
(
SRpcMsg
*
pMsg
,
int32_t
vgId
)
{
int32_t
bytes
=
sizeof
(
SyncRequestVote
);
pMsg
->
pCont
=
rpcMallocCont
(
bytes
);
pMsg
->
msgType
=
TDMT_SYNC_REQUEST_VOTE
;
return
pMsg
;
}
void
syncRequestVoteDestroy
(
SyncRequestVote
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncRequestVoteSerialize
(
const
SyncRequestVote
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncRequestVoteDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncRequestVote
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncRequestVoteSerialize2
(
const
SyncRequestVote
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncRequestVoteSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncRequestVote
*
syncRequestVoteDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncRequestVote
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncRequestVoteDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncRequestVote2RpcMsg
(
const
SyncRequestVote
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncRequestVoteSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncRequestVoteFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncRequestVote
*
pMsg
)
{
syncRequestVoteDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncRequestVote
*
syncRequestVoteFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncRequestVote
*
pMsg
=
syncRequestVoteDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncRequestVote2Json
(
const
SyncRequestVote
*
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
();
cJSON_AddNumberToObject
(
pDestId
,
"addr"
,
pMsg
->
destId
.
addr
);
{
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
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
lastLogIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastLogIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
lastLogTerm
);
cJSON_AddStringToObject
(
pRoot
,
"lastLogTerm"
,
u64buf
);
pMsg
->
contLen
=
bytes
;
if
(
pMsg
->
pCont
==
NULL
)
{
terrno
=
TDMT_SYNC_REQUEST_VOTE
;
return
-
1
;
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncRequestVote"
,
pRoot
);
return
pJson
;
}
char
*
syncRequestVote2Str
(
const
SyncRequestVote
*
pMsg
)
{
cJSON
*
pJson
=
syncRequestVote2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncRequestVotePrint
(
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
printf
(
"syncRequestVotePrint | len:%d | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncRequestVotePrint2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
printf
(
"syncRequestVotePrint2 | len:%d | %s | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncRequestVoteLog
(
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
sTrace
(
"syncRequestVoteLog | len:%d | %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncRequestVoteLog2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
sTrace
(
"syncRequestVoteLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
SyncRequestVote
*
pRequestVote
=
pMsg
->
pCont
;
pRequestVote
->
bytes
=
bytes
;
pRequestVote
->
msgType
=
TDMT_SYNC_REQUEST_VOTE
;
pRequestVote
->
vgId
=
vgId
;
return
0
;
}
// ---- message process SyncRequestVoteReply----
...
...
source/libs/sync/src/syncRequestVote.c
浏览文件 @
8cca68f2
...
...
@@ -88,8 +88,9 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM
return
false
;
}
int32_t
syncNodeOnRequestVote
(
SSyncNode
*
ths
,
SyncRequestVote
*
pMsg
)
{
int32_t
ret
=
0
;
int32_t
syncNodeOnRequestVote
(
SSyncNode
*
ths
,
const
SRpcMsg
*
pRpcMsg
)
{
int32_t
ret
=
0
;
SyncRequestVote
*
pMsg
=
pRpcMsg
->
pCont
;
// if already drop replica, do not process
if
(
!
syncNodeInRaftGroup
(
ths
,
&
(
pMsg
->
srcId
)))
{
...
...
source/libs/sync/test/sync_test_lib/inc/syncTest.h
浏览文件 @
8cca68f2
...
...
@@ -241,6 +241,24 @@ void syncClientRequestPrint2(char* s, const SyncClientRequest* pMs
void
syncClientRequestLog
(
const
SyncClientRequest
*
pMsg
);
void
syncClientRequestLog2
(
char
*
s
,
const
SyncClientRequest
*
pMsg
);
SyncRequestVote
*
syncRequestVoteBuild
(
int32_t
vgId
);
void
syncRequestVoteDestroy
(
SyncRequestVote
*
pMsg
);
void
syncRequestVoteSerialize
(
const
SyncRequestVote
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncRequestVoteDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncRequestVote
*
pMsg
);
char
*
syncRequestVoteSerialize2
(
const
SyncRequestVote
*
pMsg
,
uint32_t
*
len
);
SyncRequestVote
*
syncRequestVoteDeserialize2
(
const
char
*
buf
,
uint32_t
len
);
void
syncRequestVote2RpcMsg
(
const
SyncRequestVote
*
pMsg
,
SRpcMsg
*
pRpcMsg
);
void
syncRequestVoteFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncRequestVote
*
pMsg
);
SyncRequestVote
*
syncRequestVoteFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
);
cJSON
*
syncRequestVote2Json
(
const
SyncRequestVote
*
pMsg
);
char
*
syncRequestVote2Str
(
const
SyncRequestVote
*
pMsg
);
// for debug ----------------------
void
syncRequestVotePrint
(
const
SyncRequestVote
*
pMsg
);
void
syncRequestVotePrint2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
);
void
syncRequestVoteLog
(
const
SyncRequestVote
*
pMsg
);
void
syncRequestVoteLog2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
浏览文件 @
8cca68f2
...
...
@@ -1009,3 +1009,154 @@ void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) {
taosMemoryFree
(
serialized
);
}
}
// ---- message process SyncRequestVote----
SyncRequestVote
*
syncRequestVoteBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncRequestVote
);
SyncRequestVote
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
pMsg
->
bytes
=
bytes
;
pMsg
->
vgId
=
vgId
;
pMsg
->
msgType
=
TDMT_SYNC_REQUEST_VOTE
;
return
pMsg
;
}
void
syncRequestVoteDestroy
(
SyncRequestVote
*
pMsg
)
{
if
(
pMsg
!=
NULL
)
{
taosMemoryFree
(
pMsg
);
}
}
void
syncRequestVoteSerialize
(
const
SyncRequestVote
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
)
{
ASSERT
(
pMsg
->
bytes
<=
bufLen
);
memcpy
(
buf
,
pMsg
,
pMsg
->
bytes
);
}
void
syncRequestVoteDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncRequestVote
*
pMsg
)
{
memcpy
(
pMsg
,
buf
,
len
);
ASSERT
(
len
==
pMsg
->
bytes
);
}
char
*
syncRequestVoteSerialize2
(
const
SyncRequestVote
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
taosMemoryMalloc
(
pMsg
->
bytes
);
ASSERT
(
buf
!=
NULL
);
syncRequestVoteSerialize
(
pMsg
,
buf
,
pMsg
->
bytes
);
if
(
len
!=
NULL
)
{
*
len
=
pMsg
->
bytes
;
}
return
buf
;
}
SyncRequestVote
*
syncRequestVoteDeserialize2
(
const
char
*
buf
,
uint32_t
len
)
{
uint32_t
bytes
=
*
((
uint32_t
*
)
buf
);
SyncRequestVote
*
pMsg
=
taosMemoryMalloc
(
bytes
);
ASSERT
(
pMsg
!=
NULL
);
syncRequestVoteDeserialize
(
buf
,
len
,
pMsg
);
ASSERT
(
len
==
pMsg
->
bytes
);
return
pMsg
;
}
void
syncRequestVote2RpcMsg
(
const
SyncRequestVote
*
pMsg
,
SRpcMsg
*
pRpcMsg
)
{
memset
(
pRpcMsg
,
0
,
sizeof
(
*
pRpcMsg
));
pRpcMsg
->
msgType
=
pMsg
->
msgType
;
pRpcMsg
->
contLen
=
pMsg
->
bytes
;
pRpcMsg
->
pCont
=
rpcMallocCont
(
pRpcMsg
->
contLen
);
syncRequestVoteSerialize
(
pMsg
,
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
}
void
syncRequestVoteFromRpcMsg
(
const
SRpcMsg
*
pRpcMsg
,
SyncRequestVote
*
pMsg
)
{
syncRequestVoteDeserialize
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
,
pMsg
);
}
SyncRequestVote
*
syncRequestVoteFromRpcMsg2
(
const
SRpcMsg
*
pRpcMsg
)
{
SyncRequestVote
*
pMsg
=
syncRequestVoteDeserialize2
(
pRpcMsg
->
pCont
,
pRpcMsg
->
contLen
);
ASSERT
(
pMsg
!=
NULL
);
return
pMsg
;
}
cJSON
*
syncRequestVote2Json
(
const
SyncRequestVote
*
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
();
cJSON_AddNumberToObject
(
pDestId
,
"addr"
,
pMsg
->
destId
.
addr
);
{
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
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
lastLogIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastLogIndex"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
lastLogTerm
);
cJSON_AddStringToObject
(
pRoot
,
"lastLogTerm"
,
u64buf
);
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"SyncRequestVote"
,
pRoot
);
return
pJson
;
}
char
*
syncRequestVote2Str
(
const
SyncRequestVote
*
pMsg
)
{
cJSON
*
pJson
=
syncRequestVote2Json
(
pMsg
);
char
*
serialized
=
cJSON_Print
(
pJson
);
cJSON_Delete
(
pJson
);
return
serialized
;
}
// for debug ----------------------
void
syncRequestVotePrint
(
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
printf
(
"syncRequestVotePrint | len:%d | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncRequestVotePrint2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
printf
(
"syncRequestVotePrint2 | len:%d | %s | %s
\n
"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
taosMemoryFree
(
serialized
);
}
void
syncRequestVoteLog
(
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
sTrace
(
"syncRequestVoteLog | len:%d | %s"
,
(
int32_t
)
strlen
(
serialized
),
serialized
);
taosMemoryFree
(
serialized
);
}
void
syncRequestVoteLog2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
)
{
if
(
gRaftDetailLog
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
sTrace
(
"syncRequestVoteLog2 | len:%d | %s | %s"
,
(
int32_t
)
strlen
(
serialized
),
s
,
serialized
);
taosMemoryFree
(
serialized
);
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录