Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
aa9a5b6f
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看板
提交
aa9a5b6f
编写于
1月 14, 2022
作者:
L
Liu Jicong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add test for new heartbeat
上级
8cd25b8e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
179 addition
and
61 deletion
+179
-61
include/common/tmsg.h
include/common/tmsg.h
+9
-3
source/client/src/clientHb.c
source/client/src/clientHb.c
+5
-5
source/client/test/clientTests.cpp
source/client/test/clientTests.cpp
+38
-38
source/common/src/tmsg.c
source/common/src/tmsg.c
+66
-8
source/dnode/mnode/impl/src/mndProfile.c
source/dnode/mnode/impl/src/mndProfile.c
+22
-7
source/dnode/mnode/impl/test/profile/profile.cpp
source/dnode/mnode/impl/test/profile/profile.cpp
+39
-0
未找到文件。
include/common/tmsg.h
浏览文件 @
aa9a5b6f
...
...
@@ -155,7 +155,7 @@ typedef struct {
typedef
struct
{
SClientHbKey
connKey
;
SHashObj
*
info
;
// hash<S
lv.key, Skl
v>
SHashObj
*
info
;
// hash<S
kv.key, Sk
v>
}
SClientHbReq
;
typedef
struct
{
...
...
@@ -181,7 +181,10 @@ static FORCE_INLINE uint32_t hbKeyHashFunc(const char* key, uint32_t keyLen) {
}
int
tSerializeSClientHbReq
(
void
**
buf
,
const
SClientHbReq
*
pReq
);
void
*
tDeserializeClientHbReq
(
void
*
buf
,
SClientHbReq
*
pReq
);
void
*
tDeserializeSClientHbReq
(
void
*
buf
,
SClientHbReq
*
pReq
);
int
tSerializeSClientHbRsp
(
void
**
buf
,
const
SClientHbRsp
*
pRsp
);
void
*
tDeserializeSClientHbRsp
(
void
*
buf
,
SClientHbRsp
*
pRsp
);
static
FORCE_INLINE
void
tFreeClientHbReq
(
void
*
pReq
)
{
SClientHbReq
*
req
=
(
SClientHbReq
*
)
pReq
;
...
...
@@ -190,7 +193,7 @@ static FORCE_INLINE void tFreeClientHbReq(void *pReq) {
}
int
tSerializeSClientHbBatchReq
(
void
**
buf
,
const
SClientHbBatchReq
*
pReq
);
void
*
tDeserializeClientHbBatchReq
(
void
*
buf
,
SClientHbBatchReq
*
pReq
);
void
*
tDeserialize
S
ClientHbBatchReq
(
void
*
buf
,
SClientHbBatchReq
*
pReq
);
static
FORCE_INLINE
void
tFreeClientHbBatchReq
(
void
*
pReq
)
{
SClientHbBatchReq
*
req
=
(
SClientHbBatchReq
*
)
pReq
;
...
...
@@ -198,6 +201,9 @@ static FORCE_INLINE void tFreeClientHbBatchReq(void* pReq) {
free
(
pReq
);
}
int
tSerializeSClientHbBatchRsp
(
void
**
buf
,
const
SClientHbBatchRsp
*
pBatchRsp
);
void
*
tDeserializeSClientHbBatchRsp
(
void
*
buf
,
SClientHbBatchRsp
*
pBatchRsp
);
static
FORCE_INLINE
int
taosEncodeSKv
(
void
**
buf
,
const
SKv
*
pKv
)
{
int
tlen
=
0
;
tlen
+=
taosEncodeFixedI32
(
buf
,
pKv
->
keyLen
);
...
...
source/client/src/clientHb.c
浏览文件 @
aa9a5b6f
...
...
@@ -43,17 +43,17 @@ static FORCE_INLINE void hbMgrInitHandle() {
}
SClientHbBatchReq
*
hbGatherAllInfo
(
SAppHbMgr
*
pAppHbMgr
)
{
SClientHbBatchReq
*
pReq
=
malloc
(
sizeof
(
SClientHbBatchReq
));
if
(
pReq
==
NULL
)
{
SClientHbBatchReq
*
p
Batch
Req
=
malloc
(
sizeof
(
SClientHbBatchReq
));
if
(
p
Batch
Req
==
NULL
)
{
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
NULL
;
}
int32_t
connKeyCnt
=
atomic_load_32
(
&
pAppHbMgr
->
connKeyCnt
);
pReq
->
reqs
=
taosArrayInit
(
connKeyCnt
,
sizeof
(
SClientHbReq
));
p
Batch
Req
->
reqs
=
taosArrayInit
(
connKeyCnt
,
sizeof
(
SClientHbReq
));
void
*
pIter
=
taosHashIterate
(
pAppHbMgr
->
activeInfo
,
NULL
);
while
(
pIter
!=
NULL
)
{
taosArrayPush
(
pReq
->
reqs
,
pIter
);
taosArrayPush
(
p
Batch
Req
->
reqs
,
pIter
);
SClientHbReq
*
pOneReq
=
pIter
;
taosHashClear
(
pOneReq
->
info
);
...
...
@@ -70,7 +70,7 @@ SClientHbBatchReq* hbGatherAllInfo(SAppHbMgr *pAppHbMgr) {
pIter
=
taosHashIterate
(
pAppHbMgr
->
activeInfo
,
pIter
);
}
return
pReq
;
return
p
Batch
Req
;
}
static
void
*
hbThreadFunc
(
void
*
param
)
{
...
...
source/client/test/clientTests.cpp
浏览文件 @
aa9a5b6f
...
...
@@ -147,29 +147,29 @@ TEST(testCase, connect_Test) {
// taos_close(pConn);
//}
//
//
TEST(testCase, create_db_Test) {
//
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
//
assert(pConn != NULL);
//
//
TAOS_RES* pRes = taos_query(pConn, "create database abc1 vgroups 2");
//
if (taos_errno(pRes) != 0) {
//
printf("error in create db, reason:%s\n", taos_errstr(pRes));
//
}
//
//
TAOS_FIELD* pFields = taos_fetch_fields(pRes);
//
ASSERT_TRUE(pFields == NULL);
//
//
int32_t numOfFields = taos_num_fields(pRes);
//
ASSERT_EQ(numOfFields, 0);
//
//
taos_free_result(pRes);
//
//
pRes = taos_query(pConn, "create database abc1 vgroups 4");
//
if (taos_errno(pRes) != 0) {
//
printf("error in create db, reason:%s\n", taos_errstr(pRes));
//
}
//
taos_close(pConn);
//
}
TEST
(
testCase
,
create_db_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"create database abc1 vgroups 2"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"error in create db, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
TAOS_FIELD
*
pFields
=
taos_fetch_fields
(
pRes
);
ASSERT_TRUE
(
pFields
==
NULL
);
int32_t
numOfFields
=
taos_num_fields
(
pRes
);
ASSERT_EQ
(
numOfFields
,
0
);
taos_free_result
(
pRes
);
pRes
=
taos_query
(
pConn
,
"create database abc1 vgroups 4"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"error in create db, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_close
(
pConn
);
}
//
//TEST(testCase, create_dnode_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
...
...
@@ -293,24 +293,24 @@ TEST(testCase, connect_Test) {
// taos_close(pConn);
//}
TEST
(
testCase
,
create_ctable_Test
)
{
TAOS
*
pConn
=
taos_connect
(
"localhost"
,
"root"
,
"taosdata"
,
NULL
,
0
);
assert
(
pConn
!=
NULL
);
//
TEST(testCase, create_ctable_Test) {
//
TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
//
assert(pConn != NULL);
TAOS_RES
*
pRes
=
taos_query
(
pConn
,
"use abc1"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to use db, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
taos_free_result
(
pRes
);
//
TAOS_RES* pRes = taos_query(pConn, "use abc1");
//
if (taos_errno(pRes) != 0) {
//
printf("failed to use db, reason:%s\n", taos_errstr(pRes));
//
}
//
taos_free_result(pRes);
pRes
=
taos_query
(
pConn
,
"create table tm0 using st1 tags(1)"
);
if
(
taos_errno
(
pRes
)
!=
0
)
{
printf
(
"failed to create child table tm0, reason:%s
\n
"
,
taos_errstr
(
pRes
));
}
//
pRes = taos_query(pConn, "create table tm0 using st1 tags(1)");
//
if (taos_errno(pRes) != 0) {
//
printf("failed to create child table tm0, reason:%s\n", taos_errstr(pRes));
//
}
taos_free_result
(
pRes
);
taos_close
(
pConn
);
}
//
taos_free_result(pRes);
//
taos_close(pConn);
//
}
//TEST(testCase, show_stable_Test) {
// TAOS* pConn = taos_connect("localhost", "root", "taosdata", NULL, 0);
...
...
source/common/src/tmsg.c
浏览文件 @
aa9a5b6f
...
...
@@ -89,7 +89,7 @@ int tSerializeSClientHbReq(void **buf, const SClientHbReq *pReq) {
int
tlen
=
0
;
tlen
+=
taosEncodeSClientHbKey
(
buf
,
&
pReq
->
connKey
);
int
kvNum
=
taosHashGetSize
(
pReq
->
info
);
int
32_t
kvNum
=
taosHashGetSize
(
pReq
->
info
);
tlen
+=
taosEncodeFixedI32
(
buf
,
kvNum
);
SKv
kv
;
void
*
pIter
=
taosHashIterate
(
pReq
->
info
,
pIter
);
...
...
@@ -104,14 +104,15 @@ int tSerializeSClientHbReq(void **buf, const SClientHbReq *pReq) {
return
tlen
;
}
void
*
tDeserializeClientHbReq
(
void
*
buf
,
SClientHbReq
*
pReq
)
{
ASSERT
(
pReq
->
info
!=
NULL
);
void
*
tDeserializeSClientHbReq
(
void
*
buf
,
SClientHbReq
*
pReq
)
{
buf
=
taosDecodeSClientHbKey
(
buf
,
&
pReq
->
connKey
);
// TODO: error handling
int
kvNum
;
taosDecodeFixedI32
(
buf
,
&
kvNum
);
pReq
->
info
=
taosHashInit
(
kvNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
int32_t
kvNum
;
buf
=
taosDecodeFixedI32
(
buf
,
&
kvNum
);
if
(
pReq
->
info
==
NULL
)
{
pReq
->
info
=
taosHashInit
(
kvNum
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
}
for
(
int
i
=
0
;
i
<
kvNum
;
i
++
)
{
SKv
kv
;
buf
=
taosDecodeSKv
(
buf
,
&
kv
);
...
...
@@ -121,12 +122,69 @@ void *tDeserializeClientHbReq(void *buf, SClientHbReq *pReq) {
return
buf
;
}
int
tSerializeSClientHbBatchReq
(
void
**
buf
,
const
SClientHbBatchReq
*
pReq
)
{
int
tSerializeSClientHbRsp
(
void
**
buf
,
const
SClientHbRsp
*
pRsp
)
{
int
tlen
=
0
;
tlen
+=
taosEncodeSClientHbKey
(
buf
,
&
pRsp
->
connKey
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pRsp
->
status
);
tlen
+=
taosEncodeFixedI32
(
buf
,
pRsp
->
bodyLen
);
tlen
+=
taosEncodeBinary
(
buf
,
pRsp
->
body
,
pRsp
->
bodyLen
);
return
tlen
;
}
void
*
tDeserializeSClientHbRsp
(
void
*
buf
,
SClientHbRsp
*
pRsp
)
{
buf
=
taosDecodeSClientHbKey
(
buf
,
&
pRsp
->
connKey
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pRsp
->
status
);
buf
=
taosDecodeFixedI32
(
buf
,
&
pRsp
->
bodyLen
);
buf
=
taosDecodeBinary
(
buf
,
&
pRsp
->
body
,
pRsp
->
bodyLen
);
return
buf
;
}
int
tSerializeSClientHbBatchReq
(
void
**
buf
,
const
SClientHbBatchReq
*
pBatchReq
)
{
int
tlen
=
0
;
tlen
+=
taosEncodeFixedI64
(
buf
,
pBatchReq
->
reqId
);
int32_t
reqNum
=
taosArrayGetSize
(
pBatchReq
->
reqs
);
tlen
+=
taosEncodeFixedI32
(
buf
,
reqNum
);
for
(
int
i
=
0
;
i
<
reqNum
;
i
++
)
{
SClientHbReq
*
pReq
=
taosArrayGet
(
pBatchReq
->
reqs
,
i
);
tlen
+=
tSerializeSClientHbReq
(
buf
,
pReq
);
}
return
tlen
;
}
void
*
tDeserializeClientHbBatchReq
(
void
*
buf
,
SClientHbBatchReq
*
pReq
)
{
void
*
tDeserializeSClientHbBatchReq
(
void
*
buf
,
SClientHbBatchReq
*
pBatchReq
)
{
buf
=
taosDecodeFixedI64
(
buf
,
&
pBatchReq
->
reqId
);
if
(
pBatchReq
->
reqs
==
NULL
)
{
pBatchReq
->
reqs
=
taosArrayInit
(
0
,
sizeof
(
SClientHbReq
));
}
int32_t
reqNum
;
buf
=
taosDecodeFixedI32
(
buf
,
&
reqNum
);
for
(
int
i
=
0
;
i
<
reqNum
;
i
++
)
{
SClientHbReq
req
=
{
0
};
buf
=
tDeserializeSClientHbReq
(
buf
,
&
req
);
taosArrayPush
(
pBatchReq
->
reqs
,
&
req
);
}
return
buf
;
}
int
tSerializeSClientHbBatchRsp
(
void
**
buf
,
const
SClientHbBatchRsp
*
pBatchRsp
)
{
int
tlen
=
0
;
int32_t
sz
=
taosArrayGetSize
(
pBatchRsp
->
rsps
);
tlen
+=
taosEncodeFixedI32
(
buf
,
sz
);
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SClientHbRsp
*
pRsp
=
taosArrayGet
(
pBatchRsp
->
rsps
,
i
);
tlen
+=
tSerializeSClientHbRsp
(
buf
,
pRsp
);
}
return
tlen
;
}
void
*
tDeserializeSClientHbBatchRsp
(
void
*
buf
,
SClientHbBatchRsp
*
pBatchRsp
)
{
int32_t
sz
;
buf
=
taosDecodeFixedI32
(
buf
,
&
sz
);
pBatchRsp
->
rsps
=
taosArrayInit
(
sz
,
sizeof
(
SClientHbRsp
));
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SClientHbRsp
rsp
=
{
0
};
buf
=
tDeserializeSClientHbRsp
(
buf
,
&
rsp
);
taosArrayPush
(
pBatchRsp
->
rsps
,
&
rsp
);
}
return
buf
;
}
...
...
source/dnode/mnode/impl/src/mndProfile.c
浏览文件 @
aa9a5b6f
...
...
@@ -258,24 +258,39 @@ static int32_t mndSaveQueryStreamList(SConnObj *pConn, SHeartBeatReq *pReq) {
}
static
int32_t
mndProcessHeartBeatReq
(
SMnodeMsg
*
pReq
)
{
#if 0
SMnode
*
pMnode
=
pReq
->
pMnode
;
char
*
batchReqStr
=
pReq
->
rpcMsg
.
pCont
;
SClientHbBatchReq
batchReq
=
{
0
};
tDeserializeClientHbBatchReq(batchReqStr, &batchReq);
tDeserialize
S
ClientHbBatchReq
(
batchReqStr
,
&
batchReq
);
SArray
*
pArray
=
batchReq
.
reqs
;
int
sz
=
taosArrayGetSize
(
pArray
);
for (int i = 0; i < sz; i++) {
SClientHbReq* pReq = taosArrayGet(pArray, i);
if (pReq->connKey.hbType == HEARTBEAT_TYPE_QUERY) {
} else if (pReq->connKey.hbType == HEARTBEAT_TYPE_MQ) {
SClientHbBatchRsp
batchRsp
=
{
0
};
batchRsp
.
rsps
=
taosArrayInit
(
0
,
sizeof
(
SClientHbRsp
));
for
(
int
i
=
0
;
i
<
sz
;
i
++
)
{
SClientHbReq
*
pHbReq
=
taosArrayGet
(
pArray
,
i
);
if
(
pHbReq
->
connKey
.
hbType
==
HEARTBEAT_TYPE_QUERY
)
{
}
else
if
(
pHbReq
->
connKey
.
hbType
==
HEARTBEAT_TYPE_MQ
)
{
SClientHbRsp
rsp
=
{
.
status
=
0
,
.
connKey
=
pHbReq
->
connKey
,
.
bodyLen
=
0
,
.
body
=
NULL
};
taosArrayPush
(
batchRsp
.
rsps
,
&
rsp
);
}
}
int32_t
tlen
=
tSerializeSClientHbBatchRsp
(
NULL
,
&
batchRsp
);
void
*
buf
=
rpcMallocCont
(
tlen
);
void
*
bufCopy
=
buf
;
tSerializeSClientHbBatchRsp
(
&
bufCopy
,
&
batchRsp
);
pReq
->
contLen
=
tlen
;
pReq
->
pCont
=
buf
;
return
0
;
#else
#if 0
SMnode *pMnode = pReq->pMnode;
SProfileMgmt *pMgmt = &pMnode->profileMgmt;
...
...
source/dnode/mnode/impl/test/profile/profile.cpp
浏览文件 @
aa9a5b6f
...
...
@@ -96,6 +96,38 @@ TEST_F(MndTestProfile, 03_ConnectMsg_Show) {
}
TEST_F
(
MndTestProfile
,
04
_HeartBeatMsg
)
{
SClientHbBatchReq
batchReq
;
batchReq
.
reqs
=
taosArrayInit
(
0
,
sizeof
(
SClientHbReq
));
SClientHbReq
req
=
{
0
};
req
.
connKey
=
{.
connId
=
123
,
.
hbType
=
HEARTBEAT_TYPE_MQ
};
req
.
info
=
taosHashInit
(
64
,
hbKeyHashFunc
,
1
,
HASH_ENTRY_LOCK
);
SKv
kv
;
kv
.
key
=
(
void
*
)
"abc"
;
kv
.
keyLen
=
4
;
kv
.
value
=
(
void
*
)
"bcd"
;
kv
.
valueLen
=
4
;
taosHashPut
(
req
.
info
,
kv
.
key
,
kv
.
keyLen
,
kv
.
value
,
kv
.
valueLen
);
taosArrayPush
(
batchReq
.
reqs
,
&
req
);
int32_t
tlen
=
tSerializeSClientHbBatchReq
(
NULL
,
&
batchReq
);
void
*
buf
=
(
SClientHbBatchReq
*
)
rpcMallocCont
(
tlen
);
void
*
bufCopy
=
buf
;
tSerializeSClientHbBatchReq
(
&
bufCopy
,
&
batchReq
);
SRpcMsg
*
pMsg
=
test
.
SendReq
(
TDMT_MND_HEARTBEAT
,
buf
,
tlen
);
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
char
*
pRspChar
=
(
char
*
)
pMsg
->
pCont
;
SClientHbBatchRsp
rsp
=
{
0
};
tDeserializeSClientHbBatchRsp
(
pRspChar
,
&
rsp
);
int
sz
=
taosArrayGetSize
(
rsp
.
rsps
);
ASSERT_EQ
(
sz
,
1
);
SClientHbRsp
*
pRsp
=
(
SClientHbRsp
*
)
taosArrayGet
(
rsp
.
rsps
,
0
);
EXPECT_EQ
(
pRsp
->
connKey
.
connId
,
123
);
EXPECT_EQ
(
pRsp
->
connKey
.
hbType
,
HEARTBEAT_TYPE_MQ
);
EXPECT_EQ
(
pRsp
->
status
,
0
);
#if 0
int32_t contLen = sizeof(SHeartBeatReq);
SHeartBeatReq* pReq = (SHeartBeatReq*)rpcMallocCont(contLen);
...
...
@@ -129,9 +161,12 @@ TEST_F(MndTestProfile, 04_HeartBeatMsg) {
EXPECT_EQ(pRsp->epSet.numOfEps, 1);
EXPECT_EQ(pRsp->epSet.port[0], 9031);
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
#endif
}
TEST_F
(
MndTestProfile
,
05
_KillConnMsg
)
{
// temporary remove since kill will use new heartbeat msg
#if 0
{
int32_t contLen = sizeof(SKillConnReq);
...
...
@@ -190,6 +225,7 @@ TEST_F(MndTestProfile, 05_KillConnMsg) {
connId = pRsp->connId;
}
#endif
}
TEST_F
(
MndTestProfile
,
06
_KillConnMsg_InvalidConn
)
{
...
...
@@ -204,6 +240,8 @@ TEST_F(MndTestProfile, 06_KillConnMsg_InvalidConn) {
}
TEST_F
(
MndTestProfile
,
07
_KillQueryMsg
)
{
// temporary remove since kill will use new heartbeat msg
#if 0
{
int32_t contLen = sizeof(SKillQueryReq);
...
...
@@ -252,6 +290,7 @@ TEST_F(MndTestProfile, 07_KillQueryMsg) {
EXPECT_EQ(pRsp->epSet.port[0], 9031);
EXPECT_STREQ(pRsp->epSet.fqdn[0], "localhost");
}
#endif
}
TEST_F
(
MndTestProfile
,
08
_KillQueryMsg_InvalidConn
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录