Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
6a3869a3
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看板
提交
6a3869a3
编写于
3月 11, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
sync refactor
上级
88aef2d1
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
185 addition
and
4 deletion
+185
-4
source/libs/sync/inc/syncMessage.h
source/libs/sync/inc/syncMessage.h
+10
-2
source/libs/sync/inc/syncRaftEntry.h
source/libs/sync/inc/syncRaftEntry.h
+1
-1
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+57
-0
source/libs/sync/src/syncRaftEntry.c
source/libs/sync/src/syncRaftEntry.c
+1
-1
source/libs/sync/test/CMakeLists.txt
source/libs/sync/test/CMakeLists.txt
+14
-0
source/libs/sync/test/syncEncodeTest.cpp
source/libs/sync/test/syncEncodeTest.cpp
+6
-0
source/libs/sync/test/syncRequestVote.cpp
source/libs/sync/test/syncRequestVote.cpp
+96
-0
未找到文件。
source/libs/sync/inc/syncMessage.h
浏览文件 @
6a3869a3
...
...
@@ -83,8 +83,6 @@ typedef struct SyncPing {
char
data
[];
}
SyncPing
;
//#define SYNC_PING_FIX_LEN (sizeof(uint32_t) + sizeof(uint32_t) + sizeof(SRaftId) + sizeof(SRaftId) + sizeof(uint32_t))
SyncPing
*
syncPingBuild
(
uint32_t
dataLen
);
void
syncPingDestroy
(
SyncPing
*
pMsg
);
void
syncPingSerialize
(
const
SyncPing
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
...
...
@@ -163,9 +161,19 @@ SyncRequestVote* syncRequestVoteBuild();
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
{
...
...
source/libs/sync/inc/syncRaftEntry.h
浏览文件 @
6a3869a3
...
...
@@ -47,7 +47,7 @@ SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len);
cJSON
*
syncEntry2Json
(
const
SSyncRaftEntry
*
pEntry
);
char
*
syncEntry2Str
(
const
SSyncRaftEntry
*
pEntry
);
// for debug
// for debug
----------------------
void
syncEntryPrint
(
const
SSyncRaftEntry
*
pObj
);
void
syncEntryPrint2
(
char
*
s
,
const
SSyncRaftEntry
*
pObj
);
void
syncEntryLog
(
const
SSyncRaftEntry
*
pObj
);
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
6a3869a3
...
...
@@ -439,6 +439,25 @@ void syncRequestVoteDeserialize(const char* buf, uint32_t len, SyncRequestVote*
assert
(
len
==
pMsg
->
bytes
);
}
char
*
syncRequestVoteSerialize2
(
const
SyncRequestVote
*
pMsg
,
uint32_t
*
len
)
{
char
*
buf
=
malloc
(
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
=
malloc
(
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
;
...
...
@@ -451,6 +470,10 @@ 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
);
}
cJSON
*
syncRequestVote2Json
(
const
SyncRequestVote
*
pMsg
)
{
char
u64buf
[
128
];
...
...
@@ -499,6 +522,40 @@ cJSON* syncRequestVote2Json(const SyncRequestVote* pMsg) {
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:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncRequestVotePrint2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
printf
(
"syncRequestVotePrint2 | len:%lu | %s | %s
\n
"
,
strlen
(
serialized
),
s
,
serialized
);
fflush
(
NULL
);
free
(
serialized
);
}
void
syncRequestVoteLog
(
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
sTrace
(
"syncRequestVoteLog | len:%lu | %s"
,
strlen
(
serialized
),
serialized
);
free
(
serialized
);
}
void
syncRequestVoteLog2
(
char
*
s
,
const
SyncRequestVote
*
pMsg
)
{
char
*
serialized
=
syncRequestVote2Str
(
pMsg
);
sTrace
(
"syncRequestVoteLog2 | len:%lu | %s | %s"
,
strlen
(
serialized
),
s
,
serialized
);
free
(
serialized
);
}
// ---- message process SyncRequestVoteReply----
SyncRequestVoteReply
*
SyncRequestVoteReplyBuild
()
{
uint32_t
bytes
=
sizeof
(
SyncRequestVoteReply
);
...
...
source/libs/sync/src/syncRaftEntry.c
浏览文件 @
6a3869a3
...
...
@@ -104,7 +104,7 @@ char* syncEntry2Str(const SSyncRaftEntry* pEntry) {
return
serialized
;
}
// for debug -----------
// for debug -----------
-----------
void
syncEntryPrint
(
const
SSyncRaftEntry
*
pObj
)
{
char
*
serialized
=
syncEntry2Str
(
pObj
);
printf
(
"syncEntryPrint | len:%lu | %s
\n
"
,
strlen
(
serialized
),
serialized
);
...
...
source/libs/sync/test/CMakeLists.txt
浏览文件 @
6a3869a3
...
...
@@ -17,6 +17,7 @@ add_executable(syncVotesRespondTest "")
add_executable
(
syncIndexMgrTest
""
)
add_executable
(
syncLogStoreTest
""
)
add_executable
(
syncEntryTest
""
)
add_executable
(
syncRequestVote
""
)
target_sources
(
syncTest
...
...
@@ -95,6 +96,10 @@ target_sources(syncEntryTest
PRIVATE
"syncEntryTest.cpp"
)
target_sources
(
syncRequestVote
PRIVATE
"syncRequestVote.cpp"
)
target_include_directories
(
syncTest
...
...
@@ -192,6 +197,11 @@ target_include_directories(syncEntryTest
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_include_directories
(
syncRequestVote
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/libs/sync"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../inc"
)
target_link_libraries
(
syncTest
...
...
@@ -270,6 +280,10 @@ target_link_libraries(syncEntryTest
sync
gtest_main
)
target_link_libraries
(
syncRequestVote
sync
gtest_main
)
enable_testing
()
...
...
source/libs/sync/test/syncEncodeTest.cpp
浏览文件 @
6a3869a3
...
...
@@ -17,6 +17,8 @@ void logTest() {
#define PING_MSG_LEN 20
#define APPEND_ENTRIES_VALUE_LEN 32
#if 0
void test1() {
sTrace("test1: ---- syncPingSerialize, syncPingDeserialize");
...
...
@@ -487,11 +489,14 @@ void test12() {
syncAppendEntriesReplyDestroy(pMsg2);
}
#endif
int
main
()
{
// taosInitLog((char*)"syncPingTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
#if 0
test1();
test2();
test3();
...
...
@@ -504,6 +509,7 @@ int main() {
test10();
test11();
test12();
#endif
return
0
;
}
source/libs/sync/test/syncRequestVote.cpp
0 → 100644
浏览文件 @
6a3869a3
#include <gtest/gtest.h>
#include <stdio.h>
#include "syncIO.h"
#include "syncInt.h"
#include "syncMessage.h"
#include "syncUtil.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
sDebug
(
"--- sync log test: debug"
);
sInfo
(
"--- sync log test: info"
);
sWarn
(
"--- sync log test: warn"
);
sError
(
"--- sync log test: error"
);
sFatal
(
"--- sync log test: fatal"
);
}
SyncRequestVote
*
createMsg
()
{
SyncRequestVote
*
pMsg
=
syncRequestVoteBuild
();
pMsg
->
srcId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
1234
);
pMsg
->
srcId
.
vgId
=
100
;
pMsg
->
destId
.
addr
=
syncUtilAddr2U64
(
"127.0.0.1"
,
5678
);
pMsg
->
destId
.
vgId
=
100
;
pMsg
->
currentTerm
=
11
;
pMsg
->
lastLogIndex
=
22
;
pMsg
->
lastLogTerm
=
33
;
}
void
test1
()
{
SyncRequestVote
*
pMsg
=
createMsg
();
syncRequestVotePrint2
((
char
*
)
"test1:"
,
pMsg
);
syncRequestVoteDestroy
(
pMsg
);
}
void
test2
()
{
SyncRequestVote
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
malloc
(
len
);
syncRequestVoteSerialize
(
pMsg
,
serialized
,
len
);
SyncRequestVote
*
pMsg2
=
syncRequestVoteBuild
();
syncRequestVoteDeserialize
(
serialized
,
len
,
pMsg2
);
syncRequestVotePrint2
((
char
*
)
"test2: syncRequestVoteSerialize -> syncRequestVoteDeserialize "
,
pMsg
);
free
(
serialized
);
syncRequestVoteDestroy
(
pMsg
);
syncRequestVoteDestroy
(
pMsg2
);
}
void
test3
()
{
SyncRequestVote
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
syncRequestVoteSerialize2
(
pMsg
,
&
len
);
SyncRequestVote
*
pMsg2
=
syncRequestVoteDeserialize2
(
serialized
,
len
);
syncRequestVotePrint2
((
char
*
)
"test3: syncRequestVoteSerialize3 -> syncRequestVoteDeserialize2 "
,
pMsg
);
free
(
serialized
);
syncRequestVoteDestroy
(
pMsg
);
syncRequestVoteDestroy
(
pMsg2
);
}
void
test4
()
{
SyncRequestVote
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncRequestVote2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncRequestVote
*
pMsg2
=
syncRequestVoteBuild
();
syncRequestVoteFromRpcMsg
(
&
rpcMsg
,
pMsg2
);
syncRequestVotePrint2
((
char
*
)
"test4: syncRequestVote2RpcMsg -> syncRequestVoteFromRpcMsg "
,
pMsg
);
syncRequestVoteDestroy
(
pMsg
);
syncRequestVoteDestroy
(
pMsg2
);
}
void
test5
()
{
SyncRequestVote
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
syncRequestVote2RpcMsg
(
pMsg
,
&
rpcMsg
);
SyncRequestVote
*
pMsg2
=
syncRequestVoteFromRpcMsg2
(
&
rpcMsg
);
syncRequestVotePrint2
((
char
*
)
"test5: syncRequestVote2RpcMsg -> syncRequestVoteFromRpcMsg2 "
,
pMsg
);
syncRequestVoteDestroy
(
pMsg
);
syncRequestVoteDestroy
(
pMsg2
);
}
int
main
()
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
logTest
();
test1
();
test2
();
test3
();
test4
();
test5
();
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录