diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ac13021477..062cda701e 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -20,13 +20,13 @@ #include "taoserror.h" #include "tarray.h" #include "tcoding.h" +#include "tcol.h" #include "tencode.h" #include "thash.h" #include "tlist.h" #include "tname.h" #include "trow.h" #include "tuuid.h" -#include "tcol.h" #ifdef __cplusplus extern "C" { @@ -154,19 +154,19 @@ typedef enum _mgmt_table { TSDB_MGMT_TABLE_MAX, } EShowType; -#define TSDB_ALTER_TABLE_ADD_TAG 1 -#define TSDB_ALTER_TABLE_DROP_TAG 2 -#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME 3 -#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4 -#define TSDB_ALTER_TABLE_ADD_COLUMN 5 -#define TSDB_ALTER_TABLE_DROP_COLUMN 6 -#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES 7 -#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES 8 -#define TSDB_ALTER_TABLE_UPDATE_OPTIONS 9 -#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME 10 -#define TSDB_ALTER_TABLE_ADD_TAG_INDEX 11 -#define TSDB_ALTER_TABLE_DROP_TAG_INDEX 12 -#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS 13 +#define TSDB_ALTER_TABLE_ADD_TAG 1 +#define TSDB_ALTER_TABLE_DROP_TAG 2 +#define TSDB_ALTER_TABLE_UPDATE_TAG_NAME 3 +#define TSDB_ALTER_TABLE_UPDATE_TAG_VAL 4 +#define TSDB_ALTER_TABLE_ADD_COLUMN 5 +#define TSDB_ALTER_TABLE_DROP_COLUMN 6 +#define TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES 7 +#define TSDB_ALTER_TABLE_UPDATE_TAG_BYTES 8 +#define TSDB_ALTER_TABLE_UPDATE_OPTIONS 9 +#define TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME 10 +#define TSDB_ALTER_TABLE_ADD_TAG_INDEX 11 +#define TSDB_ALTER_TABLE_DROP_TAG_INDEX 12 +#define TSDB_ALTER_TABLE_UPDATE_COLUMN_COMPRESS 13 #define TSDB_FILL_NONE 0 #define TSDB_FILL_NULL 1 @@ -555,7 +555,7 @@ struct SSchemaExt { #define COMPRESS_L1_TYPE_U32(type) (((type) >> 24) & 0xFF) #define COMPRESS_L2_TYPE_U32(type) (((type) >> 8) & 0xFFFF) -#define COMPRESS_L2_TYPE_LEVEL_U32(type) ((type) & 0xFF) +#define COMPRESS_L2_TYPE_LEVEL_U32(type) ((type)&0xFF) // compress flag // |----l2lel--|----l2Alg---|---l1Alg--| @@ -772,14 +772,14 @@ static FORCE_INLINE int32_t tDecodeSSchema(SDecoder* pDecoder, SSchema* pSchema) } static FORCE_INLINE int32_t tEncodeSSchemaExt(SEncoder* pEncoder, const SSchemaExt* pSchemaExt) { - // if (tEncodeI16v(pEncoder, pSchemaExt->colId) < 0) return -1; - // if (tEncodeU32(pEncoder, pSchemaExt->compress) < 0) return -1; + if (tEncodeI16v(pEncoder, pSchemaExt->colId) < 0) return -1; + if (tEncodeU32(pEncoder, pSchemaExt->compress) < 0) return -1; return 0; } static FORCE_INLINE int32_t tDecodeSSchemaExt(SDecoder* pDecoder, SSchemaExt* pSchemaExt) { - // if (tDecodeI16v(pDecoder, &pSchemaExt->colId) < 0) return -1; - // if (tDecodeU32(pDecoder, &pSchemaExt->compress) < 0) return -1; + if (tDecodeI16v(pDecoder, &pSchemaExt->colId) < 0) return -1; + if (tDecodeU32(pDecoder, &pSchemaExt->compress) < 0) return -1; return 0; } @@ -4133,8 +4133,8 @@ int32_t tSerializeSViewMetaRsp(void* buf, int32_t bufLen, const SViewMetaRsp* pR int32_t tDeserializeSViewMetaRsp(void* buf, int32_t bufLen, SViewMetaRsp* pRsp); void tFreeSViewMetaRsp(SViewMetaRsp* pRsp); -void setDefaultOptionsForField(SFieldWithOptions *field); -void setFieldWithOptions(SFieldWithOptions *fieldWithOptions, SField* field); +void setDefaultOptionsForField(SFieldWithOptions* field); +void setFieldWithOptions(SFieldWithOptions* fieldWithOptions, SField* field); #pragma pack(pop) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 625bf32965..b7a65b2bb4 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -53,7 +53,7 @@ #define ENCODESQL() \ do { \ if (tEncodeI32(&encoder, pReq->sqlLen) < 0) return -1; \ - if (pReq->sqlLen > 0) { \ + if (pReq->sqlLen > 0) { \ if (tEncodeBinary(&encoder, pReq->sql, pReq->sqlLen) < 0) return -1; \ } \ } while (0) @@ -4433,9 +4433,11 @@ static int32_t tEncodeSTableMetaRsp(SEncoder *pEncoder, STableMetaRsp *pRsp) { if (tEncodeSSchema(pEncoder, pSchema) < 0) return -1; } - for (int32_t i = 0; i < pRsp->numOfColumns; ++i) { - SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; - if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1; + if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) { + for (int32_t i = 0; i < pRsp->numOfColumns; ++i) { + SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; + if (tEncodeSSchemaExt(pEncoder, pSchemaExt) < 0) return -1; + } } return 0; @@ -4470,18 +4472,24 @@ static int32_t tDecodeSTableMetaRsp(SDecoder *pDecoder, STableMetaRsp *pRsp) { } // if (tDecodeIsEnd(pDecoder)) return 0; - if (pRsp->numOfColumns > 0) { - pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns); - if (pRsp->pSchemaExt == NULL) return -1; + if (!tDecodeIsEnd(pDecoder)) { + if (pRsp->tableType == TSDB_SUPER_TABLE || pRsp->tableType == TSDB_NORMAL_TABLE) { + if (pRsp->numOfColumns > 0) { + pRsp->pSchemaExt = taosMemoryMalloc(sizeof(SSchemaExt) * pRsp->numOfColumns); + if (pRsp->pSchemaExt == NULL) return -1; - for (int32_t i = 0; i < pRsp->numOfColumns; ++i) { - SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; - if (tDecodeSSchemaExt(pDecoder, pSchemaExt) < 0) return -1; - pSchemaExt->colId = i; - pSchemaExt->compress = 0x02000303; + for (int32_t i = 0; i < pRsp->numOfColumns; ++i) { + SSchemaExt *pSchemaExt = &pRsp->pSchemaExt[i]; + if (tDecodeSSchemaExt(pDecoder, pSchemaExt) < 0) return -1; + pSchemaExt->colId = i; + pSchemaExt->compress = 0x02000303; + } + } else { + pRsp->pSchemaExt = NULL; + } + } else { + pRsp->pSchemaExt = NULL; } - } else { - pRsp->pSchemaExt = NULL; } return 0; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 4c81a8ebd0..b6a15d4ef6 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1939,6 +1939,12 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + pRsp->pSchemaExt = taosMemoryCalloc(pStb->numOfColumns, sizeof(SSchemaExt)); + if (pRsp->pSchemaExt == NULL) { + taosRUnLockLatch(&pStb->lock); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } tstrncpy(pRsp->dbFName, pStb->db, sizeof(pRsp->dbFName)); tstrncpy(pRsp->tbName, tbName, sizeof(pRsp->tbName)); @@ -1972,6 +1978,12 @@ static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbNa pSchema->colId = pSrcSchema->colId; pSchema->bytes = pSrcSchema->bytes; } + for (int32_t i = 0; i < pStb->numOfColumns; i++) { + SCmprObj *pCmpr = &pStb->pCmpr[i]; + SSchemaExt *pSchEx = &pRsp->pSchemaExt[i]; + pSchEx->colId = pCmpr->colId; + pSchEx->compress = pCmpr->cmprAlg; + } taosRUnLockLatch(&pStb->lock); return 0; @@ -2027,6 +2039,7 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, if (pStb->numOfFuncs > 0) { pRsp->pFuncs = taosArrayDup(pStb->pFuncs, NULL); } + taosRUnLockLatch(&pStb->lock); return 0; diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index b1440d0347..7f4738938b 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -142,7 +142,8 @@ static char* getSyntaxErrFormat(int32_t errCode) { case TSDB_CODE_PAR_CANNOT_DROP_PRIMARY_KEY: return "Primary timestamp column cannot be dropped"; case TSDB_CODE_PAR_INVALID_MODIFY_COL: - return "Only varbinary/binary/nchar/geometry column length could be modified, and the length can only be increased, not decreased"; + return "Only varbinary/binary/nchar/geometry column length could be modified, and the length can only be " + "increased, not decreased"; case TSDB_CODE_PAR_INVALID_TBNAME: return "Invalid tbname pseudo column"; case TSDB_CODE_PAR_INVALID_FUNCTION_NAME: @@ -265,14 +266,14 @@ int32_t getNumOfTags(const STableMeta* pTableMeta) { return getTableInfo(pTableM STableComInfo getTableInfo(const STableMeta* pTableMeta) { return pTableMeta->tableInfo; } -int32_t getTableTypeFromTableNode(SNode *pTable) { +int32_t getTableTypeFromTableNode(SNode* pTable) { if (NULL == pTable) { return -1; } if (QUERY_NODE_REAL_TABLE != nodeType(pTable)) { return -1; } - return ((SRealTableNode *)pTable)->pMeta->tableType; + return ((SRealTableNode*)pTable)->pMeta->tableType; } STableMeta* tableMetaDup(const STableMeta* pTableMeta) { @@ -707,13 +708,12 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog #ifdef TD_ENTERPRISE if (TSDB_CODE_SUCCESS == code) { code = buildTableReqFromDb(pMetaCache->pTableMeta, &pCatalogReq->pView); - } -#endif + } +#endif pCatalogReq->dNodeRequired = pMetaCache->dnodeRequired; return code; } - SNode* createSelectStmtImpl(bool isDistinct, SNodeList* pProjectionList, SNode* pTable, SNodeList* pHint) { SSelectStmt* select = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT); if (NULL == select) { @@ -848,7 +848,7 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet if (TSDB_CODE_SUCCESS == code) { code = putDbTableDataToCache(pCatalogReq->pView, pMetaData->pView, &pMetaCache->pViews); } -#endif +#endif pMetaCache->pDnodes = pMetaData->pDnodeList; return code; } @@ -930,10 +930,10 @@ int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta) { (*pMeta)->tableInfo.precision = pViewMeta->precision; (*pMeta)->tableInfo.numOfColumns = pViewMeta->numOfCols; memcpy((*pMeta)->schema, pViewMeta->pSchema, sizeof(SSchema) * pViewMeta->numOfCols); - + for (int32_t i = 0; i < pViewMeta->numOfCols; ++i) { (*pMeta)->tableInfo.rowSize += (*pMeta)->schema[i].bytes; - } + } return TSDB_CODE_SUCCESS; } @@ -941,14 +941,13 @@ int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, ST char fullName[TSDB_TABLE_FNAME_LEN]; tNameExtractFullName(pName, fullName); SViewMeta* pViewMeta = NULL; - int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pViews, (void**)&pViewMeta); + int32_t code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pViews, (void**)&pViewMeta); if (TSDB_CODE_SUCCESS == code) { code = buildTableMetaFromViewMeta(pMeta, pViewMeta); } return code; } - static int32_t reserveDbReqInCache(int32_t acctId, const char* pDb, SHashObj** pDbs) { if (NULL == *pDbs) { *pDbs = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK); @@ -1044,15 +1043,13 @@ int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pD return reserveUserAuthInCacheImpl(key, len, pMetaCache); } -int32_t reserveViewUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, AUTH_TYPE type, - SParseMetaCache* pMetaCache) { - char key[USER_AUTH_KEY_MAX_LEN] = {0}; - int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key, true); - return reserveUserAuthInCacheImpl(key, len, pMetaCache); +int32_t reserveViewUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, const char* pTable, + AUTH_TYPE type, SParseMetaCache* pMetaCache) { + char key[USER_AUTH_KEY_MAX_LEN] = {0}; + int32_t len = userAuthToString(acctId, pUser, pDb, pTable, type, key, true); + return reserveUserAuthInCacheImpl(key, len, pMetaCache); } - - int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, SUserAuthInfo* pAuthReq, SUserAuthRes* pAuthRes) { char key[USER_AUTH_KEY_MAX_LEN] = {0}; int32_t len = userAuthToString(pAuthReq->tbName.acctId, pAuthReq->user, pAuthReq->tbName.dbname, @@ -1228,5 +1225,3 @@ int64_t int64SafeSub(int64_t a, int64_t b) { } return res; } - - diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 8198fed77b..b39bd18331 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -24,7 +24,7 @@ #pragma GCC diagnostic ignored "-Wformat-truncation" #endif -int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, +int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallocFp)(int64_t)) = {0}; int32_t (*queryProcessMsgRsp[TDMT_MAX])(void *output, char *msg, int32_t msgSize) = {0}; @@ -43,7 +43,8 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { pOut->dbVgroup->hashSuffix = usedbRsp->hashSuffix; pOut->dbVgroup->stateTs = usedbRsp->stateTs; - qDebug("Got %d vgroup for db %s, vgVersion:%d, stateTs:%" PRId64, usedbRsp->vgNum, usedbRsp->db, usedbRsp->vgVersion, usedbRsp->stateTs); + qDebug("Got %d vgroup for db %s, vgVersion:%d, stateTs:%" PRId64, usedbRsp->vgNum, usedbRsp->db, usedbRsp->vgVersion, + usedbRsp->stateTs); if (usedbRsp->vgNum <= 0) { return TSDB_CODE_SUCCESS; @@ -68,7 +69,7 @@ int32_t queryBuildUseDbOutput(SUseDbOutput *pOut, SUseDbRsp *usedbRsp) { return TSDB_CODE_SUCCESS; } -int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, +int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { SBuildTableInput *pInput = input; if (NULL == input || NULL == msg || NULL == msgLen) { @@ -205,7 +206,7 @@ int32_t queryBuildGetIndexMsg(void *input, char **msg, int32_t msgSize, int32_t return TSDB_CODE_SUCCESS; } -int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, +int32_t queryBuildRetrieveFuncMsg(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void *(*mallcFp)(int64_t)) { if (NULL == msg || NULL == msgLen) { return TSDB_CODE_TSC_INVALID_INPUT; @@ -291,7 +292,7 @@ int32_t queryBuildGetViewMetaMsg(void *input, char **msg, int32_t msgSize, int32 return TSDB_CODE_TSC_INVALID_INPUT; } - SViewMetaReq req = {0}; + SViewMetaReq req = {0}; strncpy(req.fullname, input, sizeof(req.fullname) - 1); int32_t bufLen = tSerializeSViewMetaReq(NULL, 0, &req); @@ -408,7 +409,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * qError("calloc size[%d] failed", metaSize); return TSDB_CODE_OUT_OF_MEMORY; } - SSchemaExt* pSchemaExt = (SSchemaExt*)((char*)pTableMeta + metaSize); + SSchemaExt *pSchemaExt = (SSchemaExt *)((char *)pTableMeta + metaSize); pTableMeta->vgId = isStb ? 0 : msg->vgId; pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType; @@ -421,15 +422,18 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta * pTableMeta->tableInfo.precision = msg->precision; pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; - pTableMeta->schemaExt = pSchemaExt; - memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total); - memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize); + if (pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_NORMAL_TABLE) { + pTableMeta->schemaExt = pSchemaExt; + memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total); + memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize); + } for (int32_t i = 0; i < msg->numOfColumns; ++i) { pTableMeta->tableInfo.rowSize += pTableMeta->schema[i].bytes; } - qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s stb %s suid %" PRIx64 " sver %d tver %d" + qDebug("table %s uid %" PRIx64 " meta returned, type %d vgId:%d db %s stb %s suid %" PRIx64 + " sver %d tver %d" " tagNum %d colNum %d precision %d rowSize %d", msg->tbName, pTableMeta->uid, pTableMeta->tableType, pTableMeta->vgId, msg->dbFName, msg->stbName, pTableMeta->suid, pTableMeta->sversion, pTableMeta->tversion, pTableMeta->tableInfo.numOfTags, @@ -610,7 +614,7 @@ int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) { memcpy(output, funcInfo, sizeof(*funcInfo)); taosArrayDestroy(out.pFuncInfos); taosArrayDestroy(out.pFuncExtraInfos); - + return TSDB_CODE_SUCCESS; } @@ -679,7 +683,6 @@ int32_t queryProcessGetViewMetaRsp(void *output, char *msg, int32_t msgSize) { return TSDB_CODE_SUCCESS; } - void initQueryModuleMsgHandle() { queryBuildMsg[TMSG_INDEX(TDMT_VND_TABLE_META)] = queryBuildTableMetaReqMsg; queryBuildMsg[TMSG_INDEX(TDMT_MND_TABLE_META)] = queryBuildTableMetaReqMsg;