Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b5e9ba4a
T
TDengine
项目概览
taosdata
/
TDengine
12 个月 前同步成功
通知
1180
Star
22014
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,发现更多精彩内容 >>
提交
b5e9ba4a
编写于
12月 06, 2021
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-10431 cluster test
上级
c57e5d49
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
311 addition
and
88 deletion
+311
-88
source/dnode/mgmt/impl/test/CMakeLists.txt
source/dnode/mgmt/impl/test/CMakeLists.txt
+1
-0
source/dnode/mgmt/impl/test/cluster/CMakeLists.txt
source/dnode/mgmt/impl/test/cluster/CMakeLists.txt
+29
-0
source/dnode/mgmt/impl/test/cluster/cluster.cpp
source/dnode/mgmt/impl/test/cluster/cluster.cpp
+170
-0
source/dnode/mgmt/impl/test/profile/profile.cpp
source/dnode/mgmt/impl/test/profile/profile.cpp
+6
-6
source/dnode/mgmt/impl/test/show/show.cpp
source/dnode/mgmt/impl/test/show/show.cpp
+1
-1
source/dnode/mgmt/impl/test/sut/deploy.cpp
source/dnode/mgmt/impl/test/sut/deploy.cpp
+2
-2
source/dnode/mgmt/impl/test/sut/deploy.h
source/dnode/mgmt/impl/test/sut/deploy.h
+1
-0
source/dnode/mnode/impl/inc/mndDef.h
source/dnode/mnode/impl/inc/mndDef.h
+1
-1
source/dnode/mnode/impl/src/mndCluster.c
source/dnode/mnode/impl/src/mndCluster.c
+100
-78
未找到文件。
source/dnode/mgmt/impl/test/CMakeLists.txt
浏览文件 @
b5e9ba4a
add_subdirectory
(
acct
)
add_subdirectory
(
cluster
)
add_subdirectory
(
profile
)
add_subdirectory
(
show
)
source/dnode/mgmt/impl/test/cluster/CMakeLists.txt
0 → 100644
浏览文件 @
b5e9ba4a
add_executable
(
dndTestCluster
""
)
target_sources
(
dndTestCluster
PRIVATE
"cluster.cpp"
"../sut/deploy.cpp"
)
target_link_libraries
(
dndTestCluster
PUBLIC dnode
PUBLIC util
PUBLIC os
PUBLIC gtest_main
)
target_include_directories
(
dndTestCluster
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/include/server/dnode/mgmt"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../inc"
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../sut"
)
enable_testing
()
add_test
(
NAME dndTestCluster
COMMAND dndTestCluster
)
source/dnode/mgmt/impl/test/cluster/cluster.cpp
0 → 100644
浏览文件 @
b5e9ba4a
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "deploy.h"
class
DndTestCluster
:
public
::
testing
::
Test
{
protected:
void
SetUp
()
override
{}
void
TearDown
()
override
{}
static
void
SetUpTestSuite
()
{
const
char
*
user
=
"root"
;
const
char
*
pass
=
"taosdata"
;
const
char
*
path
=
"/tmp/dndTestCluster"
;
const
char
*
fqdn
=
"localhost"
;
uint16_t
port
=
9521
;
pServer
=
createServer
(
path
,
fqdn
,
port
);
ASSERT
(
pServer
);
pClient
=
createClient
(
user
,
pass
,
fqdn
,
port
);
}
static
void
TearDownTestSuite
()
{
dropServer
(
pServer
);
dropClient
(
pClient
);
}
static
SServer
*
pServer
;
static
SClient
*
pClient
;
static
int32_t
connId
;
};
SServer
*
DndTestCluster
::
pServer
;
SClient
*
DndTestCluster
::
pClient
;
int32_t
DndTestCluster
::
connId
;
TEST_F
(
DndTestCluster
,
ShowCluster
)
{
ASSERT_NE
(
pClient
,
nullptr
);
int32_t
showId
=
0
;
{
SShowMsg
*
pReq
=
(
SShowMsg
*
)
rpcMallocCont
(
sizeof
(
SShowMsg
));
pReq
->
type
=
TSDB_MGMT_TABLE_CLUSTER
;
strcpy
(
pReq
->
db
,
""
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SShowMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
SShowRsp
*
pRsp
=
(
SShowRsp
*
)
pMsg
->
pCont
;
ASSERT_NE
(
pRsp
,
nullptr
);
pRsp
->
showId
=
htonl
(
pRsp
->
showId
);
STableMetaMsg
*
pMeta
=
&
pRsp
->
tableMeta
;
pMeta
->
contLen
=
htonl
(
pMeta
->
contLen
);
pMeta
->
numOfColumns
=
htons
(
pMeta
->
numOfColumns
);
pMeta
->
sversion
=
htons
(
pMeta
->
sversion
);
pMeta
->
tversion
=
htons
(
pMeta
->
tversion
);
pMeta
->
tid
=
htonl
(
pMeta
->
tid
);
pMeta
->
uid
=
htobe64
(
pMeta
->
uid
);
pMeta
->
suid
=
htobe64
(
pMeta
->
suid
);
showId
=
pRsp
->
showId
;
EXPECT_NE
(
pRsp
->
showId
,
0
);
EXPECT_EQ
(
pMeta
->
contLen
,
0
);
EXPECT_STREQ
(
pMeta
->
tableFname
,
"show cluster"
);
EXPECT_EQ
(
pMeta
->
numOfTags
,
0
);
EXPECT_EQ
(
pMeta
->
precision
,
0
);
EXPECT_EQ
(
pMeta
->
tableType
,
0
);
EXPECT_EQ
(
pMeta
->
numOfColumns
,
3
);
EXPECT_EQ
(
pMeta
->
sversion
,
0
);
EXPECT_EQ
(
pMeta
->
tversion
,
0
);
EXPECT_EQ
(
pMeta
->
tid
,
0
);
EXPECT_EQ
(
pMeta
->
uid
,
0
);
EXPECT_STREQ
(
pMeta
->
sTableName
,
""
);
EXPECT_EQ
(
pMeta
->
suid
,
0
);
SSchema
*
pSchema
=
NULL
;
pSchema
=
&
pMeta
->
schema
[
0
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_INT
);
EXPECT_EQ
(
pSchema
->
bytes
,
4
);
EXPECT_STREQ
(
pSchema
->
name
,
"id"
);
pSchema
=
&
pMeta
->
schema
[
1
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_BINARY
);
EXPECT_EQ
(
pSchema
->
bytes
,
TSDB_CLUSTER_ID_LEN
+
VARSTR_HEADER_SIZE
);
EXPECT_STREQ
(
pSchema
->
name
,
"name"
);
pSchema
=
&
pMeta
->
schema
[
2
];
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
EXPECT_EQ
(
pSchema
->
colId
,
0
);
EXPECT_EQ
(
pSchema
->
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
EXPECT_EQ
(
pSchema
->
bytes
,
8
);
EXPECT_STREQ
(
pSchema
->
name
,
"create_time"
);
}
{
SRetrieveTableMsg
*
pReq
=
(
SRetrieveTableMsg
*
)
rpcMallocCont
(
sizeof
(
SRetrieveTableMsg
));
pReq
->
showId
=
htonl
(
showId
);
pReq
->
free
=
0
;
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
pCont
=
pReq
;
rpcMsg
.
contLen
=
sizeof
(
SRetrieveTableMsg
);
rpcMsg
.
msgType
=
TSDB_MSG_TYPE_SHOW_RETRIEVE
;
sendMsg
(
pClient
,
&
rpcMsg
);
SRpcMsg
*
pMsg
=
pClient
->
pRsp
;
ASSERT_NE
(
pMsg
,
nullptr
);
ASSERT_EQ
(
pMsg
->
code
,
0
);
SRetrieveTableRsp
*
pRsp
=
(
SRetrieveTableRsp
*
)
pMsg
->
pCont
;
ASSERT_NE
(
pRsp
,
nullptr
);
pRsp
->
numOfRows
=
htonl
(
pRsp
->
numOfRows
);
pRsp
->
offset
=
htobe64
(
pRsp
->
offset
);
pRsp
->
useconds
=
htobe64
(
pRsp
->
useconds
);
pRsp
->
compLen
=
htonl
(
pRsp
->
compLen
);
EXPECT_EQ
(
pRsp
->
numOfRows
,
1
);
EXPECT_EQ
(
pRsp
->
offset
,
0
);
EXPECT_EQ
(
pRsp
->
useconds
,
0
);
EXPECT_EQ
(
pRsp
->
completed
,
1
);
EXPECT_EQ
(
pRsp
->
precision
,
TSDB_TIME_PRECISION_MILLI
);
EXPECT_EQ
(
pRsp
->
compressed
,
0
);
EXPECT_EQ
(
pRsp
->
reserved
,
0
);
EXPECT_EQ
(
pRsp
->
compLen
,
0
);
char
*
pData
=
pRsp
->
data
;
int32_t
pos
=
0
;
int32_t
id
=
*
((
int32_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int32_t
);
int32_t
nameLen
=
varDataLen
(
pData
+
pos
);
pos
+=
sizeof
(
VarDataLenT
);
char
*
name
=
(
char
*
)(
pData
+
pos
);
pos
+=
TSDB_CLUSTER_ID_LEN
;
int64_t
create_time
=
*
((
int64_t
*
)(
pData
+
pos
));
pos
+=
sizeof
(
int64_t
);
EXPECT_NE
(
id
,
0
);
EXPECT_EQ
(
nameLen
,
36
);
EXPECT_STRNE
(
name
,
""
);
EXPECT_GT
(
create_time
,
0
);
printf
(
"--- id:%d nameLen:%d name:%s time:%"
PRId64
" ---
\n
"
,
id
,
nameLen
,
name
,
create_time
);
}
}
\ No newline at end of file
source/dnode/mgmt/impl/test/profile/profile.cpp
浏览文件 @
b5e9ba4a
...
...
@@ -25,7 +25,7 @@ class DndTestProfile : public ::testing::Test {
const
char
*
pass
=
"taosdata"
;
const
char
*
path
=
"/tmp/dndTestProfile"
;
const
char
*
fqdn
=
"localhost"
;
uint16_t
port
=
952
7
;
uint16_t
port
=
952
2
;
pServer
=
createServer
(
path
,
fqdn
,
port
);
ASSERT
(
pServer
);
...
...
@@ -79,7 +79,7 @@ TEST_F(DndTestProfile, SConnectMsg_01) {
EXPECT_EQ
(
pRsp
->
epSet
.
inUse
,
0
);
EXPECT_EQ
(
pRsp
->
epSet
.
numOfEps
,
1
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
7
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
2
);
EXPECT_STREQ
(
pRsp
->
epSet
.
fqdn
[
0
],
"localhost"
);
connId
=
pRsp
->
connId
;
...
...
@@ -272,7 +272,7 @@ TEST_F(DndTestProfile, SHeartBeatMsg_01) {
EXPECT_EQ
(
pRsp
->
epSet
.
inUse
,
0
);
EXPECT_EQ
(
pRsp
->
epSet
.
numOfEps
,
1
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
7
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
2
);
EXPECT_STREQ
(
pRsp
->
epSet
.
fqdn
[
0
],
"localhost"
);
}
...
...
@@ -344,7 +344,7 @@ TEST_F(DndTestProfile, SKillConnMsg_01) {
EXPECT_EQ
(
pRsp
->
epSet
.
inUse
,
0
);
EXPECT_EQ
(
pRsp
->
epSet
.
numOfEps
,
1
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
7
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
2
);
EXPECT_STREQ
(
pRsp
->
epSet
.
fqdn
[
0
],
"localhost"
);
connId
=
pRsp
->
connId
;
...
...
@@ -423,7 +423,7 @@ TEST_F(DndTestProfile, SKillQueryMsg_01) {
EXPECT_EQ
(
pRsp
->
epSet
.
inUse
,
0
);
EXPECT_EQ
(
pRsp
->
epSet
.
numOfEps
,
1
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
7
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
2
);
EXPECT_STREQ
(
pRsp
->
epSet
.
fqdn
[
0
],
"localhost"
);
}
}
...
...
@@ -610,7 +610,7 @@ TEST_F(DndTestProfile, SKillStreamMsg_01) {
EXPECT_EQ
(
pRsp
->
epSet
.
inUse
,
0
);
EXPECT_EQ
(
pRsp
->
epSet
.
numOfEps
,
1
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
7
);
EXPECT_EQ
(
pRsp
->
epSet
.
port
[
0
],
952
2
);
EXPECT_STREQ
(
pRsp
->
epSet
.
fqdn
[
0
],
"localhost"
);
}
}
...
...
source/dnode/mgmt/impl/test/show/show.cpp
浏览文件 @
b5e9ba4a
...
...
@@ -25,7 +25,7 @@ class DndTestShow : public ::testing::Test {
const
char
*
pass
=
"taosdata"
;
const
char
*
path
=
"/tmp/dndTestShow"
;
const
char
*
fqdn
=
"localhost"
;
uint16_t
port
=
952
8
;
uint16_t
port
=
952
3
;
pServer
=
createServer
(
path
,
fqdn
,
port
);
ASSERT
(
pServer
);
...
...
source/dnode/mgmt/impl/test/sut/deploy.cpp
浏览文件 @
b5e9ba4a
...
...
@@ -113,14 +113,14 @@ SClient* createClient(const char* user, const char* pass, const char* fqdn, uint
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
label
=
"DND-C"
;
rpcInit
.
label
=
(
char
*
)
"DND-C"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
processClientRsp
;
rpcInit
.
sessions
=
1024
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
idleTime
=
30
*
1000
;
rpcInit
.
user
=
(
char
*
)
user
;
rpcInit
.
ckey
=
"key"
;
rpcInit
.
ckey
=
(
char
*
)
"key"
;
rpcInit
.
parent
=
pClient
;
rpcInit
.
secret
=
(
char
*
)
secretEncrypt
;
rpcInit
.
parent
=
pClient
;
...
...
source/dnode/mgmt/impl/test/sut/deploy.h
浏览文件 @
b5e9ba4a
...
...
@@ -24,6 +24,7 @@
#include "trpc.h"
#include "tthread.h"
#include "ulog.h"
#include "tdataformat.h"
typedef
struct
{
SDnode
*
pDnode
;
...
...
source/dnode/mnode/impl/inc/mndDef.h
浏览文件 @
b5e9ba4a
...
...
@@ -116,7 +116,7 @@ typedef struct STrans {
typedef
struct
SClusterObj
{
int32_t
id
;
char
uid
[
TSDB_CLUSTER_ID_LEN
];
char
name
[
TSDB_CLUSTER_ID_LEN
];
int64_t
createdTime
;
int64_t
updateTime
;
}
SClusterObj
;
...
...
source/dnode/mnode/impl/src/mndCluster.c
浏览文件 @
b5e9ba4a
...
...
@@ -15,11 +15,39 @@
#define _DEFAULT_SOURCE
#include "mndCluster.h"
#include "mndTrans.h"
#include "mndShow.h"
#include "mndTrans.h"
#define SDB_CLUSTER_VER 1
static
SSdbRaw
*
mndClusterActionEncode
(
SClusterObj
*
pCluster
);
static
SSdbRow
*
mndClusterActionDecode
(
SSdbRaw
*
pRaw
);
static
int32_t
mndClusterActionInsert
(
SSdb
*
pSdb
,
SClusterObj
*
pCluster
);
static
int32_t
mndClusterActionDelete
(
SSdb
*
pSdb
,
SClusterObj
*
pCluster
);
static
int32_t
mndClusterActionUpdate
(
SSdb
*
pSdb
,
SClusterObj
*
pSrcCluster
,
SClusterObj
*
pDstCluster
);
static
int32_t
mndCreateDefaultCluster
(
SMnode
*
pMnode
);
static
int32_t
mndGetClusterMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
);
static
int32_t
mndRetrieveClusters
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
);
static
void
mndCancelGetNextCluster
(
SMnode
*
pMnode
,
void
*
pIter
);
int32_t
mndInitCluster
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_CLUSTER
,
.
keyType
=
SDB_KEY_INT32
,
.
deployFp
=
(
SdbDeployFp
)
mndCreateDefaultCluster
,
.
encodeFp
=
(
SdbEncodeFp
)
mndClusterActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndClusterActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndClusterActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndClusterActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndClusterActionDelete
};
mndAddShowMetaHandle
(
pMnode
,
TSDB_MGMT_TABLE_CLUSTER
,
mndGetClusterMeta
);
mndAddShowRetrieveHandle
(
pMnode
,
TSDB_MGMT_TABLE_CLUSTER
,
mndRetrieveClusters
);
mndAddShowFreeIterHandle
(
pMnode
,
TSDB_MGMT_TABLE_CLUSTER
,
mndCancelGetNextCluster
);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
}
void
mndCleanupCluster
(
SMnode
*
pMnode
)
{}
static
SSdbRaw
*
mndClusterActionEncode
(
SClusterObj
*
pCluster
)
{
SSdbRaw
*
pRaw
=
sdbAllocRaw
(
SDB_CLUSTER
,
SDB_CLUSTER_VER
,
sizeof
(
SClusterObj
));
if
(
pRaw
==
NULL
)
return
NULL
;
...
...
@@ -28,7 +56,7 @@ static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
SDB_SET_INT32
(
pRaw
,
dataPos
,
pCluster
->
id
);
SDB_SET_INT64
(
pRaw
,
dataPos
,
pCluster
->
createdTime
)
SDB_SET_INT64
(
pRaw
,
dataPos
,
pCluster
->
updateTime
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pCluster
->
uid
,
TSDB_CLUSTER_ID_LEN
)
SDB_SET_BINARY
(
pRaw
,
dataPos
,
pCluster
->
name
,
TSDB_CLUSTER_ID_LEN
)
return
pRaw
;
}
...
...
@@ -51,7 +79,7 @@ static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT32
(
pRaw
,
pRow
,
dataPos
,
&
pCluster
->
id
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pCluster
->
createdTime
)
SDB_GET_INT64
(
pRaw
,
pRow
,
dataPos
,
&
pCluster
->
updateTime
)
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pCluster
->
uid
,
TSDB_CLUSTER_ID_LEN
)
SDB_GET_BINARY
(
pRaw
,
pRow
,
dataPos
,
pCluster
->
name
,
TSDB_CLUSTER_ID_LEN
)
return
pRow
;
}
...
...
@@ -76,14 +104,14 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
clusterObj
.
createdTime
=
taosGetTimestampMs
();
clusterObj
.
updateTime
=
clusterObj
.
createdTime
;
int32_t
code
=
taosGetSystemUid
(
clusterObj
.
uid
,
TSDB_CLUSTER_ID_LEN
);
int32_t
code
=
taosGetSystemUid
(
clusterObj
.
name
,
TSDB_CLUSTER_ID_LEN
);
if
(
code
!=
0
)
{
strcpy
(
clusterObj
.
uid
,
"tdengine2.0"
);
mError
(
"failed to get
uid from system, set to default val %s"
,
clusterObj
.
uid
);
strcpy
(
clusterObj
.
name
,
"tdengine2.0"
);
mError
(
"failed to get
name from system, set to default val %s"
,
clusterObj
.
name
);
}
else
{
mDebug
(
"cluster:%d,
uid is %s"
,
clusterObj
.
id
,
clusterObj
.
uid
);
mDebug
(
"cluster:%d,
name is %s"
,
clusterObj
.
id
,
clusterObj
.
name
);
}
clusterObj
.
id
=
MurmurHash3_32
(
clusterObj
.
uid
,
TSDB_CLUSTER_ID_LEN
);
clusterObj
.
id
=
MurmurHash3_32
(
clusterObj
.
name
,
TSDB_CLUSTER_ID_LEN
);
clusterObj
.
id
=
abs
(
clusterObj
.
id
);
pMnode
->
clusterId
=
clusterObj
.
id
;
...
...
@@ -95,85 +123,79 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) {
return
sdbWrite
(
pMnode
->
pSdb
,
pRaw
);
}
static
int32_t
mndGetClusterMeta
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
STableMetaMsg
*
pMeta
)
{
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"id"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_CLUSTER_ID_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"name"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
strcpy
(
pMeta
->
tableFname
,
"show cluster"
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
// static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn) {
// int32_t cols = 0;
// SSchema *pSchema = pMeta->schema;
// pShow->bytes[cols] = TSDB_CLUSTER_ID_LEN + VARSTR_HEADER_SIZE;
// pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
// strcpy(pSchema[cols].name, "clusterId");
// pSchema[cols].bytes = htons(pShow->bytes[cols]);
// cols++;
// pShow->bytes[cols] = 8;
// pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
// strcpy(pSchema[cols].name, "create_time");
// pSchema[cols].bytes = htons(pShow->bytes[cols]);
// cols++;
// pMeta->numOfColumns = htons(cols);
// strcpy(pMeta->tableFname, "show cluster");
// pShow->numOfColumns = cols;
// pShow->offset[0] = 0;
// for (int32_t i = 1; i < cols; ++i) {
// pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
// }
// pShow->numOfRows = 1;
// pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
// return 0;
// }
pShow
->
numOfRows
=
1
;
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
// static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn) {
// int32_t numOfRows = 0;
// int32_t cols = 0;
// char * pWrite;
// SClusterObj *pCluster = NULL;
return
0
;
}
// while (numOfRows < rows) {
// pShow->pIter = mnodeGetNextCluster(pShow->pIter, &pCluster);
// if (pCluster == NULL) break;
// cols = 0;
static
int32_t
mndRetrieveClusters
(
SMnodeMsg
*
pMsg
,
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
)
{
SMnode
*
pMnode
=
pMsg
->
pMnode
;
SSdb
*
pSdb
=
pMnode
->
pSdb
;
int32_t
numOfRows
=
0
;
int32_t
cols
=
0
;
char
*
pWrite
;
SClusterObj
*
pCluster
=
NULL
;
// pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
// STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pCluster->uid, TSDB_CLUSTER_ID_LEN
);
// cols++
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
sdbFetch
(
pSdb
,
SDB_CLUSTER
,
pShow
->
pIter
,
(
void
**
)
&
pCluster
);
if
(
pShow
->
pIter
==
NULL
)
break
;
// pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
// *(int64_t *) pWrite = pCluster->createdTime;
// cols++;
cols
=
0
;
// mnodeDecClusterRef(pCluster)
;
// numOfRows++
;
// }
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pCluster
->
id
;
cols
++
;
// mnodeVacuumResult(data, pShow->numOfColumns, numOfRows, rows, pShow);
// pShow->numOfReads += numOfRows;
// return numOfRows;
// }
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pCluster
->
name
,
TSDB_CLUSTER_ID_LEN
);
cols
++
;
// static void mnodeCancelGetNextCluster(void *pIter) {
// sdbFreeIter(tsClusterSdb, pIter)
;
// }
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pCluster
->
createdTime
;
cols
++
;
int32_t
mndInitCluster
(
SMnode
*
pMnode
)
{
SSdbTable
table
=
{.
sdbType
=
SDB_CLUSTER
,
.
keyType
=
SDB_KEY_INT32
,
.
deployFp
=
(
SdbDeployFp
)
mndCreateDefaultCluster
,
.
encodeFp
=
(
SdbEncodeFp
)
mndClusterActionEncode
,
.
decodeFp
=
(
SdbDecodeFp
)
mndClusterActionDecode
,
.
insertFp
=
(
SdbInsertFp
)
mndClusterActionInsert
,
.
updateFp
=
(
SdbUpdateFp
)
mndClusterActionUpdate
,
.
deleteFp
=
(
SdbDeleteFp
)
mndClusterActionDelete
};
sdbRelease
(
pSdb
,
pCluster
);
numOfRows
++
;
}
// mndAddShowMetaHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeGetClusterMeta);
// mndAddShowRetrieveHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeRetrieveClusters);
// mndAddShowFreeIterHandle(TSDB_MGMT_TABLE_CLUSTER, mnodeCancelGetNextCluster);
return
sdbSetTable
(
pMnode
->
pSdb
,
table
);
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
void
mndCleanupCluster
(
SMnode
*
pMnode
)
{}
static
void
mndCancelGetNextCluster
(
SMnode
*
pMnode
,
void
*
pIter
)
{
SSdb
*
pSdb
=
pMnode
->
pSdb
;
sdbCancelFetch
(
pSdb
,
pIter
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录