Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d7c866ee
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看板
提交
d7c866ee
编写于
10月 27, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh(sync): add test
上级
54dfc8cd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
40 deletion
+40
-40
include/libs/sync/syncTools.h
include/libs/sync/syncTools.h
+2
-2
source/libs/sync/src/syncMessage.c
source/libs/sync/src/syncMessage.c
+2
-2
source/libs/sync/test/syncLocalCmdTest.cpp
source/libs/sync/test/syncLocalCmdTest.cpp
+36
-36
未找到文件。
include/libs/sync/syncTools.h
浏览文件 @
d7c866ee
...
...
@@ -680,7 +680,7 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg);
// ---------------------------------------------
typedef
enum
{
SYNC_
STEP_DOWN
=
0
,
SYNC_
LOCAL_CMD_STEP_DOWN
=
10
0
,
}
ESyncLocalCmd
;
typedef
struct
SyncLocalCmd
{
...
...
@@ -695,7 +695,7 @@ typedef struct SyncLocalCmd {
}
SyncLocalCmd
;
SyncLocalCmd
*
syncLocalCmdBuild
(
uint32_t
dataLen
,
int32_t
vgId
);
SyncLocalCmd
*
syncLocalCmdBuild
(
int32_t
vgId
);
void
syncLocalCmdDestroy
(
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdSerialize
(
const
SyncLocalCmd
*
pMsg
,
char
*
buf
,
uint32_t
bufLen
);
void
syncLocalCmdDeserialize
(
const
char
*
buf
,
uint32_t
len
,
SyncLocalCmd
*
pMsg
);
...
...
source/libs/sync/src/syncMessage.c
浏览文件 @
d7c866ee
...
...
@@ -3097,7 +3097,7 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) {
}
// ---------------------------------------------
SyncLocalCmd
*
syncLocalCmdBuild
(
uint32_t
dataLen
,
int32_t
vgId
)
{
SyncLocalCmd
*
syncLocalCmdBuild
(
int32_t
vgId
)
{
uint32_t
bytes
=
sizeof
(
SyncLocalCmd
);
SyncLocalCmd
*
pMsg
=
taosMemoryMalloc
(
bytes
);
memset
(
pMsg
,
0
,
bytes
);
...
...
@@ -3206,7 +3206,7 @@ cJSON* syncLocalCmd2Json(const SyncLocalCmd* pMsg) {
}
cJSON
*
pJson
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
pJson
,
"Sync
SnapshotRsp
"
,
pRoot
);
cJSON_AddItemToObject
(
pJson
,
"Sync
LocalCmd2Json
"
,
pRoot
);
return
pJson
;
}
...
...
source/libs/sync/test/syncLocalCmdTest.cpp
浏览文件 @
d7c866ee
...
...
@@ -14,78 +14,78 @@ void logTest() {
sFatal
(
"--- sync log test: fatal"
);
}
Sync
AppendEntries
*
createMsg
()
{
Sync
AppendEntries
*
pMsg
=
syncAppendEntriesBuild
(
20
,
1000
);
Sync
LocalCmd
*
createMsg
()
{
Sync
LocalCmd
*
pMsg
=
syncLocalCmdBuild
(
1000
);
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
->
prevLogIndex
=
11
;
pMsg
->
prevLogTerm
=
22
;
pMsg
->
commitIndex
=
33
;
pMsg
->
privateTerm
=
44
;
strcpy
(
pMsg
->
data
,
"hello world"
);
pMsg
->
sdNewTerm
=
123
;
pMsg
->
cmd
=
SYNC_LOCAL_CMD_STEP_DOWN
;
return
pMsg
;
}
void
test1
()
{
Sync
AppendEntries
*
pMsg
=
createMsg
();
sync
AppendEntries
Log2
((
char
*
)
"test1:"
,
pMsg
);
sync
AppendEntries
Destroy
(
pMsg
);
Sync
LocalCmd
*
pMsg
=
createMsg
();
sync
LocalCmd
Log2
((
char
*
)
"test1:"
,
pMsg
);
sync
LocalCmd
Destroy
(
pMsg
);
}
void
test2
()
{
Sync
AppendEntries
*
pMsg
=
createMsg
();
Sync
LocalCmd
*
pMsg
=
createMsg
();
uint32_t
len
=
pMsg
->
bytes
;
char
*
serialized
=
(
char
*
)
taosMemoryMalloc
(
len
);
sync
AppendEntries
Serialize
(
pMsg
,
serialized
,
len
);
Sync
AppendEntries
*
pMsg2
=
syncAppendEntriesBuild
(
pMsg
->
dataLen
,
1000
);
sync
AppendEntries
Deserialize
(
serialized
,
len
,
pMsg2
);
sync
AppendEntriesLog2
((
char
*
)
"test2: syncAppendEntriesSerialize -> syncAppendEntries
Deserialize "
,
pMsg2
);
sync
LocalCmd
Serialize
(
pMsg
,
serialized
,
len
);
Sync
LocalCmd
*
pMsg2
=
syncLocalCmdBuild
(
1000
);
sync
LocalCmd
Deserialize
(
serialized
,
len
,
pMsg2
);
sync
LocalCmdLog2
((
char
*
)
"test2: syncLocalCmdSerialize -> syncLocalCmd
Deserialize "
,
pMsg2
);
taosMemoryFree
(
serialized
);
sync
AppendEntries
Destroy
(
pMsg
);
sync
AppendEntries
Destroy
(
pMsg2
);
sync
LocalCmd
Destroy
(
pMsg
);
sync
LocalCmd
Destroy
(
pMsg2
);
}
void
test3
()
{
Sync
AppendEntries
*
pMsg
=
createMsg
();
Sync
LocalCmd
*
pMsg
=
createMsg
();
uint32_t
len
;
char
*
serialized
=
sync
AppendEntries
Serialize2
(
pMsg
,
&
len
);
Sync
AppendEntries
*
pMsg2
=
syncAppendEntries
Deserialize2
(
serialized
,
len
);
sync
AppendEntriesLog2
((
char
*
)
"test3: syncAppendEntriesSerialize3 -> syncAppendEntries
Deserialize2 "
,
pMsg2
);
char
*
serialized
=
sync
LocalCmd
Serialize2
(
pMsg
,
&
len
);
Sync
LocalCmd
*
pMsg2
=
syncLocalCmd
Deserialize2
(
serialized
,
len
);
sync
LocalCmdLog2
((
char
*
)
"test3: syncLocalCmdSerialize3 -> syncLocalCmd
Deserialize2 "
,
pMsg2
);
taosMemoryFree
(
serialized
);
sync
AppendEntries
Destroy
(
pMsg
);
sync
AppendEntries
Destroy
(
pMsg2
);
sync
LocalCmd
Destroy
(
pMsg
);
sync
LocalCmd
Destroy
(
pMsg2
);
}
void
test4
()
{
Sync
AppendEntries
*
pMsg
=
createMsg
();
Sync
LocalCmd
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
sync
AppendEntries
2RpcMsg
(
pMsg
,
&
rpcMsg
);
Sync
AppendEntries
*
pMsg2
=
(
SyncAppendEntries
*
)
taosMemoryMalloc
(
rpcMsg
.
contLen
);
sync
AppendEntries
FromRpcMsg
(
&
rpcMsg
,
pMsg2
);
sync
AppendEntriesLog2
((
char
*
)
"test4: syncAppendEntries2RpcMsg -> syncAppendEntries
FromRpcMsg "
,
pMsg2
);
sync
LocalCmd
2RpcMsg
(
pMsg
,
&
rpcMsg
);
Sync
LocalCmd
*
pMsg2
=
(
SyncLocalCmd
*
)
taosMemoryMalloc
(
rpcMsg
.
contLen
);
sync
LocalCmd
FromRpcMsg
(
&
rpcMsg
,
pMsg2
);
sync
LocalCmdLog2
((
char
*
)
"test4: syncLocalCmd2RpcMsg -> syncLocalCmd
FromRpcMsg "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
sync
AppendEntries
Destroy
(
pMsg
);
sync
AppendEntries
Destroy
(
pMsg2
);
sync
LocalCmd
Destroy
(
pMsg
);
sync
LocalCmd
Destroy
(
pMsg2
);
}
void
test5
()
{
Sync
AppendEntries
*
pMsg
=
createMsg
();
Sync
LocalCmd
*
pMsg
=
createMsg
();
SRpcMsg
rpcMsg
;
sync
AppendEntries
2RpcMsg
(
pMsg
,
&
rpcMsg
);
Sync
AppendEntries
*
pMsg2
=
syncAppendEntries
FromRpcMsg2
(
&
rpcMsg
);
sync
AppendEntriesLog2
((
char
*
)
"test5: syncAppendEntries2RpcMsg -> syncAppendEntries
FromRpcMsg2 "
,
pMsg2
);
sync
LocalCmd
2RpcMsg
(
pMsg
,
&
rpcMsg
);
Sync
LocalCmd
*
pMsg2
=
syncLocalCmd
FromRpcMsg2
(
&
rpcMsg
);
sync
LocalCmdLog2
((
char
*
)
"test5: syncLocalCmd2RpcMsg -> syncLocalCmd
FromRpcMsg2 "
,
pMsg2
);
rpcFreeCont
(
rpcMsg
.
pCont
);
sync
AppendEntries
Destroy
(
pMsg
);
sync
AppendEntries
Destroy
(
pMsg2
);
sync
LocalCmd
Destroy
(
pMsg
);
sync
LocalCmd
Destroy
(
pMsg2
);
}
int
main
()
{
gRaftDetailLog
=
true
;
tsAsyncLog
=
0
;
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
logTest
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录