Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
b59f6c18
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b59f6c18
编写于
3月 15, 2021
作者:
M
Minglei Jin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-3275]<feature>: [mnode] create, drop, show funcs
上级
9dfce04f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
457 addition
and
113 deletion
+457
-113
src/inc/taosdef.h
src/inc/taosdef.h
+1
-0
src/inc/taoserror.h
src/inc/taoserror.h
+6
-0
src/mnode/inc/mnodeDef.h
src/mnode/inc/mnodeDef.h
+11
-0
src/mnode/inc/mnodeFunc.h
src/mnode/inc/mnodeFunc.h
+40
-0
src/mnode/inc/mnodeSdb.h
src/mnode/inc/mnodeSdb.h
+3
-2
src/mnode/src/mnodeDb.c
src/mnode/src/mnodeDb.c
+0
-111
src/mnode/src/mnodeFunc.c
src/mnode/src/mnodeFunc.c
+388
-0
src/mnode/src/mnodeMain.c
src/mnode/src/mnodeMain.c
+2
-0
src/util/src/terror.c
src/util/src/terror.c
+6
-0
未找到文件。
src/inc/taosdef.h
浏览文件 @
b59f6c18
...
@@ -184,6 +184,7 @@ do { \
...
@@ -184,6 +184,7 @@ do { \
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
#define TSDB_TABLE_NAME_LEN 193 // it is a null-terminated string
#define TSDB_DB_NAME_LEN 33
#define TSDB_DB_NAME_LEN 33
#define TSDB_FUNC_NAME_LEN 128
#define TSDB_FUNC_NAME_LEN 128
#define TSDB_FUNC_CODE_LEN (4096 - 512)
#define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
#define TSDB_TABLE_FNAME_LEN (TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN + TSDB_TABLE_NAME_LEN)
#define TSDB_COL_NAME_LEN 65
#define TSDB_COL_NAME_LEN 65
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
#define TSDB_MAX_SAVED_SQL_LEN TSDB_MAX_COLUMNS * 64
...
...
src/inc/taoserror.h
浏览文件 @
b59f6c18
...
@@ -173,6 +173,12 @@ int32_t* taosGetErrno();
...
@@ -173,6 +173,12 @@ int32_t* taosGetErrno();
#define TSDB_CODE_MND_INVALID_STABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x036D) //"Super table does not exist")
#define TSDB_CODE_MND_INVALID_STABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x036D) //"Super table does not exist")
#define TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG TAOS_DEF_ERROR_CODE(0, 0x036E) //"Invalid create table message")
#define TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG TAOS_DEF_ERROR_CODE(0, 0x036E) //"Invalid create table message")
#define TSDB_CODE_MND_INVALID_FUNC_NAME TAOS_DEF_ERROR_CODE(0, 0x0370) //"Invalid func name")
#define TSDB_CODE_MND_INVALID_FUNC_LEN TAOS_DEF_ERROR_CODE(0, 0x0371) //"Invalid func length")
#define TSDB_CODE_MND_INVALID_FUNC_CODE TAOS_DEF_ERROR_CODE(0, 0x0372) //"Invalid func code")
#define TSDB_CODE_MND_FUNC_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0373) //"Func already exists")
#define TSDB_CODE_MND_INVALID_FUNC TAOS_DEF_ERROR_CODE(0, 0x0351) //"Invalid func")
#define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380) //"Database not specified or available")
#define TSDB_CODE_MND_DB_NOT_SELECTED TAOS_DEF_ERROR_CODE(0, 0x0380) //"Database not specified or available")
#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381) //"Database already exists")
#define TSDB_CODE_MND_DB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0381) //"Database already exists")
#define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0382) //"Invalid database options")
#define TSDB_CODE_MND_INVALID_DB_OPTION TAOS_DEF_ERROR_CODE(0, 0x0382) //"Invalid database options")
...
...
src/mnode/inc/mnodeDef.h
浏览文件 @
b59f6c18
...
@@ -214,6 +214,17 @@ typedef struct SUserObj {
...
@@ -214,6 +214,17 @@ typedef struct SUserObj {
struct
SAcctObj
*
pAcct
;
struct
SAcctObj
*
pAcct
;
}
SUserObj
;
}
SUserObj
;
typedef
struct
SFuncObj
{
char
name
[
TSDB_FUNC_NAME_LEN
];
char
path
[
PATH_MAX
];
int32_t
codeLen
;
char
code
[
TSDB_FUNC_CODE_LEN
];
int64_t
createdTime
;
int8_t
reserved
[
64
];
int8_t
updateEnd
[
4
];
int32_t
refCount
;
}
SFuncObj
;
typedef
struct
{
typedef
struct
{
int64_t
totalStorage
;
// Total storage wrtten from this account
int64_t
totalStorage
;
// Total storage wrtten from this account
int64_t
compStorage
;
// Compressed storage on disk
int64_t
compStorage
;
// Compressed storage on disk
...
...
src/mnode/inc/mnodeFunc.h
0 → 100644
浏览文件 @
b59f6c18
/*
* 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/>.
*/
#ifndef TDENGINE_MNODE_FUNC_H
#define TDENGINE_MNODE_FUNC_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include "mnodeDef.h"
int32_t
mnodeInitFuncs
();
void
mnodeCleanupFuncs
();
SFuncObj
*
mnodeGetFunc
(
char
*
name
);
void
*
mnodeGetNextFunc
(
void
*
pIter
,
SFuncObj
**
pFunc
);
void
mnodeCancelGetNextFunc
(
void
*
pIter
);
void
mnodeIncFuncRef
(
SFuncObj
*
pFunc
);
void
mnodeDecFuncRef
(
SFuncObj
*
pFunc
);
int32_t
mnodeCreateFunc
(
SAcctObj
*
pAcct
,
char
*
name
,
int32_t
codeLen
,
char
*
code
,
char
*
path
,
SMnodeMsg
*
pMsg
);
#ifdef __cplusplus
}
#endif
#endif
src/mnode/inc/mnodeSdb.h
浏览文件 @
b59f6c18
...
@@ -33,7 +33,8 @@ typedef enum {
...
@@ -33,7 +33,8 @@ typedef enum {
SDB_TABLE_VGROUP
=
6
,
SDB_TABLE_VGROUP
=
6
,
SDB_TABLE_STABLE
=
7
,
SDB_TABLE_STABLE
=
7
,
SDB_TABLE_CTABLE
=
8
,
SDB_TABLE_CTABLE
=
8
,
SDB_TABLE_MAX
=
9
SDB_TABLE_FUNC
=
9
,
SDB_TABLE_MAX
=
10
}
ESdbTable
;
}
ESdbTable
;
typedef
enum
{
typedef
enum
{
...
@@ -110,4 +111,4 @@ bool sdbCheckRowDeleted(void *pTable, void *pRow);
...
@@ -110,4 +111,4 @@ bool sdbCheckRowDeleted(void *pTable, void *pRow);
}
}
#endif
#endif
#endif
#endif
\ No newline at end of file
src/mnode/src/mnodeDb.c
浏览文件 @
b59f6c18
...
@@ -44,17 +44,12 @@ void * tsDbSdb = NULL;
...
@@ -44,17 +44,12 @@ void * tsDbSdb = NULL;
static
int32_t
tsDbUpdateSize
;
static
int32_t
tsDbUpdateSize
;
static
int32_t
mnodeCreateDb
(
SAcctObj
*
pAcct
,
SCreateDbMsg
*
pCreate
,
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeCreateDb
(
SAcctObj
*
pAcct
,
SCreateDbMsg
*
pCreate
,
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeCreateFunc
(
SAcctObj
*
pAcct
,
SCreateFuncMsg
*
pCreate
,
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeDropDb
(
SMnodeMsg
*
newMsg
);
static
int32_t
mnodeDropDb
(
SMnodeMsg
*
newMsg
);
static
int32_t
mnodeSetDbDropping
(
SDbObj
*
pDb
);
static
int32_t
mnodeSetDbDropping
(
SDbObj
*
pDb
);
static
int32_t
mnodeGetDbMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeGetDbMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeGetFuncMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeRetrieveDbs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeRetrieveDbs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeRetrieveFuncs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeProcessCreateDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessCreateDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessCreateFuncMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessDropDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessDropDbMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessDropFuncMsg
(
SMnodeMsg
*
pMsg
);
int32_t
mnodeProcessAlterDbMsg
(
SMnodeMsg
*
pMsg
);
int32_t
mnodeProcessAlterDbMsg
(
SMnodeMsg
*
pMsg
);
...
@@ -182,14 +177,10 @@ int32_t mnodeInitDbs() {
...
@@ -182,14 +177,10 @@ int32_t mnodeInitDbs() {
}
}
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_DB
,
mnodeProcessCreateDbMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_DB
,
mnodeProcessCreateDbMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_FUNCTION
,
mnodeProcessCreateFuncMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_DB
,
mnodeProcessAlterDbMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_ALTER_DB
,
mnodeProcessAlterDbMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_DB
,
mnodeProcessDropDbMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_DB
,
mnodeProcessDropDbMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_FUNCTION
,
mnodeProcessDropFuncMsg
);
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_DB
,
mnodeGetDbMeta
);
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_DB
,
mnodeGetDbMeta
);
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_FUNCTION
,
mnodeGetFuncMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_DB
,
mnodeRetrieveDbs
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_DB
,
mnodeRetrieveDbs
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_FUNCTION
,
mnodeRetrieveFuncs
);
mnodeAddShowFreeIterHandle
(
TSDB_MGMT_TABLE_DB
,
mnodeCancelGetNextDb
);
mnodeAddShowFreeIterHandle
(
TSDB_MGMT_TABLE_DB
,
mnodeCancelGetNextDb
);
mDebug
(
"table:dbs table is created"
);
mDebug
(
"table:dbs table is created"
);
...
@@ -473,17 +464,6 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *
...
@@ -473,17 +464,6 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCreateDbMsg *pCreate, SMnodeMsg *
return
code
;
return
code
;
}
}
static
int32_t
mnodeCreateFunc
(
SAcctObj
*
pAcct
,
SCreateFuncMsg
*
pCreate
,
SMnodeMsg
*
pMsg
)
{
int32_t
code
=
acctCheck
(
pAcct
,
ACCT_GRANT_DB
);
if
(
code
!=
0
)
return
code
;
mError
(
"Function name:%s, path:%s, code:%.*s"
,
pCreate
->
name
,
pCreate
->
path
,
pCreate
->
codeLen
,
pCreate
->
code
);
return
code
;
}
bool
mnodeCheckIsMonitorDB
(
char
*
db
,
char
*
monitordb
)
{
bool
mnodeCheckIsMonitorDB
(
char
*
db
,
char
*
monitordb
)
{
char
dbName
[
TSDB_DB_NAME_LEN
]
=
{
0
};
char
dbName
[
TSDB_DB_NAME_LEN
]
=
{
0
};
extractDBName
(
db
,
dbName
);
extractDBName
(
db
,
dbName
);
...
@@ -707,41 +687,6 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn
...
@@ -707,41 +687,6 @@ static int32_t mnodeGetDbMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn
return
0
;
return
0
;
}
}
static
int32_t
mnodeGetFuncMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
(
TSDB_FUNC_NAME_LEN
-
1
)
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"name"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
PATH_MAX
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"path"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
//TODO GET ROWS NUM
pShow
->
numOfRows
=
1
;
return
0
;
}
char
*
mnodeGetDbStr
(
char
*
src
)
{
char
*
mnodeGetDbStr
(
char
*
src
)
{
char
*
pos
=
strstr
(
src
,
TS_PATH_DELIMITER
);
char
*
pos
=
strstr
(
src
,
TS_PATH_DELIMITER
);
if
(
pos
!=
NULL
)
++
pos
;
if
(
pos
!=
NULL
)
++
pos
;
...
@@ -889,36 +834,6 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void
...
@@ -889,36 +834,6 @@ static int32_t mnodeRetrieveDbs(SShowObj *pShow, char *data, int32_t rows, void
return
numOfRows
;
return
numOfRows
;
}
}
static
int32_t
mnodeRetrieveFuncs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
char
*
pWrite
;
int32_t
cols
=
0
;
while
(
numOfRows
<
rows
)
{
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
"aaa"
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
"/tmp/abc"
,
pShow
->
bytes
[
cols
]);
cols
++
;
numOfRows
++
;
}
pShow
->
numOfReads
+=
numOfRows
;
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
return
numOfRows
;
}
void
mnodeAddSuperTableIntoDb
(
SDbObj
*
pDb
)
{
void
mnodeAddSuperTableIntoDb
(
SDbObj
*
pDb
)
{
atomic_add_fetch_32
(
&
pDb
->
numOfSuperTables
,
1
);
atomic_add_fetch_32
(
&
pDb
->
numOfSuperTables
,
1
);
}
}
...
@@ -980,23 +895,6 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
...
@@ -980,23 +895,6 @@ static int32_t mnodeProcessCreateDbMsg(SMnodeMsg *pMsg) {
return
code
;
return
code
;
}
}
static
int32_t
mnodeProcessCreateFuncMsg
(
SMnodeMsg
*
pMsg
)
{
SCreateFuncMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
codeLen
=
htonl
(
pCreate
->
codeLen
);
int32_t
code
;
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
code
=
TSDB_CODE_GRANT_EXPIRED
;
}
else
if
(
!
pMsg
->
pUser
->
writeAuth
)
{
code
=
TSDB_CODE_MND_NO_RIGHTS
;
}
else
{
code
=
mnodeCreateFunc
(
pMsg
->
pUser
->
pAcct
,
pCreate
,
pMsg
);
}
return
code
;
}
static
SDbCfg
mnodeGetAlterDbOption
(
SDbObj
*
pDb
,
SAlterDbMsg
*
pAlter
)
{
static
SDbCfg
mnodeGetAlterDbOption
(
SDbObj
*
pDb
,
SAlterDbMsg
*
pAlter
)
{
SDbCfg
newCfg
=
pDb
->
cfg
;
SDbCfg
newCfg
=
pDb
->
cfg
;
int32_t
maxTables
=
htonl
(
pAlter
->
maxTables
);
int32_t
maxTables
=
htonl
(
pAlter
->
maxTables
);
...
@@ -1290,15 +1188,6 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) {
...
@@ -1290,15 +1188,6 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg) {
return
mnodeDropDb
(
pMsg
);
return
mnodeDropDb
(
pMsg
);
}
}
static
int32_t
mnodeProcessDropFuncMsg
(
SMnodeMsg
*
pMsg
)
{
SDropFuncMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
mError
(
"drop function:%s"
,
pDrop
->
name
);
return
TSDB_CODE_SUCCESS
;
}
void
mnodeDropAllDbs
(
SAcctObj
*
pAcct
)
{
void
mnodeDropAllDbs
(
SAcctObj
*
pAcct
)
{
int32_t
numOfDbs
=
0
;
int32_t
numOfDbs
=
0
;
SDbObj
*
pDb
=
NULL
;
SDbObj
*
pDb
=
NULL
;
...
...
src/mnode/src/mnodeFunc.c
0 → 100644
浏览文件 @
b59f6c18
/*
* 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 "trpc.h"
#include "tutil.h"
#include "tglobal.h"
#include "tgrant.h"
#include "tdataformat.h"
#include "tkey.h"
#include "mnode.h"
#include "dnode.h"
#include "mnodeDef.h"
#include "mnodeInt.h"
#include "mnodeAcct.h"
#include "mnodeUser.h"
#include "mnodeMnode.h"
#include "mnodeSdb.h"
#include "mnodeShow.h"
#include "mnodeFunc.h"
#include "mnodeWrite.h"
#include "mnodePeer.h"
int64_t
tsFuncRid
=
-
1
;
static
void
*
tsFuncSdb
=
NULL
;
static
int32_t
tsFuncUpdateSize
=
0
;
static
int32_t
mnodeGetFuncMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
static
int32_t
mnodeRetrieveFuncs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mnodeProcessCreateFuncMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeProcessDropFuncMsg
(
SMnodeMsg
*
pMsg
);
static
int32_t
mnodeFuncActionDestroy
(
SSdbRow
*
pRow
)
{
tfree
(
pRow
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeFuncActionInsert
(
SSdbRow
*
pRow
)
{
SFuncObj
*
pFunc
=
pRow
->
pObj
;
mTrace
(
"func:%s, length: %d, insert into sdb"
,
pFunc
->
name
,
pFunc
->
codeLen
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeFuncActionDelete
(
SSdbRow
*
pRow
)
{
SFuncObj
*
pFunc
=
pRow
->
pObj
;
mTrace
(
"func:%s, length: %d, delete from sdb"
,
pFunc
->
name
,
pFunc
->
codeLen
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeFuncActionUpdate
(
SSdbRow
*
pRow
)
{
SFuncObj
*
pFunc
=
pRow
->
pObj
;
SFuncObj
*
pSaved
=
mnodeGetFunc
(
pFunc
->
name
);
if
(
pFunc
!=
pSaved
)
{
memcpy
(
pSaved
,
pFunc
,
tsFuncUpdateSize
);
free
(
pFunc
);
}
mnodeDecFuncRef
(
pSaved
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeFuncActionEncode
(
SSdbRow
*
pRow
)
{
SFuncObj
*
pFunc
=
pRow
->
pObj
;
memcpy
(
pRow
->
rowData
,
pFunc
,
tsFuncUpdateSize
);
pRow
->
rowSize
=
tsFuncUpdateSize
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeFuncActionDecode
(
SSdbRow
*
pRow
)
{
SFuncObj
*
pFunc
=
(
SFuncObj
*
)
calloc
(
1
,
sizeof
(
SFuncObj
));
if
(
pFunc
==
NULL
)
return
TSDB_CODE_MND_OUT_OF_MEMORY
;
memcpy
(
pFunc
,
pRow
->
rowData
,
tsFuncUpdateSize
);
pRow
->
pObj
=
pFunc
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mnodeFuncActionRestored
()
{
int64_t
numOfRows
=
sdbGetNumOfRows
(
tsFuncSdb
);
if
(
numOfRows
<=
0
&&
dnodeIsFirstDeploy
())
{
mInfo
(
"dnode first deploy, func restored."
);
}
return
TSDB_CODE_SUCCESS
;
}
int32_t
mnodeInitFuncs
()
{
SFuncObj
tObj
;
tsFuncUpdateSize
=
(
int32_t
)((
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
);
SSdbTableDesc
desc
=
{
.
id
=
SDB_TABLE_FUNC
,
.
name
=
"funcs"
,
.
hashSessions
=
TSDB_DEFAULT_USERS_HASH_SIZE
,
.
maxRowSize
=
tsFuncUpdateSize
,
.
refCountPos
=
(
int32_t
)((
int8_t
*
)(
&
tObj
.
refCount
)
-
(
int8_t
*
)
&
tObj
),
.
keyType
=
SDB_KEY_STRING
,
.
fpInsert
=
mnodeFuncActionInsert
,
.
fpDelete
=
mnodeFuncActionDelete
,
.
fpUpdate
=
mnodeFuncActionUpdate
,
.
fpEncode
=
mnodeFuncActionEncode
,
.
fpDecode
=
mnodeFuncActionDecode
,
.
fpDestroy
=
mnodeFuncActionDestroy
,
.
fpRestored
=
mnodeFuncActionRestored
};
tsFuncRid
=
sdbOpenTable
(
&
desc
);
tsFuncSdb
=
sdbGetTableByRid
(
tsFuncRid
);
if
(
tsFuncSdb
==
NULL
)
{
mError
(
"table:%s, failed to create hash"
,
desc
.
name
);
return
-
1
;
}
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_CREATE_FUNCTION
,
mnodeProcessCreateFuncMsg
);
mnodeAddWriteMsgHandle
(
TSDB_MSG_TYPE_CM_DROP_FUNCTION
,
mnodeProcessDropFuncMsg
);
mnodeAddShowMetaHandle
(
TSDB_MGMT_TABLE_FUNCTION
,
mnodeGetFuncMeta
);
mnodeAddShowRetrieveHandle
(
TSDB_MGMT_TABLE_FUNCTION
,
mnodeRetrieveFuncs
);
mnodeAddShowFreeIterHandle
(
TSDB_MGMT_TABLE_FUNCTION
,
mnodeCancelGetNextFunc
);
mDebug
(
"table:%s, hash is created"
,
desc
.
name
);
return
0
;
}
void
mnodeCleanupFuncs
()
{
sdbCloseTable
(
tsFuncRid
);
tsFuncSdb
=
NULL
;
}
SFuncObj
*
mnodeGetFunc
(
char
*
name
)
{
return
(
SFuncObj
*
)
sdbGetRow
(
tsFuncSdb
,
name
);
}
void
*
mnodeGetNextFunc
(
void
*
pIter
,
SFuncObj
**
pFunc
)
{
return
sdbFetchRow
(
tsFuncSdb
,
pIter
,
(
void
**
)
pFunc
);
}
void
mnodeCancelGetNextFunc
(
void
*
pIter
)
{
sdbFreeIter
(
tsFuncSdb
,
pIter
);
}
void
mnodeIncFuncRef
(
SFuncObj
*
pFunc
)
{
sdbIncRef
(
tsFuncSdb
,
pFunc
);
}
void
mnodeDecFuncRef
(
SFuncObj
*
pFunc
)
{
sdbDecRef
(
tsFuncSdb
,
pFunc
);
}
/*
static int32_t mnodeUpdateFunc(SFuncObj *pFunc, void *pMsg) {
SSdbRow row = {
.type = SDB_OPER_GLOBAL,
.pTable = tsFuncSdb,
.pObj = pFunc,
.pMsg = pMsg
};
int32_t code = sdbUpdateRow(&row);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
mError("func:%s, failed to alter by %s, reason:%s", pFunc->name, mnodeGetUserFromMsg(pMsg), tstrerror(code));
} else {
mLInfo("func:%s, is altered by %s", pFunc->name, mnodeGetUserFromMsg(pMsg));
}
return code;
}
*/
int32_t
mnodeCreateFunc
(
SAcctObj
*
pAcct
,
char
*
name
,
int32_t
codeLen
,
char
*
codeScript
,
char
*
path
,
SMnodeMsg
*
pMsg
)
{
if
(
grantCheck
(
TSDB_GRANT_TIME
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_GRANT_EXPIRED
;
}
if
(
!
pMsg
->
pUser
->
writeAuth
)
{
return
TSDB_CODE_MND_NO_RIGHTS
;
}
int32_t
code
=
acctCheck
(
pAcct
,
ACCT_GRANT_USER
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
code
=
grantCheck
(
TSDB_GRANT_USER
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
return
code
;
}
if
(
name
[
0
]
==
0
)
{
return
TSDB_CODE_MND_INVALID_FUNC_NAME
;
}
if
(
codeScript
[
0
]
==
0
)
{
return
TSDB_CODE_MND_INVALID_FUNC_CODE
;
}
if
(
codeLen
<
0
||
codeLen
>
TSDB_FUNC_CODE_LEN
-
1
)
{
return
TSDB_CODE_MND_INVALID_FUNC_LEN
;
}
SFuncObj
*
pFunc
=
mnodeGetFunc
(
name
);
if
(
pFunc
!=
NULL
)
{
mDebug
(
"func:%s, is already there"
,
name
);
mnodeDecFuncRef
(
pFunc
);
return
TSDB_CODE_MND_FUNC_ALREADY_EXIST
;
}
pFunc
=
calloc
(
1
,
sizeof
(
SFuncObj
));
tstrncpy
(
pFunc
->
name
,
name
,
TSDB_FUNC_NAME_LEN
);
tstrncpy
(
pFunc
->
path
,
path
,
PATH_MAX
);
tstrncpy
(
pFunc
->
code
,
codeScript
,
TSDB_FUNC_CODE_LEN
);
pFunc
->
codeLen
=
codeLen
;
pFunc
->
createdTime
=
taosGetTimestampMs
();
SSdbRow
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
pTable
=
tsFuncSdb
,
.
pObj
=
pFunc
,
.
rowSize
=
sizeof
(
SFuncObj
),
.
pMsg
=
pMsg
};
code
=
sdbInsertRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"func:%s, failed to create by %s, reason:%s"
,
pFunc
->
name
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
tfree
(
pFunc
);
}
else
{
mLInfo
(
"func:%s, is created by %s"
,
pFunc
->
name
,
mnodeGetUserFromMsg
(
pMsg
));
}
return
code
;
}
static
int32_t
mnodeDropFunc
(
SFuncObj
*
pFunc
,
void
*
pMsg
)
{
SSdbRow
row
=
{
.
type
=
SDB_OPER_GLOBAL
,
.
pTable
=
tsFuncSdb
,
.
pObj
=
pFunc
,
.
pMsg
=
pMsg
};
int32_t
code
=
sdbDeleteRow
(
&
row
);
if
(
code
!=
TSDB_CODE_SUCCESS
&&
code
!=
TSDB_CODE_MND_ACTION_IN_PROGRESS
)
{
mError
(
"func:%s, failed to drop by %s, reason:%s"
,
pFunc
->
name
,
mnodeGetUserFromMsg
(
pMsg
),
tstrerror
(
code
));
}
else
{
mLInfo
(
"func:%s, is dropped by %s"
,
pFunc
->
name
,
mnodeGetUserFromMsg
(
pMsg
));
}
return
code
;
}
static
int32_t
mnodeGetFuncsNum
()
{
return
(
int32_t
)
sdbGetNumOfRows
(
tsFuncSdb
);
}
static
int32_t
mnodeGetFuncMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
)
{
SUserObj
*
pUser
=
mnodeGetUserFromConn
(
pConn
);
if
(
pUser
==
NULL
)
{
return
TSDB_CODE_MND_NO_USER_FROM_CONN
;
}
int32_t
cols
=
0
;
SSchema
*
pSchema
=
pMeta
->
schema
;
pShow
->
bytes
[
cols
]
=
TSDB_FUNC_NAME_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"name"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
PATH_MAX
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"path"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
8
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_TIMESTAMP
;
strcpy
(
pSchema
[
cols
].
name
,
"create_time"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
4
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_INT
;
strcpy
(
pSchema
[
cols
].
name
,
"code_len"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pShow
->
bytes
[
cols
]
=
TSDB_FUNC_CODE_LEN
+
VARSTR_HEADER_SIZE
;
pSchema
[
cols
].
type
=
TSDB_DATA_TYPE_BINARY
;
strcpy
(
pSchema
[
cols
].
name
,
"code"
);
pSchema
[
cols
].
bytes
=
htons
(
pShow
->
bytes
[
cols
]);
cols
++
;
pMeta
->
numOfColumns
=
htons
(
cols
);
strcpy
(
pMeta
->
tableFname
,
"show funcs"
);
pShow
->
numOfColumns
=
cols
;
pShow
->
offset
[
0
]
=
0
;
for
(
int32_t
i
=
1
;
i
<
cols
;
++
i
)
{
pShow
->
offset
[
i
]
=
pShow
->
offset
[
i
-
1
]
+
pShow
->
bytes
[
i
-
1
];
}
pShow
->
numOfRows
=
mnodeGetFuncsNum
();
pShow
->
rowSize
=
pShow
->
offset
[
cols
-
1
]
+
pShow
->
bytes
[
cols
-
1
];
mnodeDecUserRef
(
pUser
);
return
0
;
}
static
int32_t
mnodeRetrieveFuncs
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
)
{
int32_t
numOfRows
=
0
;
SFuncObj
*
pFunc
=
NULL
;
int32_t
cols
=
0
;
char
*
pWrite
;
while
(
numOfRows
<
rows
)
{
pShow
->
pIter
=
mnodeGetNextFunc
(
pShow
->
pIter
,
&
pFunc
);
if
(
pFunc
==
NULL
)
break
;
cols
=
0
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pFunc
->
name
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pFunc
->
path
,
pShow
->
bytes
[
cols
]);
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int64_t
*
)
pWrite
=
pFunc
->
createdTime
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
*
(
int32_t
*
)
pWrite
=
pFunc
->
codeLen
;
cols
++
;
pWrite
=
data
+
pShow
->
offset
[
cols
]
*
rows
+
pShow
->
bytes
[
cols
]
*
numOfRows
;
STR_WITH_MAXSIZE_TO_VARSTR
(
pWrite
,
pFunc
->
code
,
pShow
->
bytes
[
cols
]);
cols
++
;
numOfRows
++
;
mnodeDecFuncRef
(
pFunc
);
}
mnodeVacuumResult
(
data
,
pShow
->
numOfColumns
,
numOfRows
,
rows
,
pShow
);
pShow
->
numOfReads
+=
numOfRows
;
return
numOfRows
;
}
static
int32_t
mnodeProcessCreateFuncMsg
(
SMnodeMsg
*
pMsg
)
{
SCreateFuncMsg
*
pCreate
=
pMsg
->
rpcMsg
.
pCont
;
pCreate
->
codeLen
=
htonl
(
pCreate
->
codeLen
);
return
mnodeCreateFunc
(
pMsg
->
pUser
->
pAcct
,
pCreate
->
name
,
pCreate
->
codeLen
,
pCreate
->
code
,
pCreate
->
path
,
pMsg
);
}
static
int32_t
mnodeProcessDropFuncMsg
(
SMnodeMsg
*
pMsg
)
{
SDropFuncMsg
*
pDrop
=
pMsg
->
rpcMsg
.
pCont
;
SFuncObj
*
pFunc
=
mnodeGetFunc
(
pDrop
->
name
);
if
(
pFunc
==
NULL
)
{
return
TSDB_CODE_MND_INVALID_FUNC
;
}
return
mnodeDropFunc
(
pFunc
,
pMsg
);
}
src/mnode/src/mnodeMain.c
浏览文件 @
b59f6c18
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include "mnodeSdb.h"
#include "mnodeSdb.h"
#include "mnodeVgroup.h"
#include "mnodeVgroup.h"
#include "mnodeUser.h"
#include "mnodeUser.h"
#include "mnodeFunc.h"
#include "mnodeTable.h"
#include "mnodeTable.h"
#include "mnodeCluster.h"
#include "mnodeCluster.h"
#include "mnodeShow.h"
#include "mnodeShow.h"
...
@@ -46,6 +47,7 @@ static SStep tsMnodeSteps[] = {
...
@@ -46,6 +47,7 @@ static SStep tsMnodeSteps[] = {
{
"cluster"
,
mnodeInitCluster
,
mnodeCleanupCluster
},
{
"cluster"
,
mnodeInitCluster
,
mnodeCleanupCluster
},
{
"accts"
,
mnodeInitAccts
,
mnodeCleanupAccts
},
{
"accts"
,
mnodeInitAccts
,
mnodeCleanupAccts
},
{
"users"
,
mnodeInitUsers
,
mnodeCleanupUsers
},
{
"users"
,
mnodeInitUsers
,
mnodeCleanupUsers
},
{
"funcs"
,
mnodeInitFuncs
,
mnodeCleanupFuncs
},
{
"dnodes"
,
mnodeInitDnodes
,
mnodeCleanupDnodes
},
{
"dnodes"
,
mnodeInitDnodes
,
mnodeCleanupDnodes
},
{
"dbs"
,
mnodeInitDbs
,
mnodeCleanupDbs
},
{
"dbs"
,
mnodeInitDbs
,
mnodeCleanupDbs
},
{
"vgroups"
,
mnodeInitVgroups
,
mnodeCleanupVgroups
},
{
"vgroups"
,
mnodeInitVgroups
,
mnodeCleanupVgroups
},
...
...
src/util/src/terror.c
浏览文件 @
b59f6c18
...
@@ -185,6 +185,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, "Field does not exist"
...
@@ -185,6 +185,12 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_FIELD_NOT_EXIST, "Field does not exist"
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_STABLE_NAME
,
"Super table does not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_STABLE_NAME
,
"Super table does not exist"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG
,
"Invalid create table message"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_CREATE_TABLE_MSG
,
"Invalid create table message"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_NAME
,
"Invalid func name"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_LEN
,
"Invalid func length"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC_CODE
,
"Invalid func code"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_FUNC_ALREADY_EXIST
,
"Func already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_FUNC
,
"Invalid func"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_NOT_SELECTED
,
"Database not specified or available"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_NOT_SELECTED
,
"Database not specified or available"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_ALREADY_EXIST
,
"Database already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_DB_ALREADY_EXIST
,
"Database already exists"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_OPTION
,
"Invalid database options"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_MND_INVALID_DB_OPTION
,
"Invalid database options"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录