Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
52b6a9c0
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
52b6a9c0
编写于
4月 21, 2022
作者:
M
Minghao Li
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add syncElectTest, config replicaNum myIndex
上级
672be6f4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
49 addition
and
52 deletion
+49
-52
source/libs/sync/test/syncElectTest.cpp
source/libs/sync/test/syncElectTest.cpp
+49
-52
未找到文件。
source/libs/sync/test/syncElectTest.cpp
浏览文件 @
52b6a9c0
...
...
@@ -3,9 +3,8 @@
#include "syncEnv.h"
#include "syncIO.h"
#include "syncInt.h"
#include "syncRaftLog.h"
#include "syncRaftStore.h"
#include "syncUtil.h"
#include "wal.h"
void
logTest
()
{
sTrace
(
"--- sync log test: trace"
);
...
...
@@ -16,43 +15,41 @@ void logTest() {
sFatal
(
"--- sync log test: fatal"
);
}
uint16_t
ports
[]
=
{
7010
,
7110
,
7210
,
7310
,
7410
};
int32_t
replicaNum
=
3
;
int32_t
myIndex
=
0
;
SRaftId
ids
[
TSDB_MAX_REPLICA
];
SSyncInfo
syncInfo
;
SSyncFSM
*
pFsm
;
SWal
*
pWal
;
SSyncNode
*
gSyncNode
;
const
char
*
pDir
=
"./syncElectTest"
;
SSyncNode
*
syncNodeInit
()
{
syncInfo
.
vgId
=
1234
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
syncInfo
.
queue
=
gSyncIO
->
pMsgQ
;
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
pFsm
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s_sync_%d"
,
pDir
,
myIndex
);
uint16_t
gPorts
[]
=
{
7010
,
7110
,
7210
,
7310
,
7410
};
const
char
*
gDir
=
"./syncElectTest"
;
int32_t
gVgId
=
1234
;
void
init
()
{
int
code
=
walInit
();
assert
(
code
==
0
);
}
void
cleanup
()
{
walCleanUp
();
}
SWal
*
createWal
(
char
*
path
,
int32_t
vgId
)
{
SWalCfg
walCfg
;
memset
(
&
walCfg
,
0
,
sizeof
(
SWalCfg
));
walCfg
.
vgId
=
syncInfo
.
vgId
;
walCfg
.
vgId
=
vgId
;
walCfg
.
fsyncPeriod
=
1000
;
walCfg
.
retentionPeriod
=
1000
;
walCfg
.
rollPeriod
=
1000
;
walCfg
.
retentionSize
=
1000
;
walCfg
.
segSize
=
1000
;
walCfg
.
level
=
TAOS_WAL_FSYNC
;
char
tmpdir
[
128
];
snprintf
(
tmpdir
,
sizeof
(
tmpdir
),
"%s_wal_%d"
,
pDir
,
myIndex
);
pWal
=
walOpen
(
tmpdir
,
&
walCfg
);
SWal
*
pWal
=
walOpen
(
path
,
&
walCfg
);
assert
(
pWal
!=
NULL
);
return
pWal
;
}
SSyncNode
*
createSyncNode
(
int32_t
replicaNum
,
int32_t
myIndex
,
int32_t
vgId
,
SWal
*
pWal
,
char
*
path
)
{
SSyncInfo
syncInfo
;
syncInfo
.
vgId
=
vgId
;
syncInfo
.
rpcClient
=
gSyncIO
->
clientRpc
;
syncInfo
.
FpSendMsg
=
syncIOSendMsg
;
syncInfo
.
queue
=
gSyncIO
->
pMsgQ
;
syncInfo
.
FpEqMsg
=
syncIOEqMsg
;
syncInfo
.
pFsm
=
NULL
;
snprintf
(
syncInfo
.
path
,
sizeof
(
syncInfo
.
path
),
"%s_sync_replica%d_index%d"
,
path
,
replicaNum
,
myIndex
);
syncInfo
.
pWal
=
pWal
;
SSyncCfg
*
pCfg
=
&
syncInfo
.
syncCfg
;
...
...
@@ -60,9 +57,9 @@ SSyncNode* syncNodeInit() {
pCfg
->
replicaNum
=
replicaNum
;
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
pCfg
->
nodeInfo
[
i
].
nodePort
=
p
orts
[
i
];
snprintf
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
,
sizeof
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
),
"%s"
,
"127.0.0.1"
);
//
taosGetFqdn(pCfg->nodeInfo[0].nodeFqdn
);
pCfg
->
nodeInfo
[
i
].
nodePort
=
gP
orts
[
i
];
taosGetFqdn
(
pCfg
->
nodeInfo
[
i
].
nodeFqdn
);
//
snprintf(pCfg->nodeInfo[i].nodeFqdn, sizeof(pCfg->nodeInfo[i].nodeFqdn), "%s", "127.0.0.1"
);
}
SSyncNode
*
pSyncNode
=
syncNodeOpen
(
&
syncInfo
);
...
...
@@ -84,46 +81,46 @@ SSyncNode* syncNodeInit() {
return
pSyncNode
;
}
SSyncNode
*
syncInitTest
()
{
return
syncNodeInit
();
}
void
initRaftId
(
SSyncNode
*
pSyncNode
)
{
for
(
int
i
=
0
;
i
<
replicaNum
;
++
i
)
{
ids
[
i
]
=
pSyncNode
->
replicasId
[
i
];
char
*
s
=
syncUtilRaftId2Str
(
&
ids
[
i
]);
printf
(
"raftId[%d] : %s
\n
"
,
i
,
s
);
taosMemoryFree
(
s
);
}
}
void
usage
(
char
*
exe
)
{
printf
(
"usage: %s replicaNum myIndex
\n
"
,
exe
);
}
int
main
(
int
argc
,
char
**
argv
)
{
// taosInitLog((char *)"syncTest.log", 100000, 10);
tsAsyncLog
=
0
;
sDebugFlag
=
143
+
64
;
myIndex
=
0
;
if
(
argc
>=
2
)
{
myIndex
=
atoi
(
argv
[
1
]);
sDebugFlag
=
DEBUG_TRACE
+
DEBUG_SCREEN
+
DEBUG_FILE
;
if
(
argc
!=
3
)
{
usage
(
argv
[
0
]);
exit
(
-
1
);
}
int32_t
replicaNum
=
atoi
(
argv
[
1
]);
int32_t
myIndex
=
atoi
(
argv
[
2
]);
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
ports
[
myIndex
]
);
assert
(
ret
==
0
);
assert
(
replicaNum
>=
1
&&
replicaNum
<=
5
);
assert
(
myIndex
>=
0
&&
myIndex
<
replicaNum
);
init
();
int32_t
ret
=
syncIOStart
((
char
*
)
"127.0.0.1"
,
gPorts
[
myIndex
]);
assert
(
ret
==
0
);
ret
=
syncEnvStart
();
assert
(
ret
==
0
);
gSyncNode
=
syncInitTest
()
;
assert
(
gSyncNode
!=
NULL
);
syncNodeLog2
((
char
*
)
""
,
gSyncNode
);
char
walPath
[
128
]
;
snprintf
(
walPath
,
sizeof
(
walPath
),
"%s_wal_replica%d_index%d"
,
gDir
,
replicaNum
,
myIndex
);
SWal
*
pWal
=
createWal
(
walPath
,
gVgId
);
initRaftId
(
gSyncNode
);
SSyncNode
*
pSyncNode
=
createSyncNode
(
replicaNum
,
myIndex
,
gVgId
,
pWal
,
(
char
*
)
gDir
);
assert
(
pSyncNode
!=
NULL
);
syncNodeLog2
((
char
*
)
"==syncElectTest=="
,
pSyncNode
);
//---------------------------
while
(
1
)
{
char
*
s
=
syncNode2SimpleStr
(
g
SyncNode
);
char
*
s
=
syncNode2SimpleStr
(
p
SyncNode
);
sTrace
(
"%s"
,
s
);
taosMemoryFree
(
s
);
taosMsleep
(
1000
);
}
syncNodeClose
(
pSyncNode
);
walClose
(
pWal
);
syncIOStop
();
cleanup
();
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录