This commit is contained in:
parent
d1f7112e3e
commit
81fef75fb8
|
@ -22,6 +22,11 @@ extern "C" {
|
|||
|
||||
#include "os.h"
|
||||
|
||||
#include "taosdef.h"
|
||||
#include "taosmsg.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
|
||||
#include "sdb.h"
|
||||
#include "tglobalcfg.h"
|
||||
#include "thash.h"
|
||||
|
@ -132,6 +137,72 @@ typedef struct _tab_obj {
|
|||
// SSchema schema[];
|
||||
} STabObj;
|
||||
|
||||
|
||||
typedef struct SSuperTableObj {
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
uint64_t uid;
|
||||
int32_t sid;
|
||||
int32_t vgId;
|
||||
int64_t createdTime;
|
||||
int32_t sversion;
|
||||
int32_t numOfTags;
|
||||
int32_t numOfMeters;
|
||||
int32_t numOfColumns;
|
||||
int32_t schemaSize;
|
||||
int8_t reserved[7];
|
||||
int8_t updateEnd[1];
|
||||
int16_t nextColId;
|
||||
pthread_rwlock_t rwLock;
|
||||
tSkipList * pSkipList;
|
||||
struct SSuperTableObj *pHead;
|
||||
struct SSuperTableObj *prev, *next;
|
||||
int8_t* schema;
|
||||
} SSuperTableObj;
|
||||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
char superTableId[TSDB_TABLE_ID_LEN + 1];
|
||||
uint64_t uid;
|
||||
int32_t sid;
|
||||
int32_t vgId;
|
||||
int64_t createdTime;
|
||||
int8_t reserved[7];
|
||||
int8_t updateEnd[1];
|
||||
SSuperTableObj *superTable;
|
||||
} SChildTableObj;
|
||||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
uint64_t uid;
|
||||
int32_t sid;
|
||||
int32_t vgId;
|
||||
int64_t createdTime;
|
||||
int32_t sversion;
|
||||
int32_t numOfColumns;
|
||||
int32_t schemaSize;
|
||||
char reserved[3];
|
||||
char updateEnd[1];
|
||||
int16_t nextColId;
|
||||
char* schema;
|
||||
} SNormalTableObj;
|
||||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
uint64_t uid;
|
||||
int32_t sid;
|
||||
int32_t vgId;
|
||||
int64_t createdTime;
|
||||
int32_t sversion;
|
||||
int32_t numOfColumns;
|
||||
int32_t schemaSize;
|
||||
char reserved[3];
|
||||
char updateEnd[1];
|
||||
int16_t nextColId;
|
||||
char* pSql; //null-terminated string
|
||||
char* schema;
|
||||
} SStreamTableObj;
|
||||
|
||||
|
||||
typedef struct _vg_obj {
|
||||
uint32_t vgId;
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
|
|
|
@ -136,6 +136,15 @@ void sdbCleanUpPeers();
|
|||
|
||||
int sdbCfgNode(char *cont);
|
||||
|
||||
int64_t sdbGetVersion();
|
||||
|
||||
|
||||
#define TSDB_MAX_TABLES 1000
|
||||
extern void* tsChildTableSdb;
|
||||
extern void* tsNormalTableSdb;
|
||||
extern void* tsStreamTableSdb;
|
||||
extern void* tsSuperTableSdb;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "tsdb.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
|
@ -294,6 +297,11 @@ typedef struct SMColumn {
|
|||
short bytes;
|
||||
} SMColumn;
|
||||
|
||||
typedef struct {
|
||||
int32_t size;
|
||||
int8_t* data;
|
||||
} SVariableMsg;
|
||||
|
||||
typedef struct {
|
||||
short vnode;
|
||||
int32_t sid;
|
||||
|
@ -310,6 +318,9 @@ typedef struct {
|
|||
char reserved[16];
|
||||
int32_t sversion;
|
||||
SMColumn schema[];
|
||||
|
||||
SVariableMsg tags;
|
||||
|
||||
} SCreateMsg;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -24,27 +24,14 @@ extern "C" {
|
|||
#include <stdbool.h>
|
||||
#include "taosdef.h"
|
||||
|
||||
struct SSuperTableObj;
|
||||
|
||||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
char superTableId[TSDB_TABLE_ID_LEN + 1];
|
||||
int64_t uid;
|
||||
int32_t sid;
|
||||
int32_t vgId;
|
||||
int64_t createdTime;
|
||||
int32_t sversion;
|
||||
char reserved[3];
|
||||
char updateEnd[1];
|
||||
struct SSuperTableObj *superTable;
|
||||
} SChildTableObj;
|
||||
#include "mnode.h"
|
||||
|
||||
int32_t mgmtInitChildTables();
|
||||
void mgmtCleanUpChildTables();
|
||||
int32_t mgmtCreateChildTable(SDbObj *pDb, SCreateTableMsg *pCreate);
|
||||
int32_t mgmtDropChildTable(SDbObj *pDb, char *meterId, int ignore);
|
||||
int32_t mgmtCreateChildTable(SDbObj *pDb, SCreateTableMsg *pCreate, int32_t vgId, int32_t sid);
|
||||
int32_t mgmtDropChildTable(SDbObj *pDb, SChildTableObj *pTable);
|
||||
int32_t mgmtAlterChildTable(SDbObj *pDb, SAlterTableMsg *pAlter);
|
||||
int32_t mgmtModifyChildTableTagValueByName(SChildTableObj *pTable, char *tagName, char *nContent);
|
||||
SChildTableObj* mgmtGetChildTable(char *tableId);
|
||||
SSchema* mgmtGetChildTableSchema(SChildTableObj *pTable);
|
||||
|
||||
|
|
|
@ -23,41 +23,16 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
char tableId[TSDB_TABLE_ID_LEN + 1];
|
||||
int64_t uid;
|
||||
int32_t sid;
|
||||
int32_t vgId;
|
||||
int32_t sversion; // schema version
|
||||
int32_t createdTime;
|
||||
|
||||
int32_t numOfTags; // for metric
|
||||
int32_t numOfMeters; // for metric
|
||||
int32_t numOfColumns;
|
||||
int32_t schemaSize;
|
||||
short nextColId;
|
||||
char tableType : 4;
|
||||
char status : 3;
|
||||
char isDirty : 1; // if the table change tag column 1 value
|
||||
char reserved[15];
|
||||
char updateEnd[1];
|
||||
|
||||
pthread_rwlock_t rwLock;
|
||||
tSkipList * pSkipList;
|
||||
struct _tab_obj *pHead; // for metric, a link list for all meters created
|
||||
// according to this metric
|
||||
char *pTagData; // TSDB_TABLE_ID_LEN(metric_name)+
|
||||
// tags_value1/tags_value2/tags_value3
|
||||
struct _tab_obj *prev, *next;
|
||||
char * pSql; // pointer to SQL, for SC, null-terminated string
|
||||
char * pReserve1;
|
||||
char * pReserve2;
|
||||
char * schema;
|
||||
// SSchema schema[];
|
||||
} SNormalTableObj;
|
||||
|
||||
|
||||
int32_t mgmtInitSTable();
|
||||
#include "mnode.h"
|
||||
|
||||
int32_t mgmtInitNormalTables();
|
||||
void mgmtCleanUpNormalTables();
|
||||
int32_t mgmtCreateNormalTable(SDbObj *pDb, SCreateTableMsg *pCreate, int32_t vgId, int32_t sid);
|
||||
int32_t mgmtDropNormalTable(SDbObj *pDb, SNormalTableObj *pTable);
|
||||
int32_t mgmtAddNormalTableColumn(SNormalTableObj *pTable, SSchema schema[], int32_t ncols);
|
||||
int32_t mgmtDropNormalTableColumnByName(SNormalTableObj *pTable, char *colName);
|
||||
SNormalTableObj* mgmtGetNormalTable(char *tableId);
|
||||
SSchema* mgmtGetNormalTableSchema(SNormalTableObj *pTable);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TBASE_MNODE_STABLE_H
|
||||
#define TBASE_MNODE_STABLE_H
|
||||
#ifndef TBASE_MNODE_STREAM_TABLE_H
|
||||
#define TBASE_MNODE_STREAM_TABLE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -23,41 +23,16 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct {
|
||||
char meterId[TSDB_TABLE_ID_LEN + 1];
|
||||
uint64_t uid;
|
||||
STableGid gid;
|
||||
#include "mnode.h"
|
||||
|
||||
int32_t sversion; // schema version
|
||||
int32_t createdTime;
|
||||
int32_t mgmtInitStreamTables();
|
||||
void mgmtCleanUpStreamTables();
|
||||
int32_t mgmtCreateStreamTable(SDbObj *pDb, SCreateTableMsg *pCreate, int32_t vgId, int32_t sid);
|
||||
int32_t mgmtDropStreamTable(SDbObj *pDb, SStreamTableObj *pTable);
|
||||
int32_t mgmtAlterStreamTable(SDbObj *pDb, SAlterTableMsg *pAlter);
|
||||
SStreamTableObj* mgmtGetStreamTable(char *tableId);
|
||||
SSchema* mgmtGetStreamTableSchema(SStreamTableObj *pTable);
|
||||
|
||||
int32_t numOfTags; // for metric
|
||||
int32_t numOfMeters; // for metric
|
||||
int32_t numOfColumns;
|
||||
int32_t schemaSize;
|
||||
short nextColId;
|
||||
char tableType : 4;
|
||||
char status : 3;
|
||||
char isDirty : 1; // if the table change tag column 1 value
|
||||
char reserved[15];
|
||||
char updateEnd[1];
|
||||
|
||||
pthread_rwlock_t rwLock;
|
||||
tSkipList * pSkipList;
|
||||
struct _tab_obj *pHead; // for metric, a link list for all meters created
|
||||
// according to this metric
|
||||
char *pTagData; // TSDB_TABLE_ID_LEN(metric_name)+
|
||||
// tags_value1/tags_value2/tags_value3
|
||||
struct _tab_obj *prev, *next;
|
||||
char * pSql; // pointer to SQL, for SC, null-terminated string
|
||||
char * pReserve1;
|
||||
char * pReserve2;
|
||||
char * schema;
|
||||
// SSchema schema[];
|
||||
} STabObj;
|
||||
|
||||
|
||||
int32_t mgmtInitSTable();
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -24,25 +24,20 @@ extern "C" {
|
|||
#include <stdbool.h>
|
||||
|
||||
#include "taosdef.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
char superTableId[TSDB_TABLE_ID_LEN + 1];
|
||||
int64_t uid;
|
||||
int32_t sid;
|
||||
int32_t vgId;
|
||||
int32_t sversion;
|
||||
int32_t createdTime;
|
||||
char reserved[7];
|
||||
char updateEnd[1];
|
||||
} SSuperTableObj;
|
||||
#include "mnode.h"
|
||||
|
||||
int32_t mgmtInitSuperTables();
|
||||
void mgmtCleanUpSuperTables();
|
||||
int32_t mgmtCreateSuperTable(SDbObj *pDb, SCreateTableMsg *pCreate);
|
||||
int32_t mgmtDropSuperTable(SDbObj *pDb, char *meterId, int ignore);
|
||||
int32_t mgmtAlterSuperTable(SDbObj *pDb, SAlterTableMsg *pAlter);
|
||||
int32_t mgmtDropSuperTable(SDbObj *pDb, SSuperTableObj *pTable);
|
||||
SSuperTableObj* mgmtGetSuperTable(char *tableId);
|
||||
int32_t mgmtFindTagCol(SSuperTableObj *pTable, const char *tagName);
|
||||
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);
|
||||
|
||||
SSchema* mgmtGetSuperTableSchema(SSuperTableObj *pTable);
|
||||
|
||||
|
||||
|
|
|
@ -25,24 +25,29 @@ extern "C" {
|
|||
#include <stdint.h>
|
||||
#include "mnode.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
ETableType type;
|
||||
void* obj;
|
||||
} STableObj;
|
||||
|
||||
int mgmtInitMeters();
|
||||
STabObj *mgmtGetTable(char *meterId);
|
||||
STableObj mgmtGetTable(char *tableId);
|
||||
|
||||
STabObj *mgmtGetTableInfo(char *src, char *tags[]);
|
||||
int mgmtRetrieveMetricMeta(SConnObj *pConn, char **pStart, SSuperTableMetaMsg *pInfo);
|
||||
int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate);
|
||||
int mgmtDropMeter(SDbObj *pDb, char *meterId, int ignore);
|
||||
int mgmtAlterMeter(SDbObj *pDb, SAlterTableMsg *pAlter);
|
||||
int mgmtCreateTable(SDbObj *pDb, SCreateTableMsg *pCreate);
|
||||
int mgmtDropTable(SDbObj *pDb, char *meterId, int ignore);
|
||||
int mgmtAlterTable(SDbObj *pDb, SAlterTableMsg *pAlter);
|
||||
int mgmtGetTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
|
||||
int mgmtRetrieveMeters(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
|
||||
int mgmtRetrieveTables(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
|
||||
void mgmtCleanUpMeters();
|
||||
SSchema *mgmtGetTableSchema(STabObj *pTable); // get schema for a meter
|
||||
|
||||
int32_t mgmtFindTagCol(STabObj * pTable, const char * tagName);
|
||||
|
||||
int mgmtAddMeterIntoMetric(STabObj *pMetric, STabObj *pTable);
|
||||
int mgmtRemoveMeterFromMetric(STabObj *pMetric, STabObj *pTable);
|
||||
int mgmtGetMetricMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
|
||||
int mgmtRetrieveMetrics(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
|
||||
int mgmtGetSuperTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
|
||||
int mgmtRetrieveSuperTables(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -33,6 +33,10 @@ int mgmtGetVgroupMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn);
|
|||
int mgmtRetrieveVgroups(SShowObj *pShow, char *data, int rows, SConnObj *pConn);
|
||||
void mgmtCleanUpVgroups();
|
||||
|
||||
|
||||
SVgObj *mgmtGetAvailVgroup(SDbObj *pDb);
|
||||
int32_t mgmtAllocateSid(SDbObj *pDb, SVgObj *pVgroup);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -35,3 +35,149 @@
|
|||
#include "ttime.h"
|
||||
#include "tstatus.h"
|
||||
|
||||
#include "sdb.h"
|
||||
|
||||
#include "mgmtChildTable.h"
|
||||
#include "mgmtSuperTable.h"
|
||||
|
||||
|
||||
|
||||
int32_t mgmtInitChildTables() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mgmtCleanUpChildTables() {
|
||||
}
|
||||
|
||||
char *mgmtBuildCreateChildTableMsg(SChildTableObj *pTable, char *pMsg, int vnode) {
|
||||
|
||||
}
|
||||
|
||||
int32_t mgmtCreateChildTable(SDbObj *pDb, SCreateTableMsg *pCreate, int32_t vgId, int32_t sid) {
|
||||
int numOfTables = sdbGetNumOfRows(tsChildTableSdb);
|
||||
if (numOfTables >= tsMaxTables) {
|
||||
mError("child table:%s, numOfTables:%d exceed maxTables:%d", pCreate->meterId, numOfTables, tsMaxTables);
|
||||
return TSDB_CODE_TOO_MANY_TABLES;
|
||||
}
|
||||
|
||||
char *pTagData = (char *)pCreate->schema; // it is a tag key
|
||||
SSuperTableObj *pSuperTable = mgmtGetSuperTable(pTagData);
|
||||
if (pSuperTable == NULL) {
|
||||
mError("table:%s, corresponding super table does not exist", pCreate->meterId);
|
||||
return TSDB_CODE_INVALID_TABLE;
|
||||
}
|
||||
|
||||
SChildTableObj *pTable = (SChildTableObj *)calloc(sizeof(SChildTableObj), 1);
|
||||
if (pTable == NULL) {
|
||||
return TSDB_CODE_SERV_OUT_OF_MEMORY;
|
||||
}
|
||||
strcpy(pTable->tableId, pCreate->meterId);
|
||||
strcpy(pTable->superTableId, pSuperTable->tableId);
|
||||
pTable->createdTime = taosGetTimestampMs();
|
||||
pTable->superTable = pSuperTable;
|
||||
pTable->vgId = vgId;
|
||||
pTable->sid = sid;
|
||||
pTable->uid = (((uint64_t) pTable->vgId) << 40) + ((((uint64_t) pTable->sid) & ((1ul << 24) - 1ul)) << 16) +
|
||||
((uint64_t) sdbGetVersion() & ((1ul << 16) - 1ul));
|
||||
|
||||
SVariableMsg tags = {0};
|
||||
tags.size = mgmtGetTagsLength(pSuperTable, INT_MAX) + (uint32_t)TSDB_TABLE_ID_LEN;
|
||||
tags.data = (char *)calloc(1, tags.size);
|
||||
if (tags.data == NULL) {
|
||||
free(pTable);
|
||||
mError("table:%s, corresponding super table schema is null", pCreate->meterId);
|
||||
return TSDB_CODE_INVALID_TABLE;
|
||||
}
|
||||
memcpy(tags.data, pTagData, tags.size);
|
||||
|
||||
if (sdbInsertRow(tsStreamTableSdb, pTable, 0) < 0) {
|
||||
mError("table:%s, update sdb error", pCreate->meterId);
|
||||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
mgmtAddTimeSeries(pTable->superTable->numOfColumns - 1);
|
||||
mgmtSendCreateMsgToVgroup(pTable, pVgroup);
|
||||
|
||||
mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%" PRIu64 " db:%s",
|
||||
pTable->tableId, vgId, sid, pVgroup->vnodeGid[0].vnode, pTable->uid, pDb->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mgmtDropChildTable(SDbObj *pDb, SChildTableObj *pTable) {
|
||||
SVgObj *pVgroup;
|
||||
SAcctObj *pAcct;
|
||||
|
||||
pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
|
||||
if (pAcct != NULL) {
|
||||
pAcct->acctInfo.numOfTimeSeries -= (pTable->superTable->numOfColumns - 1);
|
||||
}
|
||||
|
||||
pVgroup = mgmtGetVgroup(pTable->vgId);
|
||||
if (pVgroup == NULL) {
|
||||
return TSDB_CODE_OTHERS;
|
||||
}
|
||||
|
||||
mgmtRestoreTimeSeries(pTable->superTable->numOfColumns - 1);
|
||||
mgmtSendRemoveMeterMsgToDnode(pTable, pVgroup);
|
||||
sdbDeleteRow(tsChildTableSdb, pTable);
|
||||
|
||||
if (pVgroup->numOfMeters <= 0) {
|
||||
mgmtDropVgroup(pDb, pVgroup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SChildTableObj* mgmtGetChildTable(char *tableId) {
|
||||
return (SChildTableObj *)sdbGetRow(tsChildTableSdb, tableId);
|
||||
}
|
||||
|
||||
int32_t mgmtModifyChildTableTagValueByName(SChildTableObj *pTable, char *tagName, char *nContent) {
|
||||
int col = mgmtFindTagCol(pTable->superTable, tagName);
|
||||
if (col < 0 || col > pTable->superTable->numOfTags) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
//TODO send msg to dnode
|
||||
mTrace("Succeed to modify tag column %d of table %s", col, pTable->tableId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
// int rowSize = 0;
|
||||
// SSchema *schema = (SSchema *)(pSuperTable->schema + (pSuperTable->numOfColumns + col) * sizeof(SSchema));
|
||||
//
|
||||
// if (col == 0) {
|
||||
// pTable->isDirty = 1;
|
||||
// removeMeterFromMetricIndex(pSuperTable, pTable);
|
||||
// }
|
||||
// memcpy(pTable->pTagData + mgmtGetTagsLength(pMetric, col) + TSDB_TABLE_ID_LEN, nContent, schema->bytes);
|
||||
// if (col == 0) {
|
||||
// addMeterIntoMetricIndex(pMetric, pTable);
|
||||
// }
|
||||
//
|
||||
// // Encode the string
|
||||
// int size = sizeof(STabObj) + TSDB_MAX_BYTES_PER_ROW + 1;
|
||||
// char *msg = (char *)malloc(size);
|
||||
// if (msg == NULL) {
|
||||
// mError("failed to allocate message memory while modify tag value");
|
||||
// return TSDB_CODE_APP_ERROR;
|
||||
// }
|
||||
// memset(msg, 0, size);
|
||||
//
|
||||
// mgmtMeterActionEncode(pTable, msg, size, &rowSize);
|
||||
//
|
||||
// int32_t ret = sdbUpdateRow(meterSdb, msg, rowSize, 1); // Need callback function
|
||||
// tfree(msg);
|
||||
//
|
||||
// if (pTable->isDirty) pTable->isDirty = 0;
|
||||
//
|
||||
// if (ret < 0) {
|
||||
// mError("Failed to modify tag column %d of table %s", col, pTable->meterId);
|
||||
// return TSDB_CODE_APP_ERROR;
|
||||
// }
|
||||
//
|
||||
// mTrace("Succeed to modify tag column %d of table %s", col, pTable->meterId);
|
||||
// return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -282,7 +282,7 @@ void mgmtDropDbFromSdb(SDbObj *pDb) {
|
|||
STabObj *pMetric = pDb->pMetric;
|
||||
while (pMetric) {
|
||||
STabObj *pNext = pMetric->next;
|
||||
mgmtDropMeter(pDb, pMetric->meterId, 0);
|
||||
mgmtDropTable(pDb, pMetric->meterId, 0);
|
||||
pMetric = pNext;
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ int mgmtDropDbByName(SAcctObj *pAcct, char *name, short ignoreNotExists) {
|
|||
}
|
||||
|
||||
if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) {
|
||||
return TSDB_CODE_MONITOR_DB_FORBEIDDEN;
|
||||
return TSDB_CODE_MONITOR_DB_FORBEIDEN;
|
||||
}
|
||||
|
||||
return mgmtDropDb(pDb);
|
||||
|
|
|
@ -229,7 +229,7 @@ char *mgmtBuildCreateMeterIe(STabObj *pTable, char *pMsg, int vnode) {
|
|||
return pMsg;
|
||||
}
|
||||
|
||||
int mgmtSendCreateMsgToVgroup(STabObj *pTable, SVgObj *pVgroup) {
|
||||
int mgmtSendCreateMsgToVgroup(STabObj table, SVgObj *pVgroup) {
|
||||
char * pMsg, *pStart;
|
||||
int i, msgLen = 0;
|
||||
SDnodeObj *pObj;
|
||||
|
|
|
@ -35,3 +35,184 @@
|
|||
#include "ttime.h"
|
||||
#include "tstatus.h"
|
||||
|
||||
|
||||
#include "sdb.h"
|
||||
#include "mgmtNormalTable.h"
|
||||
|
||||
int32_t mgmtInitNormalTables() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mgmtCleanUpNormalTables() {
|
||||
sdbCloseTable(tsNormalTableSdb);
|
||||
}
|
||||
|
||||
int32_t mgmtCreateNormalTable(SDbObj *pDb, SCreateTableMsg *pCreate, int32_t vgId, int32_t sid) {
|
||||
int numOfTables = sdbGetNumOfRows(tsChildTableSdb);
|
||||
if (numOfTables >= TSDB_MAX_TABLES) {
|
||||
mError("normal table:%s, numOfTables:%d exceed maxTables:%d", pCreate->meterId, numOfTables, TSDB_MAX_TABLES);
|
||||
return TSDB_CODE_TOO_MANY_TABLES;
|
||||
}
|
||||
|
||||
SNormalTableObj *pTable = (SNormalTableObj *)calloc(sizeof(SNormalTableObj), 1);
|
||||
if (pTable == NULL) {
|
||||
return TSDB_CODE_SERV_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
strcpy(pTable->tableId, pCreate->meterId);
|
||||
pTable->createdTime = taosGetTimestampMs();
|
||||
pTable->vgId = vgId;
|
||||
pTable->sid = sid;
|
||||
pTable->uid = (((uint64_t)pTable->createdTime) << 16) + ((uint64_t)sdbGetVersion() & ((1ul << 16) - 1ul));
|
||||
pTable->sversion = 0;
|
||||
pTable->numOfColumns = pCreate->numOfColumns;
|
||||
|
||||
int numOfCols = pCreate->numOfColumns + pCreate->numOfTags;
|
||||
pTable->schemaSize = numOfCols * sizeof(SSchema);
|
||||
pTable->schema = (int8_t *)calloc(1, pTable->schemaSize);
|
||||
if (pTable->schema == NULL) {
|
||||
free(pTable);
|
||||
mError("table:%s, no schema input", pCreate->meterId);
|
||||
return TSDB_CODE_INVALID_TABLE;
|
||||
}
|
||||
memcpy(pTable->schema, pCreate->schema, numOfCols * sizeof(SSchema));
|
||||
|
||||
pTable->nextColId = 0;
|
||||
for (int col = 0; col < pCreate->numOfColumns; col++) {
|
||||
SSchema *tschema = (SSchema *)pTable->schema;
|
||||
tschema[col].colId = pTable->nextColId++;
|
||||
}
|
||||
|
||||
if (sdbInsertRow(tsNormalTableSdb, pTable, 0) < 0) {
|
||||
mError("table:%s, update sdb error", pCreate->meterId);
|
||||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
// mTrace("table:%s, send create table msg to dnode, vgId:%d, sid:%d, vnode:%d",
|
||||
// pTable->meterId, pTable->gid.vgId, pTable->gid.sid, pVgroup->vnodeGid[0].vnode);
|
||||
//
|
||||
// mgmtAddTimeSeries(pTable->numOfColumns - 1);
|
||||
// mgmtSendCreateMsgToVgroup(pTable, pVgroup);
|
||||
|
||||
mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%" PRIu64 " db:%s",
|
||||
pTable->meterId, pVgroup->vgId, sid, pVgroup->vnodeGid[0].vnode, pTable->uid, pDb->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mgmtDropNormalTable(SDbObj *pDb, SNormalTableObj *pTable) {
|
||||
SVgObj *pVgroup;
|
||||
SAcctObj *pAcct;
|
||||
|
||||
pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
|
||||
if (pAcct != NULL) {
|
||||
pAcct->acctInfo.numOfTimeSeries -= (pTable->numOfColumns - 1);
|
||||
}
|
||||
|
||||
pVgroup = mgmtGetVgroup(pTable->vgId);
|
||||
if (pVgroup == NULL) {
|
||||
return TSDB_CODE_OTHERS;
|
||||
}
|
||||
|
||||
mgmtRestoreTimeSeries(pTable->numOfColumns - 1);
|
||||
|
||||
mgmtSendRemoveMeterMsgToDnode(pTable, pVgroup);
|
||||
|
||||
sdbDeleteRow(tsChildTableSdb, pTable);
|
||||
|
||||
if (pVgroup->numOfMeters <= 0) {
|
||||
mgmtDropVgroup(pDb, pVgroup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SNormalTableObj* mgmtGetNormalTable(char *tableId) {
|
||||
return (SNormalTableObj *)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[], int ncols) {
|
||||
if (ncols <= 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ncols; i++) {
|
||||
if (mgmtFindNormalTableColumnIndex(pTable, schema[i].name) > 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
SDbObj *pDb = mgmtGetDbByMeterId(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;
|
||||
}
|
||||
|
||||
pTable->schema = realloc(pTable->schema, pTable->schemaSize + sizeof(SSchema) * ncols);
|
||||
|
||||
memcpy(pTable->schema + pTable->schemaSize, schema, sizeof(SSchema) * ncols);
|
||||
|
||||
SSchema *tschema = (SSchema *) (pTable->schema + sizeof(SSchema) * pTable->numOfColumns);
|
||||
for (int i = 0; i < ncols; i++) {
|
||||
tschema[i].colId = pTable->nextColId++;
|
||||
}
|
||||
|
||||
pTable->schemaSize += sizeof(SSchema) * ncols;
|
||||
pTable->numOfColumns += ncols;
|
||||
pTable->sversion++;
|
||||
pAcct->acctInfo.numOfTimeSeries += ncols;
|
||||
|
||||
sdbUpdateRow(tsNormalTableSdb, pTable, 0, 1);
|
||||
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 = mgmtGetDbByMeterId(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->schemaSize -= sizeof(SSchema);
|
||||
pTable->numOfColumns--;
|
||||
pTable->schema = realloc(pTable->schema, pTable->schemaSize);
|
||||
pTable->sversion++;
|
||||
|
||||
pAcct->acctInfo.numOfTimeSeries--;
|
||||
sdbUpdateRow(tsNormalTableSdb, pTable, 0, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ int mgmtProcessMeterMetaMsg(char *pMsg, int msgLen, SConnObj *pConn) {
|
|||
pCreateMsg->meterId, pDb, pDb->name, pMeterDb, pMeterDb->name);
|
||||
assert(pDb == pMeterDb);
|
||||
|
||||
int32_t code = mgmtCreateMeter(pDb, pCreateMsg);
|
||||
int32_t code = mgmtCreateTable(pDb, pCreateMsg);
|
||||
|
||||
char stableName[TSDB_TABLE_ID_LEN] = {0};
|
||||
strncpy(stableName, pInfo->tags, TSDB_TABLE_ID_LEN);
|
||||
|
@ -896,7 +896,7 @@ static void mgmtInitShowMsgFp() {
|
|||
mgmtGetMetaFp[TSDB_MGMT_TABLE_DNODE] = mgmtGetDnodeMeta;
|
||||
mgmtGetMetaFp[TSDB_MGMT_TABLE_MNODE] = mgmtGetMnodeMeta;
|
||||
mgmtGetMetaFp[TSDB_MGMT_TABLE_VGROUP] = mgmtGetVgroupMeta;
|
||||
mgmtGetMetaFp[TSDB_MGMT_TABLE_METRIC] = mgmtGetMetricMeta;
|
||||
mgmtGetMetaFp[TSDB_MGMT_TABLE_METRIC] = mgmtGetSuperTableMeta;
|
||||
mgmtGetMetaFp[TSDB_MGMT_TABLE_MODULE] = mgmtGetModuleMeta;
|
||||
mgmtGetMetaFp[TSDB_MGMT_TABLE_QUERIES] = mgmtGetQueryMeta;
|
||||
mgmtGetMetaFp[TSDB_MGMT_TABLE_STREAMS] = mgmtGetStreamMeta;
|
||||
|
@ -910,11 +910,11 @@ static void mgmtInitShowMsgFp() {
|
|||
mgmtRetrieveFp[TSDB_MGMT_TABLE_ACCT] = mgmtRetrieveAccts;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_USER] = mgmtRetrieveUsers;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_DB] = mgmtRetrieveDbs;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_TABLE] = mgmtRetrieveMeters;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_TABLE] = mgmtRetrieveTables;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_DNODE] = mgmtRetrieveDnodes;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_MNODE] = mgmtRetrieveMnodes;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_VGROUP] = mgmtRetrieveVgroups;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_METRIC] = mgmtRetrieveMetrics;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_METRIC] = mgmtRetrieveSuperTables;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_MODULE] = mgmtRetrieveModules;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_QUERIES] = mgmtRetrieveQueries;
|
||||
mgmtRetrieveFp[TSDB_MGMT_TABLE_STREAMS] = mgmtRetrieveStreams;
|
||||
|
@ -1097,7 +1097,7 @@ int mgmtProcessCreateTableMsg(char *pMsg, int msgLen, SConnObj *pConn) {
|
|||
if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name);
|
||||
|
||||
if (pDb) {
|
||||
code = mgmtCreateMeter(pDb, pCreate);
|
||||
code = mgmtCreateTable(pDb, pCreate);
|
||||
} else {
|
||||
code = TSDB_CODE_DB_NOT_SELECTED;
|
||||
}
|
||||
|
@ -1139,7 +1139,7 @@ int mgmtProcessDropTableMsg(char *pMsg, int msgLen, SConnObj *pConn) {
|
|||
SDbObj *pDb = NULL;
|
||||
if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name);
|
||||
|
||||
code = mgmtDropMeter(pDb, pDrop->meterId, pDrop->igNotExists);
|
||||
code = mgmtDropTable(pDb, pDrop->meterId, pDrop->igNotExists);
|
||||
if (code == 0) {
|
||||
mTrace("meter:%s is dropped by user:%s", pDrop->meterId, pConn->pUser->user);
|
||||
// mLPrint("meter:%s is dropped by user:%s", pDrop->meterId, pConn->pUser->user);
|
||||
|
@ -1177,7 +1177,7 @@ int mgmtProcessAlterTableMsg(char *pMsg, int msgLen, SConnObj *pConn) {
|
|||
pAlter->schema[i].bytes = htons(pAlter->schema[i].bytes);
|
||||
}
|
||||
|
||||
code = mgmtAlterMeter(pDb, pAlter);
|
||||
code = mgmtAlterTable(pDb, pAlter);
|
||||
if (code == 0) {
|
||||
mLPrint("meter:%s is altered by %s", pAlter->meterId, pConn->pUser->user);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "mgmtDb.h"
|
||||
#include "mgmtDnodeInt.h"
|
||||
#include "mgmtVgroup.h"
|
||||
#include "mgmtSupertableQuery.h"
|
||||
#include "mgmtStreamtableQuery.h"
|
||||
#include "mgmtTable.h"
|
||||
#include "taosmsg.h"
|
||||
#include "tast.h"
|
||||
|
@ -35,3 +35,103 @@
|
|||
#include "ttime.h"
|
||||
#include "tstatus.h"
|
||||
|
||||
|
||||
#include "sdb.h"
|
||||
#include "mgmtStreamTable.h"
|
||||
|
||||
int32_t mgmtInitStreamTables() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mgmtCleanUpStreamTables() {
|
||||
}
|
||||
|
||||
int32_t mgmtCreateStreamTable(SDbObj *pDb, SCreateTableMsg *pCreate, int32_t vgId, int32_t sid) {
|
||||
int numOfTables = sdbGetNumOfRows(tsStreamTableSdb);
|
||||
if (numOfTables >= TSDB_MAX_TABLES) {
|
||||
mError("stream table:%s, numOfTables:%d exceed maxTables:%d", pCreate->meterId, numOfTables, TSDB_MAX_TABLES);
|
||||
return TSDB_CODE_TOO_MANY_TABLES;
|
||||
}
|
||||
|
||||
SStreamTableObj *pTable = (SStreamTableObj *)calloc(sizeof(SStreamTableObj), 1);
|
||||
if (pTable == NULL) {
|
||||
return TSDB_CODE_SERV_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
strcpy(pTable->tableId, pCreate->meterId);
|
||||
pTable->createdTime = taosGetTimestampMs();
|
||||
pTable->vgId = vgId;
|
||||
pTable->sid = sid;
|
||||
pTable->uid = (((uint64_t)pTable->createdTime) << 16) + ((uint64_t)sdbGetVersion() & ((1ul << 16) - 1ul));
|
||||
pTable->sversion = 0;
|
||||
pTable->numOfColumns = pCreate->numOfColumns;
|
||||
|
||||
int numOfCols = pCreate->numOfColumns + pCreate->numOfTags;
|
||||
pTable->schemaSize = numOfCols * sizeof(SSchema) + pCreate->sqlLen;
|
||||
pTable->schema = (int8_t *)calloc(1, pTable->schemaSize);
|
||||
if (pTable->schema == NULL) {
|
||||
free(pTable);
|
||||
mError("table:%s, no schema input", pCreate->meterId);
|
||||
return TSDB_CODE_INVALID_TABLE;
|
||||
}
|
||||
memcpy(pTable->schema, pCreate->schema, numOfCols * sizeof(SSchema));
|
||||
|
||||
pTable->nextColId = 0;
|
||||
for (int col = 0; col < pCreate->numOfColumns; col++) {
|
||||
SSchema *tschema = (SSchema *)pTable->schema;
|
||||
tschema[col].colId = pTable->nextColId++;
|
||||
}
|
||||
|
||||
pTable->pSql = pTable->schema + numOfCols * sizeof(SSchema);
|
||||
memcpy(pTable->pSql, (char *)(pCreate->schema) + numOfCols * sizeof(SSchema), pCreate->sqlLen);
|
||||
pTable->pSql[pCreate->sqlLen - 1] = 0;
|
||||
mTrace("table:%s, stream sql len:%d sql:%s", pCreate->meterId, pCreate->sqlLen, pTable->pSql);
|
||||
|
||||
if (sdbInsertRow(tsStreamTableSdb, pTable, 0) < 0) {
|
||||
mError("table:%s, update sdb error", pCreate->meterId);
|
||||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
// mTrace("table:%s, send create table msg to dnode, vgId:%d, sid:%d, vnode:%d",
|
||||
// pTable->meterId, pTable->gid.vgId, pTable->gid.sid, pVgroup->vnodeGid[0].vnode);
|
||||
//
|
||||
// mgmtAddTimeSeries(pTable->numOfColumns - 1);
|
||||
// mgmtSendCreateMsgToVgroup(pTable, pVgroup);
|
||||
|
||||
mTrace("table:%s, create table in vgroup, vgId:%d sid:%d vnode:%d uid:%" PRIu64 " db:%s",
|
||||
pTable->meterId, pVgroup->vgId, sid, pVgroup->vnodeGid[0].vnode, pTable->uid, pDb->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mgmtDropStreamTable(SDbObj *pDb, SStreamTableObj *pTable) {
|
||||
SVgObj * pVgroup;
|
||||
SAcctObj *pAcct;
|
||||
|
||||
pAcct = mgmtGetAcct(pDb->cfg.acct);
|
||||
|
||||
if (pAcct != NULL) {
|
||||
pAcct->acctInfo.numOfTimeSeries -= (pTable->numOfColumns - 1);
|
||||
}
|
||||
|
||||
pVgroup = mgmtGetVgroup(pTable->vgId);
|
||||
if (pVgroup == NULL) {
|
||||
return TSDB_CODE_OTHERS;
|
||||
}
|
||||
|
||||
mgmtRestoreTimeSeries(pTable->numOfColumns - 1);
|
||||
|
||||
mgmtSendRemoveMeterMsgToDnode(pTable, pVgroup);
|
||||
|
||||
sdbDeleteRow(tsChildTableSdb, pTable);
|
||||
|
||||
if (pVgroup->numOfMeters <= 0) {
|
||||
mgmtDropVgroup(pDb, pVgroup);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
SStreamTableObj* mgmtGetStreamTable(char *tableId); {
|
||||
return (SStreamTableObj *)sdbGetRow(tsStreamTableSdb, tableId);
|
||||
}
|
|
@ -35,3 +35,439 @@
|
|||
#include "ttime.h"
|
||||
#include "tstatus.h"
|
||||
|
||||
|
||||
#include "sdb.h"
|
||||
#include "mgmtSuperTable.h"
|
||||
#include "mgmtChildTable.h"
|
||||
|
||||
|
||||
#define mgmtDestroyMeter(pMetric) \
|
||||
do { \
|
||||
tfree(pMetric->schema); \
|
||||
pMetric->pSkipList = tSkipListDestroy((pMetric)->pSkipList); \
|
||||
tfree(pMetric); \
|
||||
} while (0)
|
||||
|
||||
|
||||
typedef struct {
|
||||
char meterId[TSDB_TABLE_ID_LEN + 1];
|
||||
char type;
|
||||
uint32_t cols;
|
||||
char data[];
|
||||
} SMeterBatchUpdateMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t col;
|
||||
int32_t pos;
|
||||
SSchema schema;
|
||||
} SchemaUnit;
|
||||
|
||||
typedef struct {
|
||||
char meterId[TSDB_TABLE_ID_LEN + 1];
|
||||
char action;
|
||||
int32_t dataSize;
|
||||
char data[];
|
||||
} SMeterUpdateMsg;
|
||||
|
||||
int32_t mgmtInitSuperTables() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mgmtCleanUpSuperTables() {
|
||||
}
|
||||
|
||||
int32_t mgmtCreateSuperTable(SDbObj *pDb, SCreateTableMsg *pCreate) {
|
||||
int numOfTables = sdbGetNumOfRows(tsSuperTableSdb);
|
||||
if (numOfTables >= TSDB_MAX_TABLES) {
|
||||
mError("super table:%s, numOfTables:%d exceed maxTables:%d", pCreate->meterId, numOfTables, TSDB_MAX_TABLES);
|
||||
return TSDB_CODE_TOO_MANY_TABLES;
|
||||
}
|
||||
|
||||
SSuperTableObj *pMetric = (SSuperTableObj *)calloc(sizeof(SSuperTableObj), 1);
|
||||
if (pMetric == NULL) {
|
||||
return TSDB_CODE_SERV_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
strcpy(pMetric->tableId, pCreate->meterId);
|
||||
pMetric->createdTime = taosGetTimestampMs();
|
||||
pMetric->vgId = 0;
|
||||
pMetric->sid = 0;
|
||||
pMetric->uid = (((uint64_t)pMetric->createdTime) << 16) + ((uint64_t)sdbGetVersion() & ((1ul << 16) - 1ul));
|
||||
pMetric->sversion = 0;
|
||||
pMetric->numOfColumns = pCreate->numOfColumns;
|
||||
pMetric->numOfTags = pCreate->numOfTags;
|
||||
pMetric->numOfMeters = 0;
|
||||
|
||||
int numOfCols = pCreate->numOfColumns + pCreate->numOfTags;
|
||||
pMetric->schemaSize = numOfCols * sizeof(SSchema);
|
||||
pMetric->schema = (int8_t *)calloc(1, pMetric->schemaSize);
|
||||
if (pMetric->schema == NULL) {
|
||||
free(pMetric);
|
||||
mError("table:%s, no schema input", pCreate->meterId);
|
||||
return TSDB_CODE_INVALID_TABLE;
|
||||
}
|
||||
memcpy(pMetric->schema, pCreate->schema, numOfCols * sizeof(SSchema));
|
||||
|
||||
pMetric->nextColId = 0;
|
||||
for (int col = 0; col < pCreate->numOfColumns; col++) {
|
||||
SSchema *tschema = (SSchema *)pMetric->schema;
|
||||
tschema[col].colId = pMetric->nextColId++;
|
||||
}
|
||||
|
||||
if (sdbInsertRow(tsSuperTableSdb, pMetric, 0) < 0) {
|
||||
mError("table:%s, update sdb error", pCreate->meterId);
|
||||
return TSDB_CODE_SDB_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mgmtDropSuperTable(SDbObj *pDb, SSuperTableObj *pSuperTable) {
|
||||
SChildTableObj *pMetric;
|
||||
while ((pMetric = pSuperTable->pHead) != NULL) {
|
||||
mgmtDropChildTable(pDb, pMetric);
|
||||
}
|
||||
sdbDeleteRow(tsSuperTableSdb, pMetric);
|
||||
}
|
||||
|
||||
SSuperTableObj* mgmtGetSuperTable(char *tableId) {
|
||||
return (SSuperTableObj *)sdbGetRow(tsSuperTableSdb, tableId);
|
||||
}
|
||||
|
||||
int32_t mgmtFindTagCol(SSuperTableObj *pMetric, const char *tagName) {
|
||||
for (int i = 0; i < pMetric->numOfTags; i++) {
|
||||
SSchema *schema = (SSchema *)(pMetric->schema + (pMetric->numOfColumns + i) * sizeof(SSchema));
|
||||
if (strcasecmp(tagName, schema->name) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mgmtAddSuperTableTag(SSuperTableObj *pMetric, SSchema schema[], int32_t ntags) {
|
||||
if (pMetric->numOfTags + ntags > TSDB_MAX_TAGS) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
// check if schemas have the same name
|
||||
for (int i = 1; i < ntags; i++) {
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (strcasecmp(schema[i].name, schema[j].name) == 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < ntags; i++) {
|
||||
if (mgmtFindTagCol(pMetric, schema[i].name) >= 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t size = sizeof(SMeterBatchUpdateMsg) + sizeof(SSchema) * ntags;
|
||||
SMeterBatchUpdateMsg *msg = (SMeterBatchUpdateMsg *) malloc(size);
|
||||
memset(msg, 0, size);
|
||||
|
||||
memcpy(msg->meterId, pMetric->tableId, TSDB_TABLE_ID_LEN);
|
||||
msg->type = SDB_TYPE_INSERT;
|
||||
msg->cols = ntags;
|
||||
memcpy(msg->data, schema, sizeof(SSchema) * ntags);
|
||||
|
||||
int32_t ret = sdbBatchUpdateRow(tsSuperTableSdb, msg, size);
|
||||
tfree(msg);
|
||||
|
||||
if (ret < 0) {
|
||||
mError("Failed to add tag column %s to table %s", schema[0].name, pMetric->tableId);
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
mTrace("Succeed to add tag column %s to table %s", schema[0].name, pMetric->tableId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mgmtDropSuperTableTag(SSuperTableObj *pMetric, char *tagName) {
|
||||
int col = mgmtFindTagCol(pMetric, tagName);
|
||||
if (col <= 0 || col >= pMetric->numOfTags) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
// Pack message to do batch update
|
||||
uint32_t size = sizeof(SMeterBatchUpdateMsg) + sizeof(SchemaUnit);
|
||||
SMeterBatchUpdateMsg *msg = (SMeterBatchUpdateMsg *) malloc(size);
|
||||
memset(msg, 0, size);
|
||||
|
||||
memcpy(msg->meterId, pMetric->tableId, TSDB_TABLE_ID_LEN);
|
||||
msg->type = SDB_TYPE_DELETE;
|
||||
msg->cols = 1;
|
||||
|
||||
((SchemaUnit *) (msg->data))->col = col;
|
||||
((SchemaUnit *) (msg->data))->pos = mgmtGetTagsLength(pMetric, col) + TSDB_TABLE_ID_LEN;
|
||||
((SchemaUnit *) (msg->data))->schema = *(SSchema *) (pMetric->schema + sizeof(SSchema) * (pMetric->numOfColumns + col));
|
||||
|
||||
int32_t ret = sdbBatchUpdateRow(tsSuperTableSdb, msg, size);
|
||||
tfree(msg);
|
||||
|
||||
if (ret < 0) {
|
||||
mError("Failed to drop tag column: %d from table: %s", col, pMetric->tableId);
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
mTrace("Succeed to drop tag column: %d from table: %s", col, pMetric->tableId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mgmtModifySuperTableTagNameByName(SSuperTableObj *pMetric, char *oldTagName, char *newTagName) {
|
||||
int col = mgmtFindTagCol(pMetric, oldTagName);
|
||||
if (col < 0) {
|
||||
// Tag name does not exist
|
||||
mError("Failed to modify table %s tag column, oname: %s, nname: %s", pMetric->tableId, oldTagName, newTagName);
|
||||
return TSDB_CODE_INVALID_MSG_TYPE;
|
||||
}
|
||||
|
||||
int rowSize = 0;
|
||||
uint32_t len = strlen(newTagName);
|
||||
|
||||
if (col >= pMetric->numOfTags || len >= TSDB_COL_NAME_LEN || mgmtFindTagCol(pMetric, newTagName) >= 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
// update
|
||||
SSchema *schema = (SSchema *) (pMetric->schema + (pMetric->numOfColumns + col) * sizeof(SSchema));
|
||||
strncpy(schema->name, newTagName, TSDB_COL_NAME_LEN);
|
||||
|
||||
// Encode string
|
||||
int size = 1 + sizeof(STabObj) + TSDB_MAX_BYTES_PER_ROW;
|
||||
char *msg = (char *) malloc(size);
|
||||
if (msg == NULL) return TSDB_CODE_APP_ERROR;
|
||||
memset(msg, 0, size);
|
||||
|
||||
mgmtMeterActionEncode(pMetric, msg, size, &rowSize);
|
||||
|
||||
int32_t ret = sdbUpdateRow(tsSuperTableSdb, msg, rowSize, 1);
|
||||
tfree(msg);
|
||||
|
||||
if (ret < 0) {
|
||||
mError("Failed to modify table %s tag column", pMetric->tableId);
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
mTrace("Succeed to modify table %s tag column", pMetric->tableId);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static int32_t mgmtFindSuperTableColumnIndex(SNormalTableObj *pMetric, char *colName) {
|
||||
SSchema *schema = (SSchema *) pMetric->schema;
|
||||
for (int32_t i = 0; i < pMetric->numOfColumns; i++) {
|
||||
if (strcasecmp(schema[i].name, colName) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t mgmtAddSuperTableColumn(SSuperTableObj *pMetric, SSchema schema[], int ncols) {
|
||||
if (ncols <= 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
for (int i = 0; i < ncols; i++) {
|
||||
if (mgmtFindSuperTableColumnIndex(pMetric, schema[i].name) > 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
SDbObj *pDb = mgmtGetDbByMeterId(pMetric->tableId);
|
||||
if (pDb == NULL) {
|
||||
mError("meter: %s not belongs to any database", pMetric->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;
|
||||
}
|
||||
|
||||
pMetric->schema = realloc(pMetric->schema, pMetric->schemaSize + sizeof(SSchema) * ncols);
|
||||
|
||||
memmove(pMetric->schema + sizeof(SSchema) * (pMetric->numOfColumns + ncols),
|
||||
pMetric->schema + sizeof(SSchema) * pMetric->numOfColumns, sizeof(SSchema) * pMetric->numOfTags);
|
||||
memcpy(pMetric->schema + sizeof(SSchema) * pMetric->numOfColumns, schema, sizeof(SSchema) * ncols);
|
||||
|
||||
SSchema *tschema = (SSchema *) (pMetric->schema + sizeof(SSchema) * pMetric->numOfColumns);
|
||||
for (int i = 0; i < ncols; i++) {
|
||||
tschema[i].colId = pMetric->nextColId++;
|
||||
}
|
||||
|
||||
pMetric->schemaSize += sizeof(SSchema) * ncols;
|
||||
pMetric->numOfColumns += ncols;
|
||||
pMetric->sversion++;
|
||||
|
||||
pAcct->acctInfo.numOfTimeSeries += (ncols * pMetric->numOfMeters);
|
||||
sdbUpdateRow(tsSuperTableSdb, pMetric, 0, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t mgmtDropSuperTableColumnByName(SSuperTableObj *pMetric, char *colName) {
|
||||
int32_t col = mgmtFindSuperTableColumnIndex(pMetric, colName);
|
||||
if (col < 0) {
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
SDbObj *pDb = mgmtGetDbByMeterId(pMetric->tableId);
|
||||
if (pDb == NULL) {
|
||||
mError("table: %s not belongs to any database", pMetric->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(pMetric->schema + sizeof(SSchema) * col, pMetric->schema + sizeof(SSchema) * (col + 1),
|
||||
sizeof(SSchema) * (pMetric->numOfColumns + pMetric->numOfTags - col - 1));
|
||||
|
||||
pMetric->schemaSize -= sizeof(SSchema);
|
||||
pMetric->numOfColumns--;
|
||||
pMetric->schema = realloc(pMetric->schema, pMetric->schemaSize);
|
||||
pMetric->sversion++;
|
||||
|
||||
pAcct->acctInfo.numOfTimeSeries -= (pMetric->numOfMeters);
|
||||
sdbUpdateRow(tsSuperTableSdb, pMetric, 0, 1);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int mgmtGetSuperTableMeta(SMeterMeta *pMeta, SShowObj *pShow, SConnObj *pConn) {
|
||||
int cols = 0;
|
||||
|
||||
SDbObj *pDb = NULL;
|
||||
if (pConn->pDb != NULL) pDb = mgmtGetDb(pConn->pDb->name);
|
||||
|
||||
if (pDb == NULL) return TSDB_CODE_DB_NOT_SELECTED;
|
||||
|
||||
SSchema *pSchema = tsGetSchema(pMeta);
|
||||
|
||||
pShow->bytes[cols] = TSDB_METER_NAME_LEN;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_BINARY;
|
||||
strcpy(pSchema[cols].name, "name");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 8;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
strcpy(pSchema[cols].name, "created_time");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "columns");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 2;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_SMALLINT;
|
||||
strcpy(pSchema[cols].name, "tags");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pShow->bytes[cols] = 4;
|
||||
pSchema[cols].type = TSDB_DATA_TYPE_INT;
|
||||
strcpy(pSchema[cols].name, "tables");
|
||||
pSchema[cols].bytes = htons(pShow->bytes[cols]);
|
||||
cols++;
|
||||
|
||||
pMeta->numOfColumns = htons(cols);
|
||||
pShow->numOfColumns = cols;
|
||||
|
||||
pShow->offset[0] = 0;
|
||||
for (int i = 1; i < cols; ++i) pShow->offset[i] = pShow->offset[i - 1] + pShow->bytes[i - 1];
|
||||
|
||||
pShow->numOfRows = pDb->numOfMetrics;
|
||||
pShow->rowSize = pShow->offset[cols - 1] + pShow->bytes[cols - 1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mgmtRetrieveSuperTables(SShowObj *pShow, char *data, int rows, SConnObj *pConn) {
|
||||
int numOfRows = 0;
|
||||
char * pWrite;
|
||||
int cols = 0;
|
||||
SSuperTableObj *pTable = NULL;
|
||||
char prefix[20] = {0};
|
||||
int32_t prefixLen;
|
||||
|
||||
SDbObj *pDb = NULL;
|
||||
if (pConn->pDb != NULL) {
|
||||
pDb = mgmtGetDb(pConn->pDb->name);
|
||||
}
|
||||
|
||||
if (pDb == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (mgmtCheckIsMonitorDB(pDb->name, tsMonitorDbName)) {
|
||||
if (strcmp(pConn->pUser->user, "root") != 0 && strcmp(pConn->pUser->user, "_root") != 0 && strcmp(pConn->pUser->user, "monitor") != 0 ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
strcpy(prefix, pDb->name);
|
||||
strcat(prefix, TS_PATH_DELIMITER);
|
||||
prefixLen = strlen(prefix);
|
||||
|
||||
SPatternCompareInfo info = PATTERN_COMPARE_INFO_INITIALIZER;
|
||||
char metricName[TSDB_METER_NAME_LEN] = {0};
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pTable = (SSuperTableObj *)pShow->pNode;
|
||||
if (pTable == NULL) break;
|
||||
pShow->pNode = (void *)pTable->next;
|
||||
|
||||
if (strncmp(pTable->tableId, prefix, prefixLen)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
memset(metricName, 0, tListLen(metricName));
|
||||
extractTableName(pTable->tableId, metricName);
|
||||
|
||||
if (pShow->payloadLen > 0 &&
|
||||
patternMatch(pShow->payload, metricName, TSDB_METER_NAME_LEN, &info) != TSDB_PATTERN_MATCH)
|
||||
continue;
|
||||
|
||||
cols = 0;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
extractTableName(pTable->tableId, pWrite);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int64_t *)pWrite = pTable->createdTime;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = pTable->numOfColumns;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int16_t *)pWrite = pTable->numOfTags;
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
*(int32_t *)pWrite = pTable->numOfMeters;
|
||||
cols++;
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
pShow->numOfReads += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -26,6 +26,7 @@
|
|||
#include "tschemautil.h"
|
||||
#include "tlog.h"
|
||||
#include "tstatus.h"
|
||||
#include "taoserror.h"
|
||||
|
||||
void * vgSdb = NULL;
|
||||
int tsVgUpdateSize;
|
||||
|
@ -128,6 +129,54 @@ int mgmtInitVgroups() {
|
|||
|
||||
SVgObj *mgmtGetVgroup(int vgId) { return (SVgObj *)sdbGetRow(vgSdb, &vgId); }
|
||||
|
||||
SVgObj *mgmtGetAvailVgroup(SDbObj *pDb) {
|
||||
SVgObj *pVgroup = pDb->pHead;
|
||||
|
||||
if (pDb->vgStatus == TSDB_VG_STATUS_IN_PROGRESS) {
|
||||
terrno = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pDb->vgStatus == TSDB_VG_STATUS_FULL) {
|
||||
mError("db:%s, vgroup is full", pDb->name);
|
||||
terrno = TSDB_CODE_NO_ENOUGH_DNODES;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pDb->vgStatus == TSDB_VG_STATUS_NO_DISK_PERMISSIONS ||
|
||||
pDb->vgStatus == TSDB_VG_STATUS_SERVER_NO_PACE ||
|
||||
pDb->vgStatus == TSDB_VG_STATUS_SERV_OUT_OF_MEMORY ||
|
||||
pDb->vgStatus == TSDB_VG_STATUS_INIT_FAILED ) {
|
||||
mError("db:%s, vgroup init failed, reason:%d %s", pDb->name, pDb->vgStatus, taosGetVgroupStatusStr(pDb->vgStatus));
|
||||
terrno = pDb->vgStatus;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (pVgroup == NULL) {
|
||||
pDb->vgStatus = TSDB_VG_STATUS_IN_PROGRESS;
|
||||
mgmtCreateVgroup(pDb);
|
||||
mTrace("db:%s, vgroup malloced, wait for create progress finished", pDb->name);
|
||||
terrno = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
terrno = 0;
|
||||
return pVgroup;
|
||||
}
|
||||
|
||||
int32_t mgmtAllocateSid(SDbObj *pDb, SVgObj *pVgroup) {
|
||||
int32_t sid = taosAllocateId(pVgroup->idPool);
|
||||
if (sid < 0) {
|
||||
mWarn("table:%s, vgroup:%d run out of ID, num:%d", pDb->name, pVgroup->vgId, taosIdPoolNumOfUsed(pVgroup->idPool));
|
||||
pDb->vgStatus = TSDB_VG_STATUS_IN_PROGRESS;
|
||||
mgmtCreateVgroup(pDb);
|
||||
terrno = TSDB_CODE_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
terrno = 0;
|
||||
return sid;
|
||||
}
|
||||
|
||||
void mgmtProcessVgTimer(void *handle, void *tmrId) {
|
||||
SDbObj *pDb = (SDbObj *)handle;
|
||||
if (pDb == NULL) return;
|
||||
|
@ -178,7 +227,7 @@ int mgmtDropVgroup(SDbObj *pDb, SVgObj *pVgroup) {
|
|||
for (int i = 0; i < pDb->cfg.maxSessions; ++i) {
|
||||
if (pVgroup->meterList != NULL) {
|
||||
pTable = pVgroup->meterList[i];
|
||||
if (pTable) mgmtDropMeter(pDb, pTable->meterId, 0);
|
||||
if (pTable) mgmtDropTable(pDb, pTable->meterId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,4 +144,5 @@ int sdbRetrieveRows(int fd, SSdbTable *pTable, uint64_t version);
|
|||
void sdbResetTable(SSdbTable *pTable);
|
||||
extern const int16_t sdbFileVersion;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue