Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b8fc28fb
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看板
提交
b8fc28fb
编写于
3月 08, 2020
作者:
H
hjxilinx
浏览文件
操作
浏览文件
下载
差异文件
Merge branch '2.0' into liaohj_2
上级
9eae52e1
7afea209
变更
29
隐藏空白更改
内联
并排
Showing
29 changed file
with
1315 addition
and
982 deletion
+1315
-982
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+1
-1
src/client/src/tscAsync.c
src/client/src/tscAsync.c
+0
-1
src/client/src/tscServer.c
src/client/src/tscServer.c
+62
-52
src/client/src/tscSystem.c
src/client/src/tscSystem.c
+1
-1
src/dnode/CMakeLists.txt
src/dnode/CMakeLists.txt
+2
-2
src/dnode/inc/dnodeMClient.h
src/dnode/inc/dnodeMClient.h
+30
-0
src/dnode/inc/dnodeMgmt.h
src/dnode/inc/dnodeMgmt.h
+11
-12
src/dnode/inc/dnodeMnode.h
src/dnode/inc/dnodeMnode.h
+30
-0
src/dnode/inc/dnodeModule.h
src/dnode/inc/dnodeModule.h
+2
-8
src/dnode/inc/dnodeRead.h
src/dnode/inc/dnodeRead.h
+6
-25
src/dnode/inc/dnodeShell.h
src/dnode/inc/dnodeShell.h
+1
-19
src/dnode/inc/dnodeSystem.h
src/dnode/inc/dnodeSystem.h
+1
-20
src/dnode/inc/dnodeWrite.h
src/dnode/inc/dnodeWrite.h
+5
-34
src/dnode/src/dnodeMClient.c
src/dnode/src/dnodeMClient.c
+72
-0
src/dnode/src/dnodeMgmt.c
src/dnode/src/dnodeMgmt.c
+159
-267
src/dnode/src/dnodeMnode.c
src/dnode/src/dnodeMnode.c
+87
-0
src/dnode/src/dnodeRead.c
src/dnode/src/dnodeRead.c
+174
-34
src/dnode/src/dnodeShell.c
src/dnode/src/dnodeShell.c
+33
-159
src/dnode/src/dnodeSystem.c
src/dnode/src/dnodeSystem.c
+9
-16
src/dnode/src/dnodeWrite.c
src/dnode/src/dnodeWrite.c
+220
-56
src/mnode/inc/mgmtShell.h
src/mnode/inc/mgmtShell.h
+0
-2
src/mnode/src/mgmtDnodeInt.c
src/mnode/src/mgmtDnodeInt.c
+15
-5
src/mnode/src/mgmtShell.c
src/mnode/src/mgmtShell.c
+360
-242
src/mnode/src/mgmtTable.c
src/mnode/src/mgmtTable.c
+1
-1
src/rpc/src/rpcMain.c
src/rpc/src/rpcMain.c
+1
-1
src/vnode/CMakeLists.txt
src/vnode/CMakeLists.txt
+6
-8
src/vnode/common/CMakeLists.txt
src/vnode/common/CMakeLists.txt
+11
-6
src/vnode/common/src/vnodePeer.c_del
src/vnode/common/src/vnodePeer.c_del
+0
-0
src/vnode/tsdb/CMakeLists.txt
src/vnode/tsdb/CMakeLists.txt
+15
-10
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
b8fc28fb
...
...
@@ -380,7 +380,7 @@ int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion);
void
tscInitMsgs
();
extern
int
(
*
tscBuildMsg
[
TSDB_SQL_MAX
])(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
);
void
tscProcessMsgFromServer
(
char
type
,
void
*
pCont
,
int
contLen
,
void
*
ahandle
,
int32_t
code
);
void
tscProcessMsgFromServer
(
SRpcMsg
*
rpcMsg
);
int
tscProcessSql
(
SSqlObj
*
pSql
);
void
tscAsyncInsertMultiVnodesProxy
(
void
*
param
,
TAOS_RES
*
tres
,
int
numOfRows
);
...
...
src/client/src/tscAsync.c
浏览文件 @
b8fc28fb
...
...
@@ -324,7 +324,6 @@ void tscProcessFetchRow(SSchedMsg *pMsg) {
void
tscProcessAsyncRes
(
SSchedMsg
*
pMsg
)
{
SSqlObj
*
pSql
=
(
SSqlObj
*
)
pMsg
->
ahandle
;
STscObj
*
pTscObj
=
pSql
->
pTscObj
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
SSqlRes
*
pRes
=
&
pSql
->
res
;
...
...
src/client/src/tscServer.c
浏览文件 @
b8fc28fb
...
...
@@ -98,6 +98,7 @@ void tscSetMgmtIpList(SRpcIpSet *pIpList) {
* The retry will not be executed since only *two* retry is allowed in case of single management node in the cluster.
* Therefore, we need to multiply the retry times by factor of 2 to fix this problem.
*/
UNUSED_FUNC
static
int32_t
tscGetMgmtConnMaxRetryTimes
()
{
int32_t
factor
=
2
;
return
tscMgmtIpList
.
numOfIps
*
factor
;
...
...
@@ -187,24 +188,35 @@ int tscSendMsgToServer(SSqlObj *pSql) {
pSql
->
ipList
->
port
=
tsVnodeShellPort
;
tscPrint
(
"%p msg:%s is sent to server %d"
,
pSql
,
taosMsg
[
pSql
->
cmd
.
msgType
],
pSql
->
ipList
->
port
);
memcpy
(
pMsg
,
pSql
->
cmd
.
payload
+
tsRpcHeadSize
,
pSql
->
cmd
.
payloadLen
);
SRpcMsg
msg
=
{.
msgType
=
pCmd
->
msgType
,
.
contLen
=
pCmd
->
payloadLen
,
.
pCont
=
pMsg
,
.
handle
=
pSql
};
rpcSendRequest
(
pVnodeConn
,
pSql
->
ipList
,
&
msg
);
SRpcMsg
rpcMsg
=
{
.
msgType
=
pSql
->
cmd
.
msgType
,
.
pCont
=
pMsg
,
.
contLen
=
pSql
->
cmd
.
payloadLen
,
.
handle
=
pSql
,
.
code
=
0
};
rpcSendRequest
(
pVnodeConn
,
pSql
->
ipList
,
&
rpcMsg
);
}
else
{
pSql
->
ipList
->
port
=
tsMgmtShellPort
;
tscPrint
(
"%p msg:%s is sent to server %d"
,
pSql
,
taosMsg
[
pSql
->
cmd
.
msgType
],
pSql
->
ipList
->
port
);
memcpy
(
pMsg
,
pSql
->
cmd
.
payload
,
pSql
->
cmd
.
payloadLen
);
SRpcMsg
msg
=
{.
msgType
=
pCmd
->
msgType
,
.
contLen
=
pCmd
->
payloadLen
,
.
pCont
=
pMsg
,
.
handle
=
pSql
};
rpcSendRequest
(
pTscMgmtConn
,
pSql
->
ipList
,
&
msg
);
SRpcMsg
rpcMsg
=
{
.
msgType
=
pSql
->
cmd
.
msgType
,
.
pCont
=
pMsg
,
.
contLen
=
pSql
->
cmd
.
payloadLen
,
.
handle
=
pSql
,
.
code
=
0
};
rpcSendRequest
(
pTscMgmtConn
,
pSql
->
ipList
,
&
rpcMsg
);
}
return
TSDB_CODE_SUCCESS
;
}
void
tscProcessMsgFromServer
(
char
type
,
void
*
pCont
,
int
contLen
,
void
*
ahandle
,
int32_t
code
)
{
tscPrint
(
"response:%s is received, len:%d error:%s"
,
taosMsg
[
(
uint8_t
)
type
],
contLen
,
tstrerror
(
code
));
SSqlObj
*
pSql
=
(
SSqlObj
*
)
a
handle
;
void
tscProcessMsgFromServer
(
SRpcMsg
*
rpcMsg
)
{
tscPrint
(
"response:%s is received, len:%d error:%s"
,
taosMsg
[
rpcMsg
->
msgType
],
rpcMsg
->
contLen
,
tstrerror
(
rpcMsg
->
code
));
SSqlObj
*
pSql
=
(
SSqlObj
*
)
rpcMsg
->
handle
;
if
(
pSql
==
NULL
||
pSql
->
signature
!=
pSql
)
{
tscError
(
"%p sql is already released, signature:%p"
,
pSql
,
pSql
->
signature
);
return
;
...
...
@@ -213,24 +225,24 @@ void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle,
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
tscTrace
(
"%p msg:%p is received from server"
,
pSql
,
pCont
);
tscTrace
(
"%p msg:%p is received from server"
,
pSql
,
rpcMsg
->
pCont
);
if
(
pSql
->
freed
||
pObj
->
signature
!=
pObj
)
{
tscTrace
(
"%p sql is already released or DB connection is closed, freed:%d pObj:%p signature:%p"
,
pSql
,
pSql
->
freed
,
pObj
,
pObj
->
signature
);
tscFreeSqlObj
(
pSql
);
rpcFreeCont
(
pCont
);
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
}
if
(
pCont
==
NULL
)
{
code
=
TSDB_CODE_NETWORK_UNAVAIL
;
if
(
rpcMsg
->
pCont
==
NULL
)
{
rpcMsg
->
code
=
TSDB_CODE_NETWORK_UNAVAIL
;
}
else
{
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
pCmd
,
pCmd
->
clauseIndex
,
0
);
if
(
code
==
TSDB_CODE_NOT_ACTIVE_TABLE
||
code
==
TSDB_CODE_INVALID_TABLE_ID
||
code
==
TSDB_CODE_INVALID_VNODE_ID
||
code
==
TSDB_CODE_NOT_ACTIVE_VNODE
||
code
==
TSDB_CODE_NETWORK_UNAVAIL
||
code
==
TSDB_CODE_NOT_ACTIVE_SESSION
||
code
==
TSDB_CODE_TABLE_ID_MISMATCH
)
{
if
(
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_TABLE
||
rpcMsg
->
code
==
TSDB_CODE_INVALID_TABLE_ID
||
rpcMsg
->
code
==
TSDB_CODE_INVALID_VNODE_ID
||
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_VNODE
||
rpcMsg
->
code
==
TSDB_CODE_NETWORK_UNAVAIL
||
rpcMsg
->
code
==
TSDB_CODE_NOT_ACTIVE_SESSION
||
rpcMsg
->
code
==
TSDB_CODE_TABLE_ID_MISMATCH
)
{
/*
* not_active_table: 1. the virtual node may fail to create table, since the procedure of create table is asynchronized,
* the virtual node may have not create table till now, so try again by using the new metermeta.
...
...
@@ -242,24 +254,24 @@ void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle,
* not_active_session: db has been move to other node, the vnode does not exist on this dnode anymore.
*/
if
(
pCmd
->
command
==
TSDB_SQL_CONNECT
)
{
code
=
TSDB_CODE_NETWORK_UNAVAIL
;
rpcFreeCont
(
pCont
);
rpcMsg
->
code
=
TSDB_CODE_NETWORK_UNAVAIL
;
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
}
else
if
(
pCmd
->
command
==
TSDB_SQL_HB
)
{
code
=
TSDB_CODE_NOT_READY
;
rpcFreeCont
(
pCont
);
rpcMsg
->
code
=
TSDB_CODE_NOT_READY
;
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
}
else
{
tscTrace
(
"%p it shall renew meter meta, code:%d"
,
pSql
,
code
);
tscTrace
(
"%p it shall renew meter meta, code:%d"
,
pSql
,
rpcMsg
->
code
);
pSql
->
maxRetry
=
TSDB_VNODES_SUPPORT
*
2
;
pSql
->
res
.
code
=
(
uint8_t
)
code
;
// keep the previous error code
pSql
->
res
.
code
=
rpcMsg
->
code
;
// keep the previous error code
code
=
tscRenewMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
);
rpcMsg
->
code
=
tscRenewMeterMeta
(
pSql
,
pMeterMetaInfo
->
name
);
if
(
pMeterMetaInfo
->
pMeterMeta
)
{
tscSendMsgToServer
(
pSql
);
rpcFreeCont
(
pCont
);
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
}
}
...
...
@@ -272,16 +284,16 @@ void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle,
pRes
->
rspLen
=
0
;
if
(
pRes
->
code
!=
TSDB_CODE_QUERY_CANCELLED
)
{
pRes
->
code
=
(
code
!=
TSDB_CODE_SUCCESS
)
?
code
:
TSDB_CODE_NETWORK_UNAVAIL
;
pRes
->
code
=
(
rpcMsg
->
code
!=
TSDB_CODE_SUCCESS
)
?
rpcMsg
->
code
:
TSDB_CODE_NETWORK_UNAVAIL
;
}
else
{
tscTrace
(
"%p query is cancelled, code:%d"
,
pSql
,
pRes
->
code
);
}
if
(
pRes
->
code
!=
TSDB_CODE_QUERY_CANCELLED
)
{
assert
(
t
ype
==
pCmd
->
msgType
+
1
);
pRes
->
code
=
(
int32_t
)
code
;
pRes
->
rspType
=
t
ype
;
pRes
->
rspLen
=
contLen
;
assert
(
rpcMsg
->
msgT
ype
==
pCmd
->
msgType
+
1
);
pRes
->
code
=
(
int32_t
)
rpcMsg
->
code
;
pRes
->
rspType
=
rpcMsg
->
msgT
ype
;
pRes
->
rspLen
=
rpcMsg
->
contLen
;
char
*
tmp
=
(
char
*
)
realloc
(
pRes
->
pRsp
,
pRes
->
rspLen
);
if
(
tmp
==
NULL
)
{
...
...
@@ -289,7 +301,7 @@ void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle,
}
else
{
pRes
->
pRsp
=
tmp
;
if
(
pRes
->
rspLen
)
{
memcpy
(
pRes
->
pRsp
,
pCont
,
pRes
->
rspLen
);
memcpy
(
pRes
->
pRsp
,
rpcMsg
->
pCont
,
pRes
->
rspLen
);
}
}
...
...
@@ -302,8 +314,8 @@ void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle,
* There is not response callback function for submit response.
* The actual inserted number of points is the first number.
*/
if
(
t
ype
==
TSDB_MSG_TYPE_SUBMIT_RSP
)
{
SShellSubmitRspMsg
*
pMsg
=
pRes
->
pRsp
;
if
(
rpcMsg
->
msgT
ype
==
TSDB_MSG_TYPE_SUBMIT_RSP
)
{
SShellSubmitRspMsg
*
pMsg
=
(
SShellSubmitRspMsg
*
)
pRes
->
pRsp
;
pMsg
->
code
=
htonl
(
pMsg
->
code
);
pMsg
->
numOfRows
=
htonl
(
pMsg
->
numOfRows
);
pMsg
->
affectedRows
=
htonl
(
pMsg
->
affectedRows
);
...
...
@@ -322,14 +334,14 @@ void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle,
tsem_post
(
&
pSql
->
rspSem
);
}
else
{
if
(
pRes
->
code
==
TSDB_CODE_SUCCESS
&&
tscProcessMsgRsp
[
pCmd
->
command
])
code
=
(
*
tscProcessMsgRsp
[
pCmd
->
command
])(
pSql
);
rpcMsg
->
code
=
(
*
tscProcessMsgRsp
[
pCmd
->
command
])(
pSql
);
if
(
code
!=
TSDB_CODE_ACTION_IN_PROGRESS
)
{
if
(
rpcMsg
->
code
!=
TSDB_CODE_ACTION_IN_PROGRESS
)
{
int
command
=
pCmd
->
command
;
void
*
taosres
=
tscKeepConn
[
command
]
?
pSql
:
NULL
;
code
=
pRes
->
code
?
-
pRes
->
code
:
pRes
->
numOfRows
;
rpcMsg
->
code
=
pRes
->
code
?
-
pRes
->
code
:
pRes
->
numOfRows
;
tscTrace
(
"%p Async SQL result:%d res:%p"
,
pSql
,
code
,
taosres
);
tscTrace
(
"%p Async SQL result:%d res:%p"
,
pSql
,
rpcMsg
->
code
,
taosres
);
/*
* Whether to free sqlObj or not should be decided before call the user defined function, since this SqlObj
...
...
@@ -341,9 +353,9 @@ void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle,
*/
bool
shouldFree
=
tscShouldFreeAsyncSqlObj
(
pSql
);
if
(
command
==
TSDB_SQL_INSERT
)
{
// handle multi-vnode insertion situation
(
*
pSql
->
fp
)(
pSql
,
taosres
,
code
);
(
*
pSql
->
fp
)(
pSql
,
taosres
,
rpcMsg
->
code
);
}
else
{
(
*
pSql
->
fp
)(
pSql
->
param
,
taosres
,
code
);
(
*
pSql
->
fp
)(
pSql
->
param
,
taosres
,
rpcMsg
->
code
);
}
if
(
shouldFree
)
{
...
...
@@ -359,7 +371,7 @@ void tscProcessMsgFromServer(char type, void *pCont, int contLen, void *ahandle,
}
}
rpcFreeCont
(
pCont
);
rpcFreeCont
(
rpcMsg
->
pCont
);
}
static
SSqlObj
*
tscCreateSqlObjForSubquery
(
SSqlObj
*
pSql
,
SRetrieveSupport
*
trsupport
,
SSqlObj
*
prevSqlObj
);
...
...
@@ -1212,7 +1224,7 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pStart
=
pSql
->
cmd
.
payload
+
tsRpcHeadSize
;
pMsg
=
pStart
;
SRetrieveTableMsg
*
pRetrieveMsg
=
(
S
ShellSubmit
Msg
*
)
pMsg
;
SRetrieveTableMsg
*
pRetrieveMsg
=
(
S
RetrieveTable
Msg
*
)
pMsg
;
pRetrieveMsg
->
qhandle
=
htobe64
(
pSql
->
res
.
qhandle
);
pMsg
+=
sizeof
(
pSql
->
res
.
qhandle
);
...
...
@@ -1227,13 +1239,13 @@ int tscBuildRetrieveMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
}
void
tscUpdateVnodeInSubmitMsg
(
SSqlObj
*
pSql
,
char
*
buf
)
{
SShellSubmitMsg
*
pShellMsg
;
char
*
pMsg
;
SMeterMetaInfo
*
pMeterMetaInfo
=
tscGetMeterMetaInfo
(
&
pSql
->
cmd
,
pSql
->
cmd
.
clauseIndex
,
0
);
//
SShellSubmitMsg *pShellMsg;
//
char * pMsg;
//
SMeterMetaInfo * pMeterMetaInfo = tscGetMeterMetaInfo(&pSql->cmd, pSql->cmd.clauseIndex, 0);
STableMeta
*
pMeterMeta
=
pMeterMetaInfo
->
pMeterMeta
;
//
STableMeta *pMeterMeta = pMeterMetaInfo->pMeterMeta;
pMsg
=
buf
+
tsRpcHeadSize
;
//
pMsg = buf + tsRpcHeadSize;
//TODO set iplist
//pShellMsg = (SShellSubmitMsg *)pMsg;
...
...
@@ -2005,7 +2017,7 @@ int tscBuildCreateTableMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
memcpy
(
pMsg
,
&
pInfo
->
pCreateTableInfo
->
usingInfo
.
tagdata
,
sizeof
(
STagData
));
pMsg
+=
sizeof
(
STagData
);
}
else
{
// create (super) table
pSchema
=
pCreateTableMsg
->
schema
;
pSchema
=
(
SSchema
*
)
pCreateTableMsg
->
schema
;
for
(
int
i
=
0
;
i
<
pCmd
->
numOfCols
+
pCmd
->
count
;
++
i
)
{
TAOS_FIELD
*
pField
=
tscFieldInfoGetField
(
pQueryInfo
,
i
);
...
...
@@ -2045,7 +2057,7 @@ int tscEstimateAlterTableMsgLength(SSqlCmd *pCmd) {
int
tscBuildAlterTableMsg
(
SSqlObj
*
pSql
,
SSqlInfo
*
pInfo
)
{
SAlterTableMsg
*
pAlterTableMsg
;
char
*
pMsg
,
*
pStart
;
char
*
pMsg
;
int
msgLen
=
0
;
int
size
=
0
;
...
...
@@ -2563,7 +2575,6 @@ int tscBuildHeartBeatMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
int
tscProcessMeterMetaRsp
(
SSqlObj
*
pSql
)
{
STableMeta
*
pMeta
;
SSchema
*
pSchema
;
uint8_t
ieType
;
pMeta
=
(
STableMeta
*
)
pSql
->
res
.
pRsp
;
...
...
@@ -2667,7 +2678,7 @@ int tscProcessMultiMeterMetaRsp(SSqlObj *pSql) {
for
(
i
=
0
;
i
<
totalNum
;
i
++
)
{
SMultiTableMeta
*
pMultiMeta
=
(
SMultiTableMeta
*
)
rsp
;
STableMeta
*
pMeta
=
&
pMultiMeta
->
metas
;
STableMeta
*
pMeta
=
pMultiMeta
->
metas
;
pMeta
->
sid
=
htonl
(
pMeta
->
sid
);
pMeta
->
sversion
=
htons
(
pMeta
->
sversion
);
...
...
@@ -3029,7 +3040,7 @@ int tscProcessAlterDbMsgRsp(SSqlObj *pSql) {
int
tscProcessQueryRsp
(
SSqlObj
*
pSql
)
{
SSqlRes
*
pRes
=
&
pSql
->
res
;
SQueryTableRsp
*
pQuery
=
(
S
Retrieve
TableRsp
*
)
pRes
->
pRsp
;
SQueryTableRsp
*
pQuery
=
(
S
Query
TableRsp
*
)
pRes
->
pRsp
;
pQuery
->
qhandle
=
htobe64
(
pQuery
->
qhandle
);
pRes
->
qhandle
=
pQuery
->
qhandle
;
...
...
@@ -3041,7 +3052,6 @@ int tscProcessQueryRsp(SSqlObj *pSql) {
int
tscProcessRetrieveRspFromVnode
(
SSqlObj
*
pSql
)
{
SSqlRes
*
pRes
=
&
pSql
->
res
;
SSqlCmd
*
pCmd
=
&
pSql
->
cmd
;
STscObj
*
pObj
=
pSql
->
pTscObj
;
SRetrieveTableRsp
*
pRetrieve
=
(
SRetrieveTableRsp
*
)
pRes
->
pRsp
;
...
...
src/client/src/tscSystem.c
浏览文件 @
b8fc28fb
...
...
@@ -72,7 +72,7 @@ int32_t tscInitRpc(const char *user, const char *secret) {
rpcInit
.
cfp
=
tscProcessMsgFromServer
;
rpcInit
.
sessions
=
tsMaxVnodeConnections
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
user
=
user
;
rpcInit
.
user
=
(
char
*
)
user
;
rpcInit
.
ckey
=
"key"
;
rpcInit
.
secret
=
secretEncrypt
;
...
...
src/dnode/CMakeLists.txt
浏览文件 @
b8fc28fb
...
...
@@ -11,7 +11,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
AUX_SOURCE_DIRECTORY
(
src SRC
)
ADD_EXECUTABLE
(
taosd
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
taosd mnode sdb taos_static monitor http
tsdb
)
TARGET_LINK_LIBRARIES
(
taosd mnode sdb taos_static monitor http
)
#IF (TD_CLUSTER)
# TARGET_LINK_LIBRARIES(taosd dcluster)
...
...
@@ -24,7 +24,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM))
COMMAND echo
"make test directory"
DEPENDS taosd
COMMAND
${
CMAKE_COMMAND
}
-E make_directory
${
TD_TESTS_OUTPUT_DIR
}
/cfg/
COMMAND
${
CMAKE_COMMAND
}
-E make_directory
${
TD_TESTS_OUTPUT_DIR
}
/log/
COMMAND
${
CMAKE_COMMAND
}
-E make_directory
F
${
TD_TESTS_OUTPUT_DIR
}
/log/
COMMAND
${
CMAKE_COMMAND
}
-E make_directory
${
TD_TESTS_OUTPUT_DIR
}
/data/
COMMAND
${
CMAKE_COMMAND
}
-E echo dataDir
${
TD_TESTS_OUTPUT_DIR
}
/data >
${
TD_TESTS_OUTPUT_DIR
}
/cfg/taos.cfg
COMMAND
${
CMAKE_COMMAND
}
-E echo logDir
${
TD_TESTS_OUTPUT_DIR
}
/log >>
${
TD_TESTS_OUTPUT_DIR
}
/cfg/taos.cfg
...
...
src/dnode/inc/dnode
VnodeMgm
t.h
→
src/dnode/inc/dnode
MClien
t.h
浏览文件 @
b8fc28fb
...
...
@@ -13,62 +13,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_DNODE_
VNODE_MGM
T_H
#define TDENGINE_DNODE_
VNODE_MGM
T_H
#ifndef TDENGINE_DNODE_
MCLIEN
T_H
#define TDENGINE_DNODE_
MCLIEN
T_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include <stdint.h>
#include <stdbool.h>
#include "taosdef.h"
#include "taosmsg.h"
#include "tstatus.h"
/*
* Open all Vnodes in the local data directory
*/
int32_t
dnodeOpenVnodes
();
/*
* Close all Vnodes that have been created and opened
*/
int32_t
dnodeCleanupVnodes
();
/*
* Check if vnode already exists
*/
bool
dnodeCheckVnodeExist
(
int32_t
vid
);
/*
* Create vnode with specified configuration and open it
* if exist, config it
*/
int32_t
dnodeCreateVnode
(
SCreateVnodeMsg
*
pVnode
);
/*
* Remove vnode from local repository
*/
int32_t
dnodeDropVnode
(
int32_t
vnode
);
/*
* Get the vnode object that has been opened
*/
//tsdb_repo_t* dnodeGetVnode(int vid);
void
*
dnodeGetVnode
(
int32_t
vnode
);
int32_t
dnodeGetVnodesNum
();
/*
* get the status of vnode
*/
EVnodeStatus
dnodeGetVnodeStatus
(
int32_t
vnode
);
/*
* Check if vnode already exists, and table exist in this vnode
*/
bool
dnodeCheckTableExist
(
int32_t
vnode
,
int32_t
sid
,
int64_t
uid
);
int32_t
dnodeInitMClient
();
void
dnodeCleanupMClient
();
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeMgmt.h
浏览文件 @
b8fc28fb
...
...
@@ -20,18 +20,17 @@
extern
"C"
{
#endif
#include <stdint.h>
#include <stdbool.h>
int32_t
dnodeInitMgmt
();
void
dnodeInitMgmtIp
();
void
dnodeProcessMsgFromMgmt
(
char
msgType
,
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
,
int32_t
code
);
void
dnodeSendMsgToMnode
(
int8_t
msgType
,
void
*
pCont
,
int32_t
contLen
);
void
dnodeSendRspToMnode
(
void
*
pConn
,
int8_t
msgType
,
int32_t
code
,
void
*
pCont
,
int32_t
contLen
);
void
dnodeSendVnodeCfgMsg
(
int32_t
vnode
);
void
dnodeSendTableCfgMsg
(
int32_t
vnode
,
int32_t
sid
);
int
dnodeInitMgmt
();
void
dnodeCleanupMgmt
();
void
dnodeMgmt
(
SRpcMsg
*
);
void
*
dnodeGetVnode
(
int
vgId
);
int
dnodeGetVnodeStatus
(
void
*
);
void
*
dnodeGetVnodeRworker
(
void
*
);
void
*
dnodeGetVnodeWworker
(
void
*
);
void
*
dnodeGetVnodeWal
(
void
*
);
void
*
dnodeGetVnodeTsdb
(
void
*
);
void
dnodeReleaseVnode
(
void
*
);
#ifdef __cplusplus
}
...
...
src/dnode/
src/dnodeVnodeMgmt.c
→
src/dnode/
inc/dnodeMnode.h
浏览文件 @
b8fc28fb
...
...
@@ -13,52 +13,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "tlog.h"
#include "taoserror.h"
#include "dnodeVnodeMgmt.h"
#ifndef TDENGINE_DNODE_MNODE_H
#define TDENGINE_DNODE_MNODE_H
int32_t
dnodeOpenVnodes
()
{
dPrint
(
"open all vnodes"
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
dnodeCleanupVnodes
()
{
dPrint
(
"clean all vnodes"
);
return
TSDB_CODE_SUCCESS
;
}
#ifdef __cplusplus
extern
"C"
{
#endif
bool
dnodeCheckVnodeExist
(
int32_t
vnode
)
{
dPrint
(
"vnode:%d, check vnode exist"
,
vnode
);
return
true
;
}
int32_t
dnodeInitMnode
();
void
dnodeCleanupMnode
();
int32_t
dnodeCreateVnode
(
SCreateVnodeMsg
*
pVnode
)
{
dPrint
(
"vnode:%d, is created"
,
htonl
(
pVnode
->
vnode
));
return
TSDB_CODE_SUCCESS
;
#ifdef __cplusplus
}
#endif
int32_t
dnodeDropVnode
(
int32_t
vnode
)
{
dPrint
(
"vnode:%d, is dropped"
,
vnode
);
return
TSDB_CODE_SUCCESS
;
}
void
*
dnodeGetVnode
(
int32_t
vnode
)
{
dPrint
(
"vnode:%d, get vnode"
);
return
NULL
;
}
EVnodeStatus
dnodeGetVnodeStatus
(
int32_t
vnode
)
{
dPrint
(
"vnode:%d, get vnode status"
);
return
TSDB_VN_STATUS_MASTER
;
}
bool
dnodeCheckTableExist
(
int32_t
vnode
,
int32_t
sid
,
int64_t
uid
)
{
dPrint
(
"vnode:%d, sid:%d, check table exist"
);
return
true
;
}
int32_t
dnodeGetVnodesNum
()
{
return
1
;
}
#endif
src/dnode/inc/dnodeModule.h
浏览文件 @
b8fc28fb
...
...
@@ -20,15 +20,9 @@
extern
"C"
{
#endif
#include <stdint.h>
#include <stdbool.h>
#include <pthread.h>
void
dnodeAllocModules
();
void
dnodeAllocModules
();
int32_t
dnodeInitModules
();
void
dnodeCleanUpModules
();
extern
void
(
*
dnodeStartModules
)();
void
dnodeCleanUpModules
();
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeRead.h
浏览文件 @
b8fc28fb
...
...
@@ -20,31 +20,12 @@
extern
"C"
{
#endif
#include <stdbool.h>
#include <stdint.h>
#include "taosdef.h"
#include "taosmsg.h"
/*
* handle query message, and the result is returned by callback function
*/
void
dnodeQueryData
(
SQueryTableMsg
*
pQuery
,
void
*
pConn
,
void
(
*
callback
)(
int32_t
code
,
void
*
pQInfo
,
void
*
pConn
));
/*
* Dispose retrieve msg, and the result will passed through callback function
*/
typedef
void
(
*
SDnodeRetrieveCallbackFp
)(
int32_t
code
,
void
*
pQInfo
,
void
*
pConn
);
void
dnodeRetrieveData
(
SRetrieveTableMsg
*
pRetrieve
,
void
*
pConn
,
SDnodeRetrieveCallbackFp
callbackFp
);
/*
* Fill retrieve result according to query info
*/
int32_t
dnodeGetRetrieveData
(
void
*
pQInfo
,
SRetrieveTableRsp
*
pRetrieve
);
/*
* Get the size of retrieve result according to query info
*/
int32_t
dnodeGetRetrieveDataSize
(
void
*
pQInfo
);
int
dnodeInitRead
();
void
dnodeCleanupRead
();
void
dnodeRead
(
SRpcMsg
*
);
void
*
dnodeAllocateReadWorker
();
void
dnodeFreeReadWorker
(
void
*
rqueue
);
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeShell.h
浏览文件 @
b8fc28fb
...
...
@@ -20,26 +20,8 @@
extern
"C"
{
#endif
#include <stdint.h>
#include <stdint.h>
#include "dnode.h"
typedef
struct
{
int
sid
;
uint32_t
ip
;
uint16_t
port
;
int32_t
count
;
// track the number of imports
int32_t
code
;
// track the code of imports
int32_t
numOfTotalPoints
;
// track the total number of points imported
void
*
thandle
;
// handle from TAOS layer
void
*
qhandle
;
}
SShellObj
;
int32_t
dnodeInitShell
();
void
dnodeCleanupShell
();
//SDnodeStatisInfo dnodeGetStatisInfo()
void
dnodeCleanupShell
();
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeSystem.h
浏览文件 @
b8fc28fb
...
...
@@ -20,34 +20,15 @@
extern
"C"
{
#endif
#include <stdint.h>
#include <stdbool.h>
typedef
enum
{
TSDB_DNODE_RUN_STATUS_INITIALIZE
,
TSDB_DNODE_RUN_STATUS_RUNING
,
TSDB_DNODE_RUN_STATUS_STOPPED
}
SDnodeRunStatus
;
extern
int32_t
(
*
dnodeInitPeers
)(
int32_t
numOfThreads
);
extern
int32_t
(
*
dnodeCheckSystem
)();
extern
int32_t
(
*
dnodeInitStorage
)();
extern
void
(
*
dnodeCleanupStorage
)();
extern
int32_t
tsMaxQueues
;
extern
void
**
tsRpcQhandle
;
extern
void
*
tsQueryQhandle
;
extern
void
*
tsDnodeMgmtQhandle
;
extern
void
*
tsDnodeTmr
;
int32_t
dnodeInitSystem
();
void
dnodeCleanUpSystem
();
void
dnodeInitPlugins
();
void
dnodeCleanUpSystem
();
SDnodeRunStatus
dnodeGetRunStatus
();
void
dnodeSetRunStatus
(
SDnodeRunStatus
status
);
void
dnodeCheckDataDirOpenned
(
const
char
*
dir
);
void
dnodeLockVnodes
();
void
dnodeUnLockVnodes
();
#ifdef __cplusplus
}
...
...
src/dnode/inc/dnodeWrite.h
浏览文件 @
b8fc28fb
...
...
@@ -20,41 +20,12 @@
extern
"C"
{
#endif
#include <stdbool.h>
#include <stdint.h>
#include "taosdef.h"
#include "taosmsg.h"
int
dnodeInitWrite
();
void
dnodeCleanupWrite
();
void
dnodeWrite
(
SRpcMsg
*
pMsg
);
void
*
dnodeAllocateWriteWorker
();
void
dnodeFreeWriteWorker
(
void
*
worker
);
/*
* Write data based on dnode, the detail result can be fetched from rsponse
* pSubmit: Data to be written
* pConn: Communication handle
* callback: Pass the write result through a callback function, possibly in a different thread space
* rsp: will not be freed by callback function
*/
void
dnodeWriteData
(
SShellSubmitMsg
*
pSubmit
,
void
*
pConn
,
void
(
*
callback
)(
SShellSubmitRspMsg
*
rsp
,
void
*
pConn
));
/*
* Create table with specified configuration and open it
* if table already exist, update its schema and tag
*/
int32_t
dnodeCreateTable
(
SDCreateTableMsg
*
pTable
);
/*
* Remove table from local repository
*/
int32_t
dnodeDropTable
(
SDRemoveTableMsg
*
pTable
);
/*
* Create stream
* if stream already exist, update it
*/
int32_t
dnodeCreateStream
(
SDAlterStreamMsg
*
pStream
);
/*
* Remove all child tables of supertable from local repository
*/
int32_t
dnodeDropSuperTable
(
SDRemoveSuperTableMsg
*
pStable
);
#ifdef __cplusplus
}
...
...
src/dnode/src/dnodeMClient.c
0 → 100644
浏览文件 @
b8fc28fb
/*
* 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/>.
*/
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosmsg.h"
#include "tlog.h"
#include "trpc.h"
#include "dnodeSystem.h"
static
void
(
*
dnodeProcessMgmtRspFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
static
void
dnodeProcessRspFromMnode
(
SRpcMsg
*
pMsg
);
static
void
dnodeProcessStatusRsp
(
SRpcMsg
*
pMsg
);
static
void
*
tsDnodeMClientRpc
;
int32_t
dnodeInitMClient
()
{
dnodeProcessMgmtRspFp
[
TSDB_MSG_TYPE_STATUS_RSP
]
=
dnodeProcessStatusRsp
;
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localIp
=
tsAnyIp
?
"0.0.0.0"
:
tsPrivateIp
;
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
"DND-MC"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
dnodeProcessRspFromMnode
;
rpcInit
.
sessions
=
TSDB_SESSIONS_PER_DNODE
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
rpcInit
.
idleTime
=
tsShellActivityTimer
*
1000
;
tsDnodeMClientRpc
=
rpcOpen
(
&
rpcInit
);
if
(
tsDnodeMClientRpc
==
NULL
)
{
dError
(
"failed to init connection from mgmt"
);
return
-
1
;
}
dPrint
(
"client connection to mgmt is opened"
);
return
0
;
}
void
dnodeCleanupMClient
()
{
if
(
tsDnodeMClientRpc
)
{
rpcClose
(
tsDnodeMClientRpc
);
}
}
static
void
dnodeProcessRspFromMnode
(
SRpcMsg
*
pMsg
)
{
if
(
dnodeProcessMgmtRspFp
[
pMsg
->
msgType
])
{
(
*
dnodeProcessMgmtRspFp
[
pMsg
->
msgType
])(
pMsg
);
}
else
{
dError
(
"%s is not processed"
,
taosMsg
[
pMsg
->
msgType
]);
}
rpcFreeCont
(
pMsg
->
pCont
);
}
static
void
dnodeProcessStatusRsp
(
SRpcMsg
*
pMsg
)
{
}
src/dnode/src/dnodeMgmt.c
浏览文件 @
b8fc28fb
...
...
@@ -15,327 +15,219 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "taosmsg.h"
#include "tlog.h"
#include "taoserror.h"
#include "taosmsg.h"
#include "trpc.h"
#include "tsched.h"
#include "tsystem.h"
#include "mnode.h"
#include "dnode.h"
#include "dnodeSystem.h"
#include "dnodeMgmt.h"
#include "dnodeWrite.h"
#include "dnodeVnodeMgmt.h"
void
(
*
dnodeInitMgmtIpFp
)()
=
NULL
;
int32_t
(
*
dnodeInitMgmtFp
)()
=
NULL
;
void
(
*
dnodeCleanUpMgmtFp
)()
=
NULL
;
void
(
*
dnodeProcessStatusRspFp
)(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
=
NULL
;
void
(
*
dnodeSendMsgToMnodeFp
)(
int8_t
msgType
,
void
*
pCont
,
int32_t
contLen
)
=
NULL
;
void
(
*
dnodeSendRspToMnodeFp
)(
void
*
handle
,
int32_t
code
,
void
*
pCont
,
int
contLen
)
=
NULL
;
static
void
*
tsStatusTimer
=
NULL
;
static
void
(
*
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_MAX
])(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
);
static
void
dnodeInitProcessShellMsg
();
static
void
dnodeSendMsgToMnodeQueueFp
(
SSchedMsg
*
sched
)
{
int32_t
contLen
=
*
(
int32_t
*
)
(
sched
->
msg
-
4
);
int32_t
code
=
*
(
int32_t
*
)
(
sched
->
msg
-
8
);
int8_t
msgType
=
*
(
int8_t
*
)
(
sched
->
msg
-
9
);
void
*
handle
=
sched
->
ahandle
;
int8_t
*
pCont
=
sched
->
msg
;
mgmtProcessMsgFromDnode
(
msgType
,
pCont
,
contLen
,
handle
,
code
);
#include "dnodeRead.h"
#include "dnodeMgmt.h"
typedef
struct
{
int32_t
vgId
;
// global vnode group ID
int
status
;
// status: master, slave, notready, deleting
int
refCount
;
// reference count
int64_t
version
;
void
*
wworker
;
void
*
rworker
;
void
*
wal
;
void
*
tsdb
;
void
*
replica
;
void
*
events
;
void
*
cq
;
// continuous query
}
SVnodeObj
;
static
int
dnodeOpenVnodes
();
static
void
dnodeCleanupVnodes
();
static
int
dnodeCreateVnode
(
int32_t
vgId
,
SCreateVnodeMsg
*
cfg
);
static
int
dnodeDropVnode
(
SVnodeObj
*
pVnode
);
static
void
dnodeRemoveVnode
(
SVnodeObj
*
pVnode
);
static
void
dnodeProcessCreateVnodeMsg
(
SRpcMsg
*
pMsg
);
static
void
dnodeProcessDropVnodeMsg
(
SRpcMsg
*
pMsg
);
static
void
dnodeProcessAlterVnodeMsg
(
SRpcMsg
*
pMsg
);
static
void
(
*
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
pMsg
);
int
dnodeInitMgmt
()
{
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_FREE_VNODE
]
=
dnodeProcessDropVnodeMsg
;
}
void
dnodeSendMsgToMnode
(
int8_t
msgType
,
void
*
pCont
,
int32_t
contLen
)
{
dTrace
(
"msg:%d:%s is sent to mnode"
,
msgType
,
taosMsg
[
msgType
]);
if
(
dnodeSendMsgToMnodeFp
)
{
dnodeSendMsgToMnodeFp
(
msgType
,
pCont
,
contLen
);
}
else
{
if
(
pCont
==
NULL
)
{
pCont
=
rpcMallocCont
(
1
);
contLen
=
0
;
}
SSchedMsg
schedMsg
=
{
0
};
schedMsg
.
fp
=
dnodeSendMsgToMnodeQueueFp
;
schedMsg
.
msg
=
pCont
;
*
(
int32_t
*
)
(
pCont
-
4
)
=
contLen
;
*
(
int32_t
*
)
(
pCont
-
8
)
=
TSDB_CODE_SUCCESS
;
*
(
int8_t
*
)
(
pCont
-
9
)
=
msgType
;
taosScheduleTask
(
tsDnodeMgmtQhandle
,
&
schedMsg
);
}
void
dnodeCleanupMgmt
()
{
}
void
dnodeSendRspToMnode
(
void
*
pConn
,
int8_t
msgType
,
int32_t
code
,
void
*
pCont
,
int32_t
contLen
)
{
dTrace
(
"rsp:%d:%s is sent to mnode, pConn:%p"
,
msgType
,
taosMsg
[
msgType
],
pConn
);
if
(
dnodeSendRspToMnodeFp
)
{
dnodeSendRspToMnodeFp
(
pConn
,
code
,
pCont
,
contLen
);
void
dnodeMgmt
(
SRpcMsg
*
pMsg
)
{
terrno
=
0
;
if
(
dnodeProcessMgmtMsgFp
[
pMsg
->
msgType
])
{
(
*
dnodeProcessMgmtMsgFp
[
pMsg
->
msgType
])(
pMsg
);
}
else
{
//hack way
if
(
pCont
==
NULL
)
{
pCont
=
rpcMallocCont
(
1
);
contLen
=
0
;
}
SSchedMsg
schedMsg
=
{
0
};
schedMsg
.
fp
=
dnodeSendMsgToMnodeQueueFp
;
schedMsg
.
msg
=
pCont
;
schedMsg
.
ahandle
=
pConn
;
*
(
int32_t
*
)
(
pCont
-
4
)
=
contLen
;
*
(
int32_t
*
)
(
pCont
-
8
)
=
code
;
*
(
int8_t
*
)
(
pCont
-
9
)
=
msgType
;
taosScheduleTask
(
tsDnodeMgmtQhandle
,
&
schedMsg
);
terrno
=
TSDB_CODE_MSG_NOT_PROCESSED
;
}
SRpcMsg
rsp
;
rsp
.
handle
=
pMsg
->
handle
;
rsp
.
code
=
terrno
;
rsp
.
pCont
=
NULL
;
rpcSendResponse
(
&
rsp
);
rpcFreeCont
(
pMsg
->
pCont
);
// free the received message
}
void
*
dnodeGetVnode
(
int
vgId
)
{
SVnodeObj
*
pVnode
;
void
dnodeSendStatusMsgToMgmt
(
void
*
handle
,
void
*
tmrId
)
{
taosTmrReset
(
dnodeSendStatusMsgToMgmt
,
tsStatusInterval
*
1000
,
NULL
,
tsDnodeTmr
,
&
tsStatusTimer
);
if
(
tsStatusTimer
==
NULL
)
{
dError
(
"Failed to start status timer"
);
return
;
}
// retrieve the pVnode from vgId
int32_t
contLen
=
sizeof
(
SStatusMsg
)
+
dnodeGetVnodesNum
()
*
sizeof
(
SVnodeLoad
);
SStatusMsg
*
pStatus
=
rpcMallocCont
(
contLen
);
if
(
pStatus
==
NULL
)
{
dError
(
"Failed to malloc status message"
);
return
;
}
// if (pVnode->status == ....) {
// terrno = ;
// return NULL;
// }
int32_t
totalVnodes
=
dnodeGetVnodesNum
();
pStatus
->
version
=
htonl
(
tsVersion
);
pStatus
->
privateIp
=
htonl
(
inet_addr
(
tsPrivateIp
));
pStatus
->
publicIp
=
htonl
(
inet_addr
(
tsPublicIp
));
pStatus
->
lastReboot
=
htonl
(
tsRebootTime
);
pStatus
->
numOfTotalVnodes
=
htons
((
uint16_t
)
tsNumOfTotalVnodes
);
pStatus
->
openVnodes
=
htons
((
uint16_t
)
totalVnodes
);
pStatus
->
numOfCores
=
htons
((
uint16_t
)
tsNumOfCores
);
pStatus
->
diskAvailable
=
tsAvailDataDirGB
;
pStatus
->
alternativeRole
=
(
uint8_t
)
tsAlternativeRole
;
SVnodeLoad
*
pLoad
=
(
SVnodeLoad
*
)
pStatus
->
load
;
//TODO loop all vnodes
// for (int32_t vnode = 0, count = 0; vnode <= totalVnodes; ++vnode) {
// if (vnodeList[vnode].cfg.maxSessions <= 0) continue;
//
// SVnodeObj *pVnode = vnodeList + vnode;
// pLoad->vnode = htonl(vnode);
// pLoad->vgId = htonl(pVnode->cfg.vgId);
// pLoad->status = (uint8_t)vnodeList[vnode].vnodeStatus;
// pLoad->syncStatus =(uint8_t)vnodeList[vnode].syncStatus;
// pLoad->accessState = (uint8_t)(pVnode->accessState);
// pLoad->totalStorage = htobe64(pVnode->vnodeStatistic.totalStorage);
// pLoad->compStorage = htobe64(pVnode->vnodeStatistic.compStorage);
// if (pVnode->vnodeStatus == TSDB_VN_STATUS_MASTER) {
// pLoad->pointsWritten = htobe64(pVnode->vnodeStatistic.pointsWritten);
// } else {
// pLoad->pointsWritten = htobe64(0);
// }
// pLoad++;
//
// if (++count >= tsOpenVnodes) {
// break;
// }
// }
dnodeSendMsgToMnode
(
TSDB_MSG_TYPE_STATUS
,
pStatus
,
contLen
);
atomic_add_fetch_32
(
&
pVnode
->
refCount
,
1
);
return
pVnode
;
}
int
dnodeGetVnodeStatus
(
void
*
pVnode
)
{
return
((
SVnodeObj
*
)
pVnode
)
->
status
;
}
int32_t
dnodeInitMgmt
()
{
if
(
dnodeInitMgmtFp
)
{
dnodeInitMgmtFp
();
}
dnodeInitProcessShellMsg
();
taosTmrReset
(
dnodeSendStatusMsgToMgmt
,
500
,
NULL
,
tsDnodeTmr
,
&
tsStatusTimer
);
return
0
;
void
*
dnodeGetVnodeWworker
(
void
*
pVnode
)
{
return
((
SVnodeObj
*
)
pVnode
)
->
wworker
;
}
void
*
dnodeGetVnodeRworker
(
void
*
pVnode
)
{
return
((
SVnodeObj
*
)
pVnode
)
->
rworker
;
}
void
*
dnodeGetVnodeWal
(
void
*
pVnode
)
{
return
((
SVnodeObj
*
)
pVnode
)
->
wal
;
}
void
dnodeInitMgmtIp
()
{
if
(
dnodeInitMgmtIpFp
)
{
dnodeInitMgmtIpFp
();
}
void
*
dnodeGetVnodeTsdb
(
void
*
pVnode
)
{
return
((
SVnodeObj
*
)
pVnode
)
->
tsdb
;
}
void
dnodeCleanUpMgmt
()
{
if
(
tsStatusTimer
!=
NULL
)
{
taosTmrStopA
(
&
tsStatusTimer
);
tsStatusTimer
=
NULL
;
}
void
dnodeReleaseVnode
(
void
*
param
)
{
SVnodeObj
*
pVnode
=
(
SVnodeObj
*
)
param
;
if
(
dnodeCleanUpMgmtFp
)
{
dnodeCleanUpMgmtFp
();
}
int
refCount
=
atomic_sub_fetch_32
(
&
pVnode
->
refCount
,
1
);
if
(
refCount
==
0
)
dnodeRemoveVnode
(
pVnode
);
}
void
dnodeProcessMsgFromMgmt
(
char
msgType
,
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
,
int32_t
code
)
{
if
(
msgType
<
0
||
msgType
>=
TSDB_MSG_TYPE_MAX
)
{
dError
(
"invalid msg type:%d"
,
msgType
);
return
;
}
static
int
dnodeOpenVnode
()
{
SVnodeObj
*
pVnode
;
dTrace
(
"msg:%d:%s is received from mgmt, pConn:%p"
,
msgType
,
taosMsg
[(
int8_t
)
msgType
],
pConn
);
// create tsdb
if
(
msgType
==
TSDB_MSG_TYPE_STATUS_RSP
&&
dnodeProcessStatusRspFp
!=
NULL
)
{
dnodeProcessStatusRspFp
(
pCont
,
contLen
,
msgType
,
pConn
);
}
if
(
dnodeProcessMgmtMsgFp
[
msgType
])
{
(
*
dnodeProcessMgmtMsgFp
[
msgType
])(
pCont
,
contLen
,
msgType
,
pConn
);
}
else
{
dError
(
"%s is not processed"
,
taosMsg
[
msgType
]);
}
// create wal
//
rpcFreeCont(pCont);
}
//
allocate write worker
pVnode
->
wworker
=
dnodeAllocateWriteWorker
();
static
void
dnodeProcessCreateTableRequest
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
SDCreateTableMsg
*
pTable
=
pCont
;
pTable
->
numOfColumns
=
htons
(
pTable
->
numOfColumns
);
pTable
->
numOfTags
=
htons
(
pTable
->
numOfTags
);
pTable
->
sid
=
htonl
(
pTable
->
sid
);
pTable
->
sversion
=
htonl
(
pTable
->
sversion
);
pTable
->
tagDataLen
=
htonl
(
pTable
->
tagDataLen
);
pTable
->
sqlDataLen
=
htonl
(
pTable
->
sqlDataLen
);
pTable
->
contLen
=
htonl
(
pTable
->
contLen
);
pTable
->
numOfVPeers
=
htonl
(
pTable
->
numOfVPeers
);
pTable
->
uid
=
htobe64
(
pTable
->
uid
);
pTable
->
superTableUid
=
htobe64
(
pTable
->
superTableUid
);
pTable
->
createdTime
=
htobe64
(
pTable
->
createdTime
);
for
(
int
i
=
0
;
i
<
pTable
->
numOfVPeers
;
++
i
)
{
pTable
->
vpeerDesc
[
i
].
ip
=
htonl
(
pTable
->
vpeerDesc
[
i
].
ip
);
pTable
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pTable
->
vpeerDesc
[
i
].
vnode
);
}
// create read queue
pVnode
->
rworker
=
dnodeAllocateReadWorker
();
int32_t
totalCols
=
pTable
->
numOfColumns
+
pTable
->
numOfTags
;
SSchema
*
pSchema
=
(
SSchema
*
)
pTable
->
data
;
for
(
int32_t
col
=
0
;
col
<
totalCols
;
++
col
)
{
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
colId
=
htons
(
pSchema
->
colId
);
pSchema
++
;
}
// create the replica
int32_t
code
=
dnodeCreateTable
(
pTable
);
dnodeSendRspToMnode
(
pConn
,
msgType
+
1
,
code
,
NULL
,
0
);
}
// set the status
static
void
dnodeProcessAlterStreamRequest
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
SDAlterStreamMsg
*
pStream
=
pCont
;
pStream
->
uid
=
htobe64
(
pStream
->
uid
);
pStream
->
stime
=
htobe64
(
pStream
->
stime
);
pStream
->
vnode
=
htonl
(
pStream
->
vnode
);
pStream
->
sid
=
htonl
(
pStream
->
sid
);
pStream
->
status
=
htonl
(
pStream
->
status
);
pVnode
->
refCount
=
1
;
int32_t
code
=
dnodeCreateStream
(
pStream
);
dnodeSendRspToMnode
(
pConn
,
msgType
+
1
,
code
,
NULL
,
0
);
return
0
;
}
static
void
dnodeProcessRemoveTableRequest
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
SDRemoveTableMsg
*
pTable
=
pCont
;
pTable
->
sid
=
htonl
(
pTable
->
sid
);
pTable
->
numOfVPeers
=
htonl
(
pTable
->
numOfVPeers
);
pTable
->
uid
=
htobe64
(
pTable
->
uid
);
static
int
dnodeOpenVnodes
()
{
return
0
;
}
for
(
int
i
=
0
;
i
<
pTable
->
numOfVPeers
;
++
i
)
{
pTable
->
vpeerDesc
[
i
].
ip
=
htonl
(
pTable
->
vpeerDesc
[
i
].
ip
);
pTable
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pTable
->
vpeerDesc
[
i
].
vnode
);
}
static
void
dnodeCleanupVnode
()
{
int32_t
code
=
dnodeDropTable
(
pTable
);
dnodeSendRspToMnode
(
pConn
,
msgType
+
1
,
code
,
NULL
,
0
);
}
static
void
dnodeProcessVPeerCfgRsp
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
int32_t
code
=
htonl
(
*
((
int32_t
*
)
pCont
));
if
(
code
==
TSDB_CODE_SUCCESS
)
{
SCreateVnodeMsg
*
pVnode
=
(
SCreateVnodeMsg
*
)
(
pCont
+
sizeof
(
int32_t
));
dnodeCreateVnode
(
pVnode
);
}
else
if
(
code
==
TSDB_CODE_INVALID_VNODE_ID
)
{
SFreeVnodeMsg
*
vpeer
=
(
SFreeVnodeMsg
*
)
(
pCont
+
sizeof
(
int32_t
));
int32_t
vnode
=
htonl
(
vpeer
->
vnode
);
dError
(
"vnode:%d, not exist, remove it"
,
vnode
);
dnodeDropVnode
(
vnode
);
}
else
{
dError
(
"code:%d invalid message"
,
code
);
}
}
static
void
dnodeCleanupVnodes
()
{
static
void
dnodeProcessTableCfgRsp
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
int32_t
code
=
htonl
(
*
((
int32_t
*
)
pCont
));
if
(
code
==
TSDB_CODE_SUCCESS
)
{
SDCreateTableMsg
*
table
=
(
SDCreateTableMsg
*
)
(
pCont
+
sizeof
(
int32_t
));
dnodeCreateTable
(
table
);
}
else
if
(
code
==
TSDB_CODE_INVALID_TABLE_ID
)
{
SDRemoveTableMsg
*
pTable
=
(
SDRemoveTableMsg
*
)
(
pCont
+
sizeof
(
int32_t
));
pTable
->
sid
=
htonl
(
pTable
->
sid
);
pTable
->
uid
=
htobe64
(
pTable
->
uid
);
dError
(
"table:%s, sid:%d table is not configured, remove it"
,
pTable
->
tableId
,
pTable
->
sid
);
dnodeDropTable
(
pTable
);
}
else
{
dError
(
"code:%d invalid message"
,
code
);
}
}
static
void
dnodeProcessCreateVnodeRequest
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
SCreateVnodeMsg
*
pVnode
=
(
SCreateVnodeMsg
*
)
pCont
;
static
int
dnodeCreateVnode
(
int32_t
vgId
,
SCreateVnodeMsg
*
cfg
)
{
int32_t
code
=
dnodeCreateVnode
(
pVnode
);
dnodeSendRspToMnode
(
pConn
,
msgType
+
1
,
code
,
NULL
,
0
);
SVnodeObj
*
pVnode
=
malloc
(
sizeof
(
SVnodeObj
));
// save the vnode info in non-volatile storage
// add into hash, so it can be retrieved
dnodeOpenVnode
(
pVnode
);
return
0
;
}
static
void
dnodeProcessFreeVnodeRequest
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
SFreeVnodeMsg
*
pVnode
=
(
SFreeVnodeMsg
*
)
pCont
;
int32_t
vnode
=
htonl
(
pVnode
->
vnode
);
static
void
dnodeRemoveVnode
(
SVnodeObj
*
pVnode
)
{
// remove replica
// remove read queue
dnodeFreeReadWorker
(
pVnode
->
rworker
);
// remove write queue
dnodeFreeWriteWorker
(
pVnode
->
wworker
);
// remove wal
// remove tsdb
int32_t
code
=
dnodeDropVnode
(
vnode
);
dnodeSendRspToMnode
(
pConn
,
msgType
+
1
,
code
,
NULL
,
0
);
}
static
void
dnodeProcessDnodeCfgRequest
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
SCfgDnodeMsg
*
pCfg
=
(
SCfgDnodeMsg
*
)
pCont
;
static
int
dnodeDropVnode
(
SVnodeObj
*
pVnode
)
{
int
count
=
atomic_sub_fetch_32
(
&
pVnode
->
refCount
,
1
);
int32_t
code
=
tsCfgDynamicOptions
(
pCfg
->
config
);
dnodeSendRspToMnode
(
pConn
,
msgType
+
1
,
code
,
NULL
,
0
);
if
(
count
<=
0
)
dnodeRemoveVnode
(
pVnode
);
return
0
;
}
static
void
dnodeProcessDropStableRequest
(
void
*
pCont
,
int32_t
contLen
,
int8_t
msgType
,
void
*
pConn
)
{
dnodeSendRspToMnode
(
pConn
,
msgType
+
1
,
TSDB_CODE_SUCCESS
,
NULL
,
0
);
static
void
dnodeProcessCreateVnodeMsg
(
SRpcMsg
*
pMsg
)
{
// SVnodeObj *pVnode;
// int vgId;
// SVPeersMsg *pCfg;
// check everything, if not ok, set terrno;
// everything is ok
// dnodeCreateVnode(vgId, pCfg);
//if (pVnode == NULL) terrno = TSDB_CODE
}
void
dnodeSendVnodeCfgMsg
(
int32_t
vnode
)
{
SVpeerCfgMsg
*
cfg
=
(
SVpeerCfgMsg
*
)
rpcMallocCont
(
sizeof
(
SVpeerCfgMsg
));
if
(
cfg
==
NULL
)
{
return
;
}
static
void
dnodeProcessDropVnodeMsg
(
SRpcMsg
*
pMsg
)
{
cfg
->
vnode
=
htonl
(
vnode
);
dnodeSendMsgToMnode
(
TSDB_MSG_TYPE_VNODE_CFG
,
cfg
,
sizeof
(
SVpeerCfgMsg
));
SVnodeObj
*
pVnode
;
int
vgId
;
// check everything, if not ok, set terrno;
// everything is ok
dnodeDropVnode
(
pVnode
);
//if (pVnode == NULL) terrno = TSDB_CODE
}
void
dnodeSendTableCfgMsg
(
int32_t
vnode
,
int32_t
sid
)
{
STableCfgMsg
*
cfg
=
(
STableCfgMsg
*
)
rpcMallocCont
(
sizeof
(
STableCfgMsg
));
if
(
cfg
==
NULL
)
{
return
;
}
static
void
dnodeProcessAlterVnodeMsg
(
SRpcMsg
*
pMsg
)
{
SVnodeObj
*
pVnode
;
int
vgId
;
// check everything, if not ok, set terrno;
// everything is ok
// dnodeAlterVnode(pVnode);
cfg
->
vnode
=
htonl
(
vnode
);
dnodeSendMsgToMnode
(
TSDB_MSG_TYPE_TABLE_CFG
,
cfg
,
sizeof
(
STableCfgMsg
));
//if (pVnode == NULL) terrno = TSDB_CODE
}
static
void
dnodeInitProcessShellMsg
()
{
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_DNODE_CREATE_TABLE
]
=
dnodeProcessCreateTableRequest
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_DNODE_REMOVE_TABLE
]
=
dnodeProcessRemoveTableRequest
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_CREATE_VNODE
]
=
dnodeProcessCreateVnodeRequest
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_FREE_VNODE
]
=
dnodeProcessFreeVnodeRequest
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_DNODE_CFG
]
=
dnodeProcessDnodeCfgRequest
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_ALTER_STREAM
]
=
dnodeProcessAlterStreamRequest
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_DROP_STABLE
]
=
dnodeProcessDropStableRequest
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_VNODE_CFG_RSP
]
=
dnodeProcessVPeerCfgRsp
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_TABLE_CFG_RSP
]
=
dnodeProcessTableCfgRsp
;
}
\ No newline at end of file
src/dnode/src/dnodeMnode.c
0 → 100644
浏览文件 @
b8fc28fb
/*
* 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 "os.h"
#include "taosmsg.h"
#include "tlog.h"
#include "trpc.h"
#include "dnodeSystem.h"
#include "dnodeMgmt.h"
#include "dnodeWrite.h"
static
void
(
*
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
static
void
dnodeProcessMsgFromMnode
(
SRpcMsg
*
pMsg
);
static
void
*
tsDnodeMnodeRpc
=
NULL
;
int32_t
dnodeInitMnode
()
{
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_DNODE_CREATE_TABLE
]
=
dnodeWrite
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_DNODE_REMOVE_TABLE
]
=
dnodeWrite
;
dnodeProcessMgmtMsgFp
[
TSDB_MSG_TYPE_FREE_VNODE
]
=
dnodeMgmt
;
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localIp
=
tsAnyIp
?
"0.0.0.0"
:
tsPrivateIp
;
// note: a new port shall be assigned
// rpcInit.localPort = tsDnodeMnodePort;
rpcInit
.
label
=
"DND-mgmt"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
dnodeProcessMsgFromMnode
;
rpcInit
.
sessions
=
TSDB_SESSIONS_PER_DNODE
;
rpcInit
.
connType
=
TAOS_CONN_SERVER
;
rpcInit
.
idleTime
=
tsShellActivityTimer
*
1500
;
tsDnodeMnodeRpc
=
rpcOpen
(
&
rpcInit
);
if
(
tsDnodeMnodeRpc
==
NULL
)
{
dError
(
"failed to init connection from mgmt"
);
return
-
1
;
}
dPrint
(
"connection to mgmt is opened"
);
return
0
;
}
void
dnodeCleanupMnode
()
{
if
(
tsDnodeMnodeRpc
)
{
rpcClose
(
tsDnodeMnodeRpc
);
}
}
static
void
dnodeProcessMsgFromMnode
(
SRpcMsg
*
pMsg
)
{
SRpcMsg
rspMsg
;
rspMsg
.
handle
=
pMsg
->
handle
;
rspMsg
.
pCont
=
NULL
;
rspMsg
.
contLen
=
0
;
if
(
dnodeGetRunStatus
()
!=
TSDB_DNODE_RUN_STATUS_RUNING
)
{
rspMsg
.
code
=
TSDB_CODE_NOT_READY
;
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
dTrace
(
"conn:%p, query msg is ignored since dnode not running"
,
pMsg
->
handle
);
return
;
}
if
(
dnodeProcessMgmtMsgFp
[
pMsg
->
msgType
])
{
(
*
dnodeProcessMgmtMsgFp
[
pMsg
->
msgType
])(
pMsg
);
}
else
{
dError
(
"%s is not processed"
,
taosMsg
[
pMsg
->
msgType
]);
rspMsg
.
code
=
TSDB_CODE_MSG_NOT_PROCESSED
;
rpcSendResponse
(
&
rspMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
}
}
src/dnode/src/dnodeRead.c
浏览文件 @
b8fc28fb
...
...
@@ -17,56 +17,196 @@
#include "os.h"
#include "taoserror.h"
#include "tlog.h"
#include "tsched.h"
#include "dnode.h"
#include "trpc.h"
#include "taosmsg.h"
#include "tqueue.h"
#include "dnodeRead.h"
#include "dnode
System
.h"
#include "dnode
Mgmt
.h"
void
dnodeQueryData
(
SQueryTableMsg
*
pQuery
,
void
*
pConn
,
void
(
*
callback
)(
int32_t
code
,
void
*
pQInfo
,
void
*
pConn
))
{
dTrace
(
"conn:%p, query msg is disposed"
,
pConn
);
void
*
pQInfo
=
100
;
callback
(
TSDB_CODE_SUCCESS
,
pQInfo
,
pConn
);
typedef
struct
{
int32_t
code
;
int32_t
count
;
int32_t
numOfVnodes
;
}
SRpcContext
;
typedef
struct
{
void
*
pCont
;
int
contLen
;
SRpcMsg
rpcMsg
;
void
*
pVnode
;
SRpcContext
*
pRpcContext
;
// RPC message context
}
SReadMsg
;
static
void
*
dnodeProcessReadQueue
(
void
*
param
);
static
void
dnodeProcessReadResult
(
SReadMsg
*
pRead
);
static
void
dnodeHandleIdleReadWorker
();
static
void
dnodeProcessQueryMsg
(
SReadMsg
*
pMsg
);
static
void
dnodeProcessRetrieveMsg
(
SReadMsg
*
pMsg
);
static
void
(
*
dnodeProcessReadMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SReadMsg
*
pNode
);
// module global variable
static
taos_qset
readQset
;
static
int
threads
;
// number of query threads
static
int
maxThreads
;
static
int
minThreads
;
int
dnodeInitRead
()
{
dnodeProcessReadMsgFp
[
TSDB_MSG_TYPE_QUERY
]
=
dnodeProcessQueryMsg
;
dnodeProcessReadMsgFp
[
TSDB_MSG_TYPE_RETRIEVE
]
=
dnodeProcessRetrieveMsg
;
readQset
=
taosOpenQset
();
minThreads
=
3
;
maxThreads
=
tsNumOfCores
*
tsNumOfThreadsPerCore
;
if
(
maxThreads
<=
minThreads
*
2
)
maxThreads
=
2
*
minThreads
;
return
0
;
}
static
void
dnodeExecuteRetrieveData
(
SSchedMsg
*
pSched
)
{
SDnodeRetrieveCallbackFp
callback
=
(
SDnodeRetrieveCallbackFp
)
pSched
->
thandle
;
SRetrieveTableMsg
*
pRetrieve
=
pSched
->
msg
;
void
*
pConn
=
pSched
->
ahandle
;
void
dnodeCleanupRead
()
{
taosCloseQset
(
readQset
);
}
dTrace
(
"conn:%p, retrieve msg is disposed, qhandle:%"
PRId64
,
pConn
,
pRetrieve
->
qhandle
);
void
dnodeRead
(
SRpcMsg
*
pMsg
)
{
int
leftLen
=
pMsg
->
contLen
;
char
*
pCont
=
(
char
*
)
pMsg
->
pCont
;
int
contLen
=
0
;
int
numOfVnodes
=
0
;
int32_t
vgId
=
0
;
SRpcContext
*
pRpcContext
=
NULL
;
//examples
int32_t
code
=
TSDB_CODE_SUCCESS
;
void
*
pQInfo
=
(
void
*
)
pRetrieve
->
qhandle
;
// parse head, get number of vnodes;
if
(
numOfVnodes
>
1
)
{
pRpcContext
=
calloc
(
sizeof
(
SRpcContext
),
1
);
pRpcContext
->
numOfVnodes
=
1
;
}
(
*
callback
)(
code
,
pQInfo
,
pConn
);
while
(
leftLen
>
0
)
{
// todo: parse head, get vgId, contLen
free
(
pSched
->
msg
);
// get pVnode from vgId
void
*
pVnode
=
dnodeGetVnode
(
vgId
);
if
(
pVnode
==
NULL
)
{
continue
;
}
// put message into queue
SReadMsg
readMsg
;
readMsg
.
rpcMsg
=
*
pMsg
;
readMsg
.
pCont
=
pCont
;
readMsg
.
contLen
=
contLen
;
readMsg
.
pRpcContext
=
pRpcContext
;
readMsg
.
pVnode
=
pVnode
;
taos_queue
queue
=
dnodeGetVnodeRworker
(
pVnode
);
taosWriteQitem
(
queue
,
&
readMsg
);
// next vnode
leftLen
-=
contLen
;
pCont
-=
contLen
;
}
}
void
dnodeRetrieveData
(
SRetrieveTableMsg
*
pRetrieve
,
void
*
pConn
,
SDnodeRetrieveCallbackFp
callbackFp
)
{
dTrace
(
"conn:%p, retrieve msg is received"
,
pConn
);
void
*
dnodeAllocateReadWorker
()
{
taos_queue
*
queue
=
taosOpenQueue
(
sizeof
(
SReadMsg
));
if
(
queue
==
NULL
)
return
NULL
;
taosAddIntoQset
(
readQset
,
queue
);
void
*
msg
=
malloc
(
sizeof
(
SRetrieveTableMsg
));
memcpy
(
msg
,
pRetrieve
,
sizeof
(
SRetrieveTableMsg
));
// spawn a thread to process queue
if
(
threads
<
maxThreads
)
{
pthread_t
thread
;
pthread_attr_t
thAttr
;
pthread_attr_init
(
&
thAttr
);
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
SSchedMsg
schedMsg
;
schedMsg
.
msg
=
msg
;
schedMsg
.
ahandle
=
pConn
;
schedMsg
.
thandle
=
callbackFp
;
schedMsg
.
fp
=
dnodeExecuteRetrieveData
;
taosScheduleTask
(
tsQueryQhandle
,
&
schedMsg
)
;
if
(
pthread_create
(
&
thread
,
&
thAttr
,
dnodeProcessReadQueue
,
readQset
)
!=
0
)
{
dError
(
"failed to create thread to process read queue, reason:%s"
,
strerror
(
errno
))
;
}
}
return
queue
;
}
int32_t
dnodeGetRetrieveData
(
void
*
pQInfo
,
SRetrieveTableRsp
*
pRetrieve
)
{
dTrace
(
"qInfo:%p, data is retrieved"
);
pRetrieve
->
numOfRows
=
0
;
return
0
;
void
dnodeFreeReadWorker
(
void
*
rqueue
)
{
taosCloseQueue
(
rqueue
);
// dynamically adjust the number of threads
}
int32_t
dnodeGetRetrieveDataSize
(
void
*
pQInfo
)
{
dTrace
(
"qInfo:%p, contLen is 100"
);
return
100
;
static
void
*
dnodeProcessReadQueue
(
void
*
param
)
{
taos_qset
qset
=
(
taos_qset
)
param
;
SReadMsg
readMsg
;
while
(
1
)
{
if
(
taosReadQitemFromQset
(
qset
,
&
readMsg
)
<=
0
)
{
dnodeHandleIdleReadWorker
();
continue
;
}
terrno
=
0
;
if
(
dnodeProcessReadMsgFp
[
readMsg
.
rpcMsg
.
msgType
])
{
(
*
dnodeProcessReadMsgFp
[
readMsg
.
rpcMsg
.
msgType
])
(
&
readMsg
);
}
else
{
terrno
=
TSDB_CODE_MSG_NOT_PROCESSED
;
}
dnodeProcessReadResult
(
&
readMsg
);
}
return
NULL
;
}
static
void
dnodeHandleIdleReadWorker
()
{
int
num
=
taosGetQueueNumber
(
readQset
);
if
(
num
==
0
||
(
num
<=
minThreads
&&
threads
>
minThreads
))
{
threads
--
;
pthread_exit
(
NULL
);
}
else
{
usleep
(
100
);
sched_yield
();
}
}
static
void
dnodeProcessReadResult
(
SReadMsg
*
pRead
)
{
SRpcContext
*
pRpcContext
=
pRead
->
pRpcContext
;
int32_t
code
=
0
;
dnodeReleaseVnode
(
pRead
->
pVnode
);
if
(
pRpcContext
)
{
if
(
terrno
)
{
if
(
pRpcContext
->
code
==
0
)
pRpcContext
->
code
=
terrno
;
}
int
count
=
atomic_add_fetch_32
(
&
pRpcContext
->
count
,
1
);
if
(
count
<
pRpcContext
->
numOfVnodes
)
{
// not over yet, multiple vnodes
return
;
}
// over, result can be merged now
code
=
pRpcContext
->
code
;
}
else
{
code
=
terrno
;
}
SRpcMsg
rsp
;
rsp
.
handle
=
pRead
->
rpcMsg
.
handle
;
rsp
.
code
=
code
;
rsp
.
pCont
=
NULL
;
rpcSendResponse
(
&
rsp
);
rpcFreeCont
(
pRead
->
rpcMsg
.
pCont
);
// free the received message
}
static
void
dnodeProcessQueryMsg
(
SReadMsg
*
pMsg
)
{
}
static
void
dnodeProcessRetrieveMsg
(
SReadMsg
*
pMsg
)
{
}
src/dnode/src/dnodeShell.c
浏览文件 @
b8fc28fb
...
...
@@ -19,31 +19,22 @@
#include "taosdef.h"
#include "taosmsg.h"
#include "tlog.h"
#include "tsocket.h"
#include "tschemautil.h"
#include "textbuffer.h"
#include "trpc.h"
#include "http.h"
#include "dnode.h"
#include "dnodeMgmt.h"
#include "dnodeRead.h"
#include "dnodeSystem.h"
#include "dnodeShell.h"
#include "dnodeVnodeMgmt.h"
#include "dnodeRead.h"
#include "dnodeWrite.h"
#include "dnodeShell.h"
static
void
dnodeProcessRetrieveMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
);
static
void
dnodeProcessQueryMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
);
static
void
dnodeProcessSubmitMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
);
static
void
dnodeProcessMsgFromShell
(
char
msgType
,
void
*
pCont
,
int
contLen
,
void
*
handle
,
int32_t
code
);
static
int
dnodeRetrieveUserAuthInfo
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
static
void
*
tsDnodeShellServer
=
NULL
;
static
int32_t
tsDnodeQueryReqNum
=
0
;
static
int32_t
tsDnodeSubmitReqNum
=
0
;
static
void
(
*
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
);
static
void
dnodeProcessMsgFromShell
(
SRpcMsg
*
pMsg
);
static
void
*
tsDnodeShellRpc
=
NULL
;
int32_t
dnodeInitShell
()
{
int32_t
numOfThreads
=
tsNumOfCores
*
tsNumOfThreadsPerCore
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_SUBMIT
]
=
dnodeWrite
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_QUERY
]
=
dnodeRead
;
dnodeProcessShellMsgFp
[
TSDB_MSG_TYPE_RETRIEVE
]
=
dnodeRead
;
int
numOfThreads
=
tsNumOfCores
*
tsNumOfThreadsPerCore
;
numOfThreads
=
(
int32_t
)
((
1
.
0
-
tsRatioOfQueryThreads
)
*
numOfThreads
/
2
.
0
);
if
(
numOfThreads
<
1
)
{
numOfThreads
=
1
;
...
...
@@ -55,167 +46,50 @@ int32_t dnodeInitShell() {
rpcInit
.
localPort
=
tsVnodeShellPort
;
rpcInit
.
label
=
"DND-shell"
;
rpcInit
.
numOfThreads
=
numOfThreads
;
rpcInit
.
cfp
=
dnodeProcessMsgFromShell
;
rpcInit
.
cfp
=
dnodeProcessMsgFromShell
;
rpcInit
.
sessions
=
TSDB_SESSIONS_PER_DNODE
;
rpcInit
.
connType
=
TAOS_CONN_SERVER
;
rpcInit
.
idleTime
=
tsShellActivityTimer
*
2000
;
rpcInit
.
afp
=
dnodeRetrieveUserAuthInfo
;
rpcInit
.
idleTime
=
tsShellActivityTimer
*
1500
;
tsDnodeShell
Server
=
rpcOpen
(
&
rpcInit
);
if
(
tsDnodeShell
Server
==
NULL
)
{
tsDnodeShell
Rpc
=
rpcOpen
(
&
rpcInit
);
if
(
tsDnodeShell
Rpc
==
NULL
)
{
dError
(
"failed to init connection from shell"
);
return
-
1
;
}
dPrint
(
"shell is opened"
);
return
TSDB_CODE_SUCCESS
;
dPrint
(
"
connection to
shell is opened"
);
return
0
;
}
void
dnodeCleanupShell
()
{
if
(
tsDnodeShell
Server
)
{
rpcClose
(
tsDnodeShell
Server
);
if
(
tsDnodeShell
Rpc
)
{
rpcClose
(
tsDnodeShell
Rpc
);
}
}
SDnodeStatisInfo
dnodeGetStatisInfo
()
{
SDnodeStatisInfo
info
=
{
0
};
if
(
dnodeGetRunStatus
()
==
TSDB_DNODE_RUN_STATUS_RUNING
)
{
info
.
httpReqNum
=
httpGetReqCount
();
info
.
queryReqNum
=
atomic_exchange_32
(
&
tsDnodeQueryReqNum
,
0
);
info
.
submitReqNum
=
atomic_exchange_32
(
&
tsDnodeSubmitReqNum
,
0
);
}
void
dnodeProcessMsgFromShell
(
SRpcMsg
*
pMsg
)
{
SRpcMsg
rpcMsg
;
return
info
;
}
rpcMsg
.
handle
=
pMsg
->
handle
;
rpcMsg
.
pCont
=
NULL
;
rpcMsg
.
contLen
=
0
;
static
void
dnodeProcessMsgFromShell
(
char
msgType
,
void
*
pCont
,
int
contLen
,
void
*
handle
,
int32_t
code
)
{
if
(
dnodeGetRunStatus
()
!=
TSDB_DNODE_RUN_STATUS_RUNING
)
{
rpcSendResponse
(
handle
,
TSDB_CODE_NOT_READY
,
0
,
0
);
dTrace
(
"query msg is ignored since dnode not running"
);
dError
(
"RPC %p, shell msg is ignored since dnode not running"
,
pMsg
->
handle
);
rpcMsg
.
code
=
TSDB_CODE_NOT_READY
;
rpcSendResponse
(
&
rpcMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
return
;
}
dTrace
(
"conn:%p, msg:%s is received"
,
handle
,
taosMsg
[(
int8_t
)
msgType
]);
if
(
msgType
==
TSDB_MSG_TYPE_QUERY
)
{
dnodeProcessQueryMsg
(
pCont
,
contLen
,
handle
);
}
else
if
(
msgType
==
TSDB_MSG_TYPE_RETRIEVE
)
{
dnodeProcessRetrieveMsg
(
pCont
,
contLen
,
handle
);
}
else
if
(
msgType
==
TSDB_MSG_TYPE_SUBMIT
)
{
dnodeProcessSubmitMsg
(
pCont
,
contLen
,
handle
);
if
(
dnodeProcessShellMsgFp
[
pMsg
->
msgType
]
)
{
(
*
dnodeProcessShellMsgFp
[
pMsg
->
msgType
])(
pMsg
);
}
else
{
dError
(
"conn:%p, msg:%s is not processed"
,
handle
,
taosMsg
[(
int8_t
)
msgType
]);
}
//TODO free may be cause segmentfault
// rpcFreeCont(pCont);
}
static
int
dnodeRetrieveUserAuthInfo
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
return
TSDB_CODE_SUCCESS
;
}
static
void
dnodeProcessQueryMsgCb
(
int32_t
code
,
void
*
pQInfo
,
void
*
pConn
)
{
dTrace
(
"conn:%p, query is returned, code:%d"
,
pConn
,
code
);
int32_t
contLen
=
sizeof
(
SQueryTableRsp
);
SQueryTableRsp
*
queryRsp
=
(
SQueryTableRsp
*
)
rpcMallocCont
(
contLen
);
if
(
queryRsp
==
NULL
)
{
rpcSendResponse
(
pConn
,
TSDB_CODE_SERV_OUT_OF_MEMORY
,
NULL
,
0
);
return
;
}
queryRsp
->
code
=
htonl
(
code
);
queryRsp
->
qhandle
=
htobe64
((
uint64_t
)
(
pQInfo
));
rpcSendResponse
(
pConn
,
TSDB_CODE_SUCCESS
,
queryRsp
,
contLen
);
}
static
void
dnodeProcessQueryMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
)
{
atomic_fetch_add_32
(
&
tsDnodeQueryReqNum
,
1
);
SQueryTableMsg
*
pQuery
=
(
SQueryTableMsg
*
)
pCont
;
dnodeQueryData
(
pQuery
,
pConn
,
dnodeProcessQueryMsgCb
);
}
void
dnodeProcessRetrieveMsgCb
(
int32_t
code
,
void
*
pQInfo
,
void
*
pConn
)
{
dTrace
(
"conn:%p, retrieve is returned, code:%d"
,
pConn
,
code
);
assert
(
pConn
!=
NULL
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
rpcSendResponse
(
pConn
,
code
,
0
,
0
);
return
;
}
assert
(
pQInfo
!=
NULL
);
int32_t
contLen
=
dnodeGetRetrieveDataSize
(
pQInfo
);
SRetrieveTableRsp
*
pRetrieve
=
(
SRetrieveTableRsp
*
)
rpcMallocCont
(
contLen
);
if
(
pRetrieve
==
NULL
)
{
rpcSendResponse
(
pConn
,
TSDB_CODE_SERV_OUT_OF_MEMORY
,
0
,
0
);
return
;
}
code
=
dnodeGetRetrieveData
(
pQInfo
,
pRetrieve
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
rpcSendResponse
(
pConn
,
TSDB_CODE_INVALID_QHANDLE
,
0
,
0
);
}
pRetrieve
->
numOfRows
=
htonl
(
pRetrieve
->
numOfRows
);
pRetrieve
->
precision
=
htons
(
pRetrieve
->
precision
);
pRetrieve
->
offset
=
htobe64
(
pRetrieve
->
offset
);
pRetrieve
->
useconds
=
htobe64
(
pRetrieve
->
useconds
);
rpcSendResponse
(
pConn
,
TSDB_CODE_SUCCESS
,
pRetrieve
,
contLen
);
}
static
void
dnodeProcessRetrieveMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
)
{
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
pCont
;
pRetrieve
->
qhandle
=
htobe64
(
pRetrieve
->
qhandle
);
pRetrieve
->
free
=
htons
(
pRetrieve
->
free
);
dnodeRetrieveData
(
pRetrieve
,
pConn
,
dnodeProcessRetrieveMsgCb
);
}
void
dnodeProcessSubmitMsgCb
(
SShellSubmitRspMsg
*
result
,
void
*
pConn
)
{
assert
(
result
!=
NULL
);
dTrace
(
"conn:%p, submit is returned, code:%d"
,
pConn
,
result
->
code
);
if
(
result
->
code
!=
0
)
{
rpcSendResponse
(
pConn
,
result
->
code
,
NULL
,
0
);
return
;
}
int32_t
contLen
=
sizeof
(
SShellSubmitRspMsg
)
+
result
->
numOfFailedBlocks
*
sizeof
(
SShellSubmitRspBlock
);
SShellSubmitRspMsg
*
submitRsp
=
(
SShellSubmitRspMsg
*
)
rpcMallocCont
(
contLen
);
if
(
submitRsp
==
NULL
)
{
rpcSendResponse
(
pConn
,
TSDB_CODE_SERV_OUT_OF_MEMORY
,
NULL
,
0
);
return
;
}
memcpy
(
submitRsp
,
result
,
contLen
);
for
(
int
i
=
0
;
i
<
submitRsp
->
numOfFailedBlocks
;
++
i
)
{
SShellSubmitRspBlock
*
block
=
&
submitRsp
->
failedBlocks
[
i
];
if
(
block
->
code
==
TSDB_CODE_NOT_ACTIVE_VNODE
||
block
->
code
==
TSDB_CODE_INVALID_VNODE_ID
)
{
dnodeSendVnodeCfgMsg
(
block
->
vnode
);
}
else
if
(
block
->
code
==
TSDB_CODE_INVALID_TABLE_ID
||
block
->
code
==
TSDB_CODE_NOT_ACTIVE_TABLE
)
{
dnodeSendTableCfgMsg
(
block
->
vnode
,
block
->
sid
);
}
block
->
index
=
htonl
(
block
->
index
);
block
->
vnode
=
htonl
(
block
->
vnode
);
block
->
sid
=
htonl
(
block
->
sid
);
block
->
code
=
htonl
(
block
->
code
);
dError
(
"RPC %p, msg:%s from shell is not handled"
,
pMsg
->
handle
,
taosMsg
[
pMsg
->
msgType
]);
rpcMsg
.
code
=
TSDB_CODE_MSG_NOT_PROCESSED
;
rpcSendResponse
(
&
rpcMsg
);
rpcFreeCont
(
pMsg
->
pCont
);
}
submitRsp
->
code
=
htonl
(
submitRsp
->
code
);
submitRsp
->
numOfRows
=
htonl
(
submitRsp
->
numOfRows
);
submitRsp
->
affectedRows
=
htonl
(
submitRsp
->
affectedRows
);
submitRsp
->
failedRows
=
htonl
(
submitRsp
->
failedRows
);
submitRsp
->
numOfFailedBlocks
=
htonl
(
submitRsp
->
numOfFailedBlocks
);
rpcSendResponse
(
pConn
,
TSDB_CODE_SUCCESS
,
submitRsp
,
contLen
);
}
static
void
dnodeProcessSubmitMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
)
{
atomic_fetch_add_32
(
&
tsDnodeSubmitReqNum
,
1
);
SShellSubmitMsg
*
pSubmit
=
(
SShellSubmitMsg
*
)
pCont
;
dnodeWriteData
(
pSubmit
,
pConn
,
dnodeProcessSubmitMsgCb
);
}
src/dnode/src/dnodeSystem.c
浏览文件 @
b8fc28fb
...
...
@@ -25,12 +25,12 @@
#include "ttimer.h"
#include "tutil.h"
#include "http.h"
#include "trpc.h"
#include "dnode.h"
#include "dnodeMgmt.h"
#include "dnodeModule.h"
#include "dnodeShell.h"
#include "dnodeSystem.h"
#include "dnodeVnodeMgmt.h"
#ifdef CLUSTER
#include "account.h"
...
...
@@ -50,6 +50,11 @@ static int32_t dnodeInitRpcQHandle();
static
int32_t
dnodeInitQueryQHandle
();
static
int32_t
dnodeInitTmrCtl
();
int32_t
(
*
dnodeInitStorage
)()
=
NULL
;
void
(
*
dnodeCleanupStorage
)()
=
NULL
;
int32_t
(
*
dnodeInitPeers
)(
int32_t
numOfThreads
)
=
NULL
;
void
*
tsDnodeTmr
;
void
**
tsRpcQhandle
;
void
*
tsDnodeMgmtQhandle
;
...
...
@@ -93,7 +98,7 @@ void dnodeCleanUpSystem() {
dnodeCleanupShell
();
dnodeCleanUpModules
();
dnodeCleanup
Vnodes
();
dnodeCleanup
Mgmt
();
taosCloseLogger
();
dnodeCleanupStorage
();
dnodeCleanVnodesLock
();
...
...
@@ -154,7 +159,7 @@ int32_t dnodeInitSystem() {
return
-
1
;
}
dnodeInitMgmtIp
();
//
dnodeInitMgmtIp();
tsPrintGlobalConfig
();
...
...
@@ -193,7 +198,7 @@ int32_t dnodeInitSystem() {
return
-
1
;
}
if
(
dnode
OpenVnodes
()
<
0
)
{
if
(
dnode
InitMgmt
()
<
0
)
{
dError
(
"failed to init vnode storage"
);
return
-
1
;
}
...
...
@@ -246,12 +251,6 @@ int32_t dnodeInitStorageImp() {
return
0
;
}
int32_t
(
*
dnodeInitStorage
)()
=
dnodeInitStorageImp
;
void
dnodeCleanupStorageImp
()
{}
void
(
*
dnodeCleanupStorage
)()
=
dnodeCleanupStorageImp
;
static
int32_t
dnodeInitQueryQHandle
()
{
int32_t
numOfThreads
=
tsRatioOfQueryThreads
*
tsNumOfCores
*
tsNumOfThreadsPerCore
;
if
(
numOfThreads
<
1
)
{
...
...
@@ -303,9 +302,3 @@ int32_t (*dnodeCheckSystem)() = dnodeCheckSystemImp;
int32_t
dnodeInitPeersImp
(
int32_t
numOfThreads
)
{
return
0
;
}
int32_t
(
*
dnodeInitPeers
)(
int32_t
numOfThreads
)
=
dnodeInitPeersImp
;
src/dnode/src/dnodeWrite.c
浏览文件 @
b8fc28fb
...
...
@@ -17,82 +17,246 @@
#include "os.h"
#include "taoserror.h"
#include "tlog.h"
#include "tutil.h"
#include "trpc.h"
#include "tqueue.h"
#include "taosmsg.h"
#include "dnodeWrite.h"
#include "dnode
Vnode
Mgmt.h"
#include "dnodeMgmt.h"
void
dnodeWriteData
(
SShellSubmitMsg
*
pSubmit
,
void
*
pConn
,
void
(
*
callback
)(
SShellSubmitRspMsg
*
rsp
,
void
*
pConn
))
{
dTrace
(
"submit msg is disposed, affectrows:1"
);
typedef
struct
{
int32_t
code
;
int32_t
count
;
// number of vnodes returned result
int32_t
numOfVnodes
;
// number of vnodes involved
}
SRpcContext
;
SShellSubmitRspMsg
result
=
{
0
};
typedef
struct
_write
{
void
*
pCont
;
int
contLen
;
SRpcMsg
rpcMsg
;
void
*
pVnode
;
// pointer to vnode
SRpcContext
*
pRpcContext
;
// RPC message context
}
SWriteMsg
;
int32_t
numOfSid
=
htonl
(
pSubmit
->
numOfSid
);
if
(
numOfSid
<=
0
)
{
dError
(
"invalid num of tables:%d"
,
numOfSid
);
result
.
code
=
TSDB_CODE_INVALID_QUERY_MSG
;
callback
(
&
result
,
pConn
);
typedef
struct
{
taos_qset
qset
;
// queue set
pthread_t
thread
;
// thread
int
workerId
;
// worker ID
}
SWriteWorker
;
typedef
struct
_thread_obj
{
int
max
;
// max number of workers
int
nextId
;
// from 0 to max-1, cyclic
SWriteWorker
*
writeWorker
;
}
SWriteWorkerPool
;
static
void
(
*
dnodeProcessWriteMsgFp
[
TSDB_MSG_TYPE_MAX
])(
SWriteMsg
*
);
static
void
*
dnodeProcessWriteQueue
(
void
*
param
);
static
void
dnodeHandleIdleWorker
(
SWriteWorker
*
pWorker
);
static
void
dnodeProcessWriteResult
(
SWriteMsg
*
pWrite
);
static
void
dnodeProcessSubmitMsg
(
SWriteMsg
*
pMsg
);
static
void
dnodeProcessCreateTableMsg
(
SWriteMsg
*
pMsg
);
static
void
dnodeProcessDropTableMsg
(
SWriteMsg
*
pMsg
);
SWriteWorkerPool
wWorkerPool
;
int
dnodeInitWrite
()
{
dnodeProcessWriteMsgFp
[
TSDB_MSG_TYPE_SUBMIT
]
=
dnodeProcessSubmitMsg
;
dnodeProcessWriteMsgFp
[
TSDB_MSG_TYPE_DNODE_CREATE_TABLE
]
=
dnodeProcessCreateTableMsg
;
dnodeProcessWriteMsgFp
[
TSDB_MSG_TYPE_DNODE_REMOVE_TABLE
]
=
dnodeProcessDropTableMsg
;
wWorkerPool
.
max
=
tsNumOfCores
;
wWorkerPool
.
writeWorker
=
(
SWriteWorker
*
)
calloc
(
sizeof
(
SWriteWorker
),
wWorkerPool
.
max
);
if
(
wWorkerPool
.
writeWorker
==
NULL
)
return
-
1
;
for
(
int
i
=
0
;
i
<
wWorkerPool
.
max
;
++
i
)
{
wWorkerPool
.
writeWorker
[
i
].
workerId
=
i
;
}
result
.
code
=
0
;
result
.
numOfRows
=
1
;
result
.
affectedRows
=
1
;
result
.
numOfFailedBlocks
=
0
;
callback
(
&
result
,
pConn
);
return
0
;
}
int32_t
dnodeCreateTable
(
SDCreateTableMsg
*
pTable
)
{
if
(
pTable
->
tableType
==
TSDB_TABLE_TYPE_CHILD_TABLE
)
{
dTrace
(
"table:%s, start to create child table, stable:%s"
,
pTable
->
tableId
,
pTable
->
superTableId
);
}
else
if
(
pTable
->
tableType
==
TSDB_TABLE_TYPE_NORMAL_TABLE
){
dTrace
(
"table:%s, start to create normal table"
,
pTable
->
tableId
);
}
else
if
(
pTable
->
tableType
==
TSDB_TABLE_TYPE_STREAM_TABLE
){
dTrace
(
"table:%s, start to create stream table"
,
pTable
->
tableId
);
}
else
{
dError
(
"table:%s, invalid table type:%d"
,
pTable
->
tableType
);
void
dnodeCleanupWrite
()
{
free
(
wWorkerPool
.
writeWorker
);
}
void
dnodeWrite
(
SRpcMsg
*
pMsg
)
{
int
leftLen
=
pMsg
->
contLen
;
char
*
pCont
=
(
char
*
)
pMsg
->
pCont
;
int
contLen
=
0
;
int
numOfVnodes
=
0
;
int32_t
vgId
=
0
;
SRpcContext
*
pRpcContext
=
NULL
;
// parse head, get number of vnodes;
if
(
numOfVnodes
>
1
)
{
pRpcContext
=
calloc
(
sizeof
(
SRpcContext
),
1
);
pRpcContext
->
numOfVnodes
=
numOfVnodes
;
}
for
(
int
i
=
0
;
i
<
pTable
->
numOfVPeers
;
++
i
)
{
dTrace
(
"table:%s ip:%s vnode:%d sid:%d"
,
pTable
->
tableId
,
taosIpStr
(
pTable
->
vpeerDesc
[
i
].
ip
),
pTable
->
vpeerDesc
[
i
].
vnode
,
pTable
->
sid
);
while
(
leftLen
>
0
)
{
// todo: parse head, get vgId, contLen
// get pVnode from vgId
void
*
pVnode
=
dnodeGetVnode
(
vgId
);
if
(
pVnode
==
NULL
)
{
continue
;
}
// put message into queue
SWriteMsg
writeMsg
;
writeMsg
.
rpcMsg
=
*
pMsg
;
writeMsg
.
pCont
=
pCont
;
writeMsg
.
contLen
=
contLen
;
writeMsg
.
pRpcContext
=
pRpcContext
;
writeMsg
.
pVnode
=
pVnode
;
// pVnode shall be saved for usage later
taos_queue
queue
=
dnodeGetVnodeWworker
(
pVnode
);
taosWriteQitem
(
queue
,
&
writeMsg
);
// next vnode
leftLen
-=
contLen
;
pCont
-=
contLen
;
}
}
SSchema
*
pSchema
=
(
SSchema
*
)
pTable
->
data
;
for
(
int32_t
col
=
0
;
col
<
pTable
->
numOfColumns
;
++
col
)
{
dTrace
(
"table:%s col index:%d colId:%d bytes:%d type:%d name:%s"
,
pTable
->
tableId
,
col
,
pSchema
->
colId
,
pSchema
->
bytes
,
pSchema
->
type
,
pSchema
->
name
);
pSchema
++
;
void
*
dnodeAllocateWriteWorker
()
{
SWriteWorker
*
pWorker
=
wWorkerPool
.
writeWorker
+
wWorkerPool
.
nextId
;
if
(
pWorker
->
qset
==
NULL
)
{
pWorker
->
qset
=
taosOpenQset
();
if
(
pWorker
->
qset
==
NULL
)
return
NULL
;
pthread_attr_t
thAttr
;
pthread_attr_init
(
&
thAttr
);
pthread_attr_setdetachstate
(
&
thAttr
,
PTHREAD_CREATE_JOINABLE
);
if
(
pthread_create
(
&
pWorker
->
thread
,
&
thAttr
,
dnodeProcessWriteQueue
,
pWorker
)
!=
0
)
{
dError
(
"failed to create thread to process read queue, reason:%s"
,
strerror
(
errno
));
taosCloseQset
(
pWorker
->
qset
);
}
}
for
(
int32_t
col
=
0
;
col
<
pTable
->
numOfTags
;
++
col
)
{
dTrace
(
"table:%s tag index:%d colId:%d bytes:%d type:%d name:%s"
,
pTable
->
tableId
,
col
,
pSchema
->
colId
,
pSchema
->
bytes
,
pSchema
->
type
,
pSchema
->
name
);
pSchema
++
;
taos_queue
*
queue
=
taosOpenQueue
(
sizeof
(
SWriteMsg
));
if
(
queue
)
{
taosAddIntoQset
(
pWorker
->
qset
,
queue
);
wWorkerPool
.
nextId
=
(
wWorkerPool
.
nextId
+
1
)
%
wWorkerPool
.
max
;
}
return
queue
;
}
void
dnodeFreeWriteWorker
(
void
*
wqueue
)
{
taosCloseQueue
(
wqueue
);
return
TSDB_CODE_SUCCESS
;
// dynamically adjust the number of threads
}
/*
* Remove table from local repository
*/
int32_t
dnodeDropTable
(
SDRemoveTableMsg
*
pTable
)
{
dPrint
(
"table:%s, sid:%d is removed"
,
pTable
->
tableId
,
pTable
->
sid
);
return
TSDB_CODE_SUCCESS
;
static
void
*
dnodeProcessWriteQueue
(
void
*
param
)
{
SWriteWorker
*
pWorker
=
(
SWriteWorker
*
)
param
;
taos_qall
qall
;
SWriteMsg
writeMsg
;
int
numOfMsgs
;
while
(
1
)
{
numOfMsgs
=
taosReadAllQitemsFromQset
(
pWorker
->
qset
,
&
qall
);
if
(
numOfMsgs
<=
0
)
{
dnodeHandleIdleWorker
(
pWorker
);
// thread exit if no queues anymore
continue
;
}
for
(
int
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
// retrieve all items, and write them into WAL
taosGetQitem
(
qall
,
&
writeMsg
);
// walWrite(pVnode->whandle, writeMsg.rpcMsg.msgType, writeMsg.pCont, writeMsg.contLen);
}
// flush WAL file
// walFsync(pVnode->whandle);
// browse all items, and process them one by one
taosResetQitems
(
qall
);
for
(
int
i
=
0
;
i
<
numOfMsgs
;
++
i
)
{
taosGetQitem
(
qall
,
&
writeMsg
);
terrno
=
0
;
if
(
dnodeProcessWriteMsgFp
[
writeMsg
.
rpcMsg
.
msgType
])
{
(
*
dnodeProcessWriteMsgFp
[
writeMsg
.
rpcMsg
.
msgType
])
(
&
writeMsg
);
}
else
{
terrno
=
TSDB_CODE_MSG_NOT_PROCESSED
;
}
dnodeProcessWriteResult
(
&
writeMsg
);
}
// free the Qitems;
taosFreeQitems
(
qall
);
}
return
NULL
;
}
/*
* Create stream
* if stream already exist, update it
*/
int32_t
dnodeCreateStream
(
SDAlterStreamMsg
*
pStream
)
{
dPrint
(
"stream:%s, is created, "
,
pStream
->
tableId
);
return
TSDB_CODE_SUCCESS
;
static
void
dnodeProcessWriteResult
(
SWriteMsg
*
pWrite
)
{
SRpcContext
*
pRpcContext
=
pWrite
->
pRpcContext
;
int32_t
code
=
0
;
dnodeReleaseVnode
(
pWrite
->
pVnode
);
if
(
pRpcContext
)
{
if
(
terrno
)
{
if
(
pRpcContext
->
code
==
0
)
pRpcContext
->
code
=
terrno
;
}
int
count
=
atomic_add_fetch_32
(
&
pRpcContext
->
count
,
1
);
if
(
count
<
pRpcContext
->
numOfVnodes
)
{
// not over yet, multiple vnodes
return
;
}
// over, result can be merged now
code
=
pRpcContext
->
code
;
}
else
{
code
=
terrno
;
}
SRpcMsg
rsp
;
rsp
.
handle
=
pWrite
->
rpcMsg
.
handle
;
rsp
.
code
=
code
;
rsp
.
pCont
=
NULL
;
rpcSendResponse
(
&
rsp
);
rpcFreeCont
(
pWrite
->
rpcMsg
.
pCont
);
// free the received message
}
/*
* Remove all child tables of supertable from local repository
*/
int32_t
dnodeDropSuperTable
(
SDRemoveSuperTableMsg
*
pStable
)
{
dPrint
(
"stable:%s, is removed"
,
pStable
->
tableId
);
return
TSDB_CODE_SUCCESS
;
static
void
dnodeHandleIdleWorker
(
SWriteWorker
*
pWorker
)
{
int
num
=
taosGetQueueNumber
(
pWorker
->
qset
);
if
(
num
>
0
)
{
usleep
(
100
);
sched_yield
();
}
else
{
taosCloseQset
(
pWorker
->
qset
);
pWorker
->
qset
=
NULL
;
pthread_exit
(
NULL
);
}
}
static
void
dnodeProcessSubmitMsg
(
SWriteMsg
*
pMsg
)
{
}
static
void
dnodeProcessCreateTableMsg
(
SWriteMsg
*
pMsg
)
{
}
static
void
dnodeProcessDropTableMsg
(
SWriteMsg
*
pMsg
)
{
}
src/mnode/inc/mgmtShell.h
浏览文件 @
b8fc28fb
...
...
@@ -28,8 +28,6 @@ int32_t mgmtInitShell();
void
mgmtCleanUpShell
();
extern
int32_t
(
*
mgmtCheckRedirectMsg
)(
void
*
pConn
);
extern
void
(
*
mgmtProcessCfgMnodeMsg
)(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
);
extern
void
(
*
mgmtProcessDropMnodeMsg
)(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
);
/*
* If table not exist, will create it
...
...
src/mnode/src/mgmtDnodeInt.c
浏览文件 @
b8fc28fb
...
...
@@ -48,7 +48,7 @@ static void mgmtSendMsgToDnodeQueueFp(SSchedMsg *sched) {
void
*
ahandle
=
sched
->
ahandle
;
int8_t
*
pCont
=
sched
->
msg
;
dnodeProcessMsgFromMgmt
(
msgType
,
pCont
,
contLen
,
ahandle
,
code
);
//
dnodeProcessMsgFromMgmt(msgType, pCont, contLen, ahandle, code);
}
void
mgmtSendMsgToDnode
(
SRpcIpSet
*
ipSet
,
int8_t
msgType
,
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
...
...
@@ -157,13 +157,19 @@ static void mgmtProcessCreateTableRsp(int8_t msgType, int8_t *pCont, int32_t con
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
rpcSendResponse
(
info
->
thandle
,
code
,
NULL
,
0
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
code
=
code
;
rpcMsg
.
handle
=
info
->
thandle
;
rpcSendResponse
(
&
rpcMsg
);
}
else
{
if
(
info
->
type
==
TSDB_PROCESS_CREATE_TABLE_GET_META
)
{
mTrace
(
"table:%s, start to process get meta"
,
pTable
->
tableId
);
mgmtProcessGetTableMeta
(
pTable
,
thandle
);
}
else
{
rpcSendResponse
(
info
->
thandle
,
code
,
NULL
,
0
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
code
=
code
;
rpcMsg
.
handle
=
info
->
thandle
;
rpcSendResponse
(
&
rpcMsg
);
}
}
...
...
@@ -236,7 +242,11 @@ static void mgmtProcessDnodeGrantMsg(void *pCont, void *thandle) {
mgmtUpdateGrantInfoFp
(
pCont
);
mTrace
(
"grant info is updated"
);
}
rpcSendResponse
(
thandle
,
TSDB_CODE_SUCCESS
,
NULL
,
0
);
SRpcMsg
rpcMsg
=
{
0
};
rpcMsg
.
code
=
TSDB_CODE_SUCCESS
;
rpcMsg
.
handle
=
thandle
;
rpcSendResponse
(
&
rpcMsg
);
}
void
mgmtProcessMsgFromDnode
(
char
msgType
,
void
*
pCont
,
int32_t
contLen
,
void
*
pConn
,
int32_t
code
)
{
...
...
@@ -368,7 +378,7 @@ int32_t mgmtSendCfgDnodeMsg(char *cont) {
//#else
// (void)tsCfgDynamicOptions(pCfg->config);
//#endif
//
return 0;
return
0
;
}
int32_t
mgmtInitDnodeInt
()
{
...
...
src/mnode/src/mgmtShell.c
浏览文件 @
b8fc28fb
...
...
@@ -46,34 +46,36 @@ static RetrieveMetaFp mgmtRetrieveFp[TSDB_MGMT_TABLE_MAX] = {0};
static
void
mgmtInitShowMsgFp
();
static
void
mgmtInitProcessShellMsg
();
static
void
mgmtProcessMsgFromShell
(
char
type
,
void
*
pCont
,
int
contLen
,
void
*
ahandle
,
int32_t
code
);
static
void
(
*
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_MAX
])(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
);
static
void
mgmtProcessUnSupportMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
);
static
void
mgmtProcessMsgFromShell
(
SRpcMsg
*
msg
);
static
void
(
*
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_MAX
])(
SRpcMsg
*
msg
);
static
void
mgmtProcessUnSupportMsg
(
SRpcMsg
*
msg
);
static
int
mgmtRetriveUserAuthInfo
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
void
*
tsShellConnServer
=
NULL
;
void
mgmtProcessTranRequest
(
SSchedMsg
*
sched
)
{
int8_t
msgType
=
*
(
int8_t
*
)
(
sched
->
msg
);
int32_t
contLen
=
*
(
int32_t
*
)
(
sched
->
msg
+
sizeof
(
int8_t
));
int8_t
*
pCont
=
sched
->
msg
+
sizeof
(
int32_t
)
+
sizeof
(
int8_t
);
void
*
pConn
=
sched
->
thandle
;
(
*
mgmtProcessShellMsg
[
msgType
])(
pCont
,
contLen
,
pConn
);
SRpcMsg
rpcMsg
;
rpcMsg
.
msgType
=
*
(
int8_t
*
)
(
sched
->
msg
);
rpcMsg
.
contLen
=
*
(
int32_t
*
)
(
sched
->
msg
+
sizeof
(
int8_t
));
rpcMsg
.
pCont
=
sched
->
msg
+
sizeof
(
int32_t
)
+
sizeof
(
int8_t
);
rpcMsg
.
handle
=
sched
->
thandle
;
rpcMsg
.
code
=
TSDB_CODE_SUCCESS
;
(
*
mgmtProcessShellMsg
[
rpcMsg
.
msgType
])(
&
rpcMsg
);
if
(
sched
->
msg
)
{
free
(
sched
->
msg
);
}
}
void
mgmtAddToTranRequest
(
int8_t
type
,
void
*
pCont
,
int
contLen
,
void
*
ahandle
)
{
void
mgmtAddToTranRequest
(
SRpcMsg
*
rpcMsg
)
{
SSchedMsg
schedMsg
;
schedMsg
.
msg
=
malloc
(
contLen
+
sizeof
(
int32_t
)
+
sizeof
(
int8_t
));
schedMsg
.
msg
=
malloc
(
rpcMsg
->
contLen
+
sizeof
(
int32_t
)
+
sizeof
(
int8_t
));
schedMsg
.
fp
=
mgmtProcessTranRequest
;
schedMsg
.
tfp
=
NULL
;
schedMsg
.
thandle
=
a
handle
;
*
(
int8_t
*
)
(
schedMsg
.
msg
)
=
t
ype
;
*
(
int32_t
*
)
(
schedMsg
.
msg
+
sizeof
(
int8_t
))
=
contLen
;
memcpy
(
schedMsg
.
msg
+
sizeof
(
int32_t
)
+
sizeof
(
int8_t
),
pCont
,
contLen
);
schedMsg
.
thandle
=
rpcMsg
->
handle
;
*
(
int8_t
*
)
(
schedMsg
.
msg
)
=
rpcMsg
->
msgT
ype
;
*
(
int32_t
*
)
(
schedMsg
.
msg
+
sizeof
(
int8_t
))
=
rpcMsg
->
contLen
;
memcpy
(
schedMsg
.
msg
+
sizeof
(
int32_t
)
+
sizeof
(
int8_t
),
rpcMsg
->
pCont
,
rpcMsg
->
contLen
);
taosScheduleTask
(
tsMgmtTranQhandle
,
&
schedMsg
);
}
...
...
@@ -115,14 +117,20 @@ void mgmtCleanUpShell() {
}
}
void
mgmtProcessTableMetaMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
STableInfoMsg
*
pInfo
=
pCont
;
void
mgmtProcessTableMetaMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
;
rpcRsp
.
handle
=
rpcMsg
->
handle
;
rpcRsp
.
pCont
=
NULL
;
rpcRsp
.
contLen
=
0
;
STableInfoMsg
*
pInfo
=
rpcMsg
->
pCont
;
pInfo
->
createFlag
=
htons
(
pInfo
->
createFlag
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
mError
(
"table:%s, failed to get table meta, invalid user"
,
pInfo
->
tableId
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -130,19 +138,22 @@ void mgmtProcessTableMetaMsg(void *pCont, int32_t contLen, void *ahandle) {
if
(
pTable
==
NULL
)
{
if
(
pInfo
->
createFlag
!=
1
)
{
mError
(
"table:%s, failed to get table meta, table not exist"
,
pInfo
->
tableId
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_TABLE
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_TABLE
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
else
{
// on demand create table from super table if table does not exists
if
(
mgmtCheckRedirectMsg
(
a
handle
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"table:%s, failed to create table while get meta info, need redirect message"
,
pInfo
->
tableId
);
return
;
}
SCreateTableMsg
*
pCreateMsg
=
rpcMallocCont
(
sizeof
(
SCreateTableMsg
)
+
sizeof
(
STagData
));
int32_t
contLen
=
sizeof
(
SCreateTableMsg
)
+
sizeof
(
STagData
);
SCreateTableMsg
*
pCreateMsg
=
rpcMallocCont
(
contLen
);
if
(
pCreateMsg
==
NULL
)
{
mError
(
"table:%s, failed to create table while get meta info, no enough memory"
,
pInfo
->
tableId
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -150,31 +161,38 @@ void mgmtProcessTableMetaMsg(void *pCont, int32_t contLen, void *ahandle) {
strcpy
(
pCreateMsg
->
tableId
,
pInfo
->
tableId
);
mError
(
"table:%s, start to create table while get meta info"
,
pInfo
->
tableId
);
mgmtCreateTable
(
pCreateMsg
,
contLen
,
a
handle
,
true
);
mgmtCreateTable
(
pCreateMsg
,
contLen
,
rpcMsg
->
handle
,
true
);
}
}
else
{
mgmtProcessGetTableMeta
(
pTable
,
a
handle
);
mgmtProcessGetTableMeta
(
pTable
,
rpcMsg
->
handle
);
}
}
void
mgmtProcessMultiTableMetaMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
void
mgmtProcessMultiTableMetaMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
;
rpcRsp
.
handle
=
rpcMsg
->
handle
;
rpcRsp
.
pCont
=
NULL
;
rpcRsp
.
contLen
=
0
;
SRpcConnInfo
connInfo
;
rpcGetConnInfo
(
a
handle
,
&
connInfo
);
rpcGetConnInfo
(
rpcMsg
->
handle
,
&
connInfo
);
bool
usePublicIp
=
(
connInfo
.
serverIp
==
tsPublicIpInt
);
SUserObj
*
pUser
=
mgmtGetUser
(
connInfo
.
user
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SMultiTableInfoMsg
*
pInfo
=
pCont
;
SMultiTableInfoMsg
*
pInfo
=
rpcMsg
->
pCont
;
pInfo
->
numOfTables
=
htonl
(
pInfo
->
numOfTables
);
int32_t
totalMallocLen
=
4
*
1024
*
1024
;
// first malloc 4 MB, subsequent reallocation as twice
SMultiTableMeta
*
pMultiMeta
=
rpcMallocCont
(
totalMallocLen
);
if
(
pMultiMeta
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -211,43 +229,48 @@ void mgmtProcessMultiTableMetaMsg(void *pCont, int32_t contLen, void *ahandle) {
}
}
rpcSendResponse
(
ahandle
,
TSDB_CODE_SUCCESS
,
pMultiMeta
,
pMultiMeta
->
contLen
);
rpcRsp
.
pCont
=
pMultiMeta
;
rpcRsp
.
contLen
=
pMultiMeta
->
contLen
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessSuperTableMetaMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
SRpcConnInfo
connInfo
;
rpcGetConnInfo
(
ahandle
,
&
connInfo
);
// bool usePublicIp = (connInfo.serverIp == tsPublicIpInt);
SSuperTableInfoMsg
*
pInfo
=
pCont
;
void
mgmtProcessSuperTableMetaMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SSuperTableInfoMsg
*
pInfo
=
rpcMsg
->
pCont
;
STableInfo
*
pTable
=
mgmtGetSuperTable
(
pInfo
->
tableId
);
if
(
pTable
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_TABLE
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_TABLE
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SSuperTableInfoRsp
*
pRsp
=
mgmtGetSuperTableVgroup
((
SSuperTableObj
*
)
pTable
);
if
(
pRsp
!=
NULL
)
{
int32_t
msgLen
=
sizeof
(
SSuperTableObj
)
+
htonl
(
pRsp
->
numOfDnodes
)
*
sizeof
(
int32_t
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_SUCCESS
,
pRsp
,
msgLen
);
rpcRsp
.
pCont
=
pRsp
;
rpcRsp
.
contLen
=
msgLen
;
rpcSendResponse
(
&
rpcRsp
);
}
else
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_SUCCESS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_TABLE
;
rpcSendResponse
(
&
rpcRsp
);
}
}
void
mgmtProcessCreateDbMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessCreateDbMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SCreateDbMsg
*
pCreate
=
(
SCreateDbMsg
*
)
pCont
;
SCreateDbMsg
*
pCreate
=
(
SCreateDbMsg
*
)
rpcMsg
->
pCont
;
pCreate
->
maxSessions
=
htonl
(
pCreate
->
maxSessions
);
pCreate
->
cacheBlockSize
=
htonl
(
pCreate
->
cacheBlockSize
);
...
...
@@ -272,21 +295,24 @@ void mgmtProcessCreateDbMsg(void *pCont, int32_t contLen, void *ahandle) {
}
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessAlterDbMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessAlterDbMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SAlterDbMsg
*
pAlter
=
(
SAlterDbMsg
*
)
pCont
;
SAlterDbMsg
*
pAlter
=
(
SAlterDbMsg
*
)
rpcMsg
->
pCont
;
pAlter
->
daysPerFile
=
htonl
(
pAlter
->
daysPerFile
);
pAlter
->
daysToKeep
=
htonl
(
pAlter
->
daysToKeep
);
pAlter
->
maxSessions
=
htonl
(
pAlter
->
maxSessions
)
+
1
;
...
...
@@ -301,92 +327,104 @@ void mgmtProcessAlterDbMsg(void *pCont, int32_t contLen, void *ahandle) {
}
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessKillQueryMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessKillQueryMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SKillQueryMsg
*
pKill
=
(
SKillQueryMsg
*
)
pCont
;
SKillQueryMsg
*
pKill
=
(
SKillQueryMsg
*
)
rpcMsg
->
pCont
;
int32_t
code
;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillQuery
(
pKill
->
queryId
,
a
handle
);
code
=
mgmtKillQuery
(
pKill
->
queryId
,
rpcMsg
->
handle
);
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessKillStreamMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessKillStreamMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SKillStreamMsg
*
pKill
=
(
SKillStreamMsg
*
)
pCont
;
SKillStreamMsg
*
pKill
=
(
SKillStreamMsg
*
)
rpcMsg
->
pCont
;
int32_t
code
;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillStream
(
pKill
->
queryId
,
a
handle
);
code
=
mgmtKillStream
(
pKill
->
queryId
,
rpcMsg
->
handle
);
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessKillConnectionMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessKillConnectionMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SKillConnectionMsg
*
pKill
=
(
SKillConnectionMsg
*
)
pCont
;
SKillConnectionMsg
*
pKill
=
(
SKillConnectionMsg
*
)
rpcMsg
->
pCont
;
int32_t
code
;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtKillConnection
(
pKill
->
queryId
,
a
handle
);
code
=
mgmtKillConnection
(
pKill
->
queryId
,
rpcMsg
->
handle
);
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessCreateUserMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessCreateUserMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
int32_t
code
;
if
(
pUser
->
superAuth
)
{
SCreateUserMsg
*
pCreate
=
pCont
;
SCreateUserMsg
*
pCreate
=
rpcMsg
->
pCont
;
code
=
mgmtCreateUser
(
pUser
->
pAcct
,
pCreate
->
user
,
pCreate
->
pass
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
mLPrint
(
"user:%s is created by %s"
,
pCreate
->
user
,
pUser
->
user
);
...
...
@@ -395,29 +433,34 @@ void mgmtProcessCreateUserMsg(void *pCont, int32_t contLen, void *ahandle) {
code
=
TSDB_CODE_NO_RIGHTS
;
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessAlterUserMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessAlterUserMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pOperUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pOperUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pOperUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SAlterUserMsg
*
pAlter
=
pCont
;
SAlterUserMsg
*
pAlter
=
rpcMsg
->
pCont
;
SUserObj
*
pUser
=
mgmtGetUser
(
pAlter
->
user
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
strcmp
(
pUser
->
user
,
"monitor"
)
==
0
||
(
strcmp
(
pUser
->
user
+
1
,
pUser
->
acct
)
==
0
&&
pUser
->
user
[
0
]
==
'_'
))
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -447,7 +490,9 @@ void mgmtProcessAlterUserMsg(void *pCont, int32_t contLen, void *ahandle) {
code
=
TSDB_CODE_NO_RIGHTS
;
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -496,34 +541,40 @@ void mgmtProcessAlterUserMsg(void *pCont, int32_t contLen, void *ahandle) {
code
=
TSDB_CODE_NO_RIGHTS
;
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessDropUserMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessDropUserMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pOperUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pOperUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pOperUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SDropUserMsg
*
pDrop
=
pCont
;
SDropUserMsg
*
pDrop
=
rpcMsg
->
pCont
;
SUserObj
*
pUser
=
mgmtGetUser
(
pDrop
->
user
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
strcmp
(
pUser
->
user
,
"monitor"
)
==
0
||
(
strcmp
(
pUser
->
user
+
1
,
pUser
->
acct
)
==
0
&&
pUser
->
user
[
0
]
==
'_'
))
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -554,23 +605,26 @@ void mgmtProcessDropUserMsg(void *pCont, int32_t contLen, void *ahandle) {
code
=
TSDB_CODE_NO_RIGHTS
;
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessDropDbMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessDropDbMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
int32_t
code
;
if
(
pUser
->
superAuth
)
{
SDropDbMsg
*
pDrop
=
pCont
;
SDropDbMsg
*
pDrop
=
rpcMsg
->
pCont
;
code
=
mgmtDropDbByName
(
pUser
->
pAcct
,
pDrop
->
db
,
pDrop
->
ignoreNotExists
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
mLPrint
(
"DB:%s is dropped by %s"
,
pDrop
->
db
,
pUser
->
user
);
...
...
@@ -579,7 +633,8 @@ void mgmtProcessDropDbMsg(void *pCont, int32_t contLen, void *ahandle) {
code
=
TSDB_CODE_NO_RIGHTS
;
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
static
void
mgmtInitShowMsgFp
()
{
...
...
@@ -618,10 +673,12 @@ static void mgmtInitShowMsgFp() {
mgmtRetrieveFp
[
TSDB_MGMT_TABLE_VNODES
]
=
mgmtRetrieveVnodes
;
}
void
mgmtProcessShowMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
SShowMsg
*
pShowMsg
=
pCont
;
void
mgmtProcessShowMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SShowMsg
*
pShowMsg
=
rpcMsg
->
pCont
;
if
(
pShowMsg
->
type
==
TSDB_MGMT_TABLE_DNODE
||
TSDB_MGMT_TABLE_GRANTS
||
TSDB_MGMT_TABLE_SCORES
)
{
if
(
mgmtCheckRedirectMsg
(
a
handle
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
}
...
...
@@ -629,7 +686,8 @@ void mgmtProcessShowMsg(void *pCont, int32_t contLen, void *ahandle) {
int32_t
size
=
sizeof
(
SShowRsp
)
+
sizeof
(
SSchema
)
*
TSDB_MAX_COLUMNS
+
TSDB_EXTRA_PAYLOAD_SIZE
;
SShowRsp
*
pShowRsp
=
rpcMallocCont
(
size
);
if
(
pShowRsp
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -649,7 +707,7 @@ void mgmtProcessShowMsg(void *pCont, int32_t contLen, void *ahandle) {
mgmtSaveQhandle
(
pShow
);
pShowRsp
->
qhandle
=
htobe64
((
uint64_t
)
pShow
);
code
=
(
*
mgmtGetMetaFp
[(
uint8_t
)
pShowMsg
->
type
])(
&
pShowRsp
->
tableMeta
,
pShow
,
a
handle
);
code
=
(
*
mgmtGetMetaFp
[(
uint8_t
)
pShowMsg
->
type
])(
&
pShowRsp
->
tableMeta
,
pShow
,
rpcMsg
->
handle
);
if
(
code
==
0
)
{
size
=
sizeof
(
SShowRsp
)
+
sizeof
(
SSchema
)
*
pShow
->
numOfColumns
;
}
else
{
...
...
@@ -659,14 +717,18 @@ void mgmtProcessShowMsg(void *pCont, int32_t contLen, void *ahandle) {
}
}
rpcSendResponse
(
ahandle
,
code
,
pShowRsp
,
size
);
rpcRsp
.
pCont
=
pShowRsp
;
rpcRsp
.
contLen
=
size
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessRetrieveMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
void
mgmtProcessRetrieveMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
int32_t
rowsToRead
=
0
;
int32_t
size
=
0
;
int32_t
rowsRead
=
0
;
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
pCont
;
SRetrieveTableMsg
*
pRetrieve
=
(
SRetrieveTableMsg
*
)
rpcMsg
->
pCont
;
pRetrieve
->
qhandle
=
htobe64
(
pRetrieve
->
qhandle
);
/*
...
...
@@ -675,14 +737,16 @@ void mgmtProcessRetrieveMsg(void *pCont, int32_t contLen, void *ahandle) {
*/
if
(
!
mgmtCheckQhandle
(
pRetrieve
->
qhandle
))
{
mError
(
"retrieve:%p, qhandle:%p is invalid"
,
pRetrieve
,
pRetrieve
->
qhandle
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_QHANDLE
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_QHANDLE
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SShowObj
*
pShow
=
(
SShowObj
*
)
pRetrieve
->
qhandle
;
if
(
pShow
->
signature
!=
(
void
*
)
pShow
)
{
mError
(
"pShow:%p, signature:%p, query memory is corrupted"
,
pShow
,
pShow
->
signature
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_MEMORY_CORRUPTED
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_MEMORY_CORRUPTED
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
else
{
if
((
pRetrieve
->
free
&
TSDB_QUERY_TYPE_FREE_RESOURCE
)
!=
TSDB_QUERY_TYPE_FREE_RESOURCE
)
{
...
...
@@ -705,7 +769,7 @@ void mgmtProcessRetrieveMsg(void *pCont, int32_t contLen, void *ahandle) {
// if free flag is set, client wants to clean the resources
if
((
pRetrieve
->
free
&
TSDB_QUERY_TYPE_FREE_RESOURCE
)
!=
TSDB_QUERY_TYPE_FREE_RESOURCE
)
rowsRead
=
(
*
mgmtRetrieveFp
[(
uint8_t
)
pShow
->
type
])(
pShow
,
pRsp
->
data
,
rowsToRead
,
a
handle
);
rowsRead
=
(
*
mgmtRetrieveFp
[(
uint8_t
)
pShow
->
type
])(
pShow
,
pRsp
->
data
,
rowsToRead
,
rpcMsg
->
handle
);
if
(
rowsRead
<
0
)
{
rowsRead
=
0
;
// TSDB_CODE_ACTION_IN_PROGRESS;
...
...
@@ -716,107 +780,120 @@ void mgmtProcessRetrieveMsg(void *pCont, int32_t contLen, void *ahandle) {
pRsp
->
numOfRows
=
htonl
(
rowsRead
);
pRsp
->
precision
=
htonl
(
TSDB_TIME_PRECISION_MILLI
);
// millisecond time precision
rpcSendResponse
(
ahandle
,
TSDB_CODE_SUCCESS
,
pRsp
,
size
);
rpcRsp
.
pCont
=
pRsp
;
rpcRsp
.
contLen
=
size
;
rpcSendResponse
(
&
rpcRsp
);
if
(
rowsToRead
==
0
)
{
mgmtFreeQhandle
(
pShow
);
}
}
void
mgmtProcessCreateTableMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
SCreateTableMsg
*
pCreate
=
(
SCreateTableMsg
*
)
pCont
;
void
mgmtProcessCreateTableMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SCreateTableMsg
*
pCreate
=
(
SCreateTableMsg
*
)
rpcMsg
->
pCont
;
pCreate
->
numOfColumns
=
htons
(
pCreate
->
numOfColumns
);
pCreate
->
numOfTags
=
htons
(
pCreate
->
numOfTags
);
pCreate
->
sqlLen
=
htons
(
pCreate
->
sqlLen
);
SSchema
*
pSchema
=
pCreate
->
schema
;
SSchema
*
pSchema
=
(
SSchema
*
)
pCreate
->
schema
;
for
(
int32_t
i
=
0
;
i
<
pCreate
->
numOfColumns
+
pCreate
->
numOfTags
;
++
i
)
{
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
colId
=
i
;
pSchema
++
;
}
if
(
mgmtCheckRedirectMsg
(
a
handle
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"table:%s, failed to create table, need redirect message"
,
pCreate
->
tableId
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
mError
(
"table:%s, failed to create table, invalid user"
,
pCreate
->
tableId
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
!
pUser
->
writeAuth
)
{
mError
(
"table:%s, failed to create table, no rights"
,
pCreate
->
tableId
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
int32_t
code
=
mgmtCreateTable
(
pCreate
,
contLen
,
a
handle
,
false
);
int32_t
code
=
mgmtCreateTable
(
pCreate
,
rpcMsg
->
contLen
,
rpcMsg
->
handle
,
false
);
if
(
code
!=
TSDB_CODE_ACTION_IN_PROGRESS
)
{
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
}
void
mgmtProcessDropTableMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
SDropTableMsg
*
pDrop
=
(
SDropTableMsg
*
)
pCont
;
void
mgmtProcessDropTableMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SDropTableMsg
*
pDrop
=
(
SDropTableMsg
*
)
rpcMsg
->
pCont
;
if
(
mgmtCheckRedirectMsg
(
a
handle
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"table:%s, failed to drop table, need redirect message"
,
pDrop
->
tableId
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
mError
(
"table:%s, failed to drop table, invalid user"
,
pDrop
->
tableId
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
!
pUser
->
writeAuth
)
{
mError
(
"table:%s, failed to drop table, no rights"
,
pDrop
->
tableId
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SDbObj
*
pDb
=
mgmtGetDbByTableId
(
pDrop
->
tableId
);
if
(
pDb
==
NULL
)
{
mError
(
"table:%s, failed to drop table, db not selected"
,
pDrop
->
tableId
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_DB_NOT_SELECTED
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_DB_NOT_SELECTED
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
int32_t
code
=
mgmtDropTable
(
pDb
,
pDrop
->
tableId
,
pDrop
->
igNotExists
);
if
(
code
!=
TSDB_CODE_ACTION_IN_PROGRESS
)
{
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
}
void
mgmtProcessAlterTableMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessAlterTableMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SAlterTableMsg
*
pAlter
=
(
SAlterTableMsg
*
)
pCont
;
int32_t
code
;
SAlterTableMsg
*
pAlter
=
(
SAlterTableMsg
*
)
rpcMsg
->
pCont
;
if
(
!
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
pAlter
->
type
=
htons
(
pAlter
->
type
);
pAlter
->
numOfCols
=
htons
(
pAlter
->
numOfCols
);
if
(
pAlter
->
numOfCols
>
2
)
{
mError
(
"table:%s error numOfCols:%d in alter table"
,
pAlter
->
tableId
,
pAlter
->
numOfCols
);
code
=
TSDB_CODE_APP_ERROR
;
rpcRsp
.
code
=
TSDB_CODE_APP_ERROR
;
}
else
{
SDbObj
*
pDb
=
mgmtGetDb
(
pAlter
->
db
);
if
(
pDb
)
{
...
...
@@ -824,61 +901,61 @@ void mgmtProcessAlterTableMsg(void *pCont, int32_t contLen, void *ahandle) {
pAlter
->
schema
[
i
].
bytes
=
htons
(
pAlter
->
schema
[
i
].
bytes
);
}
code
=
mgmtAlterTable
(
pDb
,
pAlter
);
if
(
code
==
0
)
{
rpcRsp
.
code
=
mgmtAlterTable
(
pDb
,
pAlter
);
if
(
rpcRsp
.
code
==
0
)
{
mLPrint
(
"table:%s is altered by %s"
,
pAlter
->
tableId
,
pUser
->
user
);
}
}
else
{
code
=
TSDB_CODE_DB_NOT_SELECTED
;
rpcRsp
.
code
=
TSDB_CODE_DB_NOT_SELECTED
;
}
}
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
}
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessCfgDnodeMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
void
mgmtProcessCfgDnodeMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SCfgDnodeMsg
*
pCfg
=
(
SCfgDnodeMsg
*
)
pCont
;
int32_t
code
;
SCfgDnodeMsg
*
pCfg
=
(
SCfgDnodeMsg
*
)
rpcMsg
->
pCont
;
if
(
strcmp
(
pUser
->
pAcct
->
user
,
"root"
)
!=
0
)
{
code
=
TSDB_CODE_NO_RIGHTS
;
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
}
else
{
code
=
mgmtSendCfgDnodeMsg
(
pCont
);
rpcRsp
.
code
=
mgmtSendCfgDnodeMsg
(
rpcMsg
->
pCont
);
}
if
(
code
==
TSDB_CODE_SUCCESS
)
{
if
(
rpcRsp
.
code
==
TSDB_CODE_SUCCESS
)
{
mTrace
(
"dnode:%s is configured by %s"
,
pCfg
->
ip
,
pUser
->
user
);
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtProcessHeartBeatMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
SHeartBeatMsg
*
pHBMsg
=
(
SHeartBeatMsg
*
)
pCont
;
void
mgmtProcessHeartBeatMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SHeartBeatMsg
*
pHBMsg
=
(
SHeartBeatMsg
*
)
rpcMsg
->
pCont
;
mgmtSaveQueryStreamList
(
pHBMsg
);
SHeartBeatRsp
*
pHBRsp
=
(
SHeartBeatRsp
*
)
rpcMallocCont
(
contLen
);
SHeartBeatRsp
*
pHBRsp
=
(
SHeartBeatRsp
*
)
rpcMallocCont
(
sizeof
(
SHeartBeatRsp
)
);
if
(
pHBRsp
==
NULL
)
{
rpc
SendResponse
(
ahandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
,
NULL
,
0
)
;
rpc
FreeCont
(
pCont
);
rpc
Rsp
.
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
rpc
SendResponse
(
&
rpcRsp
);
return
;
}
SRpcConnInfo
connInfo
;
rpcGetConnInfo
(
a
handle
,
&
connInfo
);
rpcGetConnInfo
(
rpcMsg
->
handle
,
&
connInfo
);
pHBRsp
->
ipList
.
inUse
=
0
;
pHBRsp
->
ipList
.
port
=
htons
(
tsMgmtShellPort
);
...
...
@@ -904,7 +981,9 @@ void mgmtProcessHeartBeatMsg(void *pCont, int32_t contLen, void *ahandle) {
pHBRsp
->
streamId
=
0
;
pHBRsp
->
killConnection
=
0
;
rpcSendResponse
(
ahandle
,
TSDB_CODE_SUCCESS
,
pHBRsp
,
sizeof
(
SHeartBeatMsg
));
rpcRsp
.
pCont
=
pHBRsp
;
rpcRsp
.
contLen
=
sizeof
(
SHeartBeatRsp
);
rpcSendResponse
(
&
rpcRsp
);
}
int
mgmtRetriveUserAuthInfo
(
char
*
user
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
)
{
...
...
@@ -922,10 +1001,12 @@ int mgmtRetriveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret,
}
}
static
void
mgmtProcessConnectMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
thandle
)
{
SConnectMsg
*
pConnectMsg
=
(
SConnectMsg
*
)
pCont
;
static
void
mgmtProcessConnectMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SConnectMsg
*
pConnectMsg
=
(
SConnectMsg
*
)
rpcMsg
->
pCont
;
SRpcConnInfo
connInfo
;
rpcGetConnInfo
(
t
handle
,
&
connInfo
);
rpcGetConnInfo
(
rpcMsg
->
handle
,
&
connInfo
);
int32_t
code
;
SUserObj
*
pUser
=
mgmtGetUser
(
connInfo
.
user
);
...
...
@@ -987,13 +1068,15 @@ static void mgmtProcessConnectMsg(void *pCont, int32_t contLen, void *thandle) {
}
connect_over:
rpcRsp
.
code
=
code
;
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mLError
(
"user:%s login from %s, code:%d"
,
connInfo
.
user
,
taosIpStr
(
connInfo
.
clientIp
),
code
);
rpcSendResponse
(
thandle
,
code
,
NULL
,
0
);
}
else
{
mLPrint
(
"user:%s login from %s, code:%d"
,
connInfo
.
user
,
taosIpStr
(
connInfo
.
clientIp
),
code
);
rpcSendResponse
(
thandle
,
code
,
pConnectRsp
,
sizeof
(
SConnectRsp
));
rpcRsp
.
pCont
=
pConnectRsp
;
rpcRsp
.
contLen
=
sizeof
(
SConnectRsp
);
}
rpcSendResponse
(
&
rpcRsp
);
}
/**
...
...
@@ -1024,48 +1107,51 @@ static bool mgmtCheckMsgReadOnly(int8_t type, void *pCont) {
return
false
;
}
static
void
mgmtProcessMsgFromShell
(
char
type
,
void
*
pCont
,
int
contLen
,
void
*
ahandle
,
int32_t
code
)
{
static
void
mgmtProcessMsgFromShell
(
SRpcMsg
*
rpcMsg
)
{
if
(
sdbGetRunStatus
()
!=
SDB_STATUS_SERVING
)
{
mTrace
(
"shell msg is ignored since SDB is not ready"
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_NOT_READY
,
NULL
,
0
);
rpcFreeCont
(
pCont
);
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
TSDB_CODE_NOT_READY
,
.
msgType
=
0
};
rpcSendResponse
(
&
rpcRsp
);
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
}
if
(
mgmtCheckMsgReadOnly
(
type
,
pCont
))
{
(
*
mgmtProcessShellMsg
[
(
int8_t
)
type
])(
pCont
,
contLen
,
ahandle
);
if
(
mgmtCheckMsgReadOnly
(
rpcMsg
->
msgType
,
rpcMsg
->
pCont
))
{
(
*
mgmtProcessShellMsg
[
rpcMsg
->
msgType
])(
rpcMsg
);
}
else
{
if
(
mgmtProcessShellMsg
[
(
int8_t
)
t
ype
])
{
mgmtAddToTranRequest
(
(
int8_t
)
type
,
pCont
,
contLen
,
ahandle
);
if
(
mgmtProcessShellMsg
[
rpcMsg
->
msgT
ype
])
{
mgmtAddToTranRequest
(
rpcMsg
);
}
else
{
mError
(
"%s from shell is not processed"
,
taosMsg
[
(
int8_t
)
t
ype
]);
mError
(
"%s from shell is not processed"
,
taosMsg
[
rpcMsg
->
msgT
ype
]);
}
}
//TODO free may be cause segment fault
//
// rpcFreeCont(pCont);
rpcFreeCont
(
rpcMsg
->
pCont
);
}
void
mgmtProcessCreateVgroup
(
SCreateTableMsg
*
pCreate
,
int32_t
contLen
,
void
*
thandle
,
bool
isGetMeta
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SDbObj
*
pDb
=
mgmtGetDb
(
pCreate
->
db
);
if
(
pDb
==
NULL
)
{
mError
(
"table:%s, failed to create vgroup, db not found"
,
pCreate
->
tableId
);
rpcSendResponse
(
thandle
,
TSDB_CODE_INVALID_DB
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_DB
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SVgObj
*
pVgroup
=
mgmtCreateVgroup
(
pDb
);
if
(
pVgroup
==
NULL
)
{
mError
(
"table:%s, failed to alloc vnode to vgroup"
,
pCreate
->
tableId
);
rpcSendResponse
(
thandle
,
TSDB_CODE_NO_ENOUGH_DNODES
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_ENOUGH_DNODES
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
void
*
cont
=
rpcMallocCont
(
contLen
);
if
(
cont
==
NULL
)
{
mError
(
"table:%s, failed to create table, can not alloc memory"
,
pCreate
->
tableId
);
rpcSendResponse
(
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -1087,6 +1173,7 @@ void mgmtProcessCreateVgroup(SCreateTableMsg *pCreate, int32_t contLen, void *th
void
mgmtProcessCreateTable
(
SVgObj
*
pVgroup
,
SCreateTableMsg
*
pCreate
,
int32_t
contLen
,
void
*
thandle
,
bool
isGetMeta
)
{
assert
(
pVgroup
!=
NULL
);
SRpcMsg
rpcRsp
=
{.
handle
=
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
int32_t
sid
=
taosAllocateId
(
pVgroup
->
idPool
);
if
(
sid
<
0
)
{
...
...
@@ -1095,21 +1182,20 @@ void mgmtProcessCreateTable(SVgObj *pVgroup, SCreateTableMsg *pCreate, int32_t c
return
;
}
int32_t
code
;
STableInfo
*
pTable
;
SDCreateTableMsg
*
pDCreate
=
NULL
;
if
(
pCreate
->
numOfColumns
==
0
)
{
mTrace
(
"table:%s, start to create child table, vgroup:%d sid:%d"
,
pCreate
->
tableId
,
pVgroup
->
vgId
,
sid
);
code
=
mgmtCreateChildTable
(
pCreate
,
contLen
,
pVgroup
,
sid
,
&
pDCreate
,
&
pTable
);
rpcRsp
.
code
=
mgmtCreateChildTable
(
pCreate
,
contLen
,
pVgroup
,
sid
,
&
pDCreate
,
&
pTable
);
}
else
{
mTrace
(
"table:%s, start to create normal table, vgroup:%d sid:%d"
,
pCreate
->
tableId
,
pVgroup
->
vgId
,
sid
);
code
=
mgmtCreateNormalTable
(
pCreate
,
contLen
,
pVgroup
,
sid
,
&
pDCreate
,
&
pTable
);
rpcRsp
.
code
=
mgmtCreateNormalTable
(
pCreate
,
contLen
,
pVgroup
,
sid
,
&
pDCreate
,
&
pTable
);
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
rpcRsp
.
code
!=
TSDB_CODE_SUCCESS
)
{
mTrace
(
"table:%s, failed to create table in vgroup:%d sid:%d "
,
pCreate
->
tableId
,
pVgroup
->
vgId
,
sid
);
rpcSendResponse
(
thandle
,
code
,
NULL
,
0
);
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -1129,10 +1215,12 @@ void mgmtProcessCreateTable(SVgObj *pVgroup, SCreateTableMsg *pCreate, int32_t c
}
void
mgmtProcessGetTableMeta
(
STableInfo
*
pTable
,
void
*
thandle
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
thandle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
SDbObj
*
pDb
=
mgmtGetDbByTableId
(
pTable
->
tableId
);
if
(
pDb
==
NULL
||
pDb
->
dropStatus
!=
TSDB_DB_STATUS_READY
)
{
mError
(
"table:%s, failed to get table meta, db not selected"
,
pTable
->
tableId
);
rpcSendResponse
(
thandle
,
TSDB_CODE_DB_NOT_SELECTED
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_DB_NOT_SELECTED
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -1141,15 +1229,17 @@ void mgmtProcessGetTableMeta(STableInfo *pTable, void *thandle) {
bool
usePublicIp
=
(
connInfo
.
serverIp
==
tsPublicIpInt
);
STableMeta
*
pMeta
=
rpcMallocCont
(
sizeof
(
STableMeta
)
+
sizeof
(
SSchema
)
*
TSDB_MAX_COLUMNS
);
int32_t
code
=
mgmtGetTableMeta
(
pDb
,
pTable
,
pMeta
,
usePublicIp
);
rpcRsp
.
code
=
mgmtGetTableMeta
(
pDb
,
pTable
,
pMeta
,
usePublicIp
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
rpcRsp
.
code
!=
TSDB_CODE_SUCCESS
)
{
rpcFreeCont
(
pMeta
);
rpcSendResponse
(
thandle
,
TSDB_CODE_SUCCESS
,
NULL
,
0
);
}
else
{
pMeta
->
contLen
=
htons
(
pMeta
->
contLen
);
rpcSendResponse
(
thandle
,
TSDB_CODE_SUCCESS
,
pMeta
,
pMeta
->
contLen
);
rpcRsp
.
pCont
=
pMeta
;
rpcRsp
.
contLen
=
pMeta
->
contLen
;
}
rpcSendResponse
(
&
rpcRsp
);
}
static
int32_t
mgmtCheckRedirectMsgImp
(
void
*
pConn
)
{
...
...
@@ -1158,20 +1248,26 @@ static int32_t mgmtCheckRedirectMsgImp(void *pConn) {
int32_t
(
*
mgmtCheckRedirectMsg
)(
void
*
pConn
)
=
mgmtCheckRedirectMsgImp
;
static
void
mgmtProcessUnSupportMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_OPS_NOT_SUPPORT
,
NULL
,
0
);
static
void
mgmtProcessUnSupportMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{
.
msgType
=
0
,
.
pCont
=
0
,
.
contLen
=
0
,
.
code
=
TSDB_CODE_OPS_NOT_SUPPORT
,
.
handle
=
rpcMsg
->
handle
};
rpcSendResponse
(
&
rpcRsp
);
}
void
(
*
mgmtProcessCfgMnodeMsg
)(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
=
mgmtProcessUnSupportMsg
;
void
(
*
mgmtProcessDropMnodeMsg
)(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
=
mgmtProcessUnSupportMsg
;
static
void
mgmtProcessAlterAcctMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
static
void
mgmtProcessAlterAcctMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
!
mgmtAlterAcctFp
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_OPS_NOT_SUPPORT
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_OPS_NOT_SUPPORT
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SAlterAcctMsg
*
pAlter
=
pCont
;
SAlterAcctMsg
*
pAlter
=
rpcMsg
->
pCont
;
pAlter
->
cfg
.
maxUsers
=
htonl
(
pAlter
->
cfg
.
maxUsers
);
pAlter
->
cfg
.
maxDbs
=
htonl
(
pAlter
->
cfg
.
maxDbs
);
pAlter
->
cfg
.
maxTimeSeries
=
htonl
(
pAlter
->
cfg
.
maxTimeSeries
);
...
...
@@ -1183,21 +1279,23 @@ static void mgmtProcessAlterAcctMsg(void *pCont, int32_t contLen, void *ahandle)
pAlter
->
cfg
.
maxInbound
=
htobe64
(
pAlter
->
cfg
.
maxInbound
);
pAlter
->
cfg
.
maxOutbound
=
htobe64
(
pAlter
->
cfg
.
maxOutbound
);
if
(
mgmtCheckRedirectMsg
(
a
handle
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"account:%s, failed to alter account, need redirect message"
,
pAlter
->
user
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
mError
(
"account:%s, failed to alter account, invalid user"
,
pAlter
->
user
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
{
mError
(
"account:%s, failed to alter account, no rights"
,
pAlter
->
user
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -1208,32 +1306,36 @@ static void mgmtProcessAlterAcctMsg(void *pCont, int32_t contLen, void *ahandle)
mError
(
"account:%s, failed to alter account, reason:%s"
,
pAlter
->
user
,
tstrerror
(
code
));
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
static
void
mgmtProcessDropAcctMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
static
void
mgmtProcessDropAcctMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
!
mgmtDropAcctFp
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_OPS_NOT_SUPPORT
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_OPS_NOT_SUPPORT
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SDropAcctMsg
*
pDrop
=
(
SDropAcctMsg
*
)
pCont
;
if
(
mgmtCheckRedirectMsg
(
ahandle
)
!=
TSDB_CODE_SUCCESS
)
{
SDropAcctMsg
*
pDrop
=
(
SDropAcctMsg
*
)
rpcMsg
->
pCont
;
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"account:%s, failed to drop account, need redirect message"
,
pDrop
->
user
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
mError
(
"account:%s, failed to drop account, invalid user"
,
pDrop
->
user
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
{
mError
(
"account:%s, failed to drop account, no rights"
,
pDrop
->
user
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -1244,16 +1346,19 @@ static void mgmtProcessDropAcctMsg(void *pCont, int32_t contLen, void *ahandle)
mError
(
"account:%s, failed to drop account, reason:%s"
,
pDrop
->
user
,
tstrerror
(
code
));
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
static
void
mgmtProcessCreateAcctMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
static
void
mgmtProcessCreateAcctMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
!
mgmtCreateAcctFp
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_OPS_NOT_SUPPORT
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_OPS_NOT_SUPPORT
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SCreateAcctMsg
*
pCreate
=
(
SCreateAcctMsg
*
)
pCont
;
SCreateAcctMsg
*
pCreate
=
(
SCreateAcctMsg
*
)
rpcMsg
->
pCont
;
pCreate
->
cfg
.
maxUsers
=
htonl
(
pCreate
->
cfg
.
maxUsers
);
pCreate
->
cfg
.
maxDbs
=
htonl
(
pCreate
->
cfg
.
maxDbs
);
pCreate
->
cfg
.
maxTimeSeries
=
htonl
(
pCreate
->
cfg
.
maxTimeSeries
);
...
...
@@ -1265,21 +1370,23 @@ static void mgmtProcessCreateAcctMsg(void *pCont, int32_t contLen, void *ahandle
pCreate
->
cfg
.
maxInbound
=
htobe64
(
pCreate
->
cfg
.
maxInbound
);
pCreate
->
cfg
.
maxOutbound
=
htobe64
(
pCreate
->
cfg
.
maxOutbound
);
if
(
mgmtCheckRedirectMsg
(
a
handle
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"account:%s, failed to create account, need redirect message"
,
pCreate
->
user
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
mError
(
"account:%s, failed to create account, invalid user"
,
pCreate
->
user
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
{
mError
(
"account:%s, failed to create account, no rights"
,
pCreate
->
user
);
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -1290,31 +1397,36 @@ static void mgmtProcessCreateAcctMsg(void *pCont, int32_t contLen, void *ahandle
mError
(
"account:%s, failed to create account, reason:%s"
,
pCreate
->
user
,
tstrerror
(
code
));
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
static
void
mgmtProcessCreateDnodeMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
static
void
mgmtProcessCreateDnodeMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
!
mgmtCreateDnodeFp
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_OPS_NOT_SUPPORT
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_OPS_NOT_SUPPORT
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SCreateDnodeMsg
*
pCreate
=
(
SCreateDnodeMsg
*
)
pCont
;
if
(
mgmtCheckRedirectMsg
(
a
handle
)
!=
TSDB_CODE_SUCCESS
)
{
SCreateDnodeMsg
*
pCreate
=
(
SCreateDnodeMsg
*
)
rpcMsg
->
pCont
;
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"failed to create dnode:%s, redirect this message"
,
pCreate
->
ip
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
mError
(
"failed to create dnode:%s, reason:%s"
,
pCreate
->
ip
,
tstrerror
(
TSDB_CODE_INVALID_USER
));
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
{
mError
(
"failed to create dnode:%s, reason:%s"
,
pCreate
->
ip
,
tstrerror
(
TSDB_CODE_NO_RIGHTS
));
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -1325,31 +1437,36 @@ static void mgmtProcessCreateDnodeMsg(void *pCont, int32_t contLen, void *ahandl
mError
(
"failed to create dnode:%s, reason:%s"
,
pCreate
->
ip
,
tstrerror
(
code
));
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
static
void
mgmtProcessDropDnodeMsg
(
void
*
pCont
,
int32_t
contLen
,
void
*
ahandle
)
{
static
void
mgmtProcessDropDnodeMsg
(
SRpcMsg
*
rpcMsg
)
{
SRpcMsg
rpcRsp
=
{.
handle
=
rpcMsg
->
handle
,
.
pCont
=
NULL
,
.
contLen
=
0
,
.
code
=
0
,
.
msgType
=
0
};
if
(
!
mgmtDropDnodeByIpFp
)
{
rpcSendResponse
(
ahandle
,
TSDB_CODE_OPS_NOT_SUPPORT
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_OPS_NOT_SUPPORT
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
SDropDnodeMsg
*
pDrop
=
(
SDropDnodeMsg
*
)
pCont
;
if
(
mgmtCheckRedirectMsg
(
a
handle
)
!=
TSDB_CODE_SUCCESS
)
{
SDropDnodeMsg
*
pDrop
=
(
SDropDnodeMsg
*
)
rpcMsg
->
pCont
;
if
(
mgmtCheckRedirectMsg
(
rpcMsg
->
handle
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"failed to drop dnode:%s, redirect this message"
,
pDrop
->
ip
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
a
handle
);
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
if
(
pUser
==
NULL
)
{
mError
(
"failed to drop dnode:%s, reason:%s"
,
pDrop
->
ip
,
tstrerror
(
TSDB_CODE_INVALID_USER
));
rpcSendResponse
(
ahandle
,
TSDB_CODE_INVALID_USER
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_INVALID_USER
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
if
(
strcmp
(
pUser
->
user
,
"root"
)
!=
0
)
{
mError
(
"failed to drop dnode:%s, reason:%s"
,
pDrop
->
ip
,
tstrerror
(
TSDB_CODE_NO_RIGHTS
));
rpcSendResponse
(
ahandle
,
TSDB_CODE_NO_RIGHTS
,
NULL
,
0
);
rpcRsp
.
code
=
TSDB_CODE_NO_RIGHTS
;
rpcSendResponse
(
&
rpcRsp
);
return
;
}
...
...
@@ -1360,7 +1477,8 @@ static void mgmtProcessDropDnodeMsg(void *pCont, int32_t contLen, void *ahandle)
mError
(
"failed to drop dnode:%s, reason:%s"
,
pDrop
->
ip
,
tstrerror
(
code
));
}
rpcSendResponse
(
ahandle
,
code
,
NULL
,
0
);
rpcRsp
.
code
=
code
;
rpcSendResponse
(
&
rpcRsp
);
}
void
mgmtInitProcessShellMsg
()
{
...
...
@@ -1383,8 +1501,8 @@ void mgmtInitProcessShellMsg() {
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_DROP_DNODE
]
=
mgmtProcessDropDnodeMsg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_DNODE_CFG
]
=
mgmtProcessCfgDnodeMsg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_CREATE_MNODE
]
=
mgmtProcessUnSupportMsg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_DROP_MNODE
]
=
mgmtProcess
DropMnode
Msg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_CFG_MNODE
]
=
mgmtProcess
CfgMnode
Msg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_DROP_MNODE
]
=
mgmtProcess
UnSupport
Msg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_CFG_MNODE
]
=
mgmtProcess
UnSupport
Msg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_KILL_QUERY
]
=
mgmtProcessKillQueryMsg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_KILL_STREAM
]
=
mgmtProcessKillStreamMsg
;
mgmtProcessShellMsg
[
TSDB_MSG_TYPE_KILL_CONNECTION
]
=
mgmtProcessKillConnectionMsg
;
...
...
src/mnode/src/mgmtTable.c
浏览文件 @
b8fc28fb
...
...
@@ -133,7 +133,7 @@ int32_t mgmtCreateTable(SCreateTableMsg *pCreate, int32_t contLen, void *thandle
SAcctObj
*
pAcct
=
mgmtGetAcct
(
pDb
->
cfg
.
acct
);
assert
(
pAcct
!=
NULL
);
int32_t
code
=
mgmtCheckTableLimit
(
pAcct
,
pCreate
);
int32_t
code
=
mgmtCheckTableLimit
(
pAcct
,
pCreate
->
numOfColumns
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"table:%s, failed to create table, table num exceed the limit"
,
pCreate
->
tableId
);
return
code
;
...
...
src/rpc/src/rpcMain.c
浏览文件 @
b8fc28fb
...
...
@@ -359,7 +359,7 @@ void rpcSendRequest(void *shandle, SRpcIpSet *pIpSet, SRpcMsg *pMsg) {
// connection type is application specific.
// for TDengine, all the query, show commands shall have TCP connection
char
type
=
pMsg
->
msgType
;
if
(
type
==
TSDB_MSG_TYPE_
DNODE_QUERY
||
type
==
TSDB_MSG_TYPE_DNOD
E_RETRIEVE
||
if
(
type
==
TSDB_MSG_TYPE_
QUERY
||
type
==
TSDB_MSG_TYP
E_RETRIEVE
||
type
==
TSDB_MSG_TYPE_STABLE_META
||
type
==
TSDB_MSG_TYPE_MULTI_TABLE_META
||
type
==
TSDB_MSG_TYPE_SHOW
)
pContext
->
connType
=
RPC_CONN_TCPC
;
...
...
src/vnode/CMakeLists.txt
浏览文件 @
b8fc28fb
cmake_minimum_required
(
VERSION 2.8
)
CMAKE_MINIMUM_REQUIRED
(
VERSION 2.8
)
PROJECT
(
TDengine
)
add_subdirectory
(
common
)
add_subdirectory
(
tsdb
)
enable_testing
()
# add_subdirectory(tests)
\ No newline at end of file
ADD_SUBDIRECTORY
(
common
)
ADD_SUBDIRECTORY
(
tsdb
)
# ENABLE_TESTING()
# ADD_SUBDIRECTORY(tests)
src/vnode/common/CMakeLists.txt
浏览文件 @
b8fc28fb
aux_source_directory
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/src SOURCE_LIST
)
CMAKE_MINIMUM_REQUIRED
(
VERSION 2.8
)
PROJECT
(
TDengine
)
list
(
REMOVE_ITEM SOURCE_LIST
${
CMAKE_CURRENT_SOURCE_DIR
}
/src/vnodePeer.c
)
IF
((
TD_LINUX_64
)
OR
(
TD_LINUX_32 AND TD_ARM
))
INCLUDE_DIRECTORIES
(
${
TD_OS_DIR
}
/inc
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/inc
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/util/inc
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/dnode/inc
)
message
(
STATUS
"Common source file
${
SOURCE_LIST
}
"
)
add_library
(
common
${
SOURCE_LIST
}
)
target_include_directories
(
common PUBLIC
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
)
INCLUDE_DIRECTORIES
(
inc
)
AUX_SOURCE_DIRECTORY
(
src SRC
)
ADD_LIBRARY
(
common
${
SRC
}
)
ENDIF
(
)
src/vnode/common/src/vnodePeer.c
→
src/vnode/common/src/vnodePeer.c
_del
浏览文件 @
b8fc28fb
文件已移动
src/vnode/tsdb/CMakeLists.txt
浏览文件 @
b8fc28fb
aux_source_directory
(
${
CMAKE_CURRENT_SOURCE_DIR
}
/src SOURCE_LIST
)
CMAKE_MINIMUM_REQUIRED
(
VERSION 2.8
)
PROJECT
(
TDengine
)
add_library
(
tsdb STATIC
${
SOURCE_LIST
}
)
target_link_libraries
(
tsdb common tutil
)
IF
((
TD_LINUX_64
)
OR
(
TD_LINUX_32 AND TD_ARM
))
INCLUDE_DIRECTORIES
(
${
TD_OS_DIR
}
/inc
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/inc
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/util/inc
)
INCLUDE_DIRECTORIES
(
${
TD_COMMUNITY_DIR
}
/src/vnode/common/inc
)
target_include_directories
(
tsdb
PUBLIC
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/inc"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/src/inc"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/src/util/inc"
PUBLIC
"
${
CMAKE_SOURCE_DIR
}
/src/os/linux/inc"
)
INCLUDE_DIRECTORIES
(
inc
)
AUX_SOURCE_DIRECTORY
(
src SRC
)
add_subdirectory
(
tests
)
\ No newline at end of file
ADD_LIBRARY
(
tsdb
${
SRC
}
)
TARGET_LINK_LIBRARIES
(
tsdb common tutil
)
# Someone has no gtest directory, so comment it
#ADD_SUBDIRECTORY(tests)
ENDIF
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录