提交 95f748ca 编写于 作者: S slguan

mgmtTable.c

上级 b7050af1
/*
* 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_SUPER_TABLE_QUERY_H
#define TBASE_MNODE_SUPER_TABLE_QUERY_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "mnode.h"
#include "tast.h"
int32_t mgmtRetrieveMetersFromSuperTable(SSuperTableMetaMsg* pInfo, int32_t tableIndex, tQueryResultset* pRes);
int32_t mgmtDoJoin(SSuperTableMetaMsg* pSuperTableMetaMsg, tQueryResultset* pRes);
void mgmtReorganizeMetersInMetricMeta(SSuperTableMetaMsg* pInfo, int32_t index, tQueryResultset* pRes);
#endif
...@@ -25,30 +25,23 @@ extern "C" { ...@@ -25,30 +25,23 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
#include "mnode.h" #include "mnode.h"
int32_t mgmtInitTables();
typedef struct {
ETableType type;
void* obj;
} STableObj;
int mgmtInitMeters();
STableInfo* mgmtGetTable(char *tableId); STableInfo* mgmtGetTable(char *tableId);
STableInfo* mgmtGetTableByPos(uint32_t dnodeIp, int32_t vnode, int32_t sid); STableInfo* mgmtGetTableByPos(uint32_t dnodeIp, int32_t vnode, int32_t sid);
STabObj *mgmtGetTableInfo(char *src, char *tags[]); int32_t mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SSuperTableMetaMsg *pInfo);
int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SSuperTableMetaMsg *pInfo); int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate);
int mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate); int32_t mgmtDropTable(SDbObj *pDb, char *meterId, int32_t ignore);
int mgmtDropTable(SDbObj *pDb, char *meterId, int ignore); int32_t mgmtAlterTable(SDbObj *pDb, SAlterTableMsg *pAlter);
int mgmtAlterTable(SDbObj *pDb, SAlterTableMsg *pAlter); int32_t mgmtGetTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
int mgmtGetTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); int32_t mgmtRetrieveTables(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn);
int mgmtRetrieveTables(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
void mgmtCleanUpMeters(); void mgmtCleanUpMeters();
SSchema *mgmtGetTableSchema(STabObj *pTable); // get schema for a meter SSchema *mgmtGetTableSchema(STabObj *pTable); // get schema for a meter
int mgmtAddMeterIntoMetric(STabObj *pMetric, STabObj *pTable); int32_t mgmtAddMeterIntoMetric(STabObj *pMetric, STabObj *pTable);
int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pTable); int32_t mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pTable);
int mgmtGetSuperTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn); int32_t mgmtGetSuperTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
int mgmtRetrieveSuperTables(SShowObj *pShow, char *data, int rows, SConnObj *pConn); int32_t mgmtRetrieveSuperTables(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn);
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "mgmtDb.h" #include "mgmtDb.h"
#include "mgmtDnodeInt.h" #include "mgmtDnodeInt.h"
#include "mgmtVgroup.h" #include "mgmtVgroup.h"
#include "mgmtSupertableQuery.h"
#include "mgmtTable.h" #include "mgmtTable.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tast.h" #include "tast.h"
......
...@@ -101,7 +101,7 @@ int32_t mgmtStartSystem() { ...@@ -101,7 +101,7 @@ int32_t mgmtStartSystem() {
return -1; return -1;
} }
if (mgmtInitMeters() < 0) { if (mgmtInitTables() < 0) {
mError("failed to init meters"); mError("failed to init meters");
return -1; return -1;
} }
......
...@@ -15,16 +15,7 @@ ...@@ -15,16 +15,7 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taoserror.h"
#include "mnode.h"
#include "mgmtAcct.h"
#include "mgmtGrant.h"
#include "mgmtUtil.h"
#include "mgmtDb.h"
#include "mgmtDnodeInt.h"
#include "mgmtVgroup.h"
#include "mgmtSupertableQuery.h"
#include "mgmtTable.h"
#include "taosmsg.h" #include "taosmsg.h"
#include "tast.h" #include "tast.h"
#include "textbuffer.h" #include "textbuffer.h"
...@@ -32,46 +23,23 @@ ...@@ -32,46 +23,23 @@
#include "tscompression.h" #include "tscompression.h"
#include "tskiplist.h" #include "tskiplist.h"
#include "tsqlfunction.h" #include "tsqlfunction.h"
#include "ttime.h"
#include "tstatus.h" #include "tstatus.h"
#include "ttime.h"
#include "mgmtSuperTable.h" #include "mnode.h"
#include "mgmtAcct.h"
#include "mgmtChildTable.h" #include "mgmtChildTable.h"
#include "mgmtDb.h"
#include "mgmtDnode.h"
#include "mgmtDnodeInt.h"
#include "mgmtGrant.h"
#include "mgmtNormalTable.h" #include "mgmtNormalTable.h"
#include "mgmtStreamTable.h" #include "mgmtStreamTable.h"
#include "mgmtSuperTable.h"
#include "mgmtTable.h"
#include "mgmtUtil.h"
#include "mgmtVgroup.h"
#include "taoserror.h" int32_t mgmtInitTables() {
extern int64_t sdbVersion;
static int32_t mgmtGetReqTagsLength(STabObj *pMetric, int16_t *cols, int32_t numOfCols) {
assert(mgmtIsSuperTable(pMetric) && numOfCols >= 0 && numOfCols <= TSDB_MAX_TAGS + 1);
int32_t len = 0;
for (int32_t i = 0; i < numOfCols; ++i) {
assert(cols[i] < pMetric->numOfTags);
if (cols[i] == -1) {
len += TSDB_METER_NAME_LEN;
} else {
len += ((SSchema *)pMetric->schema)[pMetric->numOfColumns + cols[i]].bytes;
}
}
return len;
}
/*
* remove the hole in result set
*/
static void mgmtVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) {
if (rows < capacity) {
for (int32_t i = 0; i < numOfCols; ++i) {
memmove(data + pShow->offset[i] * rows, data + pShow->offset[i] * capacity, pShow->bytes[i] * rows);
}
}
}
int mgmtInitMeters() {
int32_t code = mgmtInitSuperTables(); int32_t code = mgmtInitSuperTables();
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
return code; return code;
...@@ -120,12 +88,21 @@ STableInfo* mgmtGetTable(char *tableId) { ...@@ -120,12 +88,21 @@ STableInfo* mgmtGetTable(char *tableId) {
} }
STableInfo* mgmtGetTableByPos(uint32_t dnodeIp, int32_t vnode, int32_t sid) { STableInfo* mgmtGetTableByPos(uint32_t dnodeIp, int32_t vnode, int32_t sid) {
SDnodeObj *pObj = mgmtGetDnode(dnodeIp);
if (pObj != NULL && vnode >= 0 && vnode < pObj->numOfVnodes) {
int32_t vgId = pObj->vload[vnode].vgId;
SVgObj *pVgroup = mgmtGetVgroup(vgId);
if (pVgroup) {
return pVgroup->tableList[sid];
}
}
return NULL; return NULL;
} }
int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) { int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) {
STableInfo *table = mgmtGetTable(pCreate->meterId); STableInfo *pTable = mgmtGetTable(pCreate->meterId);
if (table != NULL) { if (pTable != NULL) {
if (pCreate->igExists) { if (pCreate->igExists) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
...@@ -135,7 +112,7 @@ int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -135,7 +112,7 @@ int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) {
SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct); SAcctObj *pAcct = mgmtGetAcct(pDb->cfg.acct);
assert(pAcct != NULL); assert(pAcct != NULL);
int code = mgmtCheckTableLimit(pAcct, pCreate); int32_t code = mgmtCheckTableLimit(pAcct, pCreate);
if (code != 0) { if (code != 0) {
mError("table:%s, exceed the limit", pCreate->meterId); mError("table:%s, exceed the limit", pCreate->meterId);
return code; return code;
...@@ -147,7 +124,7 @@ int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -147,7 +124,7 @@ int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) {
} }
if (pCreate->numOfTags == 0) { if (pCreate->numOfTags == 0) {
int grantCode = mgmtCheckTimeSeries(pCreate->numOfColumns); int32_t grantCode = mgmtCheckTimeSeries(pCreate->numOfColumns);
if (grantCode != 0) { if (grantCode != 0) {
mError("table:%s, grant expired", pCreate->meterId); mError("table:%s, grant expired", pCreate->meterId);
return grantCode; return grantCode;
...@@ -175,9 +152,9 @@ int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -175,9 +152,9 @@ int32_t mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate) {
} }
} }
int mgmtDropTable(SDbObj *pDb, char *tableId, int ignore) { int32_t mgmtDropTable(SDbObj *pDb, char *tableId, int32_t ignore) {
STableInfo *table = mgmtGetTable(tableId); STableInfo *pTable = mgmtGetTable(tableId);
if (table == NULL) { if (pTable == NULL) {
if (ignore) { if (ignore) {
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} else { } else {
...@@ -185,72 +162,61 @@ int mgmtDropTable(SDbObj *pDb, char *tableId, int ignore) { ...@@ -185,72 +162,61 @@ int mgmtDropTable(SDbObj *pDb, char *tableId, int ignore) {
} }
} }
// 0.log
if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) { if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) {
return TSDB_CODE_MONITOR_DB_FORBIDDEN; return TSDB_CODE_MONITOR_DB_FORBIDDEN;
} }
switch (table->type) { switch (pTable->type) {
case TSDB_TABLE_TYPE_SUPER_TABLE: case TSDB_TABLE_TYPE_SUPER_TABLE:
return mgmtDropSuperTable(pDb, table); return mgmtDropSuperTable(pDb, (SSuperTableObj *) pTable);
case TSDB_TABLE_TYPE_CHILD_TABLE: case TSDB_TABLE_TYPE_CHILD_TABLE:
return mgmtDropChildTable(pDb, table); return mgmtDropChildTable(pDb, (SChildTableObj *) pTable);
case TSDB_TABLE_TYPE_STREAM_TABLE: case TSDB_TABLE_TYPE_STREAM_TABLE:
return mgmtDropStreamTable(pDb, table); return mgmtDropStreamTable(pDb, (SStreamTableObj *) pTable);
case TSDB_TABLE_TYPE_NORMAL_TABLE: case TSDB_TABLE_TYPE_NORMAL_TABLE:
return mgmtDropNormalTable(pDb, table); return mgmtDropNormalTable(pDb, (SNormalTableObj *) pTable);
default: default:
return TSDB_CODE_INVALID_TABLE; return TSDB_CODE_INVALID_TABLE;
} }
} }
int mgmtAlterTable(SDbObj *pDb, SAlterTableMsg *pAlter) { int32_t mgmtAlterTable(SDbObj *pDb, SAlterTableMsg *pAlter) {
STableInfo *table = mgmtGetTable(pAlter->meterId); STableInfo *pTable = mgmtGetTable(pAlter->meterId);
if (table == NULL) { if (pTable == NULL) {
return TSDB_CODE_INVALID_TABLE; return TSDB_CODE_INVALID_TABLE;
} }
// 0.log
if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) { if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) {
return TSDB_CODE_MONITOR_DB_FORBIDDEN; return TSDB_CODE_MONITOR_DB_FORBIDDEN;
} }
// if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
// return mgmtUpdate
// if (!mgmtIsNormalTable(pTable) || !mgmtTableCreateFromSuperTable(pTable)) {
// return TSDB_CODE_OPS_NOT_SUPPORT;
// }
// }
// todo add
/* mgmtMeterAddTags */
if (pAlter->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) { if (pAlter->type == TSDB_ALTER_TABLE_ADD_TAG_COLUMN) {
if (table->type == TSDB_TABLE_TYPE_SUPER_TABLE) { if (pTable->type == TSDB_TABLE_TYPE_SUPER_TABLE) {
return mgmtAddSuperTableTag(table, pAlter->schema, 1); return mgmtAddSuperTableTag((SSuperTableObj *) pTable, pAlter->schema, 1);
} }
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_DROP_TAG_COLUMN) {
if (table->type == TSDB_TABLE_TYPE_SUPER_TABLE) { if (pTable->type == TSDB_TABLE_TYPE_SUPER_TABLE) {
return mgmtDropSuperTableTag(table, pAlter->schema[0].name); return mgmtDropSuperTableTag((SSuperTableObj *) pTable, pAlter->schema[0].name);
} }
} else if (pAlter->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN) {
if (table->type == TSDB_TABLE_TYPE_SUPER_TABLE) { if (pTable->type == TSDB_TABLE_TYPE_SUPER_TABLE) {
return mgmtModifySuperTableTagNameByName(table, pAlter->schema[0].name, pAlter->schema[1].name); return mgmtModifySuperTableTagNameByName((SSuperTableObj *) pTable, pAlter->schema[0].name, pAlter->schema[1].name);
} }
} else if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) { } else if (pAlter->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) {
if (table->type == TSDB_TABLE_TYPE_CHILD_TABLE) { if (pTable->type == TSDB_TABLE_TYPE_CHILD_TABLE) {
return mgmtModifyChildTableTagValueByName(table, pAlter->schema[0].name, pAlter->tagVal); return mgmtModifyChildTableTagValueByName((SChildTableObj *) pTable, pAlter->schema[0].name, pAlter->tagVal);
} }
} else if (pAlter->type == TSDB_ALTER_TABLE_ADD_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_ADD_COLUMN) {
if (table->type == TSDB_TABLE_TYPE_NORMAL_TABLE) { if (pTable->type == TSDB_TABLE_TYPE_NORMAL_TABLE) {
return mgmtAddNormalTableColumn(table, pAlter->schema, 1); return mgmtAddNormalTableColumn((SNormalTableObj *) pTable, pAlter->schema, 1);
} else if (table->type == TSDB_TABLE_TYPE_SUPER_TABLE) { } else if (pTable->type == TSDB_TABLE_TYPE_SUPER_TABLE) {
return mgmtAddSuperTableColumn(table, pAlter->schema, 1); return mgmtAddSuperTableColumn((SSuperTableObj *) pTable, pAlter->schema, 1);
} else {} } else {}
} else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) { } else if (pAlter->type == TSDB_ALTER_TABLE_DROP_COLUMN) {
if (table->type == TSDB_TABLE_TYPE_NORMAL_TABLE) { if (pTable->type == TSDB_TABLE_TYPE_NORMAL_TABLE) {
return mgmtDropNormalTableColumnByName(table, pAlter->schema[0].name); return mgmtDropNormalTableColumnByName((SNormalTableObj *) pTable, pAlter->schema[0].name);
} else if (table->type == TSDB_TABLE_TYPE_SUPER_TABLE) { } else if (pTable->type == TSDB_TABLE_TYPE_SUPER_TABLE) {
return mgmtDropSuperTableColumnByName(table, pAlter->schema[0].name); return mgmtDropSuperTableColumnByName((SSuperTableObj *) pTable, pAlter->schema[0].name);
} else {} } else {}
} else {} } else {}
...@@ -316,7 +282,18 @@ int32_t mgmtGetTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) { ...@@ -316,7 +282,18 @@ int32_t mgmtGetTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
return 0; return 0;
} }
int32_t mgmtRetrieveTables(SShowObj *pShow, char *data, int rows, SConnObj *pConn) { /*
* remove the hole in result set
*/
static void mgmtVacuumResult(char *data, int32_t numOfCols, int32_t rows, int32_t capacity, SShowObj *pShow) {
if (rows < capacity) {
for (int32_t i = 0; i < numOfCols; ++i) {
memmove(data + pShow->offset[i] * rows, data + pShow->offset[i] * capacity, pShow->bytes[i] * rows);
}
}
}
int32_t mgmtRetrieveTables(SShowObj *pShow, char *data, int32_t rows, SConnObj *pConn) {
int32_t numOfRows = 0; int32_t numOfRows = 0;
int32_t numOfRead = 0; int32_t numOfRead = 0;
int32_t cols = 0; int32_t cols = 0;
...@@ -327,7 +304,7 @@ int32_t mgmtRetrieveTables(SShowObj *pShow, char *data, int rows, SConnObj *pCon ...@@ -327,7 +304,7 @@ int32_t mgmtRetrieveTables(SShowObj *pShow, char *data, int rows, SConnObj *pCon
int64_t createdTime; int64_t createdTime;
char *tableId; char *tableId;
char *superTableId; char *superTableId;
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER; SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
SDbObj *pDb = NULL; SDbObj *pDb = NULL;
if (pConn->pDb != NULL) { if (pConn->pDb != NULL) {
...@@ -415,9 +392,9 @@ int32_t mgmtRetrieveTables(SShowObj *pShow, char *data, int rows, SConnObj *pCon ...@@ -415,9 +392,9 @@ int32_t mgmtRetrieveTables(SShowObj *pShow, char *data, int rows, SConnObj *pCon
cols++; cols++;
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
// if (pTable->pTagData) { if (superTableId != NULL) {
// extractTableName(superTableId, pWrite); extractTableName(superTableId, pWrite);
// } }
cols++; cols++;
numOfRows++; numOfRows++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册