diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index e9d231171512c8cb9c54b0ababf386bfa821dbf2..25a5db61182294b07bad4f11949e001923289e47 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -32,7 +32,7 @@ extern "C" { #define UTIL_TABLE_IS_SUPERTABLE(metaInfo) \ (((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_SUPER_TABLE)) #define UTIL_TABLE_IS_NOMRAL_TABLE(metaInfo) (!(UTIL_TABLE_IS_SUPERTABLE(metaInfo))) -#define UTIL_TABLE_CREATE_FROM_STABLE(metaInfo) \ +#define UTIL_TABLE_IS_CHILD_TABLE(metaInfo) \ (((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_CHILD_TABLE)) #define TSDB_COL_IS_TAG(f) (((f)&TSDB_COL_TAG) != 0) diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 2bab6e03fe0ab4fd746d4c246299252b4f85fe44..1b9b0a365fa7de25fee6ca8ca9d997cef28001a9 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -406,11 +406,6 @@ void tscTableMetaCallBack(void *param, TAOS_RES *res, int code) { SSqlCmd *pCmd = &pSql->cmd; SSqlRes *pRes = &pSql->res; - if (pSql->fp == NULL) { - tscError("%p callBack is NULL!!!", pSql); - return; - } - if (pSql->fp == (void *)1) { pSql->fp = NULL; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 6427578e82fd73909e04ab8cd9329efafd014e15..34f043a15bb6e182e2afbcc788d0ae02fe683499 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4240,7 +4240,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { } else if ((pAlterSQL->type == TSDB_ALTER_TABLE_UPDATE_TAG_VAL) && (UTIL_TABLE_IS_SUPERTABLE(pTableMetaInfo))) { return invalidSqlErrMsg(pQueryInfo->msg, msg4); } else if ((pAlterSQL->type == TSDB_ALTER_TABLE_ADD_COLUMN || pAlterSQL->type == TSDB_ALTER_TABLE_DROP_COLUMN) && - UTIL_TABLE_CREATE_FROM_STABLE(pTableMetaInfo)) { + UTIL_TABLE_IS_CHILD_TABLE(pTableMetaInfo)) { return invalidSqlErrMsg(pQueryInfo->msg, msg6); } diff --git a/src/client/src/tscSchemaUtil.c b/src/client/src/tscSchemaUtil.c index 78d29be1af4e388791396fd17c99c61cb08b4edc..66776e36f7a635a7e616e44c902f16d76de7cb08 100644 --- a/src/client/src/tscSchemaUtil.c +++ b/src/client/src/tscSchemaUtil.c @@ -51,12 +51,12 @@ int32_t tscGetNumOfColumns(const STableMeta* pTableMeta) { SSchema *tscGetTableSchema(const STableMeta *pTableMeta) { assert(pTableMeta != NULL); - if (pTableMeta->tableType == TSDB_CHILD_TABLE) { - STableMeta* pSTableMeta = pTableMeta->pSTable; - assert (pSTableMeta != NULL); - - return pSTableMeta->schema; - } +// if (pTableMeta->tableType == TSDB_CHILD_TABLE) { +// STableMeta* pSTableMeta = pTableMeta->pSTable; +// assert (pSTableMeta != NULL); +// +// return pSTableMeta->schema; +// } return (SSchema*) pTableMeta->schema; } @@ -72,12 +72,14 @@ SSchema* tscGetTableTagSchema(const STableMeta* pTableMeta) { STableComInfo tscGetTableInfo(const STableMeta* pTableMeta) { assert(pTableMeta != NULL); - + +#if 0 if (pTableMeta->tableType == TSDB_CHILD_TABLE) { assert (pTableMeta->pSTable != NULL); return pTableMeta->pSTable->tableInfo; } - +#endif + return pTableMeta->tableInfo; } @@ -130,12 +132,13 @@ SSchema* tscGetTableColumnSchema(const STableMeta* pTableMeta, int32_t startCol) assert(pTableMeta != NULL); SSchema* pSchema = pTableMeta->schema; - +#if 0 if (pTableMeta->tableType == TSDB_CHILD_TABLE) { assert (pTableMeta->pSTable != NULL); pSchema = pTableMeta->pSTable->schema; } - +#endif + return &pSchema[startCol]; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index decf9875d28e3483ab4b0f064c5d523a9f1e92a0..5826d02cf2c97675be6beba10bff2308cccf7e10 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -325,8 +325,9 @@ void tscProcessMsgFromServer(SRpcMsg *rpcMsg) { rpcMsg->code = (*tscProcessMsgRsp[pCmd->command])(pSql); if (rpcMsg->code != TSDB_CODE_ACTION_IN_PROGRESS) { - int command = pCmd->command; - void *taosres = tscKeepConn[command] ? pSql : NULL; + void *taosres = tscKeepConn[pCmd->command] ? pSql : NULL; + rpcMsg->code = pRes->code ? -pRes->code : pRes->numOfRows; + tscTrace("%p Async SQL result:%s res:%p", pSql, tstrerror(pRes->code), taosres); /* @@ -1817,14 +1818,13 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { pMetaMsg->vgId = htonl(pMetaMsg->vgId); pMetaMsg->uid = htobe64(pMetaMsg->uid); pMetaMsg->contLen = htons(pMetaMsg->contLen); + pMetaMsg->numOfColumns = htons(pMetaMsg->numOfColumns); if (pMetaMsg->sid < 0 || pMetaMsg->vgId < 0) { tscError("invalid meter vgId:%d, sid%d", pMetaMsg->vgId, pMetaMsg->sid); return TSDB_CODE_INVALID_VALUE; } - pMetaMsg->numOfColumns = htons(pMetaMsg->numOfColumns); - if (pMetaMsg->numOfTags > TSDB_MAX_TAGS || pMetaMsg->numOfTags < 0) { tscError("invalid numOfTags:%d", pMetaMsg->numOfTags); return TSDB_CODE_INVALID_VALUE; @@ -1848,23 +1848,20 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { pSchema++; } -// rsp += numOfTotalCols * sizeof(SSchema); -// -// int32_t tagLen = 0; -// SSchema *pTagsSchema = tscGetTableTagSchema(pMetaMsg); -// -// if (pMetaMsg->tableType == TSDB_CHILD_TABLE) { -// for (int32_t i = 0; i < pMetaMsg->numOfTags; ++i) { -// tagLen += pTagsSchema[i].bytes; -// } -// } -// -// rsp += tagLen; -// int32_t size = (int32_t)(rsp - (char *)pMetaMsg); - size_t size = 0; STableMeta* pTableMeta = tscCreateTableMetaFromMsg(pMetaMsg, &size); +#if 0 + // if current table is created according to super table, get the table meta of super table + if (pTableMeta->tableType == TSDB_CHILD_TABLE) { + char id[TSDB_TABLE_ID_LEN + 1] = {0}; + strncpy(id, pMetaMsg->stableId, TSDB_TABLE_ID_LEN); + + // NOTE: if the table meta of super table is not cached at client side yet, the pSTable is NULL + pTableMeta->pSTable = taosCacheAcquireByName(tscCacheHandle, id); + } +#endif + // todo add one more function: taosAddDataIfNotExists(); STableMetaInfo *pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pSql->cmd, 0, 0); assert(pTableMetaInfo->pTableMeta == NULL); @@ -1878,6 +1875,7 @@ int tscProcessTableMetaRsp(SSqlObj *pSql) { } free(pTableMeta); + return TSDB_CODE_SUCCESS; } @@ -2343,7 +2341,7 @@ int tscProcessRetrieveRspFromLocal(SSqlObj *pSql) { void tscTableMetaCallBack(void *param, TAOS_RES *res, int code); -static int32_t doGetMeterMetaFromServer(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { +static int32_t getTableMetaFromMgmt(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { SSqlObj *pNew = calloc(1, sizeof(SSqlObj)); if (NULL == pNew) { tscError("%p malloc failed for new sqlobj to get meter meta", pSql); @@ -2370,7 +2368,7 @@ static int32_t doGetMeterMetaFromServer(SSqlObj *pSql, STableMetaInfo *pTableMet STableMetaInfo *pNewMeterMetaInfo = tscAddEmptyMetaInfo(pNewQueryInfo); assert(pNew->cmd.numOfClause == 1 && pNewQueryInfo->numOfTables == 1); - strcpy(pNewMeterMetaInfo->name, pTableMetaInfo->name); + strncpy(pNewMeterMetaInfo->name, pTableMetaInfo->name, tListLen(pNewMeterMetaInfo->name)); memcpy(pNew->cmd.payload, pSql->cmd.payload, TSDB_DEFAULT_PAYLOAD_SIZE); // tag information if table does not exists. tscTrace("%p new pSqlObj:%p to get tableMeta", pSql, pNew); @@ -2388,7 +2386,7 @@ static int32_t doGetMeterMetaFromServer(SSqlObj *pSql, STableMetaInfo *pTableMet int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { assert(strlen(pTableMetaInfo->name) != 0); - // If this STableMetaInfo owns a metermeta, release it first + // If this STableMetaInfo owns a table meta, release it first if (pTableMetaInfo->pTableMeta != NULL) { taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pTableMeta), false); } @@ -2401,12 +2399,8 @@ int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { return TSDB_CODE_SUCCESS; } - - /* - * for async insert operation, release data block buffer before issue new object to get metermeta - * because in table meta callback function, the tscParse function will generate the submit data blocks - */ - return doGetMeterMetaFromServer(pSql, pTableMetaInfo); + + return getTableMetaFromMgmt(pSql, pTableMetaInfo); } int tscGetMeterMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists) { @@ -2455,7 +2449,7 @@ int tscRenewMeterMeta(SSqlObj *pSql, char *tableId) { tscWaitingForCreateTable(pCmd); taosCacheRelease(tscCacheHandle, (void **)&(pTableMetaInfo->pTableMeta), true); - code = doGetMeterMetaFromServer(pSql, pTableMetaInfo); // todo ?? + code = getTableMetaFromMgmt(pSql, pTableMetaInfo); // todo ?? } else { tscTrace("%p metric query not update metric meta, numOfTags:%d, numOfCols:%d, uid:%" PRId64 ", addr:%p", pSql, tscGetNumOfTags(pTableMetaInfo->pTableMeta), pCmd->numOfCols, pTableMetaInfo->pTableMeta->uid, diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index d62dac088ba73d3bd96720b25a778c1ec273a97c..eb46d6101c72d6fa2aba7d20ee24cd746f6ea7dd 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -651,8 +651,7 @@ static void **tscBuildResFromSubqueries(SSqlObj *pSql) { static void asyncFetchCallback(void *param, TAOS_RES *tres, int numOfRows) { SSqlObj* pSql = (SSqlObj*) tres; - if (numOfRows < 0) { - // set the error code + if (numOfRows < 0) { // set the error code pSql->res.code = -numOfRows; } diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 49e498d22fa32babe6af475023ca4372e1a23348..838b43da1e5978169f4a432e8d6909936bf9b8e0 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -206,14 +206,6 @@ typedef struct SMsgHead { int32_t vgId; } SMsgHead; -// typedef struct { -// SMsgDesc desc; -// SMsgHead header; -// int16_t import; -// int32_t numOfTables; // total number of sid -// char blks[]; // number of data blocks, each table has at least one data block -//} SShellSubmitMsg; - // Submit message for one table typedef struct SSubmitBlk { int64_t uid; // table unique id @@ -683,14 +675,15 @@ typedef struct { } SSuperTableMeta; typedef struct STableMetaMsg { - char tableId[TSDB_TABLE_ID_LEN]; // note: This field must be at the front - int32_t contLen; - uint8_t numOfTags; - uint8_t precision; - uint8_t tableType; - int16_t numOfColumns; - int16_t sversion; - + int32_t contLen; + + char tableId[TSDB_TABLE_ID_LEN]; // table id + char stableId[TSDB_TABLE_ID_LEN]; // stable name if it is created according to super table + uint8_t numOfTags; + uint8_t precision; + uint8_t tableType; + int16_t numOfColumns; + int16_t sversion; int8_t numOfVpeers; SVnodeDesc vpeerDesc[TSDB_VNODES_SUPPORT]; int32_t sid; diff --git a/src/mnode/src/mgmtChildTable.c b/src/mnode/src/mgmtChildTable.c index 58cee331b30d315078155a47c0deacdd610b5015..4936c941ca61d987972f83c330128217e7dbe4a7 100644 --- a/src/mnode/src/mgmtChildTable.c +++ b/src/mnode/src/mgmtChildTable.c @@ -728,6 +728,7 @@ static int32_t mgmtDoGetChildTableMeta(SDbObj *pDb, SChildTableObj *pTable, STab pMeta->numOfTags = 0; pMeta->numOfColumns = htons((int16_t)pTable->superTable->numOfColumns); pMeta->contLen = sizeof(STableMetaMsg) + mgmtSetSchemaFromSuperTable(pMeta->schema, pTable->superTable); + strncpy(pMeta->stableId, pTable->superTable->info.tableId, tListLen(pMeta->stableId)); } else { pMeta->sversion = htons(pTable->sversion); pMeta->numOfTags = 0;