From 9cc0702a7775f6522c0ec6c2bcf6df16d36a8b9b Mon Sep 17 00:00:00 2001 From: kailixu Date: Thu, 19 Sep 2024 18:34:49 +0800 Subject: [PATCH] enh: drop table with uid --- include/common/tmsg.h | 4 +++- include/libs/parser/parser.h | 5 ++--- include/libs/qcom/query.h | 1 - source/common/src/tmsg.c | 6 +++--- source/dnode/vnode/src/vnd/vnodeQuery.c | 8 ++++---- source/libs/catalog/src/ctgAsync.c | 4 ++-- source/libs/catalog/src/ctgRemote.c | 4 ++-- source/libs/parser/inc/parUtil.h | 1 - source/libs/parser/src/parAstParser.c | 2 -- source/libs/parser/src/parTranslater.c | 9 ++++----- source/libs/qcom/src/querymsg.c | 7 ++++--- tools/shell/src/shellAuto.c | 3 --- 12 files changed, 24 insertions(+), 30 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 98e0f02522..9395c30f29 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -2046,11 +2046,13 @@ typedef struct { int32_t tSerializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq); int32_t tDeserializeSAlterVnodeHashRangeReq(void* buf, int32_t bufLen, SAlterVnodeHashRangeReq* pReq); +#define REQ_OPT_TBNAME 0x0 +#define REQ_OPT_TBUID 0x01 typedef struct { SMsgHead header; char dbFName[TSDB_DB_FNAME_LEN]; char tbName[TSDB_TABLE_NAME_LEN]; - uint8_t option; // 0x01 for table uid + uint8_t option; } STableInfoReq; int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq); diff --git a/include/libs/parser/parser.h b/include/libs/parser/parser.h index 8ada0d0a5f..7271da8ff6 100644 --- a/include/libs/parser/parser.h +++ b/include/libs/parser/parser.h @@ -72,6 +72,7 @@ typedef struct SParseContext { int64_t requestRid; int32_t acctId; const char* db; + bool topicQuery; void* pTransporter; SEpSet mgmtEpSet; const char* pSql; // sql string @@ -82,7 +83,6 @@ typedef struct SParseContext { SStmtCallback* pStmtCb; const char* pUser; const char* pEffectiveUser; - bool topicQuery; bool parseOnly; bool isSuperUser; bool enableSysInfo; @@ -92,14 +92,13 @@ typedef struct SParseContext { bool isAudit; bool nodeOffline; bool isStmtBind; - // bool withOpt; - int8_t biMode; const char* svrVer; SArray* pTableMetaPos; // sql table pos => catalog data pos SArray* pTableVgroupPos; // sql table pos => catalog data pos int64_t allocatorId; parseSqlFn parseSqlFp; void* parseSqlParam; + int8_t biMode; SArray* pSubMetaList; setQueryFn setQueryFp; } SParseContext; diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 47426353ce..bcb1aa90d1 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -123,7 +123,6 @@ typedef struct STableMeta { // the schema content. SSchema schema[]; } STableMeta; - #pragma pack(pop) typedef struct SViewMeta { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 48f504b050..557ac07bbd 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -5761,10 +5761,10 @@ int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq TAOS_CHECK_EXIT(tStartDecode(&decoder)); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName)); TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->tbName)); - if (tDecodeIsEnd(&decoder)) { - pReq->option = 0; - } else { + if (!tDecodeIsEnd(&decoder)) { TAOS_CHECK_EXIT(tDecodeU8(&decoder, &pReq->option)); + } else { + pReq->option = 0; } tEndDecode(&decoder); diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 889e873f78..333246dacd 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -55,7 +55,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { SMetaReader mer1 = {0}; SMetaReader mer2 = {0}; char tableFName[TSDB_TABLE_FNAME_LEN]; - bool reqFromUid = false; + bool optTbUid = false; SRpcMsg rpcMsg = {0}; int32_t code = 0; int32_t rspLen = 0; @@ -69,12 +69,12 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { goto _exit4; } - if (infoReq.option == 0x01) reqFromUid = true; + if (infoReq.option == REQ_OPT_TBUID) optTbUid = true; metaRsp.dbId = pVnode->config.dbId; (void)strcpy(metaRsp.tbName, infoReq.tbName); (void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName)); - if (!reqFromUid) { + if (!optTbUid) { TAOS_UNUSED(sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName)); code = vnodeValidateTableHash(pVnode, tableFName); if (code) { @@ -84,7 +84,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) { // query meta metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK); - if (reqFromUid) { + if (optTbUid) { uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10); if (errno == ERANGE || tbUid == 0) { code = TSDB_CODE_TDB_TABLE_NOT_EXIST; diff --git a/source/libs/catalog/src/ctgAsync.c b/source/libs/catalog/src/ctgAsync.c index 9bfac46fe8..fac1269f85 100644 --- a/source/libs/catalog/src/ctgAsync.c +++ b/source/libs/catalog/src/ctgAsync.c @@ -599,9 +599,9 @@ static int32_t ctgInitGetTbNamesTask(SCtgJob* pJob, int32_t taskId, void* param) CTG_ERR_RET(terrno); } task.taskCtx = pTaskCtx; + taosInitRWLatch(&pTaskCtx->lock); pTaskCtx->pNames = param; pTaskCtx->pResList = taosArrayInit(pJob->tbNameNum, sizeof(SMetaRes)); - taosInitRWLatch(&pTaskCtx->lock); if (NULL == pTaskCtx->pResList) { qError("qid:0x%" PRIx64 " taosArrayInit %d SMetaRes %d failed", pJob->queryId, pJob->tbNameNum, (int32_t)sizeof(SMetaRes)); @@ -2083,7 +2083,7 @@ _return: } } } else { - pRes->pRes == NULL; + pRes->pRes = NULL; pRes->code = code; } if (taskDone == true) { diff --git a/source/libs/catalog/src/ctgRemote.c b/source/libs/catalog/src/ctgRemote.c index 4caa9f056d..d7d1512385 100644 --- a/source/libs/catalog/src/ctgRemote.c +++ b/source/libs/catalog/src/ctgRemote.c @@ -669,7 +669,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT (void)tNameGetFullDbName(pName, newBatch.dbFName); } - newBatch.msgType = (vgId > 1) ? TDMT_VND_BATCH_META : TDMT_MND_BATCH_META; + newBatch.msgType = (vgId > 0) ? TDMT_VND_BATCH_META : TDMT_MND_BATCH_META; newBatch.batchId = atomic_add_fetch_32(&pJob->batchId, 1); if (0 != taosHashPut(pBatchs, &vgId, sizeof(vgId), &newBatch, sizeof(newBatch))) { @@ -1376,7 +1376,7 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port, tbFName); SBuildTableInput bInput = {.vgId = vgroupInfo->vgId, - .option = reqType == TDMT_VND_TABLE_NAME ? 0x01 : 0x00, + .option = reqType == TDMT_VND_TABLE_NAME ? REQ_OPT_TBNAME : REQ_OPT_TBUID, .dbFName = dbFName, .tbName = (char*)tNameGetTableName(pTableName)}; char* msg = NULL; diff --git a/source/libs/parser/inc/parUtil.h b/source/libs/parser/inc/parUtil.h index 7a20eeb90a..857c7604a9 100644 --- a/source/libs/parser/inc/parUtil.h +++ b/source/libs/parser/inc/parUtil.h @@ -115,7 +115,6 @@ typedef struct SParseMetaCache { SHashObj* pTableName; // key is tbFUid, elements is STableMeta*(append with tbName) SArray* pDnodes; // element is SEpSet bool dnodeRequired; - bool qnodeRequired; } SParseMetaCache; int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...); diff --git a/source/libs/parser/src/parAstParser.c b/source/libs/parser/src/parAstParser.c index c73cd7f98c..f4dd91f392 100644 --- a/source/libs/parser/src/parAstParser.c +++ b/source/libs/parser/src/parAstParser.c @@ -389,12 +389,10 @@ static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableS } } else { code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); - if (TSDB_CODE_SUCCESS == code) { code = reserveTableVgroupInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache); } - if (TSDB_CODE_SUCCESS == code) { code = reserveUserAuthInCache(pCxt->pParseCxt->acctId, pCxt->pParseCxt->pUser, pClause->dbName, pClause->tableName, AUTH_TYPE_WRITE, pCxt->pMetaCache); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index b5449f819b..8abe212630 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -14523,8 +14523,8 @@ int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut) return code; } -static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SQuery* pQuery) { - int32_t code = TSDB_CODE_SUCCESS; +static int32_t rewriteDropTableWithOpt(STranslateContext* pCxt, SQuery* pQuery) { + int32_t code = TSDB_CODE_SUCCESS; SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot; if (!pStmt->withOpt) return code; pCxt->withOpt = true; @@ -14533,7 +14533,6 @@ static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SQuery* pQuery) char pTableName[TSDB_TABLE_NAME_LEN] = {0}; FOREACH(pNode, pStmt->pTables) { SDropTableClause* pClause = (SDropTableClause*)pNode; - SName name = {0}; toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name); int32_t code = getTargetName(pCxt, &name, pTableName); @@ -14554,7 +14553,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { SNode* pNode; SArray* pTsmas = NULL; - TAOS_CHECK_RETURN(rewriteDropTablewithOpt(pCxt, pQuery)); + TAOS_CHECK_RETURN(rewriteDropTableWithOpt(pCxt, pQuery)); SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); if (NULL == pVgroupHashmap) { @@ -14575,7 +14574,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) { taosHashCleanup(pVgroupHashmap); return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DROP_STABLE); } - if (pCxt->withOpt) continue; + if (pCxt->withOpt) continue; // TODO if (pCxt->pMetaCache) code = getTableTsmasFromCache(pCxt->pMetaCache, &name, &pTsmas); if (TSDB_CODE_SUCCESS != code) { taosHashCleanup(pVgroupHashmap); diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 793e748a71..c784e7a2a2 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -76,7 +76,8 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3 return TSDB_CODE_TSC_INVALID_INPUT; } - STableInfoReq infoReq = {.option = pInput->option}; + STableInfoReq infoReq = {0}; + infoReq.option = pInput->option; infoReq.header.vgId = pInput->vgId; if (pInput->dbFName) { tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN); @@ -627,10 +628,10 @@ int32_t queryCreateTableMetaExFromMsg(STableMetaRsp *msg, bool isStb, STableMeta pTableMeta->tableInfo.precision = msg->precision; pTableMeta->tableInfo.numOfColumns = msg->numOfColumns; - memcpy(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total); + TAOS_MEMCPY(pTableMeta->schema, msg->pSchemas, sizeof(SSchema) * total); if (useCompress(msg->tableType) && msg->pSchemaExt) { pTableMeta->schemaExt = pSchemaExt; - memcpy(pSchemaExt, msg->pSchemaExt, schemaExtSize); + TAOS_MEMCPY(pSchemaExt, msg->pSchemaExt, schemaExtSize); } else { pTableMeta->schemaExt = NULL; } diff --git a/tools/shell/src/shellAuto.c b/tools/shell/src/shellAuto.c index 0ab150dbae..1a661beb0e 100644 --- a/tools/shell/src/shellAuto.c +++ b/tools/shell/src/shellAuto.c @@ -956,8 +956,6 @@ void* varObtainThread(void* param) { // return true is need update value by async bool updateTireValue(int type, bool autoFill) { // TYPE CONTEXT GET FROM DB - return true; -#if 0 taosThreadMutexLock(&tiresMutex); // check need obtain from server @@ -984,7 +982,6 @@ bool updateTireValue(int type, bool autoFill) { } taosThreadMutexUnlock(&tiresMutex); return false; -#endif } // only match next one word from all match words, return valuue must free by caller