Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Rattenking
TDengine
提交
2180f6eb
T
TDengine
项目概览
Rattenking
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2180f6eb
编写于
3月 26, 2020
作者:
S
slguan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-9] merge normal table with child table
上级
e1fdc40f
变更
15
展开全部
隐藏空白更改
内联
并排
Showing
15 changed file
with
1015 addition
and
1589 deletion
+1015
-1589
src/inc/mnode.h
src/inc/mnode.h
+29
-51
src/inc/taosmsg.h
src/inc/taosmsg.h
+2
-2
src/mnode/inc/mgmtChildTable.h
src/mnode/inc/mgmtChildTable.h
+6
-11
src/mnode/inc/mgmtNormalTable.h
src/mnode/inc/mgmtNormalTable.h
+0
-46
src/mnode/inc/mgmtSuperTable.h
src/mnode/inc/mgmtSuperTable.h
+5
-17
src/mnode/inc/mgmtTable.h
src/mnode/inc/mgmtTable.h
+2
-7
src/mnode/inc/mgmtUser.h
src/mnode/inc/mgmtUser.h
+1
-1
src/mnode/inc/mgmtVgroup.h
src/mnode/inc/mgmtVgroup.h
+2
-2
src/mnode/src/mgmtChildTable.c
src/mnode/src/mgmtChildTable.c
+806
-100
src/mnode/src/mgmtNormalTable.c
src/mnode/src/mgmtNormalTable.c
+0
-551
src/mnode/src/mgmtShell.c
src/mnode/src/mgmtShell.c
+9
-1
src/mnode/src/mgmtSuperTable.c
src/mnode/src/mgmtSuperTable.c
+79
-49
src/mnode/src/mgmtTable.c
src/mnode/src/mgmtTable.c
+70
-748
src/mnode/src/mgmtUser.c
src/mnode/src/mgmtUser.c
+2
-1
src/mnode/src/mgmtVgroup.c
src/mnode/src/mgmtVgroup.c
+2
-2
未找到文件。
src/inc/mnode.h
浏览文件 @
2180f6eb
...
...
@@ -98,67 +98,45 @@ typedef struct {
}
SVnodeGid
;
typedef
struct
{
char
tableId
[
TSDB_TABLE_ID_LEN
];
int8_t
type
;
int8_t
dirty
;
uint64_t
uid
;
int32_t
sid
;
int32_t
vgId
;
int64_t
createdTime
;
char
tableId
[
TSDB_TABLE_ID_LEN
];
int8_t
type
;
int8_t
dirty
;
}
STableInfo
;
struct
_vg_obj
;
typedef
struct
SSuperTableObj
{
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
int8_t
type
;
int8_t
dirty
;
uint64_t
uid
;
int32_t
sid
;
int32_t
vgId
;
int64_t
createdTime
;
int32_t
sversion
;
int32_t
numOfColumns
;
int32_t
numOfTags
;
int8_t
reserved
[
15
];
int8_t
updateEnd
[
1
];
int32_t
numOfTables
;
int16_t
nextColId
;
SSchema
*
schema
;
STableInfo
info
;
uint64_t
uid
;
int64_t
createdTime
;
int32_t
sversion
;
int32_t
numOfColumns
;
int32_t
numOfTags
;
int8_t
reserved
[
15
];
int8_t
updateEnd
[
1
];
int32_t
numOfTables
;
int16_t
nextColId
;
SSchema
*
schema
;
}
SSuperTableObj
;
typedef
struct
{
char
tableId
[
TSDB_TABLE_ID_LEN
+
1
];
int8_t
type
;
int8_t
dirty
;
uint64_t
uid
;
int32_t
sid
;
int32_t
vgId
;
int64_t
createdTime
;
char
superTableId
[
TSDB_TABLE_ID_LEN
+
1
];
int8_t
reserved
[
1
];
int8_t
updateEnd
[
1
];
STableInfo
info
;
uint64_t
uid
;
int64_t
createdTime
;
int32_t
sversion
;
//used by normal table
int32_t
numOfColumns
;
//used by normal table
int32_t
sid
;
int32_t
vgId
;
char
superTableId
[
TSDB_TABLE_ID_LEN
+
1
];
int32_t
sqlLen
;
int8_t
reserved
[
1
];
int8_t
updateEnd
[
1
];
int16_t
nextColId
;
//used by normal table
char
*
sql
;
//used by normal table
SSchema
*
schema
;
//used by normal table
SSuperTableObj
*
superTable
;
}
SChildTableObj
;
typedef
struct
{
char
tableId
[
TSDB_TABLE_ID_LEN
];
int8_t
type
;
int8_t
dirty
;
uint64_t
uid
;
int32_t
sid
;
int32_t
vgId
;
int64_t
createdTime
;
int32_t
sversion
;
int32_t
numOfColumns
;
int32_t
sqlLen
;
int8_t
reserved
[
7
];
int8_t
updateEnd
[
1
];
char
*
sql
;
//null-terminated string
int16_t
nextColId
;
SSchema
*
schema
;
}
SNormalTableObj
;
struct
_db_obj
;
typedef
struct
_vg_obj
{
...
...
@@ -260,7 +238,7 @@ typedef struct {
typedef
struct
{
uint8_t
msgType
;
int8_t
expected
;
int8_t
usePublicIp
;
int8_t
received
;
int8_t
successed
;
int32_t
contLen
;
...
...
src/inc/taosmsg.h
浏览文件 @
2180f6eb
...
...
@@ -94,8 +94,8 @@ extern "C" {
#define TSDB_MSG_TYPE_CM_ALTER_TABLE_RSP 62
#define TSDB_MSG_TYPE_CM_TABLE_META 63
#define TSDB_MSG_TYPE_CM_TABLE_META_RSP 64
#define TSDB_MSG_TYPE_CM_STABLE_
META
65
#define TSDB_MSG_TYPE_CM_STABLE_
META
_RSP 66
#define TSDB_MSG_TYPE_CM_STABLE_
VGROUP
65
#define TSDB_MSG_TYPE_CM_STABLE_
VGROUP
_RSP 66
#define TSDB_MSG_TYPE_CM_TABLES_META 67
#define TSDB_MSG_TYPE_CM_TABLES_META_RSP 68
#define TSDB_MSG_TYPE_CM_ALTER_STREAM 69
...
...
src/mnode/inc/mgmtChildTable.h
浏览文件 @
2180f6eb
...
...
@@ -23,23 +23,18 @@ extern "C" {
#include <stdint.h>
#include <stdbool.h>
#include "taosdef.h"
#include "mnode.h"
int32_t
mgmtInitChildTables
();
void
mgmtCleanUpChildTables
();
void
*
mgmtGetChildTable
(
char
*
tableId
);
void
*
mgmtCreateChildTable
(
SCMCreateTableMsg
*
pCreate
,
SVgObj
*
pVgroup
,
int32_t
sid
);
void
*
mgmtBuildCreateChildTableMsg
(
SCMCreateTableMsg
*
pCreate
,
SChildTableObj
*
pTable
);
int32_t
mgmtDropChildTable
(
SQueuedMsg
*
newMsg
,
SChildTableObj
*
pTable
);
int32_t
mgmtModifyChildTableTagValueByName
(
SChildTableObj
*
pTable
,
char
*
tagName
,
char
*
nContent
);
int32_t
mgmtGetChildTableMeta
(
SDbObj
*
pDb
,
SChildTableObj
*
pTable
,
STableMetaMsg
*
pMeta
,
bool
usePublicIp
);
void
mgmtDropAllChildTables
(
SDbObj
*
pDropDb
);
void
mgmtDropAllChildTablesInStable
(
SSuperTableObj
*
pStable
);
void
mgmtCreateChildTable
(
SQueuedMsg
*
pMsg
);
void
mgmtDropChildTable
(
SQueuedMsg
*
pMsg
,
SChildTableObj
*
pTable
);
void
mgmtGetChildTableMeta
(
SQueuedMsg
*
pMsg
,
SChildTableObj
*
pTable
);
void
mgmtAlterChildTable
(
SQueuedMsg
*
pMsg
,
SChildTableObj
*
pTable
);
void
mgmtDropAllChildTables
(
SDbObj
*
pDropDb
);
void
mgmtDropAllChildTablesInStable
(
SSuperTableObj
*
pStable
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mgmtNormalTable.h
已删除
100644 → 0
浏览文件 @
e1fdc40f
/*
* 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 TBASE_MNODE_NORMAL_TABLE_H
#define TBASE_MNODE_NORMAL_TABLE_H
#ifdef __cplusplus
extern
"C"
{
#endif
#include <stdint.h>
#include <stdbool.h>
#include "mnode.h"
int32_t
mgmtInitNormalTables
();
void
mgmtCleanUpNormalTables
();
void
*
mgmtGetNormalTable
(
char
*
tableId
);
void
*
mgmtCreateNormalTable
(
SCMCreateTableMsg
*
pCreate
,
SVgObj
*
pVgroup
,
int32_t
sid
);
void
*
mgmtBuildCreateNormalTableMsg
(
SNormalTableObj
*
pTable
);
int32_t
mgmtDropNormalTable
(
SQueuedMsg
*
newMsg
,
SNormalTableObj
*
pTable
);
int32_t
mgmtAddNormalTableColumn
(
SNormalTableObj
*
pTable
,
SSchema
schema
[],
int32_t
ncols
);
int32_t
mgmtDropNormalTableColumnByName
(
SNormalTableObj
*
pTable
,
char
*
colName
);
int32_t
mgmtGetNormalTableMeta
(
SDbObj
*
pDb
,
SNormalTableObj
*
pTable
,
STableMetaMsg
*
pMeta
,
bool
usePublicIp
);
void
mgmtDropAllNormalTables
(
SDbObj
*
pDropDb
);
#ifdef __cplusplus
}
#endif
#endif
src/mnode/inc/mgmtSuperTable.h
浏览文件 @
2180f6eb
...
...
@@ -22,31 +22,19 @@ extern "C" {
#include <stdint.h>
#include <stdbool.h>
#include "taosdef.h"
#include "mnode.h"
int32_t
mgmtInitSuperTables
();
void
mgmtCleanUpSuperTables
();
void
*
mgmtGetSuperTable
(
char
*
tableId
);
int32_t
mgmtCreateSuperTable
(
SCMCreateTableMsg
*
pCreate
);
int32_t
mgmtDropSuperTable
(
SQueuedMsg
*
newMsg
,
SDbObj
*
pDb
,
SSuperTableObj
*
pTable
);
int32_t
mgmtAddSuperTableTag
(
SSuperTableObj
*
pTable
,
SSchema
schema
[],
int32_t
ntags
);
int32_t
mgmtDropSuperTableTag
(
SSuperTableObj
*
pTable
,
char
*
tagName
);
int32_t
mgmtModifySuperTableTagNameByName
(
SSuperTableObj
*
pTable
,
char
*
oldTagName
,
char
*
newTagName
);
int32_t
mgmtAddSuperTableColumn
(
SSuperTableObj
*
pTable
,
SSchema
schema
[],
int32_t
ncols
);
int32_t
mgmtDropSuperTableColumnByName
(
SSuperTableObj
*
pTable
,
char
*
colName
);
int32_t
mgmtGetSuperTableMeta
(
SDbObj
*
pDb
,
SSuperTableObj
*
pTable
,
STableMetaMsg
*
pMeta
,
bool
usePublicIp
);
void
*
mgmtGetSuperTableVgroup
(
SSuperTableObj
*
pStable
);
int32_t
mgmtFindSuperTableTagIndex
(
SSuperTableObj
*
pTable
,
const
char
*
tagName
);
int32_t
mgmtSetSchemaFromSuperTable
(
SSchema
*
pSchema
,
SSuperTableObj
*
pTable
);
void
mgmtCreateSuperTable
(
SQueuedMsg
*
pMsg
);
void
mgmtDropSuperTable
(
SQueuedMsg
*
pMsg
,
SSuperTableObj
*
pTable
);
void
mgmtGetSuperTableMeta
(
SQueuedMsg
*
pMsg
,
SSuperTableObj
*
pTable
);
void
mgmtAlterSuperTable
(
SQueuedMsg
*
pMsg
,
SSuperTableObj
*
pTable
);
void
mgmtDropAllSuperTables
(
SDbObj
*
pDropDb
);
int32_t
mgmt
ExtractTableName
(
const
char
*
tableId
,
char
*
nam
e
);
int32_t
mgmt
SetSchemaFromSuperTable
(
SSchema
*
pSchema
,
SSuperTableObj
*
pTabl
e
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mgmtTable.h
浏览文件 @
2180f6eb
...
...
@@ -27,13 +27,8 @@ extern "C" {
int32_t
mgmtInitTables
();
void
mgmtCleanUpTables
();
STableInfo
*
mgmtGetTable
(
char
*
tableId
);
STableInfo
*
mgmtGetTableByPos
(
uint32_t
dnodeIp
,
int32_t
vnode
,
int32_t
sid
);
int32_t
mgmtGetTableMeta
(
SDbObj
*
pDb
,
STableInfo
*
pTable
,
STableMetaMsg
*
pMeta
,
bool
usePublicIp
);
void
mgmtAddTableIntoSuperTable
(
SSuperTableObj
*
pStable
);
void
mgmtRemoveTableFromSuperTable
(
SSuperTableObj
*
pStable
);
STableInfo
*
mgmtGetTable
(
char
*
tableId
);
void
mgmtExtractTableName
(
char
*
tableId
,
char
*
tableName
);
#ifdef __cplusplus
}
...
...
src/mnode/inc/mgmtUser.h
浏览文件 @
2180f6eb
...
...
@@ -24,7 +24,7 @@ extern "C" {
int32_t
mgmtInitUsers
();
void
mgmtCleanUpUsers
();
SUserObj
*
mgmtGetUser
(
char
*
name
);
SUserObj
*
mgmtGetUserFromConn
(
void
*
pConn
);
SUserObj
*
mgmtGetUserFromConn
(
void
*
pConn
,
bool
*
usePublicIp
)
#ifdef __cplusplus
}
...
...
src/mnode/inc/mgmtVgroup.h
浏览文件 @
2180f6eb
...
...
@@ -36,8 +36,8 @@ void mgmtUpdateVgroup(SVgObj *pVgroup);
void
mgmtAlterVgroup
(
SVgObj
*
pVgroup
,
void
*
ahandle
);
SVgObj
*
mgmtGetAvailableVgroup
(
SDbObj
*
pDb
);
void
mgmtAddTableIntoVgroup
(
SVgObj
*
pVgroup
,
S
TableInfo
*
pTable
);
void
mgmtRemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
S
TableInfo
*
pTable
);
void
mgmtAddTableIntoVgroup
(
SVgObj
*
pVgroup
,
S
ChildTableObj
*
pTable
);
void
mgmtRemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
S
ChildTableObj
*
pTable
);
void
mgmtSendCreateVnodeMsg
(
SVgObj
*
pVgroup
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
);
void
mgmtSendDropVnodeMsg
(
int32_t
vgId
,
SRpcIpSet
*
ipSet
,
void
*
ahandle
);
...
...
src/mnode/src/mgmtChildTable.c
浏览文件 @
2180f6eb
此差异已折叠。
点击以展开。
src/mnode/src/mgmtNormalTable.c
已删除
100644 → 0
浏览文件 @
e1fdc40f
/*
* 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 "tscompression.h"
#include "tskiplist.h"
#include "ttime.h"
#include "tstatus.h"
#include "tutil.h"
#include "mnode.h"
#include "mgmtAcct.h"
#include "mgmtDb.h"
#include "mgmtDClient.h"
#include "mgmtGrant.h"
#include "mgmtMnode.h"
#include "mgmtNormalTable.h"
#include "mgmtSdb.h"
#include "mgmtSuperTable.h"
#include "mgmtTable.h"
#include "mgmtVgroup.h"
void
*
tsNormalTableSdb
;
int32_t
tsNormalTableUpdateSize
;
static
void
mgmtDestroyNormalTable
(
SNormalTableObj
*
pTable
)
{
tfree
(
pTable
->
schema
);
tfree
(
pTable
->
sql
);
tfree
(
pTable
);
}
static
int32_t
mgmtNormalTableActionDestroy
(
SSdbOperDesc
*
pOper
)
{
mgmtDestroyNormalTable
(
pOper
->
pObj
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mgmtNormalTableActionInsert
(
SSdbOperDesc
*
pOper
)
{
SNormalTableObj
*
pTable
=
pOper
->
pObj
;
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
mError
(
"ntable:%s not in vgroup:%d"
,
pTable
->
tableId
,
pTable
->
vgId
);
return
TSDB_CODE_INVALID_VGROUP_ID
;
}
SDbObj
*
pDb
=
mgmtGetDb
(
pVgroup
->
dbName
);
if
(
pDb
==
NULL
)
{
mError
(
"ntable:%s, vgroup:%d not in DB:%s"
,
pTable
->
tableId
,
pVgroup
->
vgId
,
pVgroup
->
dbName
);
return
TSDB_CODE_INVALID_DB
;
}
SAcctObj
*
pAcct
=
mgmtGetAcct
(
pDb
->
cfg
.
acct
);
if
(
pAcct
==
NULL
)
{
mError
(
"ntable:%s, account:%s not exists"
,
pTable
->
tableId
,
pDb
->
cfg
.
acct
);
return
TSDB_CODE_INVALID_ACCT
;
}
mgmtAddTimeSeries
(
pAcct
,
pTable
->
numOfColumns
-
1
);
mgmtAddTableIntoDb
(
pDb
);
mgmtAddTableIntoVgroup
(
pVgroup
,
(
STableInfo
*
)
pTable
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mgmtNormalTableActionDelete
(
SSdbOperDesc
*
pOper
)
{
SNormalTableObj
*
pTable
=
pOper
->
pObj
;
if
(
pTable
->
vgId
==
0
)
{
return
TSDB_CODE_INVALID_VGROUP_ID
;
}
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
return
TSDB_CODE_INVALID_VGROUP_ID
;
}
SDbObj
*
pDb
=
mgmtGetDb
(
pVgroup
->
dbName
);
if
(
pDb
==
NULL
)
{
mError
(
"ntable:%s, vgroup:%d not in DB:%s"
,
pTable
->
tableId
,
pVgroup
->
vgId
,
pVgroup
->
dbName
);
return
TSDB_CODE_INVALID_DB
;
}
SAcctObj
*
pAcct
=
mgmtGetAcct
(
pDb
->
cfg
.
acct
);
if
(
pAcct
==
NULL
)
{
mError
(
"account not exists"
);
return
TSDB_CODE_INVALID_ACCT
;
}
mgmtRestoreTimeSeries
(
pAcct
,
pTable
->
numOfColumns
-
1
);
mgmtRemoveTableFromDb
(
pDb
);
mgmtRemoveTableFromVgroup
(
pVgroup
,
(
STableInfo
*
)
pTable
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mgmtNormalTableActionUpdate
(
SSdbOperDesc
*
pOper
)
{
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mgmtNormalTableActionEncode
(
SSdbOperDesc
*
pOper
)
{
SNormalTableObj
*
pTable
=
pOper
->
pObj
;
assert
(
pOper
->
pObj
!=
NULL
&&
pOper
->
rowData
!=
NULL
);
int32_t
schemaSize
=
pTable
->
numOfColumns
*
sizeof
(
SSchema
);
if
(
pOper
->
maxRowSize
<
tsNormalTableUpdateSize
+
schemaSize
)
{
return
TSDB_CODE_INVALID_MSG_LEN
;
}
memcpy
(
pOper
->
rowData
,
pTable
,
tsNormalTableUpdateSize
);
memcpy
(
pOper
->
rowData
+
tsNormalTableUpdateSize
,
pTable
->
schema
,
schemaSize
);
memcpy
(
pOper
->
rowData
+
tsNormalTableUpdateSize
+
schemaSize
,
pTable
->
sql
,
pTable
->
sqlLen
);
pOper
->
rowSize
=
tsNormalTableUpdateSize
+
schemaSize
+
pTable
->
sqlLen
;
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mgmtNormalTableActionDecode
(
SSdbOperDesc
*
pOper
)
{
assert
(
pOper
->
rowData
!=
NULL
);
SNormalTableObj
*
pTable
=
(
SNormalTableObj
*
)
calloc
(
1
,
sizeof
(
SNormalTableObj
));
if
(
pTable
==
NULL
)
TSDB_CODE_SERV_OUT_OF_MEMORY
;
memcpy
(
pTable
,
pOper
->
rowData
,
tsNormalTableUpdateSize
);
int32_t
schemaSize
=
pTable
->
numOfColumns
*
sizeof
(
SSchema
);
pTable
->
schema
=
(
SSchema
*
)
malloc
(
schemaSize
);
if
(
pTable
->
schema
==
NULL
)
{
mgmtDestroyNormalTable
(
pTable
);
return
-
1
;
}
memcpy
(
pTable
->
schema
,
pOper
->
rowData
+
tsNormalTableUpdateSize
,
schemaSize
);
pTable
->
sql
=
(
char
*
)
malloc
(
pTable
->
sqlLen
);
if
(
pTable
->
sql
==
NULL
)
{
mgmtDestroyNormalTable
(
pTable
);
return
-
1
;
}
memcpy
(
pTable
->
sql
,
pOper
->
rowData
+
tsNormalTableUpdateSize
+
schemaSize
,
pTable
->
sqlLen
);
pOper
->
pObj
=
pTable
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
mgmtInitNormalTables
()
{
void
*
pNode
=
NULL
;
void
*
pLastNode
=
NULL
;
SNormalTableObj
*
pTable
=
NULL
;
SNormalTableObj
tObj
;
tsNormalTableUpdateSize
=
(
int8_t
*
)
tObj
.
updateEnd
-
(
int8_t
*
)
&
tObj
;
SSdbTableDesc
tableDesc
=
{
.
tableName
=
"ntables"
,
.
hashSessions
=
TSDB_MAX_NORMAL_TABLES
,
.
maxRowSize
=
sizeof
(
SNormalTableObj
)
+
sizeof
(
SSchema
)
*
TSDB_MAX_COLUMNS
,
.
keyType
=
SDB_KEY_TYPE_STRING
,
.
insertFp
=
mgmtNormalTableActionInsert
,
.
deleteFp
=
mgmtNormalTableActionDelete
,
.
updateFp
=
mgmtNormalTableActionUpdate
,
.
encodeFp
=
mgmtNormalTableActionEncode
,
.
decodeFp
=
mgmtNormalTableActionDecode
,
.
destroyFp
=
mgmtNormalTableActionDestroy
,
};
tsNormalTableSdb
=
sdbOpenTable
(
&
tableDesc
);
if
(
tsNormalTableSdb
==
NULL
)
{
mError
(
"failed to init ntables data"
);
return
-
1
;
}
while
(
1
)
{
pLastNode
=
pNode
;
pNode
=
sdbFetchRow
(
tsNormalTableSdb
,
pNode
,
(
void
**
)
&
pTable
);
if
(
pTable
==
NULL
)
break
;
SDbObj
*
pDb
=
mgmtGetDbByTableId
(
pTable
->
tableId
);
if
(
pDb
==
NULL
)
{
mError
(
"ntable:%s, failed to get db, discard it"
,
pTable
->
tableId
);
SSdbOperDesc
desc
=
{
0
};
desc
.
type
=
SDB_OPER_TYPE_LOCAL
;
desc
.
pObj
=
pTable
;
desc
.
table
=
tsNormalTableSdb
;
sdbDeleteRow
(
&
desc
);
pNode
=
pLastNode
;
continue
;
}
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
mError
(
"ntable:%s, failed to get vgroup:%d sid:%d, discard it"
,
pTable
->
tableId
,
pTable
->
vgId
,
pTable
->
sid
);
pTable
->
vgId
=
0
;
SSdbOperDesc
desc
=
{
0
};
desc
.
type
=
SDB_OPER_TYPE_LOCAL
;
desc
.
pObj
=
pTable
;
desc
.
table
=
tsNormalTableSdb
;
sdbDeleteRow
(
&
desc
);
pNode
=
pLastNode
;
continue
;
}
if
(
strcmp
(
pVgroup
->
dbName
,
pDb
->
name
)
!=
0
)
{
mError
(
"ntable:%s, db:%s not match with vgroup:%d db:%s sid:%d, discard it"
,
pTable
->
tableId
,
pDb
->
name
,
pTable
->
vgId
,
pVgroup
->
dbName
,
pTable
->
sid
);
pTable
->
vgId
=
0
;
SSdbOperDesc
desc
=
{
0
};
desc
.
type
=
SDB_OPER_TYPE_LOCAL
;
desc
.
pObj
=
pTable
;
desc
.
table
=
tsNormalTableSdb
;
sdbDeleteRow
(
&
desc
);
pNode
=
pLastNode
;
continue
;
}
if
(
pVgroup
->
tableList
==
NULL
)
{
mError
(
"ntable:%s, vgroup:%d tableList is null"
,
pTable
->
tableId
,
pTable
->
vgId
);
pTable
->
vgId
=
0
;
SSdbOperDesc
desc
=
{
0
};
desc
.
type
=
SDB_OPER_TYPE_LOCAL
;
desc
.
pObj
=
pTable
;
desc
.
table
=
tsNormalTableSdb
;
sdbDeleteRow
(
&
desc
);
pNode
=
pLastNode
;
continue
;
}
}
mTrace
(
"ntables is initialized"
);
return
0
;
}
void
mgmtCleanUpNormalTables
()
{
sdbCloseTable
(
tsNormalTableSdb
);
}
void
*
mgmtBuildCreateNormalTableMsg
(
SNormalTableObj
*
pTable
)
{
int32_t
totalCols
=
pTable
->
numOfColumns
;
int32_t
contLen
=
sizeof
(
SMDCreateTableMsg
)
+
totalCols
*
sizeof
(
SSchema
)
+
pTable
->
sqlLen
;
SMDCreateTableMsg
*
pCreate
=
rpcMallocCont
(
contLen
);
if
(
pCreate
==
NULL
)
{
terrno
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
return
NULL
;
}
memcpy
(
pCreate
->
tableId
,
pTable
->
tableId
,
TSDB_TABLE_ID_LEN
+
1
);
pCreate
->
contLen
=
htonl
(
contLen
);
pCreate
->
vgId
=
htonl
(
pTable
->
vgId
);
pCreate
->
tableType
=
pTable
->
type
;
pCreate
->
numOfColumns
=
htons
(
pTable
->
numOfColumns
);
pCreate
->
numOfTags
=
0
;
pCreate
->
sid
=
htonl
(
pTable
->
sid
);
pCreate
->
sversion
=
htonl
(
pTable
->
sversion
);
pCreate
->
tagDataLen
=
0
;
pCreate
->
sqlDataLen
=
htonl
(
pTable
->
sqlLen
);
pCreate
->
uid
=
htobe64
(
pTable
->
uid
);
pCreate
->
superTableUid
=
0
;
pCreate
->
createdTime
=
htobe64
(
pTable
->
createdTime
);
SSchema
*
pSchema
=
(
SSchema
*
)
pCreate
->
data
;
memcpy
(
pSchema
,
pTable
->
schema
,
totalCols
*
sizeof
(
SSchema
));
for
(
int32_t
col
=
0
;
col
<
totalCols
;
++
col
)
{
pSchema
->
bytes
=
htons
(
pSchema
->
bytes
);
pSchema
->
colId
=
htons
(
pSchema
->
colId
);
pSchema
++
;
}
memcpy
(
pCreate
+
sizeof
(
SMDCreateTableMsg
)
+
totalCols
*
sizeof
(
SSchema
),
pTable
->
sql
,
pTable
->
sqlLen
);
return
pCreate
;
}
void
*
mgmtCreateNormalTable
(
SCMCreateTableMsg
*
pCreate
,
SVgObj
*
pVgroup
,
int32_t
sid
)
{
SNormalTableObj
*
pTable
=
(
SNormalTableObj
*
)
calloc
(
sizeof
(
SNormalTableObj
),
1
);
if
(
pTable
==
NULL
)
{
mError
(
"table:%s, failed to alloc memory"
,
pCreate
->
tableId
);
terrno
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
return
NULL
;
}
strcpy
(
pTable
->
tableId
,
pCreate
->
tableId
);
pTable
->
type
=
TSDB_NORMAL_TABLE
;
pTable
->
vgId
=
pVgroup
->
vgId
;
pTable
->
createdTime
=
taosGetTimestampMs
();
pTable
->
uid
=
(((
uint64_t
)
pTable
->
createdTime
)
<<
16
)
+
(
sdbGetVersion
()
&
((
1ul
<<
16
)
-
1ul
));
pTable
->
sid
=
sid
;
pTable
->
sversion
=
0
;
pTable
->
numOfColumns
=
htons
(
pCreate
->
numOfColumns
);
pTable
->
sqlLen
=
htons
(
pCreate
->
sqlLen
);
int32_t
numOfCols
=
pTable
->
numOfColumns
;
int32_t
schemaSize
=
numOfCols
*
sizeof
(
SSchema
);
pTable
->
schema
=
(
SSchema
*
)
calloc
(
1
,
schemaSize
);
if
(
pTable
->
schema
==
NULL
)
{
free
(
pTable
);
terrno
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
return
NULL
;
}
memcpy
(
pTable
->
schema
,
pCreate
->
schema
,
numOfCols
*
sizeof
(
SSchema
));
pTable
->
nextColId
=
0
;
for
(
int32_t
col
=
0
;
col
<
numOfCols
;
col
++
)
{
SSchema
*
tschema
=
pTable
->
schema
;
tschema
[
col
].
colId
=
pTable
->
nextColId
++
;
tschema
[
col
].
bytes
=
htons
(
tschema
[
col
].
bytes
);
}
if
(
pTable
->
sqlLen
!=
0
)
{
pTable
->
type
=
TSDB_STREAM_TABLE
;
pTable
->
sql
=
calloc
(
1
,
pTable
->
sqlLen
);
if
(
pTable
->
sql
==
NULL
)
{
free
(
pTable
);
terrno
=
TSDB_CODE_SERV_OUT_OF_MEMORY
;
return
NULL
;
}
memcpy
(
pTable
->
sql
,
(
char
*
)
(
pCreate
->
schema
)
+
numOfCols
*
sizeof
(
SSchema
),
pTable
->
sqlLen
);
pTable
->
sql
[
pTable
->
sqlLen
-
1
]
=
0
;
mTrace
(
"table:%s, stream sql len:%d sql:%s"
,
pTable
->
tableId
,
pTable
->
sqlLen
,
pTable
->
sql
);
}
SSdbOperDesc
desc
=
{
0
};
desc
.
type
=
SDB_OPER_TYPE_GLOBAL
;
desc
.
pObj
=
pTable
;
desc
.
table
=
tsNormalTableSdb
;
if
(
sdbInsertRow
(
&
desc
)
!=
TSDB_CODE_SUCCESS
)
{
mError
(
"table:%s, update sdb error"
,
pTable
->
tableId
);
free
(
pTable
);
terrno
=
TSDB_CODE_SDB_ERROR
;
return
NULL
;
}
mTrace
(
"table:%s, create ntable in vgroup, uid:%"
PRIu64
,
pTable
->
tableId
,
pTable
->
uid
);
return
pTable
;
}
int32_t
mgmtDropNormalTable
(
SQueuedMsg
*
newMsg
,
SNormalTableObj
*
pTable
)
{
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
mError
(
"table:%s, failed to drop normal table, vgroup not exist"
,
pTable
->
tableId
);
return
TSDB_CODE_OTHERS
;
}
SMDDropTableMsg
*
pDrop
=
rpcMallocCont
(
sizeof
(
SMDDropTableMsg
));
if
(
pDrop
==
NULL
)
{
mError
(
"table:%s, failed to drop normal table, no enough memory"
,
pTable
->
tableId
);
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
}
strcpy
(
pDrop
->
tableId
,
pTable
->
tableId
);
pDrop
->
contLen
=
htonl
(
sizeof
(
SMDDropTableMsg
));
pDrop
->
vgId
=
htonl
(
pVgroup
->
vgId
);
pDrop
->
sid
=
htonl
(
pTable
->
sid
);
pDrop
->
uid
=
htobe64
(
pTable
->
uid
);
SRpcIpSet
ipSet
=
mgmtGetIpSetFromVgroup
(
pVgroup
);
mTrace
(
"table:%s, send drop table msg"
,
pDrop
->
tableId
);
SRpcMsg
rpcMsg
=
{
.
handle
=
newMsg
,
.
pCont
=
pDrop
,
.
contLen
=
sizeof
(
SMDDropTableMsg
),
.
code
=
0
,
.
msgType
=
TSDB_MSG_TYPE_MD_DROP_TABLE
};
newMsg
->
ahandle
=
pTable
;
mgmtSendMsgToDnode
(
&
ipSet
,
&
rpcMsg
);
return
TSDB_CODE_SUCCESS
;
}
void
*
mgmtGetNormalTable
(
char
*
tableId
)
{
return
sdbGetRow
(
tsNormalTableSdb
,
tableId
);
}
static
int32_t
mgmtFindNormalTableColumnIndex
(
SNormalTableObj
*
pTable
,
char
*
colName
)
{
SSchema
*
schema
=
(
SSchema
*
)
pTable
->
schema
;
for
(
int32_t
i
=
0
;
i
<
pTable
->
numOfColumns
;
i
++
)
{
if
(
strcasecmp
(
schema
[
i
].
name
,
colName
)
==
0
)
{
return
i
;
}
}
return
-
1
;
}
int32_t
mgmtAddNormalTableColumn
(
SNormalTableObj
*
pTable
,
SSchema
schema
[],
int32_t
ncols
)
{
if
(
ncols
<=
0
)
{
return
TSDB_CODE_APP_ERROR
;
}
for
(
int32_t
i
=
0
;
i
<
ncols
;
i
++
)
{
if
(
mgmtFindNormalTableColumnIndex
(
pTable
,
schema
[
i
].
name
)
>
0
)
{
return
TSDB_CODE_APP_ERROR
;
}
}
SDbObj
*
pDb
=
mgmtGetDbByTableId
(
pTable
->
tableId
);
if
(
pDb
==
NULL
)
{
mError
(
"table: %s not belongs to any database"
,
pTable
->
tableId
);
return
TSDB_CODE_APP_ERROR
;
}
SAcctObj
*
pAcct
=
mgmtGetAcct
(
pDb
->
cfg
.
acct
);
if
(
pAcct
==
NULL
)
{
mError
(
"DB: %s not belongs to andy account"
,
pDb
->
name
);
return
TSDB_CODE_APP_ERROR
;
}
int32_t
schemaSize
=
pTable
->
numOfColumns
*
sizeof
(
SSchema
);
pTable
->
schema
=
realloc
(
pTable
->
schema
,
schemaSize
+
sizeof
(
SSchema
)
*
ncols
);
memcpy
(
pTable
->
schema
+
schemaSize
,
schema
,
sizeof
(
SSchema
)
*
ncols
);
SSchema
*
tschema
=
(
SSchema
*
)
(
pTable
->
schema
+
sizeof
(
SSchema
)
*
pTable
->
numOfColumns
);
for
(
int32_t
i
=
0
;
i
<
ncols
;
i
++
)
{
tschema
[
i
].
colId
=
pTable
->
nextColId
++
;
}
pTable
->
numOfColumns
+=
ncols
;
pTable
->
sversion
++
;
pAcct
->
acctInfo
.
numOfTimeSeries
+=
ncols
;
SSdbOperDesc
desc
=
{
0
};
desc
.
type
=
SDB_OPER_TYPE_GLOBAL
;
desc
.
pObj
=
pTable
;
desc
.
table
=
tsNormalTableSdb
;
desc
.
rowData
=
pTable
;
desc
.
rowSize
=
tsNormalTableUpdateSize
;
sdbUpdateRow
(
&
desc
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
mgmtDropNormalTableColumnByName
(
SNormalTableObj
*
pTable
,
char
*
colName
)
{
int32_t
col
=
mgmtFindNormalTableColumnIndex
(
pTable
,
colName
);
if
(
col
<
0
)
{
return
TSDB_CODE_APP_ERROR
;
}
SDbObj
*
pDb
=
mgmtGetDbByTableId
(
pTable
->
tableId
);
if
(
pDb
==
NULL
)
{
mError
(
"table: %s not belongs to any database"
,
pTable
->
tableId
);
return
TSDB_CODE_APP_ERROR
;
}
SAcctObj
*
pAcct
=
mgmtGetAcct
(
pDb
->
cfg
.
acct
);
if
(
pAcct
==
NULL
)
{
mError
(
"DB: %s not belongs to any account"
,
pDb
->
name
);
return
TSDB_CODE_APP_ERROR
;
}
memmove
(
pTable
->
schema
+
sizeof
(
SSchema
)
*
col
,
pTable
->
schema
+
sizeof
(
SSchema
)
*
(
col
+
1
),
sizeof
(
SSchema
)
*
(
pTable
->
numOfColumns
-
col
-
1
));
pTable
->
numOfColumns
--
;
pTable
->
sversion
++
;
pAcct
->
acctInfo
.
numOfTimeSeries
--
;
SSdbOperDesc
desc
=
{
0
};
desc
.
type
=
SDB_OPER_TYPE_GLOBAL
;
desc
.
pObj
=
pTable
;
desc
.
table
=
tsNormalTableSdb
;
desc
.
rowData
=
pTable
;
desc
.
rowSize
=
tsNormalTableUpdateSize
;
sdbUpdateRow
(
&
desc
);
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
mgmtSetSchemaFromNormalTable
(
SSchema
*
pSchema
,
SNormalTableObj
*
pTable
)
{
int32_t
numOfCols
=
pTable
->
numOfColumns
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
strcpy
(
pSchema
->
name
,
pTable
->
schema
[
i
].
name
);
pSchema
->
type
=
pTable
->
schema
[
i
].
type
;
pSchema
->
bytes
=
htons
(
pTable
->
schema
[
i
].
bytes
);
pSchema
->
colId
=
htons
(
pTable
->
schema
[
i
].
colId
);
pSchema
++
;
}
return
numOfCols
*
sizeof
(
SSchema
);
}
int32_t
mgmtGetNormalTableMeta
(
SDbObj
*
pDb
,
SNormalTableObj
*
pTable
,
STableMetaMsg
*
pMeta
,
bool
usePublicIp
)
{
pMeta
->
uid
=
htobe64
(
pTable
->
uid
);
pMeta
->
sid
=
htonl
(
pTable
->
sid
);
pMeta
->
vgId
=
htonl
(
pTable
->
vgId
);
pMeta
->
sversion
=
htons
(
pTable
->
sversion
);
pMeta
->
precision
=
pDb
->
cfg
.
precision
;
pMeta
->
numOfTags
=
0
;
pMeta
->
numOfColumns
=
htons
(
pTable
->
numOfColumns
);
pMeta
->
tableType
=
pTable
->
type
;
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mgmtSetSchemaFromNormalTable
(
pMeta
->
schema
,
pTable
);
strncpy
(
pMeta
->
tableId
,
pTable
->
tableId
,
tListLen
(
pTable
->
tableId
));
SVgObj
*
pVgroup
=
mgmtGetVgroup
(
pTable
->
vgId
);
if
(
pVgroup
==
NULL
)
{
return
TSDB_CODE_INVALID_TABLE
;
}
for
(
int32_t
i
=
0
;
i
<
TSDB_VNODES_SUPPORT
;
++
i
)
{
if
(
usePublicIp
)
{
pMeta
->
vpeerDesc
[
i
].
ip
=
pVgroup
->
vnodeGid
[
i
].
publicIp
;
}
else
{
pMeta
->
vpeerDesc
[
i
].
ip
=
pVgroup
->
vnodeGid
[
i
].
privateIp
;
}
pMeta
->
vpeerDesc
[
i
].
vnode
=
htonl
(
pVgroup
->
vnodeGid
[
i
].
vnode
);
}
pMeta
->
numOfVpeers
=
pVgroup
->
numOfVnodes
;
return
TSDB_CODE_SUCCESS
;
}
void
mgmtDropAllNormalTables
(
SDbObj
*
pDropDb
)
{
void
*
pNode
=
NULL
;
void
*
pLastNode
=
NULL
;
int32_t
numOfTables
=
0
;
int32_t
dbNameLen
=
strlen
(
pDropDb
->
name
);
SNormalTableObj
*
pTable
=
NULL
;
while
(
1
)
{
pNode
=
sdbFetchRow
(
tsNormalTableSdb
,
pNode
,
(
void
**
)
&
pTable
);
if
(
pTable
==
NULL
)
break
;
if
(
strncmp
(
pDropDb
->
name
,
pTable
->
tableId
,
dbNameLen
)
==
0
)
{
SSdbOperDesc
oper
=
{
.
type
=
SDB_OPER_TYPE_LOCAL
,
.
table
=
tsNormalTableSdb
,
.
pObj
=
pTable
,
};
sdbDeleteRow
(
&
oper
);
pNode
=
pLastNode
;
numOfTables
++
;
continue
;
}
}
mTrace
(
"db:%s, all normal tables:%d is dropped from sdb"
,
pDropDb
->
name
,
numOfTables
);
}
src/mnode/src/mgmtShell.c
浏览文件 @
2180f6eb
...
...
@@ -138,13 +138,19 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) {
return
;
}
if
(
mgmtCheckExpired
())
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_GRANT_EXPIRED
);
return
;
}
if
(
tsMgmtProcessShellMsgFp
[
rpcMsg
->
msgType
]
==
NULL
)
{
mgmtProcessUnSupportMsg
(
rpcMsg
);
rpcFreeCont
(
rpcMsg
->
pCont
);
return
;
}
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
);
bool
usePublicIp
=
false
;
SUserObj
*
pUser
=
mgmtGetUserFromConn
(
rpcMsg
->
handle
,
&
usePublicIp
);
if
(
pUser
==
NULL
)
{
mgmtSendSimpleResp
(
rpcMsg
->
handle
,
TSDB_CODE_INVALID_USER
);
rpcFreeCont
(
rpcMsg
->
pCont
);
...
...
@@ -158,6 +164,7 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) {
queuedMsg
.
contLen
=
rpcMsg
->
contLen
;
queuedMsg
.
pCont
=
rpcMsg
->
pCont
;
queuedMsg
.
pUser
=
pUser
;
queuedMsg
.
usePublicIp
=
usePublicIp
;
(
*
tsMgmtProcessShellMsgFp
[
rpcMsg
->
msgType
])(
&
queuedMsg
);
rpcFreeCont
(
rpcMsg
->
pCont
);
}
else
{
...
...
@@ -167,6 +174,7 @@ static void mgmtProcessMsgFromShell(SRpcMsg *rpcMsg) {
queuedMsg
->
contLen
=
rpcMsg
->
contLen
;
queuedMsg
->
pCont
=
rpcMsg
->
pCont
;
queuedMsg
->
pUser
=
pUser
;
queuedMsg
.
usePublicIp
=
usePublicIp
;
mgmtAddToShellQueue
(
queuedMsg
);
}
}
...
...
src/mnode/src/mgmtSuperTable.c
浏览文件 @
2180f6eb
...
...
@@ -15,7 +15,8 @@
#define _DEFAULT_SOURCE
#include "os.h"
#include "name.h"
#include "tsqlfunction.h"
#include "mgmtAcct.h"
#include "mgmtChildTable.h"
#include "mgmtDb.h"
...
...
@@ -27,14 +28,11 @@
#include "mgmtTable.h"
#include "mgmtUser.h"
#include "mgmtVgroup.h"
#include "mnode.h"
#include "name.h"
#include "tsqlfunction.h"
static
void
*
tsSuperTableSdb
;
static
int32_t
tsSuperTableUpdateSize
;
static
void
mgmtProcessSuperTableVgroupMsg
(
SQueuedMsg
*
queueMsg
);
static
void
mgmtProcessDropStableRsp
(
SRpcMsg
*
rpcMsg
);
static
int32_t
mgmtRetrieveShowSuperTables
(
SShowObj
*
pShow
,
char
*
data
,
int32_t
rows
,
void
*
pConn
);
static
int32_t
mgmtGetShowSuperTableMeta
(
STableMetaMsg
*
pMeta
,
SShowObj
*
pShow
,
void
*
pConn
);
...
...
@@ -132,8 +130,10 @@ int32_t mgmtInitSuperTables() {
return
-
1
;
}
mgmtAddShellMsgHandle
(
TSDB_MSG_TYPE_CM_STABLE_VGROUP
,
mgmtProcessSuperTableVgroupMsg
);
mgmtAddShellShowMetaHandle
(
TSDB_MGMT_TABLE_METRIC
,
mgmtGetShowSuperTableMeta
);
mgmtAddShellShowRetrieveHandle
(
TSDB_MGMT_TABLE_METRIC
,
mgmtRetrieveShowSuperTables
);
mgmtAddDClientRspHandle
(
TSDB_MSG_TYPE_MD_DROP_STABLE_RSP
,
mgmtProcessDropStableRsp
);
mTrace
(
"stables is initialized"
);
return
0
;
...
...
@@ -143,10 +143,12 @@ void mgmtCleanUpSuperTables() {
sdbCloseTable
(
tsSuperTableSdb
);
}
int32_t
mgmtCreateSuperTable
(
SCMCreateTableMsg
*
pCreate
)
{
void
mgmtCreateSuperTable
(
SQueuedMsg
*
pMsg
)
{
SCMCreateTableMsg
*
pCreate
=
pMsg
->
pCont
;
SSuperTableObj
*
pStable
=
(
SSuperTableObj
*
)
calloc
(
1
,
sizeof
(
SSuperTableObj
));
if
(
pStable
==
NULL
)
{
return
TSDB_CODE_SERV_OUT_OF_MEMORY
;
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SERV_OUT_OF_MEMORY
);
return
;
}
strcpy
(
pStable
->
tableId
,
pCreate
->
tableId
);
...
...
@@ -165,7 +167,8 @@ int32_t mgmtCreateSuperTable(SCMCreateTableMsg *pCreate) {
if
(
pStable
->
schema
==
NULL
)
{
free
(
pStable
);
mError
(
"stable:%s, no schema input"
,
pCreate
->
tableId
);
return
TSDB_CODE_INVALID_TABLE
;
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
);
return
;
}
memcpy
(
pStable
->
schema
,
pCreate
->
schema
,
numOfCols
*
sizeof
(
SSchema
));
...
...
@@ -186,17 +189,17 @@ int32_t mgmtCreateSuperTable(SCMCreateTableMsg *pCreate) {
int32_t
code
=
sdbInsertRow
(
&
oper
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
mgmtDestroySuperTable
(
pStable
);
return
TSDB_CODE_SDB_ERROR
;
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SDB_ERROR
)
;
}
else
{
mLPrint
(
"stable:%s, is created, tags:%d cols:%d"
,
pStable
->
tableId
,
pStable
->
numOfTags
,
pStable
->
numOfColumns
);
return
TSDB_CODE_SUCCESS
;
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_SUCCESS
)
;
}
}
int32_t
mgmtDropSuperTable
(
SQueuedMsg
*
newMsg
,
SDbObj
*
pDb
,
SSuperTableObj
*
pSt
able
)
{
void
mgmtDropSuperTable
(
SQueuedMsg
*
newMsg
,
SSuperTableObj
*
pT
able
)
{
if
(
pStable
->
numOfTables
!=
0
)
{
mError
(
"stable:%s, numOfTables:%d not 0"
,
pStable
->
tableId
,
pStable
->
numOfTables
);
return
TSDB_CODE_OTHERS
;
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_OTHERS
)
;
}
else
{
SSdbOperDesc
oper
=
{
.
type
=
SDB_OPER_TYPE_GLOBAL
,
...
...
@@ -205,7 +208,7 @@ int32_t mgmtDropSuperTable(SQueuedMsg *newMsg, SDbObj *pDb, SSuperTableObj *pSta
};
int32_t
code
=
sdbDeleteRow
(
&
oper
);
mLPrint
(
"stable:%s, is dropped from sdb, result:%s"
,
pStable
->
tableId
,
tstrerror
(
code
));
return
code
;
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
)
;
}
}
...
...
@@ -213,14 +216,14 @@ void* mgmtGetSuperTable(char *tableId) {
return
sdbGetRow
(
tsSuperTableSdb
,
tableId
);
}
void
*
mgmtGetSuperTableVgroup
(
SSuperTableObj
*
pStable
)
{
static
void
*
mgmtGetSuperTableVgroup
(
SSuperTableObj
*
pStable
)
{
SCMSuperTableInfoRsp
*
rsp
=
rpcMallocCont
(
sizeof
(
SCMSuperTableInfoRsp
)
+
sizeof
(
uint32_t
)
*
mgmtGetDnodesNum
());
rsp
->
numOfDnodes
=
htonl
(
1
);
rsp
->
dnodeIps
[
0
]
=
htonl
(
inet_addr
(
tsPrivateIp
));
return
rsp
;
}
int32_t
mgmtFindSuperTableTagIndex
(
SSuperTableObj
*
pStable
,
const
char
*
tagName
)
{
static
int32_t
mgmtFindSuperTableTagIndex
(
SSuperTableObj
*
pStable
,
const
char
*
tagName
)
{
for
(
int32_t
i
=
0
;
i
<
pStable
->
numOfTags
;
i
++
)
{
SSchema
*
schema
=
(
SSchema
*
)(
pStable
->
schema
+
(
pStable
->
numOfColumns
+
i
)
*
sizeof
(
SSchema
));
if
(
strcasecmp
(
tagName
,
schema
->
name
)
==
0
)
{
...
...
@@ -231,7 +234,7 @@ int32_t mgmtFindSuperTableTagIndex(SSuperTableObj *pStable, const char *tagName)
return
-
1
;
}
int32_t
mgmtAddSuperTableTag
(
SSuperTableObj
*
pStable
,
SSchema
schema
[],
int32_t
ntags
)
{
static
int32_t
mgmtAddSuperTableTag
(
SSuperTableObj
*
pStable
,
SSchema
schema
[],
int32_t
ntags
)
{
if
(
pStable
->
numOfTags
+
ntags
>
TSDB_MAX_TAGS
)
{
return
TSDB_CODE_APP_ERROR
;
}
...
...
@@ -279,7 +282,7 @@ int32_t mgmtAddSuperTableTag(SSuperTableObj *pStable, SSchema schema[], int32_t
return
TSDB_CODE_SUCCESS
;
}
int32_t
mgmtDropSuperTableTag
(
SSuperTableObj
*
pStable
,
char
*
tagName
)
{
static
int32_t
mgmtDropSuperTableTag
(
SSuperTableObj
*
pStable
,
char
*
tagName
)
{
int32_t
col
=
mgmtFindSuperTableTagIndex
(
pStable
,
tagName
);
if
(
col
<=
0
||
col
>=
pStable
->
numOfTags
)
{
return
TSDB_CODE_APP_ERROR
;
...
...
@@ -311,7 +314,7 @@ int32_t mgmtDropSuperTableTag(SSuperTableObj *pStable, char *tagName) {
return
TSDB_CODE_SUCCESS
;
}
int32_t
mgmtModifySuperTableTagNameByName
(
SSuperTableObj
*
pStable
,
char
*
oldTagName
,
char
*
newTagName
)
{
static
int32_t
mgmtModifySuperTableTagNameByName
(
SSuperTableObj
*
pStable
,
char
*
oldTagName
,
char
*
newTagName
)
{
int32_t
col
=
mgmtFindSuperTableTagIndex
(
pStable
,
oldTagName
);
if
(
col
<
0
)
{
// Tag name does not exist
...
...
@@ -362,7 +365,7 @@ static int32_t mgmtFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colN
return
-
1
;
}
int32_t
mgmtAddSuperTableColumn
(
SSuperTableObj
*
pStable
,
SSchema
schema
[],
int32_t
ncols
)
{
static
int32_t
mgmtAddSuperTableColumn
(
SSuperTableObj
*
pStable
,
SSchema
schema
[],
int32_t
ncols
)
{
if
(
ncols
<=
0
)
{
return
TSDB_CODE_APP_ERROR
;
}
...
...
@@ -406,7 +409,7 @@ int32_t mgmtAddSuperTableColumn(SSuperTableObj *pStable, SSchema schema[], int32
return
TSDB_CODE_SUCCESS
;
}
int32_t
mgmtDropSuperTableColumnByName
(
SSuperTableObj
*
pStable
,
char
*
colName
)
{
static
int32_t
mgmtDropSuperTableColumnByName
(
SSuperTableObj
*
pStable
,
char
*
colName
)
{
int32_t
col
=
mgmtFindSuperTableColumnIndex
(
pStable
,
colName
);
if
(
col
<
0
)
{
return
TSDB_CODE_APP_ERROR
;
...
...
@@ -519,12 +522,12 @@ int32_t mgmtRetrieveShowSuperTables(SShowObj *pShow, char *data, int32_t rows, v
while
(
numOfRows
<
rows
)
{
pShow
->
pNode
=
sdbFetchRow
(
tsSuperTableSdb
,
pShow
->
pNode
,
(
void
**
)
&
pTable
);
if
(
pTable
==
NULL
)
break
;
if
(
strncmp
(
pTable
->
tableId
,
prefix
,
prefixLen
))
{
if
(
strncmp
(
pTable
->
info
.
tableId
,
prefix
,
prefixLen
))
{
continue
;
}
memset
(
stableName
,
0
,
tListLen
(
stableName
));
mgmtExtractTableName
(
pTable
->
tableId
,
stableName
);
mgmtExtractTableName
(
pTable
->
info
.
tableId
,
stableName
);
if
(
pShow
->
payloadLen
>
0
&&
patternMatch
(
pShow
->
payload
,
stableName
,
TSDB_TABLE_NAME_LEN
,
&
info
)
!=
TSDB_PATTERN_MATCH
)
...
...
@@ -572,7 +575,7 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
break
;
}
if
(
strncmp
(
pDropDb
->
name
,
pTable
->
tableId
,
dbNameLen
)
==
0
)
{
if
(
strncmp
(
pDropDb
->
name
,
pTable
->
info
.
tableId
,
dbNameLen
)
==
0
)
{
SSdbOperDesc
oper
=
{
.
type
=
SDB_OPER_TYPE_LOCAL
,
.
table
=
tsSuperTableSdb
,
...
...
@@ -588,14 +591,6 @@ void mgmtDropAllSuperTables(SDbObj *pDropDb) {
mTrace
(
"db:%s, all super tables:%d is dropped from sdb"
,
pDropDb
->
name
,
numOfTables
);
}
void
mgmtAddTableIntoSuperTable
(
SSuperTableObj
*
pStable
)
{
pStable
->
numOfTables
++
;
}
void
mgmtRemoveTableFromSuperTable
(
SSuperTableObj
*
pStable
)
{
pStable
->
numOfTables
--
;
}
int32_t
mgmtSetSchemaFromSuperTable
(
SSchema
*
pSchema
,
SSuperTableObj
*
pTable
)
{
int32_t
numOfCols
=
pTable
->
numOfColumns
+
pTable
->
numOfTags
;
for
(
int32_t
i
=
0
;
i
<
numOfCols
;
++
i
)
{
...
...
@@ -609,32 +604,67 @@ int32_t mgmtSetSchemaFromSuperTable(SSchema *pSchema, SSuperTableObj *pTable) {
return
(
pTable
->
numOfColumns
+
pTable
->
numOfTags
)
*
sizeof
(
SSchema
);
}
int32_t
mgmtGetSuperTableMeta
(
SDbObj
*
pDb
,
SSuperTableObj
*
pTable
,
STableMetaMsg
*
pMeta
,
bool
usePublicIp
)
{
void
mgmtGetSuperTableMeta
(
SQueuedMsg
*
pMsg
,
SSuperTableObj
*
pTable
)
{
SCMTableInfoMsg
*
pInfo
=
pMsg
->
pCont
;
SDbObj
*
pDb
=
pMsg
->
pDb
;
STableMetaMsg
*
pMeta
=
rpcMallocCont
(
sizeof
(
STableMetaMsg
)
+
sizeof
(
SSchema
)
*
TSDB_MAX_COLUMNS
);
pMeta
->
uid
=
htobe64
(
pTable
->
uid
);
pMeta
->
sid
=
htonl
(
pTable
->
sid
);
pMeta
->
vgId
=
htonl
(
pTable
->
vgId
);
pMeta
->
sversion
=
htons
(
pTable
->
sversion
);
pMeta
->
precision
=
pDb
->
cfg
.
precision
;
pMeta
->
numOfTags
=
pTable
->
numOfTags
;
pMeta
->
numOfColumns
=
htons
(
pTable
->
numOfColumns
);
pMeta
->
tableType
=
pTable
->
type
;
pMeta
->
tableType
=
pTable
->
info
.
type
;
pMeta
->
contLen
=
sizeof
(
STableMetaMsg
)
+
mgmtSetSchemaFromSuperTable
(
pMeta
->
schema
,
pTable
);
strcpy
(
pMeta
->
tableId
,
pTable
->
tableId
);
strcpy
(
pMeta
->
tableId
,
pTable
->
info
.
tableId
);
return
TSDB_CODE_SUCCESS
;
}
SRpcMsg
rpcRsp
=
{
.
handle
=
pMsg
->
thandle
,
.
pCont
=
pMeta
,
.
contLen
=
pMeta
->
contLen
,
};
pMeta
->
contLen
=
htons
(
pMeta
->
contLen
);
rpcSendResponse
(
&
rpcRsp
);
int32_t
mgmtExtractTableName
(
const
char
*
tableId
,
char
*
name
)
{
int
pos
=
-
1
;
int
num
=
0
;
for
(
pos
=
0
;
tableId
[
pos
]
!=
0
;
++
pos
)
{
if
(
tableId
[
pos
]
==
'.'
)
num
++
;
if
(
num
==
2
)
break
;
}
mTrace
(
"stable:%%s, uid:%"
PRIu64
" table meta is retrieved"
,
pTable
->
info
.
tableId
,
pTable
->
uid
);
}
if
(
num
==
2
)
{
strcpy
(
name
,
tableId
+
pos
+
1
);
static
void
mgmtProcessSuperTableVgroupMsg
(
SQueuedMsg
*
pMsg
)
{
SCMSuperTableInfoMsg
*
pInfo
=
pMsg
->
pCont
;
STableInfo
*
pTable
=
mgmtGetSuperTable
(
pInfo
->
tableId
);
if
(
pTable
==
NULL
)
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
);
return
;
}
SCMSuperTableInfoRsp
*
pRsp
=
mgmtGetSuperTableVgroup
((
SSuperTableObj
*
)
pTable
);
if
(
pRsp
!=
NULL
)
{
int32_t
msgLen
=
sizeof
(
SSuperTableObj
)
+
htonl
(
pRsp
->
numOfDnodes
)
*
sizeof
(
int32_t
);
SRpcMsg
rpcRsp
=
{
0
};
rpcRsp
.
handle
=
pMsg
->
thandle
;
rpcRsp
.
pCont
=
pRsp
;
rpcRsp
.
contLen
=
msgLen
;
rpcSendResponse
(
&
rpcRsp
);
}
else
{
mgmtSendSimpleResp
(
pMsg
->
thandle
,
TSDB_CODE_INVALID_TABLE
);
}
return
0
;
}
void
mgmtAlterSuperTable
(
SQueuedMsg
*
pMsg
,
SSuperTableObj
*
pTable
)
{
int32_t
code
=
TSDB_CODE_OPS_NOT_SUPPORT
;
SCMAlterTableMsg
*
pAlter
=
pMsg
->
pCont
;
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
)
{
code
=
mgmtAddSuperTableTag
((
SSuperTableObj
*
)
pTable
,
pAlter
->
schema
,
1
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
)
{
code
=
mgmtDropSuperTableTag
((
SSuperTableObj
*
)
pTable
,
pAlter
->
schema
[
0
].
name
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN
)
{
code
=
mgmtModifySuperTableTagNameByName
((
SSuperTableObj
*
)
pTable
,
pAlter
->
schema
[
0
].
name
,
pAlter
->
schema
[
1
].
name
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_ADD_COLUMN
)
{
code
=
mgmtAddSuperTableColumn
((
SSuperTableObj
*
)
pTable
,
pAlter
->
schema
,
1
);
}
else
if
(
pAlter
->
type
==
TSDB_ALTER_TABLE_DROP_COLUMN
)
{
code
=
mgmtDropSuperTableColumnByName
((
SSuperTableObj
*
)
pTable
,
pAlter
->
schema
[
0
].
name
);
}
else
{}
mgmtSendSimpleResp
(
pMsg
->
thandle
,
code
);
}
\ No newline at end of file
src/mnode/src/mgmtTable.c
浏览文件 @
2180f6eb
此差异已折叠。
点击以展开。
src/mnode/src/mgmtUser.c
浏览文件 @
2180f6eb
...
...
@@ -310,9 +310,10 @@ static int32_t mgmtRetrieveUsers(SShowObj *pShow, char *data, int32_t rows, void
return
numOfRows
;
}
SUserObj
*
mgmtGetUserFromConn
(
void
*
pConn
)
{
SUserObj
*
mgmtGetUserFromConn
(
void
*
pConn
,
bool
*
usePublicIp
)
{
SRpcConnInfo
connInfo
;
if
(
rpcGetConnInfo
(
pConn
,
&
connInfo
)
==
0
)
{
*
usePublicIp
=
(
connInfo
.
serverIp
==
tsPublicIpInt
);
return
mgmtGetUser
(
connInfo
.
user
);
}
...
...
src/mnode/src/mgmtVgroup.c
浏览文件 @
2180f6eb
...
...
@@ -428,7 +428,7 @@ int32_t mgmtRetrieveVgroups(SShowObj *pShow, char *data, int32_t rows, void *pCo
return
numOfRows
;
}
void
mgmtAddTableIntoVgroup
(
SVgObj
*
pVgroup
,
S
TableInfo
*
pTable
)
{
void
mgmtAddTableIntoVgroup
(
SVgObj
*
pVgroup
,
S
ChildTableObj
*
pTable
)
{
if
(
pTable
->
sid
>=
0
&&
pVgroup
->
tableList
[
pTable
->
sid
]
==
NULL
)
{
pVgroup
->
tableList
[
pTable
->
sid
]
=
pTable
;
taosIdPoolMarkStatus
(
pVgroup
->
idPool
,
pTable
->
sid
);
...
...
@@ -439,7 +439,7 @@ void mgmtAddTableIntoVgroup(SVgObj *pVgroup, STableInfo *pTable) {
mgmtAddVgroupIntoDbTail
(
pVgroup
);
}
void
mgmtRemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
S
TableInfo
*
pTable
)
{
void
mgmtRemoveTableFromVgroup
(
SVgObj
*
pVgroup
,
S
ChildTableObj
*
pTable
)
{
if
(
pTable
->
sid
>=
0
&&
pVgroup
->
tableList
[
pTable
->
sid
]
!=
NULL
)
{
pVgroup
->
tableList
[
pTable
->
sid
]
=
NULL
;
taosFreeId
(
pVgroup
->
idPool
,
pTable
->
sid
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录