Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
0137a7dc
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,发现更多精彩内容 >>
You need to sign in or sign up before continuing.
未验证
提交
0137a7dc
编写于
1月 07, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
1月 07, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9667 from taosdata/feature/dnode3
test for create table
上级
a2a7ac1c
5f72c178
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
282 addition
and
94 deletion
+282
-94
include/common/tmsg.h
include/common/tmsg.h
+1
-1
source/dnode/mgmt/impl/src/dndMnode.c
source/dnode/mgmt/impl/src/dndMnode.c
+25
-25
source/dnode/mgmt/impl/src/dndTransport.c
source/dnode/mgmt/impl/src/dndTransport.c
+37
-37
source/dnode/mgmt/impl/test/mnode/qmnode.cpp
source/dnode/mgmt/impl/test/mnode/qmnode.cpp
+157
-0
tests/test/c/create_table.c
tests/test/c/create_table.c
+62
-31
未找到文件。
include/common/tmsg.h
浏览文件 @
0137a7dc
...
...
@@ -996,7 +996,7 @@ typedef struct {
char
encrypt
;
char
secret
[
TSDB_PASSWORD_LEN
];
char
ckey
[
TSDB_PASSWORD_LEN
];
}
SAuth
Msg
,
SAuthRsp
;
}
SAuth
Req
,
SAuthRsp
;
typedef
struct
{
int8_t
finished
;
...
...
source/dnode/mgmt/impl/src/dndMnode.c
浏览文件 @
0137a7dc
...
...
@@ -305,18 +305,18 @@ static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) {
memcpy
(
&
pOption
->
replicas
,
pMgmt
->
replicas
,
sizeof
(
SReplica
)
*
TSDB_MAX_REPLICA
);
}
static
int32_t
dndBuildMnodeOptionFrom
Msg
(
SDnode
*
pDnode
,
SMnodeOpt
*
pOption
,
SDCreateMnodeMsg
*
pMsg
)
{
static
int32_t
dndBuildMnodeOptionFrom
Req
(
SDnode
*
pDnode
,
SMnodeOpt
*
pOption
,
SDCreateMnodeMsg
*
pReq
)
{
dndInitMnodeOption
(
pDnode
,
pOption
);
pOption
->
dnodeId
=
dndGetDnodeId
(
pDnode
);
pOption
->
clusterId
=
dndGetClusterId
(
pDnode
);
pOption
->
replica
=
p
Msg
->
replica
;
pOption
->
replica
=
p
Req
->
replica
;
pOption
->
selfIndex
=
-
1
;
for
(
int32_t
i
=
0
;
i
<
p
Msg
->
replica
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
p
Req
->
replica
;
++
i
)
{
SReplica
*
pReplica
=
&
pOption
->
replicas
[
i
];
pReplica
->
id
=
p
Msg
->
replicas
[
i
].
id
;
pReplica
->
port
=
p
Msg
->
replicas
[
i
].
port
;
memcpy
(
pReplica
->
fqdn
,
p
Msg
->
replicas
[
i
].
fqdn
,
TSDB_FQDN_LEN
);
pReplica
->
id
=
p
Req
->
replicas
[
i
].
id
;
pReplica
->
port
=
p
Req
->
replicas
[
i
].
port
;
memcpy
(
pReplica
->
fqdn
,
p
Req
->
replicas
[
i
].
fqdn
,
TSDB_FQDN_LEN
);
if
(
pReplica
->
id
==
pOption
->
dnodeId
)
{
pOption
->
selfIndex
=
i
;
}
...
...
@@ -423,26 +423,26 @@ static int32_t dndDropMnode(SDnode *pDnode) {
return
0
;
}
static
SDCreateMnodeMsg
*
dndParseCreateMnode
Msg
(
SRpcMsg
*
pRpcMsg
)
{
SDCreateMnodeMsg
*
p
Msg
=
pRpcMsg
->
pCont
;
p
Msg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
for
(
int32_t
i
=
0
;
i
<
p
Msg
->
replica
;
++
i
)
{
p
Msg
->
replicas
[
i
].
id
=
htonl
(
pMsg
->
replicas
[
i
].
id
);
p
Msg
->
replicas
[
i
].
port
=
htons
(
pMsg
->
replicas
[
i
].
port
);
static
SDCreateMnodeMsg
*
dndParseCreateMnode
Req
(
SRpcMsg
*
pReq
)
{
SDCreateMnodeMsg
*
p
Create
=
pReq
->
pCont
;
p
Create
->
dnodeId
=
htonl
(
pCreate
->
dnodeId
);
for
(
int32_t
i
=
0
;
i
<
p
Create
->
replica
;
++
i
)
{
p
Create
->
replicas
[
i
].
id
=
htonl
(
pCreate
->
replicas
[
i
].
id
);
p
Create
->
replicas
[
i
].
port
=
htons
(
pCreate
->
replicas
[
i
].
port
);
}
return
p
Msg
;
return
p
Create
;
}
int32_t
dndProcessCreateMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pR
pcMsg
)
{
SDCreateMnodeMsg
*
p
Msg
=
dndParseCreateMnodeMsg
(
pRpcMsg
);
int32_t
dndProcessCreateMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pR
eq
)
{
SDCreateMnodeMsg
*
p
Create
=
dndParseCreateMnodeReq
(
pReq
);
if
(
p
Msg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
p
Create
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
return
-
1
;
}
else
{
SMnodeOpt
option
=
{
0
};
if
(
dndBuildMnodeOptionFrom
Msg
(
pDnode
,
&
option
,
pMsg
)
!=
0
)
{
if
(
dndBuildMnodeOptionFrom
Req
(
pDnode
,
&
option
,
pCreate
)
!=
0
)
{
return
-
1
;
}
...
...
@@ -450,16 +450,16 @@ int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
}
}
int32_t
dndProcessAlterMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pR
pcMsg
)
{
SDAlterMnodeMsg
*
p
Msg
=
dndParseCreateMnodeMsg
(
pRpcMsg
);
int32_t
dndProcessAlterMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pR
eq
)
{
SDAlterMnodeMsg
*
p
Alter
=
dndParseCreateMnodeReq
(
pReq
);
if
(
p
Msg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
p
Alter
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
return
-
1
;
}
SMnodeOpt
option
=
{
0
};
if
(
dndBuildMnodeOptionFrom
Msg
(
pDnode
,
&
option
,
pMsg
)
!=
0
)
{
if
(
dndBuildMnodeOptionFrom
Req
(
pDnode
,
&
option
,
pAlter
)
!=
0
)
{
return
-
1
;
}
...
...
@@ -470,11 +470,11 @@ int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) {
return
dndWriteMnodeFile
(
pDnode
);
}
int32_t
dndProcessDropMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pR
pcMsg
)
{
SDDropMnodeMsg
*
p
Msg
=
pRpcMsg
->
pCont
;
p
Msg
->
dnodeId
=
htonl
(
pMsg
->
dnodeId
);
int32_t
dndProcessDropMnodeReq
(
SDnode
*
pDnode
,
SRpcMsg
*
pR
eq
)
{
SDDropMnodeMsg
*
p
Drop
=
pReq
->
pCont
;
p
Drop
->
dnodeId
=
htonl
(
pDrop
->
dnodeId
);
if
(
p
Msg
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
if
(
p
Drop
->
dnodeId
!=
dndGetDnodeId
(
pDnode
))
{
terrno
=
TSDB_CODE_DND_MNODE_ID_INVALID
;
return
-
1
;
}
else
{
...
...
source/dnode/mgmt/impl/src/dndTransport.c
浏览文件 @
0137a7dc
...
...
@@ -143,26 +143,26 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
pMgmt
->
msgFp
[
TMSG_INDEX
(
TDMT_VND_SHOW_TABLES_FETCH
)]
=
dndProcessVnodeFetchMsg
;
}
static
void
dndProcessResponse
(
void
*
parent
,
SRpcMsg
*
p
Msg
,
SEpSet
*
pEpSet
)
{
static
void
dndProcessResponse
(
void
*
parent
,
SRpcMsg
*
p
Rsp
,
SEpSet
*
pEpSet
)
{
SDnode
*
pDnode
=
parent
;
STransMgmt
*
pMgmt
=
&
pDnode
->
tmgmt
;
tmsg_t
msgType
=
p
Msg
->
msgType
;
tmsg_t
msgType
=
p
Rsp
->
msgType
;
if
(
dndGetStat
(
pDnode
)
==
DND_STAT_STOPPED
)
{
if
(
p
Msg
==
NULL
||
pMsg
->
pCont
==
NULL
)
return
;
dTrace
(
"RPC %p, rsp:%s is ignored since dnode is stopping"
,
p
Msg
->
handle
,
TMSG_INFO
(
msgType
));
rpcFreeCont
(
p
Msg
->
pCont
);
if
(
p
Rsp
==
NULL
||
pRsp
->
pCont
==
NULL
)
return
;
dTrace
(
"RPC %p, rsp:%s is ignored since dnode is stopping"
,
p
Rsp
->
handle
,
TMSG_INFO
(
msgType
));
rpcFreeCont
(
p
Rsp
->
pCont
);
return
;
}
DndMsgFp
fp
=
pMgmt
->
msgFp
[
TMSG_INDEX
(
msgType
)];
if
(
fp
!=
NULL
)
{
dTrace
(
"RPC %p, rsp:%s will be processed, code:0x%x"
,
p
Msg
->
handle
,
TMSG_INFO
(
msgType
),
pMsg
->
code
&
0XFFFF
);
(
*
fp
)(
pDnode
,
p
Msg
,
pEpSet
);
dTrace
(
"RPC %p, rsp:%s will be processed, code:0x%x"
,
p
Rsp
->
handle
,
TMSG_INFO
(
msgType
),
pRsp
->
code
&
0XFFFF
);
(
*
fp
)(
pDnode
,
p
Rsp
,
pEpSet
);
}
else
{
dError
(
"RPC %p, rsp:%s not processed"
,
p
Msg
->
handle
,
TMSG_INFO
(
msgType
));
rpcFreeCont
(
p
Msg
->
pCont
);
dError
(
"RPC %p, rsp:%s not processed"
,
p
Rsp
->
handle
,
TMSG_INFO
(
msgType
));
rpcFreeCont
(
p
Rsp
->
pCont
);
}
}
...
...
@@ -201,48 +201,48 @@ static void dndCleanupClient(SDnode *pDnode) {
}
}
static
void
dndProcessRequest
(
void
*
param
,
SRpcMsg
*
p
Msg
,
SEpSet
*
pEpSet
)
{
static
void
dndProcessRequest
(
void
*
param
,
SRpcMsg
*
p
Req
,
SEpSet
*
pEpSet
)
{
SDnode
*
pDnode
=
param
;
STransMgmt
*
pMgmt
=
&
pDnode
->
tmgmt
;
tmsg_t
msgType
=
p
Msg
->
msgType
;
tmsg_t
msgType
=
p
Req
->
msgType
;
if
(
msgType
==
TDMT_DND_NETWORK_TEST
)
{
dTrace
(
"RPC %p, network test req, app:%p will be processed, code:0x%x"
,
p
Msg
->
handle
,
pMsg
->
ahandle
,
pMsg
->
code
);
dndProcessStartupReq
(
pDnode
,
p
Msg
);
dTrace
(
"RPC %p, network test req, app:%p will be processed, code:0x%x"
,
p
Req
->
handle
,
pReq
->
ahandle
,
pReq
->
code
);
dndProcessStartupReq
(
pDnode
,
p
Req
);
return
;
}
if
(
dndGetStat
(
pDnode
)
==
DND_STAT_STOPPED
)
{
dError
(
"RPC %p, req:%s app:%p is ignored since dnode exiting"
,
p
Msg
->
handle
,
TMSG_INFO
(
msgType
),
pMsg
->
ahandle
);
SRpcMsg
rspMsg
=
{.
handle
=
p
Msg
->
handle
,
.
code
=
TSDB_CODE_DND_OFFLINE
};
dError
(
"RPC %p, req:%s app:%p is ignored since dnode exiting"
,
p
Req
->
handle
,
TMSG_INFO
(
msgType
),
pReq
->
ahandle
);
SRpcMsg
rspMsg
=
{.
handle
=
p
Req
->
handle
,
.
code
=
TSDB_CODE_DND_OFFLINE
};
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
p
Msg
->
pCont
);
rpcFreeCont
(
p
Req
->
pCont
);
return
;
}
else
if
(
dndGetStat
(
pDnode
)
!=
DND_STAT_RUNNING
)
{
dError
(
"RPC %p, req:%s app:%p is ignored since dnode not running"
,
p
Msg
->
handle
,
TMSG_INFO
(
msgType
),
pMsg
->
ahandle
);
SRpcMsg
rspMsg
=
{.
handle
=
p
Msg
->
handle
,
.
code
=
TSDB_CODE_APP_NOT_READY
};
dError
(
"RPC %p, req:%s app:%p is ignored since dnode not running"
,
p
Req
->
handle
,
TMSG_INFO
(
msgType
),
pReq
->
ahandle
);
SRpcMsg
rspMsg
=
{.
handle
=
p
Req
->
handle
,
.
code
=
TSDB_CODE_APP_NOT_READY
};
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
p
Msg
->
pCont
);
rpcFreeCont
(
p
Req
->
pCont
);
return
;
}
if
(
p
Msg
->
pCont
==
NULL
)
{
dTrace
(
"RPC %p, req:%s app:%p not processed since content is null"
,
p
Msg
->
handle
,
TMSG_INFO
(
msgType
),
p
Msg
->
ahandle
);
SRpcMsg
rspMsg
=
{.
handle
=
p
Msg
->
handle
,
.
code
=
TSDB_CODE_DND_INVALID_MSG_LEN
};
if
(
p
Req
->
pCont
==
NULL
)
{
dTrace
(
"RPC %p, req:%s app:%p not processed since content is null"
,
p
Req
->
handle
,
TMSG_INFO
(
msgType
),
p
Req
->
ahandle
);
SRpcMsg
rspMsg
=
{.
handle
=
p
Req
->
handle
,
.
code
=
TSDB_CODE_DND_INVALID_MSG_LEN
};
rpcSendResponse
(
&
rspMsg
);
return
;
}
DndMsgFp
fp
=
pMgmt
->
msgFp
[
TMSG_INDEX
(
msgType
)];
if
(
fp
!=
NULL
)
{
dTrace
(
"RPC %p, req:%s app:%p will be processed"
,
p
Msg
->
handle
,
TMSG_INFO
(
msgType
),
pMsg
->
ahandle
);
(
*
fp
)(
pDnode
,
p
Msg
,
pEpSet
);
dTrace
(
"RPC %p, req:%s app:%p will be processed"
,
p
Req
->
handle
,
TMSG_INFO
(
msgType
),
pReq
->
ahandle
);
(
*
fp
)(
pDnode
,
p
Req
,
pEpSet
);
}
else
{
dError
(
"RPC %p, req:%s app:%p is not processed since no handle"
,
p
Msg
->
handle
,
TMSG_INFO
(
msgType
),
pMsg
->
ahandle
);
SRpcMsg
rspMsg
=
{.
handle
=
p
Msg
->
handle
,
.
code
=
TSDB_CODE_MSG_NOT_PROCESSED
};
dError
(
"RPC %p, req:%s app:%p is not processed since no handle"
,
p
Req
->
handle
,
TMSG_INFO
(
msgType
),
pReq
->
ahandle
);
SRpcMsg
rspMsg
=
{.
handle
=
p
Req
->
handle
,
.
code
=
TSDB_CODE_MSG_NOT_PROCESSED
};
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
p
Msg
->
pCont
);
rpcFreeCont
(
p
Req
->
pCont
);
}
}
...
...
@@ -254,7 +254,7 @@ static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRp
rpcSendRecv
(
pMgmt
->
clientRpc
,
&
epSet
,
pRpcMsg
,
pRpcRsp
);
}
static
int32_t
dndAuthInternal
Msg
(
SDnode
*
pDnode
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
static
int32_t
dndAuthInternal
Req
(
SDnode
*
pDnode
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
if
(
strcmp
(
user
,
INTERNAL_USER
)
==
0
)
{
// A simple temporary implementation
char
pass
[
TSDB_PASSWORD_LEN
]
=
{
0
};
...
...
@@ -281,7 +281,7 @@ static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *e
static
int32_t
dndRetrieveUserAuthInfo
(
void
*
parent
,
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
SDnode
*
pDnode
=
parent
;
if
(
dndAuthInternal
Msg
(
parent
,
user
,
spi
,
encrypt
,
secret
,
ckey
)
==
0
)
{
if
(
dndAuthInternal
Req
(
parent
,
user
,
spi
,
encrypt
,
secret
,
ckey
)
==
0
)
{
// dTrace("get internal auth success");
return
0
;
}
...
...
@@ -298,10 +298,10 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char
// dDebug("user:%s, send auth msg to other mnodes", user);
SAuth
Msg
*
pMsg
=
rpcMallocCont
(
sizeof
(
SAuthMsg
));
tstrncpy
(
p
Msg
->
user
,
user
,
TSDB_USER_LEN
);
SAuth
Req
*
pReq
=
rpcMallocCont
(
sizeof
(
SAuthReq
));
tstrncpy
(
p
Req
->
user
,
user
,
TSDB_USER_LEN
);
SRpcMsg
rpcMsg
=
{.
pCont
=
p
Msg
,
.
contLen
=
sizeof
(
SAuthMsg
),
.
msgType
=
TDMT_MND_AUTH
};
SRpcMsg
rpcMsg
=
{.
pCont
=
p
Req
,
.
contLen
=
sizeof
(
SAuthReq
),
.
msgType
=
TDMT_MND_AUTH
};
SRpcMsg
rpcRsp
=
{
0
};
dndSendMsgToMnodeRecv
(
pDnode
,
&
rpcMsg
,
&
rpcRsp
);
...
...
@@ -381,19 +381,19 @@ void dndCleanupTrans(SDnode *pDnode) {
dInfo
(
"dnode-transport is cleaned up"
);
}
int32_t
dndSendReqToDnode
(
SDnode
*
pDnode
,
SEpSet
*
pEpSet
,
SRpcMsg
*
p
Msg
)
{
int32_t
dndSendReqToDnode
(
SDnode
*
pDnode
,
SEpSet
*
pEpSet
,
SRpcMsg
*
p
Req
)
{
STransMgmt
*
pMgmt
=
&
pDnode
->
tmgmt
;
if
(
pMgmt
->
clientRpc
==
NULL
)
{
terrno
=
TSDB_CODE_DND_OFFLINE
;
return
-
1
;
}
rpcSendRequest
(
pMgmt
->
clientRpc
,
pEpSet
,
p
Msg
,
NULL
);
rpcSendRequest
(
pMgmt
->
clientRpc
,
pEpSet
,
p
Req
,
NULL
);
return
0
;
}
int32_t
dndSendReqToMnode
(
SDnode
*
pDnode
,
SRpcMsg
*
p
Msg
)
{
int32_t
dndSendReqToMnode
(
SDnode
*
pDnode
,
SRpcMsg
*
p
Req
)
{
SEpSet
epSet
=
{
0
};
dndGetMnodeEpSet
(
pDnode
,
&
epSet
);
return
dndSendReqToDnode
(
pDnode
,
&
epSet
,
p
Msg
);
return
dndSendReqToDnode
(
pDnode
,
&
epSet
,
p
Req
);
}
source/dnode/mgmt/impl/test/mnode/qmnode.cpp
浏览文件 @
0137a7dc
...
...
@@ -24,3 +24,160 @@ class DndTestMnode : public ::testing::Test {
};
Testbase
DndTestMnode
::
test
;
#if 0
TEST_F(DndTestMnode, 01_Create_Mnode) {
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ID_INVALID);
}
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
}
test.Restart();
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
}
}
TEST_F(DndTestMnode, 02_Alter_Mnode) {
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ID_INVALID);
}
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
}
test.Restart();
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ALREADY_DEPLOYED);
}
}
TEST_F(DndTestMnode, 03_Drop_Mnode) {
{
int32_t contLen = sizeof(SDDropMnodeReq);
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(2);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_ID_INVALID);
}
{
int32_t contLen = sizeof(SDDropMnodeReq);
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
int32_t contLen = sizeof(SDDropMnodeReq);
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
}
test.Restart();
{
int32_t contLen = sizeof(SDDropMnodeReq);
SDDropMnodeReq* pReq = (SDDropMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_DROP_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_DND_MNODE_NOT_DEPLOYED);
}
{
int32_t contLen = sizeof(SDCreateMnodeReq);
SDCreateMnodeReq* pReq = (SDCreateMnodeReq*)rpcMallocCont(contLen);
pReq->dnodeId = htonl(1);
SRpcMsg* pRsp = test.SendReq(TDMT_DND_CREATE_MNODE, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
}
#endif
\ No newline at end of file
tests/test/c/create_table.c
浏览文件 @
0137a7dc
...
...
@@ -25,20 +25,21 @@
char
dbName
[
32
]
=
"db"
;
char
stbName
[
64
]
=
"st"
;
int32_t
numOfThreads
=
1
;
int
32_t
numOfTables
=
1
0000
;
int
64_t
numOfTables
=
20
0000
;
int32_t
createTable
=
1
;
int32_t
insertData
=
0
;
int32_t
batchNum
=
10
;
int32_t
batchNum
=
10
0
;
int32_t
numOfVgroups
=
2
;
typedef
struct
{
int
32
_t
tableBeginIndex
;
int
32
_t
tableEndIndex
;
int
64
_t
tableBeginIndex
;
int
64
_t
tableEndIndex
;
int32_t
threadIndex
;
char
dbName
[
32
];
char
stbName
[
64
];
float
createTableSpeed
;
float
insertDataSpeed
;
int64_t
startMs
;
pthread_t
thread
;
}
SThreadInfo
;
...
...
@@ -57,7 +58,7 @@ int32_t main(int32_t argc, char *argv[]) {
pthread_attr_setdetachstate
(
&
thattr
,
PTHREAD_CREATE_JOINABLE
);
SThreadInfo
*
pInfo
=
(
SThreadInfo
*
)
calloc
(
numOfThreads
,
sizeof
(
SThreadInfo
));
int
32
_t
numOfTablesPerThread
=
numOfTables
/
numOfThreads
;
int
64
_t
numOfTablesPerThread
=
numOfTables
/
numOfThreads
;
numOfTables
=
numOfTablesPerThread
*
numOfThreads
;
for
(
int32_t
i
=
0
;
i
<
numOfThreads
;
++
i
)
{
pInfo
[
i
].
tableBeginIndex
=
i
*
numOfTablesPerThread
;
...
...
@@ -83,8 +84,10 @@ int32_t main(int32_t argc, char *argv[]) {
insertDataSpeed
+=
pInfo
[
i
].
insertDataSpeed
;
}
pPrint
(
"%s total %.1f tables/second, threads:%d %s"
,
GREEN
,
createTableSpeed
,
numOfThreads
,
NC
);
pPrint
(
"%s total %.1f rows/second, threads:%d %s"
,
GREEN
,
insertDataSpeed
,
numOfThreads
,
NC
);
pPrint
(
"%s total %"
PRId64
" tables, %.1f tables/second, threads:%d %s"
,
GREEN
,
numOfTables
,
createTableSpeed
,
numOfThreads
,
NC
);
pPrint
(
"%s total %"
PRId64
" tables, %.1f rows/second, threads:%d %s"
,
GREEN
,
numOfTables
,
insertDataSpeed
,
numOfThreads
,
NC
);
pthread_attr_destroy
(
&
thattr
);
free
(
pInfo
);
...
...
@@ -130,6 +133,26 @@ void createDbAndStb() {
taos_close
(
con
);
}
void
printCreateProgress
(
SThreadInfo
*
pInfo
,
int64_t
t
)
{
int64_t
endMs
=
taosGetTimestampMs
();
int64_t
totalTables
=
t
-
pInfo
->
tableBeginIndex
;
float
seconds
=
(
endMs
-
pInfo
->
startMs
)
/
1000
.
0
;
float
speed
=
totalTables
/
seconds
;
pInfo
->
createTableSpeed
=
speed
;
pPrint
(
"thread:%d, %"
PRId64
" tables created, time:%.2f sec, speed:%.1f tables/second, "
,
pInfo
->
threadIndex
,
totalTables
,
seconds
,
speed
);
}
void
printInsertProgress
(
SThreadInfo
*
pInfo
,
int64_t
t
)
{
int64_t
endMs
=
taosGetTimestampMs
();
int64_t
totalTables
=
t
-
pInfo
->
tableBeginIndex
;
float
seconds
=
(
endMs
-
pInfo
->
startMs
)
/
1000
.
0
;
float
speed
=
totalTables
/
seconds
;
pInfo
->
insertDataSpeed
=
speed
;
pPrint
(
"thread:%d, %"
PRId64
" rows inserted, time:%.2f sec, speed:%.1f rows/second, "
,
pInfo
->
threadIndex
,
totalTables
,
seconds
,
speed
);
}
void
*
threadFunc
(
void
*
param
)
{
SThreadInfo
*
pInfo
=
(
SThreadInfo
*
)
param
;
char
*
qstr
=
malloc
(
2000
*
1000
);
...
...
@@ -146,47 +169,55 @@ void *threadFunc(void *param) {
taos_free_result
(
pSql
);
if
(
createTable
)
{
int64_t
startMs
=
taosGetTimestampMs
();
for
(
int
32
_t
t
=
pInfo
->
tableBeginIndex
;
t
<
pInfo
->
tableEndIndex
;
++
t
)
{
int
32
_t
batch
=
(
pInfo
->
tableEndIndex
-
t
);
pInfo
->
startMs
=
taosGetTimestampMs
();
for
(
int
64
_t
t
=
pInfo
->
tableBeginIndex
;
t
<
pInfo
->
tableEndIndex
;
++
t
)
{
int
64
_t
batch
=
(
pInfo
->
tableEndIndex
-
t
);
batch
=
MIN
(
batch
,
batchNum
);
int32_t
len
=
sprintf
(
qstr
,
"create table"
);
for
(
int32_t
i
=
0
;
i
<
batch
;
++
i
)
{
len
+=
sprintf
(
qstr
+
len
,
" t%
d using %s tags(%d
)"
,
t
+
i
,
stbName
,
t
+
i
);
len
+=
sprintf
(
qstr
+
len
,
" t%
"
PRId64
" using %s tags(%"
PRId64
"
)"
,
t
+
i
,
stbName
,
t
+
i
);
}
TAOS_RES
*
pSql
=
taos_query
(
con
,
qstr
);
code
=
taos_errno
(
pSql
);
if
(
code
!=
0
)
{
pError
(
"failed to create table t%
d
, reason:%s"
,
t
,
tstrerror
(
code
));
pError
(
"failed to create table t%
"
PRId64
"
, reason:%s"
,
t
,
tstrerror
(
code
));
}
taos_free_result
(
pSql
);
if
(
t
%
100000
==
0
)
{
printCreateProgress
(
pInfo
,
t
);
}
t
+=
(
batch
-
1
);
}
int64_t
endMs
=
taosGetTimestampMs
();
int32_t
totalTables
=
pInfo
->
tableEndIndex
-
pInfo
->
tableBeginIndex
;
float
seconds
=
(
endMs
-
startMs
)
/
1000
.
0
;
float
speed
=
totalTables
/
seconds
;
pInfo
->
createTableSpeed
=
speed
;
pPrint
(
"thread:%d, time:%.2f sec, speed:%.1f tables/second, "
,
pInfo
->
threadIndex
,
seconds
,
speed
);
printCreateProgress
(
pInfo
,
pInfo
->
tableEndIndex
);
}
if
(
insertData
)
{
int64_t
startMs
=
taosGetTimestampMs
();
for
(
int32_t
t
=
pInfo
->
tableBeginIndex
;
t
<
pInfo
->
tableEndIndex
;
++
t
)
{
sprintf
(
qstr
,
"insert into %s%d values(now, 1)"
,
stbName
,
t
);
pInfo
->
startMs
=
taosGetTimestampMs
();
for
(
int64_t
t
=
pInfo
->
tableBeginIndex
;
t
<
pInfo
->
tableEndIndex
;
++
t
)
{
int64_t
batch
=
(
pInfo
->
tableEndIndex
-
t
);
batch
=
MIN
(
batch
,
batchNum
);
int32_t
len
=
sprintf
(
qstr
,
"insert into"
);
for
(
int32_t
i
=
0
;
i
<
batch
;
++
i
)
{
len
+=
sprintf
(
qstr
+
len
,
" t%"
PRId64
" values(now, %"
PRId64
")"
,
t
+
i
,
t
+
i
);
}
TAOS_RES
*
pSql
=
taos_query
(
con
,
qstr
);
code
=
taos_errno
(
pSql
);
if
(
code
!=
0
)
{
pError
(
"failed to
create table %s%d, reason:%s"
,
stbName
,
t
,
tstrerror
(
code
));
pError
(
"failed to
insert table t%"
PRId64
", reason:%s"
,
t
,
tstrerror
(
code
));
}
taos_free_result
(
pSql
);
if
(
t
%
100000
==
0
)
{
printInsertProgress
(
pInfo
,
t
);
}
t
+=
(
batch
-
1
);
}
int64_t
endMs
=
taosGetTimestampMs
();
int32_t
totalTables
=
pInfo
->
tableEndIndex
-
pInfo
->
tableBeginIndex
;
float
seconds
=
(
endMs
-
startMs
)
/
1000
.
0
;
float
speed
=
totalTables
/
seconds
;
pInfo
->
insertDataSpeed
=
speed
;
pPrint
(
"thread:%d, time:%.2f sec, speed:%.1f rows/second, "
,
pInfo
->
threadIndex
,
seconds
,
speed
);
printInsertProgress
(
pInfo
,
pInfo
->
tableEndIndex
);
}
taos_close
(
con
);
...
...
@@ -207,7 +238,7 @@ void printHelp() {
printf
(
"%s%s
\n
"
,
indent
,
"-t"
);
printf
(
"%s%s%s%d
\n
"
,
indent
,
indent
,
"numOfThreads, default is "
,
numOfThreads
);
printf
(
"%s%s
\n
"
,
indent
,
"-n"
);
printf
(
"%s%s%s%
d
\n
"
,
indent
,
indent
,
"numOfTables, default is "
,
numOfTables
);
printf
(
"%s%s%s%
"
PRId64
"
\n
"
,
indent
,
indent
,
"numOfTables, default is "
,
numOfTables
);
printf
(
"%s%s
\n
"
,
indent
,
"-v"
);
printf
(
"%s%s%s%d
\n
"
,
indent
,
indent
,
"numOfVgroups, default is "
,
numOfVgroups
);
printf
(
"%s%s
\n
"
,
indent
,
"-a"
);
...
...
@@ -234,7 +265,7 @@ void parseArgument(int32_t argc, char *argv[]) {
}
else
if
(
strcmp
(
argv
[
i
],
"-t"
)
==
0
)
{
numOfThreads
=
atoi
(
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-n"
)
==
0
)
{
numOfTables
=
ato
i
(
argv
[
++
i
]);
numOfTables
=
ato
ll
(
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-n"
)
==
0
)
{
numOfVgroups
=
atoi
(
argv
[
++
i
]);
}
else
if
(
strcmp
(
argv
[
i
],
"-a"
)
==
0
)
{
...
...
@@ -250,7 +281,7 @@ void parseArgument(int32_t argc, char *argv[]) {
pPrint
(
"%s dbName:%s %s"
,
GREEN
,
dbName
,
NC
);
pPrint
(
"%s stbName:%s %s"
,
GREEN
,
stbName
,
NC
);
pPrint
(
"%s configDir:%s %s"
,
GREEN
,
configDir
,
NC
);
pPrint
(
"%s numOfTables:%
d
%s"
,
GREEN
,
numOfTables
,
NC
);
pPrint
(
"%s numOfTables:%
"
PRId64
"
%s"
,
GREEN
,
numOfTables
,
NC
);
pPrint
(
"%s numOfThreads:%d %s"
,
GREEN
,
numOfThreads
,
NC
);
pPrint
(
"%s numOfVgroups:%d %s"
,
GREEN
,
numOfVgroups
,
NC
);
pPrint
(
"%s createTable:%d %s"
,
GREEN
,
createTable
,
NC
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录