Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9c1f2997
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看板
提交
9c1f2997
编写于
12月 30, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: test compile error
上级
c2323db0
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
144 addition
and
117 deletion
+144
-117
source/libs/sync/test/syncRaftCfgIndexTest.cpp
source/libs/sync/test/syncRaftCfgIndexTest.cpp
+12
-12
source/libs/sync/test/syncRaftCfgTest.cpp
source/libs/sync/test/syncRaftCfgTest.cpp
+28
-28
source/libs/sync/test/syncTest.cpp
source/libs/sync/test/syncTest.cpp
+0
-44
source/libs/sync/test/sync_test_lib/inc/syncTest.h
source/libs/sync/test/sync_test_lib/inc/syncTest.h
+5
-0
source/libs/sync/test/sync_test_lib/src/syncBatch.c
source/libs/sync/test/sync_test_lib/src/syncBatch.c
+1
-1
source/libs/sync/test/sync_test_lib/src/syncIO.c
source/libs/sync/test/sync_test_lib/src/syncIO.c
+71
-7
source/libs/sync/test/sync_test_lib/src/syncIndexMgrDebug.c
source/libs/sync/test/sync_test_lib/src/syncIndexMgrDebug.c
+2
-2
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
+7
-7
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
+2
-2
source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c
source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c
+7
-6
source/libs/sync/test/sync_test_lib/src/syncUtilDebug.c
source/libs/sync/test/sync_test_lib/src/syncUtilDebug.c
+5
-4
source/libs/sync/test/sync_test_lib/src/syncVoteMgrDebug.c
source/libs/sync/test/sync_test_lib/src/syncVoteMgrDebug.c
+4
-4
未找到文件。
source/libs/sync/test/syncRaftCfgIndexTest.cpp
浏览文件 @
9c1f2997
...
@@ -51,26 +51,26 @@ SSyncCfg* createSyncCfg() {
...
@@ -51,26 +51,26 @@ SSyncCfg* createSyncCfg() {
const
char
*
pFile
=
"./raft_config_index.json"
;
const
char
*
pFile
=
"./raft_config_index.json"
;
void
test1
()
{
void
test1
()
{
int32_t
code
=
raftCfgIndexCreateFile
(
pFile
);
//
int32_t code = raftCfgIndexCreateFile(pFile);
ASSERT
(
code
==
0
);
//
ASSERT(code == 0);
SRaftCfgIndex
*
pRaftCfgIndex
=
raftCfgIndexOpen
(
pFile
);
//
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
raftCfgIndexClose
(
pRaftCfgIndex
);
//
raftCfgIndexClose(pRaftCfgIndex);
}
}
void
test2
()
{
void
test2
()
{
SRaftCfgIndex
*
pRaftCfgIndex
=
raftCfgIndexOpen
(
pFile
);
//
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
for
(
int
i
=
0
;
i
<
500
;
++
i
)
{
//
for (int i = 0; i < 500; ++i) {
raftCfgIndexAddConfigIndex
(
pRaftCfgIndex
,
i
);
//
raftCfgIndexAddConfigIndex(pRaftCfgIndex, i);
}
//
}
raftCfgIndexPersist
(
pRaftCfgIndex
);
//
raftCfgIndexPersist(pRaftCfgIndex);
raftCfgIndexClose
(
pRaftCfgIndex
);
//
raftCfgIndexClose(pRaftCfgIndex);
}
}
void
test3
()
{
void
test3
()
{
SRaftCfgIndex
*
pRaftCfgIndex
=
raftCfgIndexOpen
(
pFile
);
//
SRaftCfgIndex* pRaftCfgIndex = raftCfgIndexOpen(pFile);
raftCfgIndexClose
(
pRaftCfgIndex
);
//
raftCfgIndexClose(pRaftCfgIndex);
}
}
int
main
()
{
int
main
()
{
...
...
source/libs/sync/test/syncRaftCfgTest.cpp
浏览文件 @
9c1f2997
...
@@ -67,12 +67,12 @@ void test3() {
...
@@ -67,12 +67,12 @@ void test3() {
if
(
taosCheckExistFile
(
s
))
{
if
(
taosCheckExistFile
(
s
))
{
printf
(
"%s file: %s already exist!
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
printf
(
"%s file: %s already exist!
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
}
else
{
}
else
{
SRaftCfgMeta
meta
;
//
SRaftCfgMeta meta;
meta
.
isStandBy
=
7
;
//
meta.isStandBy = 7;
meta
.
snapshotStrategy
=
9
;
//
meta.snapshotStrategy = 9;
meta
.
batchSize
=
10
;
//
meta.batchSize = 10;
meta
.
lastConfigIndex
=
789
;
//
meta.lastConfigIndex = 789;
raftCfgCreateFile
(
pCfg
,
meta
,
s
);
//
raftCfgCreateFile(pCfg, meta, s);
printf
(
"%s create json file: %s
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
printf
(
"%s create json file: %s
\n
"
,
(
char
*
)
__FUNCTION__
,
s
);
}
}
...
@@ -80,37 +80,37 @@ void test3() {
...
@@ -80,37 +80,37 @@ void test3() {
}
}
void
test4
()
{
void
test4
()
{
SRaftCfg
*
pCfg
=
raftCfgOpen
(
"./test3_raft_cfg.json"
);
//
SRaftCfg* pCfg = raftCfgOpen("./test3_raft_cfg.json");
assert
(
pCfg
!=
NULL
);
//
assert(pCfg != NULL);
int32_t
ret
=
raftCfgClose
(
pCfg
);
//
int32_t ret = raftCfgClose(pCfg);
assert
(
ret
==
0
);
//
assert(ret == 0);
}
}
void
test5
()
{
void
test5
()
{
SRaftCfg
*
pCfg
=
raftCfgOpen
(
"./test3_raft_cfg.json"
);
//
SRaftCfg* pCfg = raftCfgOpen("./test3_raft_cfg.json");
assert
(
pCfg
!=
NULL
);
//
assert(pCfg != NULL);
pCfg
->
cfg
.
myIndex
=
taosGetTimestampSec
();
//
pCfg->cfg.myIndex = taosGetTimestampSec();
pCfg
->
isStandBy
+=
2
;
//
pCfg->isStandBy += 2;
pCfg
->
snapshotStrategy
+=
3
;
//
pCfg->snapshotStrategy += 3;
pCfg
->
batchSize
+=
4
;
//
pCfg->batchSize += 4;
pCfg
->
lastConfigIndex
+=
1000
;
//
pCfg->lastConfigIndex += 1000;
pCfg
->
configIndexCount
=
5
;
//
pCfg->configIndexCount = 5;
for
(
int
i
=
0
;
i
<
MAX_CONFIG_INDEX_COUNT
;
++
i
)
{
//
for (int i = 0; i < MAX_CONFIG_INDEX_COUNT; ++i) {
(
pCfg
->
configIndexArr
)[
i
]
=
-
1
;
//
(pCfg->configIndexArr)[i] = -1;
}
//
}
for
(
int
i
=
0
;
i
<
pCfg
->
configIndexCount
;
++
i
)
{
//
for (int i = 0; i < pCfg->configIndexCount; ++i) {
(
pCfg
->
configIndexArr
)[
i
]
=
i
*
100
;
//
(pCfg->configIndexArr)[i] = i * 100;
}
//
}
raftCfgPersist
(
pCfg
);
// //
raftCfgPersist(pCfg);
printf
(
"%s update json file: %s myIndex->%d
\n
"
,
(
char
*
)
__FUNCTION__
,
"./test3_raft_cfg.json"
,
pCfg
->
cfg
.
myIndex
);
//
printf("%s update json file: %s myIndex->%d \n", (char*)__FUNCTION__, "./test3_raft_cfg.json", pCfg->cfg.myIndex);
int32_t
ret
=
raftCfgClose
(
pCfg
);
//
int32_t ret = raftCfgClose(pCfg);
assert
(
ret
==
0
);
//
assert(ret == 0);
}
}
int
main
()
{
int
main
()
{
...
...
source/libs/sync/test/syncTest.cpp
浏览文件 @
9c1f2997
...
@@ -70,47 +70,3 @@ int main(int argc, char** argv) {
...
@@ -70,47 +70,3 @@ int main(int argc, char** argv) {
taosCloseLog
();
taosCloseLog
();
return
0
;
return
0
;
}
}
static
inline
bool
syncUtilCanPrint
(
char
c
)
{
if
(
c
>=
32
&&
c
<=
126
)
{
return
true
;
}
else
{
return
false
;
}
}
char
*
syncUtilPrintBin
(
char
*
ptr
,
uint32_t
len
)
{
int64_t
memLen
=
(
int64_t
)(
len
+
1
);
char
*
s
=
taosMemoryMalloc
(
memLen
);
ASSERT
(
s
!=
NULL
);
memset
(
s
,
0
,
len
+
1
);
memcpy
(
s
,
ptr
,
len
);
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
if
(
!
syncUtilCanPrint
(
s
[
i
]))
{
s
[
i
]
=
'.'
;
}
}
return
s
;
}
char
*
syncUtilPrintBin2
(
char
*
ptr
,
uint32_t
len
)
{
uint32_t
len2
=
len
*
4
+
1
;
char
*
s
=
taosMemoryMalloc
(
len2
);
ASSERT
(
s
!=
NULL
);
memset
(
s
,
0
,
len2
);
char
*
p
=
s
;
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
int32_t
n
=
sprintf
(
p
,
"%d,"
,
ptr
[
i
]);
p
+=
n
;
}
return
s
;
}
void
syncUtilMsgNtoH
(
void
*
msg
)
{
SMsgHead
*
pHead
=
msg
;
pHead
->
contLen
=
ntohl
(
pHead
->
contLen
);
pHead
->
vgId
=
ntohl
(
pHead
->
vgId
);
}
source/libs/sync/test/sync_test_lib/inc/syncTest.h
浏览文件 @
9c1f2997
...
@@ -474,6 +474,11 @@ void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg);
...
@@ -474,6 +474,11 @@ void syncLocalCmdPrint2(char* s, const SyncLocalCmd* pMsg);
void
syncLocalCmdLog
(
const
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdLog
(
const
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdLog2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
);
void
syncLocalCmdLog2
(
char
*
s
,
const
SyncLocalCmd
*
pMsg
);
char
*
syncUtilPrintBin
(
char
*
ptr
,
uint32_t
len
);
char
*
syncUtilPrintBin2
(
char
*
ptr
,
uint32_t
len
);
void
syncUtilU642Addr
(
uint64_t
u64
,
char
*
host
,
int64_t
len
,
uint16_t
*
port
);
uint64_t
syncUtilAddr2U64
(
const
char
*
host
,
uint16_t
port
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
source/libs/sync/test/sync_test_lib/src/syncBatch.c
浏览文件 @
9c1f2997
...
@@ -311,7 +311,7 @@ cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) {
...
@@ -311,7 +311,7 @@ cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) {
cJSON
*
pTmp
=
pSrcId
;
cJSON
*
pTmp
=
pSrcId
;
char
host
[
128
]
=
{
0
};
char
host
[
128
]
=
{
0
};
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
//
syncUtilU642Addr(u64, host, sizeof(host), &port);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
}
...
...
source/libs/sync/test/sync_test_lib/src/syncIO.c
浏览文件 @
9c1f2997
...
@@ -73,7 +73,7 @@ int32_t syncIOSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
...
@@ -73,7 +73,7 @@ int32_t syncIOSendMsg(const SEpSet *pEpSet, SRpcMsg *pMsg) {
int32_t
ret
=
0
;
int32_t
ret
=
0
;
{
{
syncUtilMsgNtoH
(
pMsg
->
pCont
);
//
syncUtilMsgNtoH(pMsg->pCont);
char
logBuf
[
256
]
=
{
0
};
char
logBuf
[
256
]
=
{
0
};
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==syncIOSendMsg== %s:%d msgType:%d"
,
pEpSet
->
eps
[
0
].
fqdn
,
pEpSet
->
eps
[
0
].
port
,
snprintf
(
logBuf
,
sizeof
(
logBuf
),
"==syncIOSendMsg== %s:%d msgType:%d"
,
pEpSet
->
eps
[
0
].
fqdn
,
pEpSet
->
eps
[
0
].
port
,
...
@@ -376,7 +376,7 @@ static void *syncIOConsumerFunc(void *param) {
...
@@ -376,7 +376,7 @@ static void *syncIOConsumerFunc(void *param) {
}
}
static
void
syncIOProcessRequest
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
static
void
syncIOProcessRequest
(
void
*
pParent
,
SRpcMsg
*
pMsg
,
SEpSet
*
pEpSet
)
{
syncUtilMsgNtoH
(
pMsg
->
pCont
);
//
syncUtilMsgNtoH(pMsg->pCont);
syncRpcMsgLog2
((
char
*
)
"==syncIOProcessRequest=="
,
pMsg
);
syncRpcMsgLog2
((
char
*
)
"==syncIOProcessRequest=="
,
pMsg
);
SSyncIO
*
io
=
pParent
;
SSyncIO
*
io
=
pParent
;
...
@@ -432,9 +432,9 @@ static void syncIOTickQ(void *param, void *tmrId) {
...
@@ -432,9 +432,9 @@ static void syncIOTickQ(void *param, void *tmrId) {
SSyncIO
*
io
=
(
SSyncIO
*
)
param
;
SSyncIO
*
io
=
(
SSyncIO
*
)
param
;
SRaftId
srcId
,
destId
;
SRaftId
srcId
,
destId
;
srcId
.
addr
=
syncUtilAddr2U64
(
io
->
myAddr
.
eps
[
0
].
fqdn
,
io
->
myAddr
.
eps
[
0
].
port
);
//
srcId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
srcId
.
vgId
=
-
1
;
srcId
.
vgId
=
-
1
;
destId
.
addr
=
syncUtilAddr2U64
(
io
->
myAddr
.
eps
[
0
].
fqdn
,
io
->
myAddr
.
eps
[
0
].
port
);
//
destId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
destId
.
vgId
=
-
1
;
destId
.
vgId
=
-
1
;
SyncPingReply
*
pMsg
=
syncPingReplyBuild2
(
&
srcId
,
&
destId
,
-
1
,
"syncIOTickQ"
);
SyncPingReply
*
pMsg
=
syncPingReplyBuild2
(
&
srcId
,
&
destId
,
-
1
,
"syncIOTickQ"
);
...
@@ -454,9 +454,9 @@ static void syncIOTickPing(void *param, void *tmrId) {
...
@@ -454,9 +454,9 @@ static void syncIOTickPing(void *param, void *tmrId) {
SSyncIO
*
io
=
(
SSyncIO
*
)
param
;
SSyncIO
*
io
=
(
SSyncIO
*
)
param
;
SRaftId
srcId
,
destId
;
SRaftId
srcId
,
destId
;
srcId
.
addr
=
syncUtilAddr2U64
(
io
->
myAddr
.
eps
[
0
].
fqdn
,
io
->
myAddr
.
eps
[
0
].
port
);
//
srcId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
srcId
.
vgId
=
-
1
;
srcId
.
vgId
=
-
1
;
destId
.
addr
=
syncUtilAddr2U64
(
io
->
myAddr
.
eps
[
0
].
fqdn
,
io
->
myAddr
.
eps
[
0
].
port
);
//
destId.addr = syncUtilAddr2U64(io->myAddr.eps[0].fqdn, io->myAddr.eps[0].port);
destId
.
vgId
=
-
1
;
destId
.
vgId
=
-
1
;
SyncPing
*
pMsg
=
syncPingBuild2
(
&
srcId
,
&
destId
,
-
1
,
"syncIOTickPing"
);
SyncPing
*
pMsg
=
syncPingBuild2
(
&
srcId
,
&
destId
,
-
1
,
"syncIOTickPing"
);
// SyncPing *pMsg = syncPingBuild3(&srcId, &destId);
// SyncPing *pMsg = syncPingBuild3(&srcId, &destId);
...
@@ -470,4 +470,68 @@ static void syncIOTickPing(void *param, void *tmrId) {
...
@@ -470,4 +470,68 @@ static void syncIOTickPing(void *param, void *tmrId) {
taosTmrReset
(
syncIOTickPing
,
io
->
pingTimerMS
,
io
,
io
->
timerMgr
,
&
io
->
pingTimer
);
taosTmrReset
(
syncIOTickPing
,
io
->
pingTimerMS
,
io
,
io
->
timerMgr
,
&
io
->
pingTimer
);
}
}
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
)
{}
void
syncEntryDestory
(
SSyncRaftEntry
*
pEntry
)
{}
\ No newline at end of file
void
syncUtilMsgNtoH
(
void
*
msg
)
{
SMsgHead
*
pHead
=
msg
;
pHead
->
contLen
=
ntohl
(
pHead
->
contLen
);
pHead
->
vgId
=
ntohl
(
pHead
->
vgId
);
}
static
inline
bool
syncUtilCanPrint
(
char
c
)
{
if
(
c
>=
32
&&
c
<=
126
)
{
return
true
;
}
else
{
return
false
;
}
}
char
*
syncUtilPrintBin
(
char
*
ptr
,
uint32_t
len
)
{
int64_t
memLen
=
(
int64_t
)(
len
+
1
);
char
*
s
=
taosMemoryMalloc
(
memLen
);
ASSERT
(
s
!=
NULL
);
memset
(
s
,
0
,
len
+
1
);
memcpy
(
s
,
ptr
,
len
);
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
if
(
!
syncUtilCanPrint
(
s
[
i
]))
{
s
[
i
]
=
'.'
;
}
}
return
s
;
}
char
*
syncUtilPrintBin2
(
char
*
ptr
,
uint32_t
len
)
{
uint32_t
len2
=
len
*
4
+
1
;
char
*
s
=
taosMemoryMalloc
(
len2
);
ASSERT
(
s
!=
NULL
);
memset
(
s
,
0
,
len2
);
char
*
p
=
s
;
for
(
int32_t
i
=
0
;
i
<
len
;
++
i
)
{
int32_t
n
=
sprintf
(
p
,
"%d,"
,
ptr
[
i
]);
p
+=
n
;
}
return
s
;
}
void
syncUtilU642Addr
(
uint64_t
u64
,
char
*
host
,
int64_t
len
,
uint16_t
*
port
)
{
uint32_t
hostU32
=
(
uint32_t
)((
u64
>>
32
)
&
0x00000000FFFFFFFF
);
struct
in_addr
addr
=
{.
s_addr
=
hostU32
};
taosInetNtoa
(
addr
,
host
,
len
);
*
port
=
(
uint16_t
)((
u64
&
0x00000000FFFF0000
)
>>
16
);
}
uint64_t
syncUtilAddr2U64
(
const
char
*
host
,
uint16_t
port
)
{
uint32_t
hostU32
=
taosGetIpv4FromFqdn
(
host
);
if
(
hostU32
==
(
uint32_t
)
-
1
)
{
sError
(
"failed to resolve ipv4 addr, host:%s"
,
host
);
terrno
=
TSDB_CODE_TSC_INVALID_FQDN
;
return
-
1
;
}
uint64_t
u64
=
(((
uint64_t
)
hostU32
)
<<
32
)
|
(((
uint32_t
)
port
)
<<
16
);
return
u64
;
}
\ No newline at end of file
source/libs/sync/test/sync_test_lib/src/syncIndexMgrDebug.c
浏览文件 @
9c1f2997
...
@@ -53,7 +53,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
...
@@ -53,7 +53,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
for
(
int
i
=
0
;
i
<
pSyncIndexMgr
->
replicaNum
;
++
i
)
{
for
(
int
i
=
0
;
i
<
pSyncIndexMgr
->
replicaNum
;
++
i
)
{
cJSON_AddItemToArray
(
pReplicas
,
syncUtilRaftId2Json
(
&
(
*
(
pSyncIndexMgr
->
replicas
))[
i
]));
//
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pSyncIndexMgr->replicas))[i]));
}
}
{
{
...
@@ -76,7 +76,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
...
@@ -76,7 +76,7 @@ cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr) {
cJSON_AddItemToObject
(
pRoot
,
"privateTerm"
,
pIndex
);
cJSON_AddItemToObject
(
pRoot
,
"privateTerm"
,
pIndex
);
}
}
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncIndexMgr
->
pSyncNode
);
//
snprintf(u64buf, sizeof(u64buf), "%p", pSyncIndexMgr->pSyncNode);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
}
}
...
...
source/libs/sync/test/sync_test_lib/src/syncMainDebug.c
浏览文件 @
9c1f2997
...
@@ -23,7 +23,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
...
@@ -23,7 +23,7 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
if
(
pSyncNode
!=
NULL
)
{
if
(
pSyncNode
!=
NULL
)
{
// init by SSyncInfo
// init by SSyncInfo
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pSyncNode
->
vgId
);
cJSON_AddNumberToObject
(
pRoot
,
"vgId"
,
pSyncNode
->
vgId
);
cJSON_AddItemToObject
(
pRoot
,
"SRaftCfg"
,
raftCfg2Json
(
pSyncNode
->
pRaftCfg
));
//
cJSON_AddItemToObject(pRoot, "SRaftCfg", raftCfg2Json(pSyncNode->pRaftCfg));
cJSON_AddStringToObject
(
pRoot
,
"path"
,
pSyncNode
->
path
);
cJSON_AddStringToObject
(
pRoot
,
"path"
,
pSyncNode
->
path
);
cJSON_AddStringToObject
(
pRoot
,
"raftStorePath"
,
pSyncNode
->
raftStorePath
);
cJSON_AddStringToObject
(
pRoot
,
"raftStorePath"
,
pSyncNode
->
raftStorePath
);
cJSON_AddStringToObject
(
pRoot
,
"configPath"
,
pSyncNode
->
configPath
);
cJSON_AddStringToObject
(
pRoot
,
"configPath"
,
pSyncNode
->
configPath
);
...
@@ -44,8 +44,8 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
...
@@ -44,8 +44,8 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
// init internal
// init internal
cJSON
*
pMe
=
syncUtilNodeInfo2Json
(
&
pSyncNode
->
myNodeInfo
);
cJSON
*
pMe
=
syncUtilNodeInfo2Json
(
&
pSyncNode
->
myNodeInfo
);
cJSON_AddItemToObject
(
pRoot
,
"myNodeInfo"
,
pMe
);
cJSON_AddItemToObject
(
pRoot
,
"myNodeInfo"
,
pMe
);
cJSON
*
pRaftId
=
syncUtilRaftId2Json
(
&
pSyncNode
->
myRaftId
);
//
cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId);
cJSON_AddItemToObject
(
pRoot
,
"myRaftId"
,
pRaftId
);
//
cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId);
cJSON_AddNumberToObject
(
pRoot
,
"peersNum"
,
pSyncNode
->
peersNum
);
cJSON_AddNumberToObject
(
pRoot
,
"peersNum"
,
pSyncNode
->
peersNum
);
cJSON
*
pPeers
=
cJSON_CreateArray
();
cJSON
*
pPeers
=
cJSON_CreateArray
();
...
@@ -56,22 +56,22 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
...
@@ -56,22 +56,22 @@ cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
cJSON
*
pPeersId
=
cJSON_CreateArray
();
cJSON
*
pPeersId
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"peersId"
,
pPeersId
);
cJSON_AddItemToObject
(
pRoot
,
"peersId"
,
pPeersId
);
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
peersNum
;
++
i
)
{
cJSON_AddItemToArray
(
pPeersId
,
syncUtilRaftId2Json
(
&
pSyncNode
->
peersId
[
i
]));
//
cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i]));
}
}
cJSON_AddNumberToObject
(
pRoot
,
"replicaNum"
,
pSyncNode
->
replicaNum
);
cJSON_AddNumberToObject
(
pRoot
,
"replicaNum"
,
pSyncNode
->
replicaNum
);
cJSON
*
pReplicasId
=
cJSON_CreateArray
();
cJSON
*
pReplicasId
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicasId"
,
pReplicasId
);
cJSON_AddItemToObject
(
pRoot
,
"replicasId"
,
pReplicasId
);
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pSyncNode
->
replicaNum
;
++
i
)
{
cJSON_AddItemToArray
(
pReplicasId
,
syncUtilRaftId2Json
(
&
pSyncNode
->
replicasId
[
i
]));
//
cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i]));
}
}
// raft algorithm
// raft algorithm
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pFsm
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pSyncNode
->
pFsm
);
cJSON_AddStringToObject
(
pRoot
,
"pFsm"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"pFsm"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"quorum"
,
pSyncNode
->
quorum
);
cJSON_AddNumberToObject
(
pRoot
,
"quorum"
,
pSyncNode
->
quorum
);
cJSON
*
pLaderCache
=
syncUtilRaftId2Json
(
&
pSyncNode
->
leaderCache
);
//
cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache);
cJSON_AddItemToObject
(
pRoot
,
"leaderCache"
,
pLaderCache
);
//
cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache);
// life cycle
// life cycle
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pSyncNode
->
rid
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pSyncNode
->
rid
);
...
...
source/libs/sync/test/sync_test_lib/src/syncMessageDebug.c
浏览文件 @
9c1f2997
...
@@ -181,7 +181,7 @@ cJSON* syncPing2Json(const SyncPing* pMsg) {
...
@@ -181,7 +181,7 @@ cJSON* syncPing2Json(const SyncPing* pMsg) {
cJSON
*
pTmp
=
pSrcId
;
cJSON
*
pTmp
=
pSrcId
;
char
host
[
128
]
=
{
0
};
char
host
[
128
]
=
{
0
};
uint16_t
port
;
uint16_t
port
;
syncUtilU642Addr
(
u64
,
host
,
sizeof
(
host
),
&
port
);
//
syncUtilU642Addr(u64, host, sizeof(host), &port);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddStringToObject
(
pTmp
,
"addr_host"
,
host
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
cJSON_AddNumberToObject
(
pTmp
,
"addr_port"
,
port
);
}
}
...
@@ -748,7 +748,7 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
...
@@ -748,7 +748,7 @@ cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
lastConfigIndex
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRId64
,
pMsg
->
lastConfigIndex
);
cJSON_AddStringToObject
(
pRoot
,
"lastConfigIndex"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"lastConfigIndex"
,
u64buf
);
cJSON_AddItemToObject
(
pRoot
,
"lastConfig"
,
syncCfg2Json
((
SSyncCfg
*
)
&
(
pMsg
->
lastConfig
)));
//
cJSON_AddItemToObject(pRoot, "lastConfig", syncCfg2Json((SSyncCfg*)&(pMsg->lastConfig)));
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
lastTerm
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pMsg
->
lastTerm
);
cJSON_AddStringToObject
(
pRoot
,
"lastTerm"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"lastTerm"
,
u64buf
);
...
...
source/libs/sync/test/sync_test_lib/src/syncRaftCfgDebug.c
浏览文件 @
9c1f2997
...
@@ -17,18 +17,19 @@
...
@@ -17,18 +17,19 @@
#include "syncTest.h"
#include "syncTest.h"
char
*
syncCfg2Str
(
SSyncCfg
*
pSyncCfg
)
{
char
*
syncCfg2Str
(
SSyncCfg
*
pSyncCfg
)
{
cJSON
*
pJson
=
syncCfg2Json
(
pSyncCfg
);
// cJSON *pJson = syncCfg2Json(pSyncCfg);
char
*
serialized
=
cJSON_Print
(
pJson
);
// char *serialized = cJSON_Print(pJson);
cJSON_Delete
(
pJson
);
// cJSON_Delete(pJson);
return
serialized
;
// return serialized;
return
""
;
}
}
int32_t
syncCfgFromStr
(
const
char
*
s
,
SSyncCfg
*
pSyncCfg
)
{
int32_t
syncCfgFromStr
(
const
char
*
s
,
SSyncCfg
*
pSyncCfg
)
{
cJSON
*
pRoot
=
cJSON_Parse
(
s
);
cJSON
*
pRoot
=
cJSON_Parse
(
s
);
ASSERT
(
pRoot
!=
NULL
);
ASSERT
(
pRoot
!=
NULL
);
int32_t
ret
=
syncCfgFromJson
(
pRoot
,
pSyncCfg
);
//
int32_t ret = syncCfgFromJson(pRoot, pSyncCfg);
ASSERT
(
ret
==
0
);
//
ASSERT(ret == 0);
cJSON_Delete
(
pRoot
);
cJSON_Delete
(
pRoot
);
return
0
;
return
0
;
...
...
source/libs/sync/test/sync_test_lib/src/syncUtilDebug.c
浏览文件 @
9c1f2997
...
@@ -29,8 +29,9 @@ cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p) {
...
@@ -29,8 +29,9 @@ cJSON* syncUtilNodeInfo2Json(const SNodeInfo* p) {
}
}
char
*
syncUtilRaftId2Str
(
const
SRaftId
*
p
)
{
char
*
syncUtilRaftId2Str
(
const
SRaftId
*
p
)
{
cJSON
*
pJson
=
syncUtilRaftId2Json
(
p
);
// cJSON* pJson = syncUtilRaftId2Json(p);
char
*
serialized
=
cJSON_Print
(
pJson
);
// char* serialized = cJSON_Print(pJson);
cJSON_Delete
(
pJson
);
// cJSON_Delete(pJson);
return
serialized
;
// return serialized;
return
""
;
}
}
source/libs/sync/test/sync_test_lib/src/syncVoteMgrDebug.c
浏览文件 @
9c1f2997
...
@@ -25,7 +25,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
...
@@ -25,7 +25,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
for
(
int32_t
i
=
0
;
i
<
pVotesGranted
->
replicaNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pVotesGranted
->
replicaNum
;
++
i
)
{
cJSON_AddItemToArray
(
pReplicas
,
syncUtilRaftId2Json
(
&
(
*
(
pVotesGranted
->
replicas
))[
i
]));
//
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesGranted->replicas))[i]));
}
}
int32_t
*
arr
=
(
int32_t
*
)
taosMemoryMalloc
(
sizeof
(
int32_t
)
*
pVotesGranted
->
replicaNum
);
int32_t
*
arr
=
(
int32_t
*
)
taosMemoryMalloc
(
sizeof
(
int32_t
)
*
pVotesGranted
->
replicaNum
);
for
(
int32_t
i
=
0
;
i
<
pVotesGranted
->
replicaNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pVotesGranted
->
replicaNum
;
++
i
)
{
...
@@ -40,7 +40,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
...
@@ -40,7 +40,7 @@ cJSON *voteGranted2Json(SVotesGranted *pVotesGranted) {
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddNumberToObject
(
pRoot
,
"quorum"
,
pVotesGranted
->
quorum
);
cJSON_AddNumberToObject
(
pRoot
,
"quorum"
,
pVotesGranted
->
quorum
);
cJSON_AddNumberToObject
(
pRoot
,
"toLeader"
,
pVotesGranted
->
toLeader
);
cJSON_AddNumberToObject
(
pRoot
,
"toLeader"
,
pVotesGranted
->
toLeader
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesGranted
->
p
Sync
Node
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesGranted
->
pNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
bool
majority
=
voteGrantedMajority
(
pVotesGranted
);
bool
majority
=
voteGrantedMajority
(
pVotesGranted
);
...
@@ -68,7 +68,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
...
@@ -68,7 +68,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON
*
pReplicas
=
cJSON_CreateArray
();
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
cJSON_AddItemToObject
(
pRoot
,
"replicas"
,
pReplicas
);
for
(
int32_t
i
=
0
;
i
<
pVotesRespond
->
replicaNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
pVotesRespond
->
replicaNum
;
++
i
)
{
cJSON_AddItemToArray
(
pReplicas
,
syncUtilRaftId2Json
(
&
(
*
(
pVotesRespond
->
replicas
))[
i
]));
//
cJSON_AddItemToArray(pReplicas, syncUtilRaftId2Json(&(*(pVotesRespond->replicas))[i]));
}
}
int32_t
respondNum
=
0
;
int32_t
respondNum
=
0
;
int32_t
*
arr
=
(
int32_t
*
)
taosMemoryMalloc
(
sizeof
(
int32_t
)
*
pVotesRespond
->
replicaNum
);
int32_t
*
arr
=
(
int32_t
*
)
taosMemoryMalloc
(
sizeof
(
int32_t
)
*
pVotesRespond
->
replicaNum
);
...
@@ -85,7 +85,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
...
@@ -85,7 +85,7 @@ cJSON *votesRespond2Json(SVotesRespond *pVotesRespond) {
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pVotesRespond
->
term
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%"
PRIu64
,
pVotesRespond
->
term
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"term"
,
u64buf
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesRespond
->
p
Sync
Node
);
snprintf
(
u64buf
,
sizeof
(
u64buf
),
"%p"
,
pVotesRespond
->
pNode
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
cJSON_AddStringToObject
(
pRoot
,
"pSyncNode"
,
u64buf
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录