enh: support drop table with uid

This commit is contained in:
kailixu 2024-09-17 10:33:38 +08:00
parent cd358de7ce
commit 302c08331f
10 changed files with 89 additions and 47 deletions

View File

@ -96,7 +96,7 @@ typedef struct SCatalogReq {
SArray* pView; // element is STablesReq
SArray* pTableTSMAs; // element is STablesReq
SArray* pTSMAs; // element is STablesReq
SArray* pTableUid; // element is STablesReq
SArray* pTableName; // element is STablesReq
bool qNodeRequired; // valid qnode
bool dNodeRequired; // valid dnode
bool svrVerRequired;

View File

@ -92,7 +92,7 @@ typedef struct SParseContext {
bool isAudit;
bool nodeOffline;
bool isStmtBind;
bool withOpt;
// bool withOpt;
int8_t biMode;
const char* svrVer;
SArray* pTableMetaPos; // sql table pos => catalog data pos

View File

@ -132,7 +132,7 @@ typedef enum {
CTG_TASK_GET_VIEW,
CTG_TASK_GET_TB_TSMA,
CTG_TASK_GET_TSMA,
CTG_TASK_GET_TB_UID,
CTG_TASK_GET_TB_NAME,
} CTG_TASK_TYPE;
typedef enum {
@ -206,12 +206,12 @@ typedef struct SCtgTbMetasCtx {
SArray* pFetchs;
} SCtgTbMetasCtx;
typedef struct SCtgTbUidsCtx {
typedef struct SCtgTbNamesCtx {
int32_t fetchNum;
SArray* pNames;
SArray* pResList;
SArray* pFetchs;
} SCtgTbUidsCtx;
} SCtgTbNamesCtx;
typedef struct SCtgTbIndexCtx {
SName* pName;
@ -429,7 +429,7 @@ typedef struct SCtgJob {
int32_t viewNum;
int32_t tbTsmaNum;
int32_t tsmaNum; // currently, only 1 is possible
int32_t tbUidNum;
int32_t tbNameNum;
} SCtgJob;
typedef struct SCtgMsgCtx {
@ -807,7 +807,7 @@ typedef struct SCtgCacheItemInfo {
#define CTG_IS_BATCH_TASK(_taskType) \
((CTG_TASK_GET_TB_META_BATCH == (_taskType)) || (CTG_TASK_GET_TB_HASH_BATCH == (_taskType)) || \
(CTG_TASK_GET_VIEW == (_taskType)) || (CTG_TASK_GET_TB_TSMA == (_taskType)) || \
(CTG_TASK_GET_TB_UID == (_taskType)))
(CTG_TASK_GET_TB_NAME == (_taskType)))
#define CTG_GET_TASK_MSGCTX(_task, _id) \
(CTG_IS_BATCH_TASK((_task)->type) ? taosArrayGet((_task)->msgCtxs, (_id)) : &(_task)->msgCtx)
@ -1006,7 +1006,7 @@ int32_t ctgRemoveTbMetaFromCache(SCatalog* pCtg, SName* pTableName, bool syncReq
int32_t ctgGetTbMetaFromCache(SCatalog* pCtg, SCtgTbMetaCtx* ctx, STableMeta** pTableMeta);
int32_t ctgGetTbMetasFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbMetasCtx* ctx, int32_t dbIdx,
int32_t* fetchIdx, int32_t baseResIdx, SArray* pList);
int32_t ctgGetTbUidsFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbUidsCtx* ctx, int32_t dbIdx,
int32_t ctgGetTbUidsFromCache(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgTbNamesCtx* ctx, int32_t dbIdx,
int32_t* fetchIdx, int32_t baseResIdx, SArray* pList);
int32_t ctgCloneDbCfgInfo(void* pSrc, SDbCfgInfo** ppDst);

View File

@ -588,21 +588,21 @@ int32_t ctgInitGetTSMATask(SCtgJob* pJob, int32_t taskId, void* param) {
return TSDB_CODE_SUCCESS;
}
static int32_t ctgInitGetTbUidTask(SCtgJob* pJob, int32_t taskId, void* param) {
static int32_t ctgInitGetTbNamesTask(SCtgJob* pJob, int32_t taskId, void* param) {
SCtgTask task = {0};
task.type = CTG_TASK_GET_TB_UID;
task.type = CTG_TASK_GET_TB_NAME;
task.taskId = taskId;
task.pJob = pJob;
SCtgTbUidsCtx* pTaskCtx = taosMemoryCalloc(1, sizeof(SCtgTbTSMACtx));
SCtgTbNamesCtx* pTaskCtx = taosMemoryCalloc(1, sizeof(SCtgTbNamesCtx));
if (NULL == pTaskCtx) {
CTG_ERR_RET(terrno);
}
task.taskCtx = pTaskCtx;
pTaskCtx->pNames = param;
pTaskCtx->pResList = taosArrayInit(pJob->tbUidNum, sizeof(SMetaRes));
pTaskCtx->pResList = taosArrayInit(pJob->tbNameNum, sizeof(SMetaRes));
if (NULL == pTaskCtx->pResList) {
qError("qid:0x%" PRIx64 " taosArrayInit %d SMetaRes %d failed", pJob->queryId, pJob->tbUidNum,
qError("qid:0x%" PRIx64 " taosArrayInit %d SMetaRes %d failed", pJob->queryId, pJob->tbNameNum,
(int32_t)sizeof(SMetaRes));
ctgFreeTask(&task, true);
CTG_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
@ -850,10 +850,10 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
int32_t viewNum = (int32_t)ctgGetTablesReqNum(pReq->pView);
int32_t tbTsmaNum = (int32_t)taosArrayGetSize(pReq->pTableTSMAs);
int32_t tsmaNum = (int32_t)taosArrayGetSize(pReq->pTSMAs);
int32_t tbUidNum = (int32_t)taosArrayGetSize(pReq->pTableUid);
int32_t tbNameNum = (int32_t)taosArrayGetSize(pReq->pTableName);
int32_t taskNum = tbMetaNum + dbVgNum + udfNum + tbHashNum + qnodeNum + dnodeNum + svrVerNum + dbCfgNum + indexNum +
userNum + dbInfoNum + tbIndexNum + tbCfgNum + tbTagNum + viewNum + tbTsmaNum + tbUidNum;
userNum + dbInfoNum + tbIndexNum + tbCfgNum + tbTagNum + viewNum + tbTsmaNum + tbNameNum;
*job = taosMemoryCalloc(1, sizeof(SCtgJob));
if (NULL == *job) {
@ -888,7 +888,7 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
pJob->viewNum = viewNum;
pJob->tbTsmaNum = tbTsmaNum;
pJob->tsmaNum = tsmaNum;
pJob->tbUidNum = tbUidNum;
pJob->tbNameNum = tbNameNum;
#if CTG_BATCH_FETCH
pJob->pBatchs =
@ -1021,8 +1021,8 @@ int32_t ctgInitJob(SCatalog* pCtg, SRequestConnInfo* pConn, SCtgJob** job, const
if (tsmaNum > 0) {
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_TSMA, pReq->pTSMAs, NULL));
}
if(tbUidNum > 0) {
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_TB_UID, pReq->pTableUid, NULL));
if (tbNameNum > 0) {
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_TB_NAME, pReq->pTableName, NULL));
}
if (qnodeNum) {
CTG_ERR_JRET(ctgInitTask(pJob, CTG_TASK_GET_QNODE, NULL, NULL));
@ -1092,7 +1092,7 @@ int32_t ctgDumpTbMetasRes(SCtgTask* pTask) {
return TSDB_CODE_SUCCESS;
}
int32_t ctgDumpTbUidsRes(SCtgTask* pTask) {
static int32_t ctgDumpTbNamesRes(SCtgTask* pTask) {
if (pTask->subTask) {
return TSDB_CODE_SUCCESS;
}
@ -1903,14 +1903,14 @@ _return:
CTG_RET(code);
}
static int32_t ctgHandleGetTbUidsRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) {
static int32_t ctgHandleGetTbNamesRsp(SCtgTaskReq* tReq, int32_t reqType, const SDataBuf* pMsg, int32_t rspCode) {
int32_t code = 0;
SCtgDBCache* dbCache = NULL;
SCtgTask* pTask = tReq->pTask;
SCatalog* pCtg = pTask->pJob->pCtg;
SRequestConnInfo* pConn = &pTask->pJob->conn;
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx);
SCtgTbUidsCtx* ctx = (SCtgTbUidsCtx*)pTask->taskCtx;
SCtgTbNamesCtx* ctx = (SCtgTbNamesCtx*)pTask->taskCtx;
bool taskDone = false;
if (NULL == pMsgCtx) {
@ -3988,10 +3988,10 @@ int32_t ctgLaunchGetTSMATask(SCtgTask* pTask) {
return TSDB_CODE_SUCCESS;
}
int32_t ctgLaunchGetTbUidTask(SCtgTask* pTask) {
static int32_t ctgLaunchGetTbNamesTask(SCtgTask* pTask) {
SCatalog* pCtg = pTask->pJob->pCtg;
SRequestConnInfo* pConn = &pTask->pJob->conn;
SCtgTbUidsCtx* pCtx = (SCtgTbUidsCtx*)pTask->taskCtx;
SCtgTbNamesCtx* pCtx = (SCtgTbNamesCtx*)pTask->taskCtx;
SCtgJob* pJob = pTask->pJob;
SName* pName = NULL;
@ -4198,7 +4198,7 @@ SCtgAsyncFps gCtgAsyncFps[] = {
{ctgInitGetViewsTask, ctgLaunchGetViewsTask, ctgHandleGetViewsRsp, ctgDumpViewsRes, NULL, NULL},
{ctgInitGetTbTSMATask, ctgLaunchGetTbTSMATask, ctgHandleGetTbTSMARsp, ctgDumpTbTSMARes, NULL, NULL},
{ctgInitGetTSMATask, ctgLaunchGetTSMATask, ctgHandleGetTSMARsp, ctgDumpTSMARes, NULL, NULL},
{ctgInitGetTbUidTask, ctgLaunchGetTbUidTask, ctgHandleGetTbUidsRsp, ctgDumpTbUidsRes, NULL, NULL},
{ctgInitGetTbNamesTask, ctgLaunchGetTbNamesTask, ctgHandleGetTbNamesRsp, ctgDumpTbNamesRes, NULL, NULL},
};
int32_t ctgMakeAsyncRes(SCtgJob* pJob) {

View File

@ -3691,7 +3691,7 @@ _return:
CTG_RET(code);
}
int32_t ctgGetTbUidsFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbUidsCtx *ctx, int32_t dbIdx,
int32_t ctgGetTbUidsFromCache(SCatalog *pCtg, SRequestConnInfo *pConn, SCtgTbNamesCtx *ctx, int32_t dbIdx,
int32_t *fetchIdx, int32_t baseResIdx, SArray *pList) {
int32_t tbNum = taosArrayGetSize(pList);
char dbFName[TSDB_DB_FNAME_LEN] = {0};

View File

@ -614,8 +614,8 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT
ctgError("fail to get %d SName, totalTables:%d", pFetch->tbIdx, (int32_t)taosArrayGetSize(pTbReq->pTables));
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
}
} else if (CTG_TASK_GET_TB_UID == pTask->type) {
SCtgTbUidsCtx* ctx = (SCtgTbUidsCtx*)pTask->taskCtx;
} else if (CTG_TASK_GET_TB_NAME == pTask->type) {
SCtgTbNamesCtx* ctx = (SCtgTbNamesCtx*)pTask->taskCtx;
SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx);
CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName));
} else {
@ -1351,7 +1351,7 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa
vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port, tbFName);
SBuildTableInput bInput = {.vgId = vgroupInfo->vgId,
.option = pTask && pTask->type == CTG_TASK_GET_TB_UID ? 0x01 : 0x00,
.option = pTask && pTask->type == CTG_TASK_GET_TB_NAME ? 0x01 : 0x00,
.dbFName = dbFName,
.tbName = (char*)tNameGetTableName(pTableName)};
char* msg = NULL;

View File

@ -111,8 +111,8 @@ char* ctgTaskTypeStr(CTG_TASK_TYPE type) {
return "[get table TSMA]";
case CTG_TASK_GET_TSMA:
return "[get TSMA]";
case CTG_TASK_GET_TB_UID:
return "[bget table uid]";
case CTG_TASK_GET_TB_NAME:
return "[bget table name]";
default:
return "unknown";
}
@ -846,7 +846,7 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void** pRes) {
*pRes = NULL;
break;
}
case CTG_TASK_GET_TB_UID: {
case CTG_TASK_GET_TB_NAME: {
SArray* pArray = (SArray*)*pRes;
int32_t num = taosArrayGetSize(pArray);
for (int32_t i = 0; i < num; ++i) {
@ -917,7 +917,7 @@ void ctgFreeSubTaskRes(CTG_TASK_TYPE type, void** pRes) {
*pRes = NULL;
break;
}
case CTG_TASK_GET_TB_UID: {
case CTG_TASK_GET_TB_NAME: {
taosArrayDestroyEx(*pRes, ctgFreeBatchMeta);
*pRes = NULL;
break;
@ -1032,8 +1032,8 @@ void ctgFreeTaskCtx(SCtgTask* pTask) {
taosMemoryFreeClear(pTask->taskCtx);
break;
}
case CTG_TASK_GET_TB_UID: {
SCtgTbUidsCtx* taskCtx = (SCtgTbUidsCtx*)pTask->taskCtx;
case CTG_TASK_GET_TB_NAME: {
SCtgTbNamesCtx* taskCtx = (SCtgTbNamesCtx*)pTask->taskCtx;
taosArrayDestroyEx(taskCtx->pResList, ctgFreeBatchMeta);
taosArrayDestroy(taskCtx->pFetchs);
// NO NEED TO FREE pNames

View File

@ -111,12 +111,11 @@ typedef struct SParseMetaCache {
SHashObj* pTableCfg; // key is tbFName, element is STableCfg*
SHashObj* pViews; // key is viewFName, element is SViewMeta*
SHashObj* pTableTSMAs; // key is tbFName, elements are SArray<STableTSMAInfo*>
SHashObj* pTSMAs; // key is tsmaFName, elemetns are STableTSMAInfo*
SHashObj* pTableUid; // key is tbUid, elemetn is STableMeta*
SHashObj* pTSMAs; // key is tsmaFName, elements are STableTSMAInfo*
SHashObj* pTableName; // key is tbFUid, elements is tbName
SArray* pDnodes; // element is SEpSet
bool dnodeRequired;
bool qnodeRequired;
bool fromTableUid;
} SParseMetaCache;
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
@ -163,6 +162,7 @@ int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache);
int32_t reserveTableTSMAInfoInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
int32_t reserveTSMAInfoInCache(int32_t acctId, const char* pDb, const char* pTsmaName, SParseMetaCache* pMetaCache);
int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
int32_t getTableNameFromCache(SParseMetaCache* pMetaCache, const SName* pName, char* pTbName);
int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta);
int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo);

View File

@ -478,12 +478,42 @@ static int32_t getViewMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCac
}
#endif
static int32_t getTargetNameImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName,
char* pTbName) {
int32_t code = TSDB_CODE_SUCCESS;
if (pParCxt->async) {
code = getTableNameFromCache(pMetaCache, pName, pTbName);
} else {
code = TSDB_CODE_PAR_INTERNAL_ERROR;
}
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_PAR_TABLE_NOT_EXIST != code) {
parserError("0x%" PRIx64 " catalogGetTableMeta error, code:%s, dbName:%s, tbName:%s", pParCxt->requestId,
tstrerror(code), pName->dbname, pName->tname);
}
return code;
}
static int32_t getTargetName(STranslateContext* pCxt, const SName* pName, char* pTbName) {
SParseContext* pParCxt = pCxt->pParseCxt;
int32_t code = collectUseDatabase(pName, pCxt->pDbs);
if (TSDB_CODE_SUCCESS == code) {
code = collectUseTable(pName, pCxt->pTables);
}
if (TSDB_CODE_SUCCESS == code) {
code = getTargetNameImpl(pParCxt, pCxt->pMetaCache, pName, pTbName);
}
if (TSDB_CODE_SUCCESS != code && TSDB_CODE_PAR_TABLE_NOT_EXIST != code) {
parserError("0x%" PRIx64 " catalogGetTableMeta error, code:%s, dbName:%s, tbName:%s", pCxt->pParseCxt->requestId,
tstrerror(code), pName->dbname, pName->tname);
}
return code;
}
int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta,
bool couldBeView) {
int32_t code = TSDB_CODE_SUCCESS;
if (pParCxt->async) {
if (pParCxt->withOpt) pMetaCache->fromTableUid = true;
code = getTableMetaFromCache(pMetaCache, pName, pMeta);
#ifdef TD_ENTERPRISE
if ((TSDB_CODE_PAR_TABLE_NOT_EXIST == code || TSDB_CODE_PAR_INTERNAL_ERROR == code) && couldBeView) {
@ -14431,7 +14461,6 @@ int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut)
static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SDropTableStmt* pStmt) {
if (!pStmt->withOpt) return TSDB_CODE_SUCCESS;
pCxt->pParseCxt->withOpt = pStmt->withOpt;
SNode* pNode = NULL;
FOREACH(pNode, pStmt->pTables) {

View File

@ -805,7 +805,7 @@ int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalog
code = buildTableReqFromDb(pMetaCache->pTSMAs, &pCatalogReq->pTSMAs);
}
if (TSDB_CODE_SUCCESS == code) {
code = buildTableReqFromDb(pMetaCache->pTableUid, &pCatalogReq->pTableUid);
code = buildTableReqFromDb(pMetaCache->pTableName, &pCatalogReq->pTableName);
}
#ifdef TD_ENTERPRISE
if (TSDB_CODE_SUCCESS == code) {
@ -965,7 +965,7 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet
code = putDbTableDataToCache(pCatalogReq->pTSMAs, pMetaData->pTsmas, &pMetaCache->pTSMAs);
}
if (TSDB_CODE_SUCCESS == code) {
code = putDbTableDataToCache(pCatalogReq->pTableUid, pMetaData->pTableMeta, &pMetaCache->pTableUid);
code = putDbTableDataToCache(pCatalogReq->pTableName, pMetaData->pTableMeta, &pMetaCache->pTableName);
}
#ifdef TD_ENTERPRISE
if (TSDB_CODE_SUCCESS == code) {
@ -1027,7 +1027,7 @@ int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCac
}
int32_t reserveTableUidInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache) {
return reserveTableReqInDbCache(acctId, pDb, pTable, &pMetaCache->pTableUid);
return reserveTableReqInDbCache(acctId, pDb, pTable, &pMetaCache->pTableName);
}
int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) {
@ -1037,9 +1037,7 @@ int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, S
return code;
}
STableMeta* pTableMeta = NULL;
code = getMetaDataFromHash(fullName, strlen(fullName),
pMetaCache->fromTableUid ? pMetaCache->pTableUid : pMetaCache->pTableMeta,
(void**)&pTableMeta);
code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableMeta, (void**)&pTableMeta);
if (TSDB_CODE_SUCCESS == code) {
*pMeta = tableMetaDup(pTableMeta);
if (NULL == *pMeta) {
@ -1049,6 +1047,21 @@ int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, S
return code;
}
int32_t getTableNameFromCache(SParseMetaCache* pMetaCache, const SName* pName, char* pTbName) {
char fullName[TSDB_TABLE_FNAME_LEN];
int32_t code = tNameExtractFullName(pName, fullName);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
const char* pTableName = NULL;
code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableName,
(void**)&pTableName);
if (TSDB_CODE_SUCCESS == code) {
tstrncpy(pTbName, pTableName, TSDB_TABLE_NAME_LEN);
}
return code;
}
int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta) {
*pMeta = taosMemoryCalloc(1, sizeof(STableMeta) + pViewMeta->numOfCols * sizeof(SSchema));
if (NULL == *pMeta) {
@ -1389,13 +1402,13 @@ void destoryParseMetaCache(SParseMetaCache* pMetaCache, bool request) {
destoryParseTablesMetaReqHash(pMetaCache->pTableVgroup);
destoryParseTablesMetaReqHash(pMetaCache->pViews);
destoryParseTablesMetaReqHash(pMetaCache->pTSMAs);
destoryParseTablesMetaReqHash(pMetaCache->pTableUid);
destoryParseTablesMetaReqHash(pMetaCache->pTableName);
} else {
taosHashCleanup(pMetaCache->pTableMeta);
taosHashCleanup(pMetaCache->pTableVgroup);
taosHashCleanup(pMetaCache->pViews);
taosHashCleanup(pMetaCache->pTSMAs);
taosHashCleanup(pMetaCache->pTableUid);
taosHashCleanup(pMetaCache->pTableName);
}
taosHashCleanup(pMetaCache->pDbVgroup);
taosHashCleanup(pMetaCache->pDbCfg);