TD-10431 create stable
This commit is contained in:
parent
90512f6ef5
commit
2164b8ef20
|
@ -74,10 +74,10 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_COMPACT_DB, "compact-db" )
|
|||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_FUNCTION, "create-function" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_RETRIEVE_FUNCTION, "retrieve-function" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_FUNCTION, "drop-function" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STABLE, "create-stable" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STABLE, "alter-stable" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STABLE, "drop-stable" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_STABLE_VGROUP, "stable-vgroup" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB, "create-stb" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB, "alter-stb" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB, "drop-stb" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_STB_VGROUP, "stb-vgroup" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_QUERY, "kill-query" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_STREAM, "kill-stream" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_KILL_CONN, "kill-conn" )
|
||||
|
@ -94,9 +94,9 @@ TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_NETWORK_TEST, "nettest" )
|
|||
// message from vnode to dnode
|
||||
|
||||
// message from mnode to vnode
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STABLE_IN, "create-stable" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STABLE_IN, "alter-stable" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STABLE_IN, "drop-stable" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_CREATE_STB_IN, "create-stb-in" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_ALTER_STB_IN, "alter-stb-in" )
|
||||
TAOS_DEFINE_MESSAGE_TYPE( TSDB_MSG_TYPE_DROP_STB_IN, "drop-stb-in" )
|
||||
// message from mnode to mnode
|
||||
// message from mnode to qnode
|
||||
// message from mnode to dnode
|
||||
|
@ -159,7 +159,7 @@ typedef enum _mgmt_table {
|
|||
TSDB_MGMT_TABLE_DNODE,
|
||||
TSDB_MGMT_TABLE_MNODE,
|
||||
TSDB_MGMT_TABLE_VGROUP,
|
||||
TSDB_MGMT_TABLE_STABLE,
|
||||
TSDB_MGMT_TABLE_STB,
|
||||
TSDB_MGMT_TABLE_MODULE,
|
||||
TSDB_MGMT_TABLE_QUERIES,
|
||||
TSDB_MGMT_TABLE_STREAMS,
|
||||
|
@ -294,7 +294,7 @@ typedef struct {
|
|||
uint64_t superTableUid;
|
||||
uint64_t createdTime;
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||
char stableFname[TSDB_TABLE_FNAME_LEN];
|
||||
char stbFname[TSDB_TABLE_FNAME_LEN];
|
||||
char data[];
|
||||
} SMDCreateTableMsg;
|
||||
|
||||
|
@ -311,9 +311,12 @@ typedef struct {
|
|||
} SCreateTableMsg;
|
||||
|
||||
typedef struct {
|
||||
int32_t numOfTables;
|
||||
int32_t contLen;
|
||||
} SCMCreateTableMsg;
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t igExists;
|
||||
int32_t numOfTags;
|
||||
int32_t numOfColumns;
|
||||
SSchema pSchema[];
|
||||
} SCreateStbMsg;
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
|
@ -765,7 +768,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
} SStableInfoMsg;
|
||||
} SStbInfoMsg;
|
||||
|
||||
typedef struct {
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN];
|
||||
|
@ -798,7 +801,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char tableFname[TSDB_TABLE_FNAME_LEN]; // table id
|
||||
char stableFname[TSDB_TABLE_FNAME_LEN];
|
||||
char stbFname[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t numOfTags;
|
||||
int32_t numOfColumns;
|
||||
int8_t precision;
|
||||
|
|
|
@ -159,7 +159,7 @@ typedef enum {
|
|||
SDB_AUTH = 6,
|
||||
SDB_ACCT = 7,
|
||||
SDB_VGROUP = 9,
|
||||
SDB_STABLE = 9,
|
||||
SDB_STB = 9,
|
||||
SDB_DB = 10,
|
||||
SDB_FUNC = 11,
|
||||
SDB_MAX = 12
|
||||
|
|
|
@ -183,8 +183,18 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0348) //"Mnode already exists")
|
||||
#define TSDB_CODE_MND_MNODE_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0349) //"Mnode not there")
|
||||
|
||||
// mnode-table
|
||||
#define TSDB_CODE_MND_TABLE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360) //"Table already exists")
|
||||
// mnode-stable
|
||||
#define TSDB_CODE_MND_STB_NOT_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_IGEXIST TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COLS_NUM TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_TAGS_NUM TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COL_TYPE TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COL_ID TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COL_BYTES TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
#define TSDB_CODE_MND_STB_INVALID_COL_NAME TAOS_DEF_ERROR_CODE(0, 0x0360)
|
||||
|
||||
|
||||
#define TSDB_CODE_MND_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0361) //"Table name too long")
|
||||
#define TSDB_CODE_MND_INVALID_TABLE_NAME TAOS_DEF_ERROR_CODE(0, 0x0362) //"Table does not exist")
|
||||
#define TSDB_CODE_MND_INVALID_TABLE_TYPE TAOS_DEF_ERROR_CODE(0, 0x0363) //"Invalid table type in tsdb")
|
||||
|
|
|
@ -69,10 +69,10 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_FUNCTION] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_RETRIEVE_FUNCTION] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_FUNCTION] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STABLE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STABLE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STABLE] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_STABLE_VGROUP] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_STB_VGROUP] = dndProcessMnodeReadMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_QUERY] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_STREAM] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_KILL_CONN] = dndProcessMnodeWriteMsg;
|
||||
|
@ -84,12 +84,12 @@ static void dndInitMsgFp(STransMgmt *pMgmt) {
|
|||
pMgmt->msgFp[TSDB_MSG_TYPE_NETWORK_TEST] = dndProcessDnodeReq;
|
||||
|
||||
// message from mnode to vnode
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STABLE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STABLE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STABLE_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_STB_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_ALTER_STB_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB_IN] = dndProcessVnodeWriteMsg;
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_DROP_STB_IN_RSP] = dndProcessMnodeWriteMsg;
|
||||
|
||||
// message from mnode to dnode
|
||||
pMgmt->msgFp[TSDB_MSG_TYPE_CREATE_VNODE_IN] = dndProcessVnodeMgmtMsg;
|
||||
|
|
|
@ -241,7 +241,7 @@ typedef struct SVgObj {
|
|||
SVnodeGid vnodeGid[TSDB_MAX_REPLICA];
|
||||
} SVgObj;
|
||||
|
||||
typedef struct SStableObj {
|
||||
typedef struct {
|
||||
char name[TSDB_TABLE_FNAME_LEN];
|
||||
char db[TSDB_FULL_DB_NAME_LEN];
|
||||
int64_t createdTime;
|
||||
|
@ -251,9 +251,8 @@ typedef struct SStableObj {
|
|||
int32_t numOfColumns;
|
||||
int32_t numOfTags;
|
||||
SRWLatch lock;
|
||||
SSchema *columnSchema;
|
||||
SSchema *tagSchema;
|
||||
} SStableObj;
|
||||
SSchema *pSchema;
|
||||
} SStbObj;
|
||||
|
||||
typedef struct SFuncObj {
|
||||
char name[TSDB_FUNC_NAME_LEN];
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mndInitStable(SMnode *pMnode);
|
||||
void mndCleanupStable(SMnode *pMnode);
|
||||
int32_t mndInitStb(SMnode *pMnode);
|
||||
void mndCleanupStb(SMnode *pMnode);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -270,7 +270,7 @@ char *mndShowStr(int32_t showType) {
|
|||
return "show mnodes";
|
||||
case TSDB_MGMT_TABLE_VGROUP:
|
||||
return "show vgroups";
|
||||
case TSDB_MGMT_TABLE_STABLE:
|
||||
case TSDB_MGMT_TABLE_STB:
|
||||
return "show stables";
|
||||
case TSDB_MGMT_TABLE_MODULE:
|
||||
return "show modules";
|
||||
|
|
|
@ -15,62 +15,62 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "mndStable.h"
|
||||
#include "mndDb.h"
|
||||
#include "mndDnode.h"
|
||||
#include "mndMnode.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndDb.h"
|
||||
#include "tname.h"
|
||||
|
||||
#define TSDB_STABLE_VER_NUM 1
|
||||
#define TSDB_STABLE_RESERVE_SIZE 64
|
||||
#define TSDB_STB_VER_NUM 1
|
||||
#define TSDB_STB_RESERVE_SIZE 64
|
||||
|
||||
static SSdbRaw *mndStableActionEncode(SStableObj *pStb);
|
||||
static SSdbRow *mndStableActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndStableActionInsert(SSdb *pSdb, SStableObj *pStb);
|
||||
static int32_t mndStableActionDelete(SSdb *pSdb, SStableObj *pStb);
|
||||
static int32_t mndStableActionUpdate(SSdb *pSdb, SStableObj *pOldStb, SStableObj *pNewStb);
|
||||
static int32_t mndProcessCreateStableMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessAlterStableMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropStableMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessCreateStableInRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessAlterStableInRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropStableInRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessStableMetaMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetStableMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveStables(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextStable(SMnode *pMnode, void *pIter);
|
||||
static SSdbRaw *mndStbActionEncode(SStbObj *pStb);
|
||||
static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw);
|
||||
static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb);
|
||||
static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb);
|
||||
static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb);
|
||||
static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessCreateStbInRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessAlterStbInRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg);
|
||||
static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg);
|
||||
static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta);
|
||||
static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows);
|
||||
static void mndCancelGetNextStb(SMnode *pMnode, void *pIter);
|
||||
|
||||
int32_t mndInitStable(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_STABLE,
|
||||
int32_t mndInitStb(SMnode *pMnode) {
|
||||
SSdbTable table = {.sdbType = SDB_STB,
|
||||
.keyType = SDB_KEY_BINARY,
|
||||
.encodeFp = (SdbEncodeFp)mndStableActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndStableActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndStableActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndStableActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndStableActionDelete};
|
||||
.encodeFp = (SdbEncodeFp)mndStbActionEncode,
|
||||
.decodeFp = (SdbDecodeFp)mndStbActionDecode,
|
||||
.insertFp = (SdbInsertFp)mndStbActionInsert,
|
||||
.updateFp = (SdbUpdateFp)mndStbActionUpdate,
|
||||
.deleteFp = (SdbDeleteFp)mndStbActionDelete};
|
||||
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_STABLE, mndProcessCreateStableMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_STABLE, mndProcessAlterStableMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_STABLE, mndProcessDropStableMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_STABLE_IN_RSP, mndProcessCreateStableInRsp);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_STABLE_IN_RSP, mndProcessAlterStableInRsp);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_STABLE_IN_RSP, mndProcessDropStableInRsp);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_TABLE_META, mndProcessStableMetaMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_STB, mndProcessCreateStbMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_STB, mndProcessAlterStbMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_STB, mndProcessDropStbMsg);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_CREATE_STB_IN_RSP, mndProcessCreateStbInRsp);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_ALTER_STB_IN_RSP, mndProcessAlterStbInRsp);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_DROP_STB_IN_RSP, mndProcessDropStbInRsp);
|
||||
mndSetMsgHandle(pMnode, TSDB_MSG_TYPE_TABLE_META, mndProcessStbMetaMsg);
|
||||
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_STABLE, mndGetStableMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STABLE, mndRetrieveStables);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STABLE, mndCancelGetNextStable);
|
||||
mndAddShowMetaHandle(pMnode, TSDB_MGMT_TABLE_STB, mndGetStbMeta);
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_STB, mndRetrieveStb);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_STB, mndCancelGetNextStb);
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
||||
void mndCleanupStable(SMnode *pMnode) {}
|
||||
void mndCleanupStb(SMnode *pMnode) {}
|
||||
|
||||
static SSdbRaw *mndStableActionEncode(SStableObj *pStb) {
|
||||
int32_t size = sizeof(SStableObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STABLE, TSDB_STABLE_VER_NUM, size);
|
||||
static SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
|
||||
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema);
|
||||
SSdbRaw *pRaw = sdbAllocRaw(SDB_STB, TSDB_STB_VER_NUM, size);
|
||||
if (pRaw == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -82,41 +82,34 @@ static SSdbRaw *mndStableActionEncode(SStableObj *pStb) {
|
|||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfColumns)
|
||||
SDB_SET_INT32(pRaw, dataPos, pStb->numOfTags)
|
||||
|
||||
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
|
||||
SSchema *pSchema = &pStb->columnSchema[i];
|
||||
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pStb->pSchema[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type);
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->colId);
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
|
||||
SSchema *pSchema = &pStb->tagSchema[i];
|
||||
SDB_SET_INT8(pRaw, dataPos, pSchema->type);
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->colId);
|
||||
SDB_SET_INT32(pRaw, dataPos, pSchema->bytes);
|
||||
SDB_SET_BINARY(pRaw, dataPos, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
}
|
||||
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_STABLE_RESERVE_SIZE)
|
||||
SDB_SET_RESERVE(pRaw, dataPos, TSDB_STB_RESERVE_SIZE)
|
||||
SDB_SET_DATALEN(pRaw, dataPos);
|
||||
|
||||
return pRaw;
|
||||
}
|
||||
|
||||
static SSdbRow *mndStableActionDecode(SSdbRaw *pRaw) {
|
||||
static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
|
||||
int8_t sver = 0;
|
||||
if (sdbGetRawSoftVer(pRaw, &sver) != 0) return NULL;
|
||||
|
||||
if (sver != TSDB_STABLE_VER_NUM) {
|
||||
if (sver != TSDB_STB_VER_NUM) {
|
||||
mError("failed to decode stable since %s", terrstr());
|
||||
terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t size = sizeof(SStableObj) + TSDB_MAX_COLUMNS * sizeof(SSchema);
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
SStableObj *pStb = sdbGetRowObj(pRow);
|
||||
int32_t size = sizeof(SStbObj) + TSDB_MAX_COLUMNS * sizeof(SSchema);
|
||||
SSdbRow *pRow = sdbAllocRow(size);
|
||||
SStbObj *pStb = sdbGetRowObj(pRow);
|
||||
if (pStb == NULL) return NULL;
|
||||
|
||||
int32_t dataPos = 0;
|
||||
|
@ -128,87 +121,61 @@ static SSdbRow *mndStableActionDecode(SSdbRaw *pRaw) {
|
|||
SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfColumns)
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pStb->numOfTags)
|
||||
|
||||
pStb->columnSchema = calloc(pStb->numOfColumns, sizeof(SSchema));
|
||||
pStb->tagSchema = calloc(pStb->numOfTags, sizeof(SSchema));
|
||||
int32_t totalCols = pStb->numOfColumns + pStb->numOfTags;
|
||||
pStb->pSchema = calloc(totalCols, sizeof(SSchema));
|
||||
|
||||
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
|
||||
SSchema *pSchema = &pStb->columnSchema[i];
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pStb->pSchema[i];
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pSchema->type);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->colId);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->bytes);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
|
||||
SSchema *pSchema = &pStb->tagSchema[i];
|
||||
SDB_GET_INT8(pRaw, pRow, dataPos, &pSchema->type);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->colId);
|
||||
SDB_GET_INT32(pRaw, pRow, dataPos, &pSchema->bytes);
|
||||
SDB_GET_BINARY(pRaw, pRow, dataPos, pSchema->name, TSDB_COL_NAME_LEN);
|
||||
}
|
||||
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_STABLE_RESERVE_SIZE)
|
||||
SDB_GET_RESERVE(pRaw, pRow, dataPos, TSDB_STB_RESERVE_SIZE)
|
||||
|
||||
return pRow;
|
||||
}
|
||||
|
||||
static int32_t mndStableActionInsert(SSdb *pSdb, SStableObj *pStb) {
|
||||
mTrace("stable:%s, perform insert action", pStb->name);
|
||||
static int32_t mndStbActionInsert(SSdb *pSdb, SStbObj *pStb) {
|
||||
mTrace("stb:%s, perform insert action", pStb->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndStableActionDelete(SSdb *pSdb, SStableObj *pStb) {
|
||||
mTrace("stable:%s, perform delete action", pStb->name);
|
||||
static int32_t mndStbActionDelete(SSdb *pSdb, SStbObj *pStb) {
|
||||
mTrace("stb:%s, perform delete action", pStb->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndStableActionUpdate(SSdb *pSdb, SStableObj *pOldStb, SStableObj *pNewStb) {
|
||||
mTrace("stable:%s, perform update action", pOldStb->name);
|
||||
static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOldStb, SStbObj *pNewStb) {
|
||||
mTrace("stb:%s, perform update action", pOldStb->name);
|
||||
atomic_exchange_32(&pOldStb->updateTime, pNewStb->updateTime);
|
||||
atomic_exchange_32(&pOldStb->version, pNewStb->version);
|
||||
|
||||
taosWLockLatch(&pOldStb->lock);
|
||||
int32_t numOfTags = pNewStb->numOfTags;
|
||||
int32_t tagSize = numOfTags * sizeof(SSchema);
|
||||
int32_t numOfColumns = pNewStb->numOfColumns;
|
||||
int32_t columnSize = numOfColumns * sizeof(SSchema);
|
||||
int32_t totalCols = pNewStb->numOfTags + pNewStb->numOfColumns;
|
||||
int32_t totalSize = totalCols * sizeof(SSchema);
|
||||
|
||||
if (pOldStb->numOfTags < numOfTags) {
|
||||
pOldStb->tagSchema = malloc(tagSize);
|
||||
}
|
||||
if (pOldStb->numOfColumns < numOfColumns) {
|
||||
pOldStb->columnSchema = malloc(columnSize);
|
||||
if (pOldStb->numOfTags + pOldStb->numOfColumns < totalCols) {
|
||||
pOldStb->pSchema = malloc(totalSize);
|
||||
}
|
||||
|
||||
memcpy(pOldStb->tagSchema, pNewStb->tagSchema, tagSize);
|
||||
memcpy(pOldStb->columnSchema, pNewStb->columnSchema, columnSize);
|
||||
memcpy(pOldStb->pSchema, pNewStb->pSchema, totalSize);
|
||||
taosWUnLockLatch(&pOldStb->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SStableObj *mndAcquireStb(SMnode *pMnode, char *stbName) {
|
||||
SStbObj *mndAcquireStb(SMnode *pMnode, char *stbName) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
return sdbAcquire(pSdb, SDB_STABLE, stbName);
|
||||
return sdbAcquire(pSdb, SDB_STB, stbName);
|
||||
}
|
||||
|
||||
void mndReleaseStb(SMnode *pMnode, SStableObj *pStb) {
|
||||
void mndReleaseStb(SMnode *pMnode, SStbObj *pStb) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbRelease(pSdb, pStb);
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateStableMsg(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessCreateStableInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessAlterStableMsg(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessAlterStableInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessDropStableMsg(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessDropStableInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static SDbObj *mndGetDbByStbName(SMnode *pMnode, char *stbName) {
|
||||
static SDbObj *mndAcquireDbByStb(SMnode *pMnode, char *stbName) {
|
||||
SName name = {0};
|
||||
tNameFromString(&name, stbName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE);
|
||||
|
||||
|
@ -218,24 +185,187 @@ static SDbObj *mndGetDbByStbName(SMnode *pMnode, char *stbName) {
|
|||
return mndAcquireDb(pMnode, db);
|
||||
}
|
||||
|
||||
static int32_t mndProcessStableMetaMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SStableInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||
static int32_t mndCheckStbMsg(SCreateStbMsg *pCreate) {
|
||||
pCreate->numOfColumns = htonl(pCreate->numOfColumns);
|
||||
pCreate->numOfTags = htonl(pCreate->numOfTags);
|
||||
int32_t totalCols = pCreate->numOfColumns + pCreate->numOfTags;
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pCreate->pSchema[i];
|
||||
pSchema->colId = htonl(pSchema->colId);
|
||||
pSchema->bytes = htonl(pSchema->bytes);
|
||||
}
|
||||
|
||||
mDebug("stable:%s, start to retrieve meta", pInfo->name);
|
||||
|
||||
SDbObj *pDb = mndGetDbByStbName(pMnode, pInfo->name);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
mError("stable:%s, failed to retrieve meta since %s", pInfo->name, terrstr());
|
||||
if (pCreate->igExists < 0 || pCreate->igExists > 1) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_IGEXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
SStableObj *pStb = mndAcquireStb(pMnode, pInfo->name);
|
||||
if (pCreate->numOfColumns < TSDB_MIN_COLUMNS || pCreate->numOfColumns > TSDB_MAX_COLUMNS) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COLS_NUM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pCreate->numOfTags <= 0 || pCreate->numOfTags > TSDB_MAX_TAGS) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_TAGS_NUM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t maxColId = (TSDB_MAX_COLUMNS + TSDB_MAX_TAGS);
|
||||
for (int32_t i = 0; i < totalCols; ++i) {
|
||||
SSchema *pSchema = &pCreate->pSchema[i];
|
||||
if (pSchema->type <= 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_TYPE;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->colId < 0 || pSchema->colId >= maxColId) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_ID;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->bytes <= 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_BYTES;
|
||||
return -1;
|
||||
}
|
||||
if (pSchema->name[0] == 0) {
|
||||
terrno = TSDB_CODE_MND_STB_INVALID_COL_NAME;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndCreateStb(SMnode *pMnode, SMnodeMsg *pMsg, SCreateStbMsg *pCreate, SDbObj *pDb) {
|
||||
SStbObj stbObj = {0};
|
||||
tstrncpy(stbObj.name, pCreate->name, TSDB_TABLE_FNAME_LEN);
|
||||
tstrncpy(stbObj.db, pDb->name, TSDB_FULL_DB_NAME_LEN);
|
||||
stbObj.createdTime = taosGetTimestampMs();
|
||||
stbObj.updateTime = stbObj.createdTime;
|
||||
stbObj.uid = 1234;
|
||||
stbObj.version = 1;
|
||||
stbObj.numOfColumns = pCreate->numOfColumns;
|
||||
stbObj.numOfTags = pCreate->numOfTags;
|
||||
|
||||
int32_t totalCols = stbObj.numOfColumns + stbObj.numOfTags;
|
||||
int32_t totalSize = totalCols * sizeof(SSchema);
|
||||
stbObj.pSchema = malloc(totalSize);
|
||||
if (stbObj.pSchema == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
memcpy(stbObj.pSchema, pCreate->pSchema, totalSize);
|
||||
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, pMsg->rpcMsg.handle);
|
||||
if (pTrans == NULL) {
|
||||
mError("stb:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
mDebug("trans:%d, used to create stb:%s", pTrans->id, pCreate->name);
|
||||
|
||||
SSdbRaw *pRedoRaw = mndStbActionEncode(&stbObj);
|
||||
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
|
||||
mError("trans:%d, failed to append redo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_CREATING);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndStbActionEncode(&stbObj);
|
||||
if (pUndoRaw == NULL || mndTransAppendUndolog(pTrans, pUndoRaw) != 0) {
|
||||
mError("trans:%d, failed to append undo log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
SSdbRaw *pCommitRaw = mndStbActionEncode(&stbObj);
|
||||
if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
|
||||
mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
sdbSetRawStatus(pCommitRaw, SDB_STATUS_READY);
|
||||
|
||||
if (mndTransPrepare(pTrans) != 0) {
|
||||
mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
}
|
||||
|
||||
mndTransDrop(pTrans);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateStbMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SCreateStbMsg *pCreate = pMsg->rpcMsg.pCont;
|
||||
|
||||
mDebug("stb:%s, start to create", pCreate->name);
|
||||
|
||||
if (mndCheckStbMsg(pCreate) != 0) {
|
||||
mError("stb:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SStbObj *pStb = mndAcquireStb(pMnode, pCreate->name);
|
||||
if (pStb != NULL) {
|
||||
sdbRelease(pMnode->pSdb, pStb);
|
||||
if (pCreate->igExists) {
|
||||
mDebug("stb:%s, already exist, ignore exist is set", pCreate->name);
|
||||
return 0;
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_STB_ALREADY_EXIST;
|
||||
mError("db:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
SDbObj *pDb = mndAcquireDbByStb(pMnode, pCreate->name);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
mError("stb:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
int32_t code = mndCreateStb(pMnode, pMsg, pCreate, pDb);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
if (code != 0) {
|
||||
terrno = code;
|
||||
mError("stb:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return TSDB_CODE_MND_ACTION_IN_PROGRESS;
|
||||
}
|
||||
|
||||
static int32_t mndProcessCreateStbInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessAlterStbMsg(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessAlterStbInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessDropStbMsg(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessDropStbInRsp(SMnodeMsg *pMsg) { return 0; }
|
||||
|
||||
static int32_t mndProcessStbMetaMsg(SMnodeMsg *pMsg) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SStbInfoMsg *pInfo = pMsg->rpcMsg.pCont;
|
||||
|
||||
mDebug("stb:%s, start to retrieve meta", pInfo->name);
|
||||
|
||||
SDbObj *pDb = mndAcquireDbByStb(pMnode, pInfo->name);
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_SELECTED;
|
||||
mError("stb:%s, failed to retrieve meta since %s", pInfo->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
SStbObj *pStb = mndAcquireStb(pMnode, pInfo->name);
|
||||
if (pStb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
terrno = TSDB_CODE_MND_INVALID_TABLE_NAME;
|
||||
mError("stable:%s, failed to get meta since %s", pInfo->name, terrstr());
|
||||
mError("stb:%s, failed to get meta since %s", pInfo->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -243,11 +373,11 @@ static int32_t mndProcessStableMetaMsg(SMnodeMsg *pMsg) {
|
|||
STableMetaMsg *pMeta = rpcMallocCont(contLen);
|
||||
if (pMeta == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
mError("stable:%s, failed to get meta since %s", pInfo->name, terrstr());
|
||||
mError("stb:%s, failed to get meta since %s", pInfo->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pMeta->stableFname, pStb->name, TSDB_TABLE_FNAME_LEN);
|
||||
memcpy(pMeta->stbFname, pStb->name, TSDB_TABLE_FNAME_LEN);
|
||||
pMeta->numOfTags = htonl(pStb->numOfTags);
|
||||
pMeta->numOfColumns = htonl(pStb->numOfColumns);
|
||||
pMeta->precision = pDb->cfg.precision;
|
||||
|
@ -258,30 +388,21 @@ static int32_t mndProcessStableMetaMsg(SMnodeMsg *pMsg) {
|
|||
|
||||
for (int32_t i = 0; i < pStb->numOfColumns; ++i) {
|
||||
SSchema *pSchema = &pMeta->pSchema[i];
|
||||
SSchema *pColumn = &pStb->columnSchema[i];
|
||||
memcpy(pSchema->name, pColumn->name, TSDB_COL_NAME_LEN);
|
||||
pSchema->type = pColumn->type;
|
||||
pSchema->colId = htonl(pColumn->colId);
|
||||
pSchema->bytes = htonl(pColumn->bytes);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < pStb->numOfTags; ++i) {
|
||||
SSchema *pSchema = &pMeta->pSchema[i + pStb->numOfColumns];
|
||||
SSchema *pTag = &pStb->tagSchema[i];
|
||||
memcpy(pSchema->name, pTag->name, TSDB_COL_NAME_LEN);
|
||||
pSchema->type = pTag->type;
|
||||
pSchema->colId = htons(pTag->colId);
|
||||
pSchema->bytes = htonl(pTag->bytes);
|
||||
SSchema *pSrcSchema = &pStb->pSchema[i];
|
||||
memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN);
|
||||
pSchema->type = pSrcSchema->type;
|
||||
pSchema->colId = htonl(pSrcSchema->colId);
|
||||
pSchema->bytes = htonl(pSrcSchema->bytes);
|
||||
}
|
||||
|
||||
pMsg->pCont = pMeta;
|
||||
pMsg->contLen = contLen;
|
||||
|
||||
mDebug("stable:%s, meta is retrieved, cols:%d tags:%d", pInfo->name, pStb->numOfColumns, pStb->numOfTags);
|
||||
mDebug("stb:%s, meta is retrieved, cols:%d tags:%d", pInfo->name, pStb->numOfColumns, pStb->numOfTags);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetNumOfStables(SMnode *pMnode, char *dbName, int32_t *pNumOfStables) {
|
||||
static int32_t mndGetNumOfStbs(SMnode *pMnode, char *dbName, int32_t *pNumOfStbs) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, dbName);
|
||||
|
@ -290,29 +411,29 @@ static int32_t mndGetNumOfStables(SMnode *pMnode, char *dbName, int32_t *pNumOfS
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t numOfStables = 0;
|
||||
int32_t numOfStbs = 0;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
SStableObj *pStb = NULL;
|
||||
SStbObj *pStb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pStb);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (strcmp(pStb->db, dbName) == 0) {
|
||||
numOfStables++;
|
||||
numOfStbs++;
|
||||
}
|
||||
|
||||
sdbRelease(pSdb, pStb);
|
||||
}
|
||||
|
||||
*pNumOfStables = numOfStables;
|
||||
*pNumOfStbs = numOfStbs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndGetStableMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
static int32_t mndGetStbMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg *pMeta) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
if (mndGetNumOfStables(pMnode, pShow->db, &pShow->numOfRows) != 0) {
|
||||
if (mndGetNumOfStbs(pMnode, pShow->db, &pShow->numOfRows) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -357,7 +478,7 @@ static int32_t mndGetStableMeta(SMnodeMsg *pMsg, SShowObj *pShow, STableMetaMsg
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void mnodeExtractTableName(char* tableId, char* name) {
|
||||
static void mnodeExtractTableName(char *tableId, char *name) {
|
||||
int pos = -1;
|
||||
int num = 0;
|
||||
for (pos = 0; tableId[pos] != 0; ++pos) {
|
||||
|
@ -370,21 +491,21 @@ static void mnodeExtractTableName(char* tableId, char* name) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveStables(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
SStableObj *pStb = NULL;
|
||||
int32_t cols = 0;
|
||||
char *pWrite;
|
||||
char prefix[64] = {0};
|
||||
static int32_t mndRetrieveStb(SMnodeMsg *pMsg, SShowObj *pShow, char *data, int32_t rows) {
|
||||
SMnode *pMnode = pMsg->pMnode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
SStbObj *pStb = NULL;
|
||||
int32_t cols = 0;
|
||||
char *pWrite;
|
||||
char prefix[64] = {0};
|
||||
|
||||
tstrncpy(prefix, pShow->db, 64);
|
||||
strcat(prefix, TS_PATH_DELIMITER);
|
||||
int32_t prefixLen = (int32_t)strlen(prefix);
|
||||
|
||||
while (numOfRows < rows) {
|
||||
pShow->pIter = sdbFetch(pSdb, SDB_STABLE, pShow->pIter, (void **)&pStb);
|
||||
pShow->pIter = sdbFetch(pSdb, SDB_STB, pShow->pIter, (void **)&pStb);
|
||||
if (pShow->pIter == NULL) break;
|
||||
|
||||
if (strncmp(pStb->name, prefix, prefixLen) != 0) {
|
||||
|
@ -394,10 +515,10 @@ static int32_t mndRetrieveStables(SMnodeMsg *pMsg, SShowObj *pShow, char *data,
|
|||
|
||||
cols = 0;
|
||||
|
||||
char stableName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
memcpy(stableName, pStb->name + prefixLen, TSDB_TABLE_FNAME_LEN - prefixLen);
|
||||
char stbName[TSDB_TABLE_FNAME_LEN] = {0};
|
||||
memcpy(stbName, pStb->name + prefixLen, TSDB_TABLE_FNAME_LEN - prefixLen);
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
STR_TO_VARSTR(pWrite, stableName);
|
||||
STR_TO_VARSTR(pWrite, stbName);
|
||||
cols++;
|
||||
|
||||
pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;
|
||||
|
@ -421,7 +542,7 @@ static int32_t mndRetrieveStables(SMnodeMsg *pMsg, SShowObj *pShow, char *data,
|
|||
return numOfRows;
|
||||
}
|
||||
|
||||
static void mndCancelGetNextStable(SMnode *pMnode, void *pIter) {
|
||||
static void mndCancelGetNextStb(SMnode *pMnode, void *pIter) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
|
@ -131,7 +131,7 @@ static int32_t mndInitSteps(SMnode *pMnode) {
|
|||
if (mndAllocStep(pMnode, "mnode-user", mndInitUser, mndCleanupUser) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-vgroup", mndInitVgroup, mndCleanupVgroup) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-stable", mndInitStable, mndCleanupStable) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-stb", mndInitStb, mndCleanupStb) != 0) return -1;
|
||||
if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1;
|
||||
if (pMnode->clusterId <= 0) {
|
||||
if (mndAllocStep(pMnode, "mnode-sdb-deploy", mndDeploySdb, NULL) != 0) return -1;
|
||||
|
|
|
@ -121,7 +121,7 @@ typedef struct SRelationInfo {
|
|||
|
||||
typedef struct SCreatedTableInfo {
|
||||
SToken name; // table name token
|
||||
SToken stableName; // super table name token , for using clause
|
||||
SToken stbName; // super table name token , for using clause
|
||||
SArray *pTagNames; // create by using super table, tag name
|
||||
SArray *pTagVals; // create by using super table, tag value
|
||||
char *fullname; // table full name
|
||||
|
|
|
@ -112,13 +112,13 @@ cmd ::= SHOW dbPrefix(X) TABLES LIKE ids(Y). {
|
|||
}
|
||||
|
||||
cmd ::= SHOW dbPrefix(X) STABLES. {
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_STABLE, &X, 0);
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_STB, &X, 0);
|
||||
}
|
||||
|
||||
cmd ::= SHOW dbPrefix(X) STABLES LIKE ids(Y). {
|
||||
SToken token;
|
||||
tSetDbName(&token, &X);
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_STABLE, &token, &Y);
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_STB, &token, &Y);
|
||||
}
|
||||
|
||||
cmd ::= SHOW dbPrefix(X) VGROUPS. {
|
||||
|
|
|
@ -634,7 +634,7 @@ SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames,
|
|||
info.name = *pToken;
|
||||
info.pTagNames = pTagNames;
|
||||
info.pTagVals = pTagVals;
|
||||
info.stableName = *pTableName;
|
||||
info.stbName = *pTableName;
|
||||
info.igExist = (igExists->n > 0)? 1:0;
|
||||
|
||||
return info;
|
||||
|
|
|
@ -2312,14 +2312,14 @@ static void yy_reduce(
|
|||
break;
|
||||
case 26: /* cmd ::= SHOW dbPrefix STABLES */
|
||||
{
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_STABLE, &yymsp[-1].minor.yy0, 0);
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_STB, &yymsp[-1].minor.yy0, 0);
|
||||
}
|
||||
break;
|
||||
case 27: /* cmd ::= SHOW dbPrefix STABLES LIKE ids */
|
||||
{
|
||||
SToken token;
|
||||
tSetDbName(&token, &yymsp[-3].minor.yy0);
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_STABLE, &token, &yymsp[0].minor.yy0);
|
||||
setShowOptions(pInfo, TSDB_MGMT_TABLE_STB, &token, &yymsp[0].minor.yy0);
|
||||
}
|
||||
break;
|
||||
case 28: /* cmd ::= SHOW dbPrefix VGROUPS */
|
||||
|
|
|
@ -406,7 +406,7 @@ void rpcSendRequest(void *shandle, const SEpSet *pEpSet, SRpcMsg *pMsg, int64_t
|
|||
// for TDengine, all the query, show commands shall have TCP connection
|
||||
char type = pMsg->msgType;
|
||||
if (type == TSDB_MSG_TYPE_QUERY || type == TSDB_MSG_TYPE_SHOW_RETRIEVE
|
||||
|| type == TSDB_MSG_TYPE_FETCH || type == TSDB_MSG_TYPE_STABLE_VGROUP
|
||||
|| type == TSDB_MSG_TYPE_FETCH || type == TSDB_MSG_TYPE_STB_VGROUP
|
||||
|| type == TSDB_MSG_TYPE_TABLES_META || type == TSDB_MSG_TYPE_TABLE_META
|
||||
|| type == TSDB_MSG_TYPE_SHOW || type == TSDB_MSG_TYPE_STATUS || type == TSDB_MSG_TYPE_ALTER_TABLE)
|
||||
pContext->connType = RPC_CONN_TCPC;
|
||||
|
|
|
@ -193,8 +193,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_TOO_MANY_USERS, "Too many users")
|
|||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_MNODE_ALREADY_EXIST, "Mnode already exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_MNODE_NOT_EXIST, "Mnode not there")
|
||||
|
||||
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_TABLE_ALREADY_EXIST, "Table already exists")
|
||||
// mnode-stable
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_STB_ALREADY_EXIST, "Stable already exists")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_ID, "Table name too long")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_NAME, "Table does not exist")
|
||||
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_TABLE_TYPE, "Invalid table type in tsdb")
|
||||
|
|
|
@ -28,7 +28,7 @@ typedef struct {
|
|||
} TAOS_SML_KV;
|
||||
|
||||
typedef struct {
|
||||
char* stableName;
|
||||
char* stbName;
|
||||
|
||||
char* childTableName;
|
||||
TAOS_SML_KV* tags;
|
||||
|
|
Loading…
Reference in New Issue