enh: support drop table with uid

This commit is contained in:
kailixu 2024-09-16 18:54:53 +08:00
parent a6c76329fc
commit cd358de7ce
7 changed files with 37 additions and 24 deletions

View File

@ -72,7 +72,6 @@ typedef struct SParseContext {
int64_t requestRid;
int32_t acctId;
const char* db;
bool topicQuery;
void* pTransporter;
SEpSet mgmtEpSet;
const char* pSql; // sql string
@ -83,6 +82,7 @@ typedef struct SParseContext {
SStmtCallback* pStmtCb;
const char* pUser;
const char* pEffectiveUser;
bool topicQuery;
bool parseOnly;
bool isSuperUser;
bool enableSysInfo;
@ -92,13 +92,14 @@ 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;

View File

@ -84,19 +84,18 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
// query meta
metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
if (reqFromUid) {
uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
if (errno == ERANGE || tbUid == 0) {
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
goto _exit3;
}
char tbName[TSDB_TABLE_NAME_LEN] = {0};
char tbName[TSDB_TABLE_NAME_LEN + VARSTR_HEADER_SIZE] = {0};
if (metaGetTableNameByUid(pVnode, tbUid, tbName) < 0) {
code = terrno;
goto _exit3;
}
if (metaGetTableEntryByName(&mer1, tbName) < 0) {
if (metaGetTableEntryByName(&mer1, tbName + VARSTR_HEADER_SIZE) < 0) {
code = terrno;
goto _exit3;
}

View File

@ -1910,7 +1910,7 @@ static int32_t ctgHandleGetTbUidsRsp(SCtgTaskReq* tReq, int32_t reqType, const S
SCatalog* pCtg = pTask->pJob->pCtg;
SRequestConnInfo* pConn = &pTask->pJob->conn;
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx);
SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx;
SCtgTbUidsCtx* ctx = (SCtgTbUidsCtx*)pTask->taskCtx;
bool taskDone = false;
if (NULL == pMsgCtx) {

View File

@ -43,6 +43,7 @@ typedef struct STranslateContext {
bool createStream;
bool stableQuery;
bool showRewrite;
bool withOpt;
SNode* pPrevRoot;
SNode* pPostRoot;
bool dual; // whether select stmt without from stmt, true for without.

View File

@ -116,6 +116,7 @@ typedef struct SParseMetaCache {
SArray* pDnodes; // element is SEpSet
bool dnodeRequired;
bool qnodeRequired;
bool fromTableUid;
} SParseMetaCache;
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);

View File

@ -483,6 +483,7 @@ int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, c
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) {
@ -14428,22 +14429,27 @@ int32_t serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap, SArray** pOut)
return code;
}
// static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SDropTableStmt* pStmt) {
// if (!pStmt->withOpt) return TSDB_CODE_SUCCESS;
static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SDropTableStmt* pStmt) {
if (!pStmt->withOpt) return TSDB_CODE_SUCCESS;
pCxt->pParseCxt->withOpt = pStmt->withOpt;
// SNode* pNode = NULL;
// const char* pTableName = NULL;
// FOREACH(pNode, pStmt->pTables) {
// SDropTableClause* pClause = (SDropTableClause*)pNode;
// pTableName = "aa\u00bf\u200bstb0";
// if (!pTableName) {
// return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist: '%s'",
// pClause->tableName);
// }
// tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN);
// }
// return TSDB_CODE_SUCCESS;
// }
SNode* pNode = NULL;
FOREACH(pNode, pStmt->pTables) {
SDropTableClause* pClause = (SDropTableClause*)pNode;
STableMeta* pTableMeta = NULL;
SName name = {0};
toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name);
int32_t code = getTargetMeta(pCxt, &name, &pTableMeta, false);
if (TSDB_CODE_SUCCESS != code) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, "Table uid does not exist: '%s'",
pClause->tableName);
}
// tstrncpy(pClause->tableName, pTableMeta->, TSDB_TABLE_NAME_LEN); // rewrite table uid to table name
taosMemoryFree(pTableMeta);
}
return TSDB_CODE_SUCCESS;
}
static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot;
@ -14451,7 +14457,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
SNode* pNode;
SArray* pTsmas = NULL;
// TAOS_CHECK_RETURN(rewriteDropTablewithOpt(pCxt, pStmt));
TAOS_CHECK_RETURN(rewriteDropTablewithOpt(pCxt, pStmt));
SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
if (NULL == pVgroupHashmap) {

View File

@ -964,6 +964,9 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet
if (TSDB_CODE_SUCCESS == code) {
code = putDbTableDataToCache(pCatalogReq->pTSMAs, pMetaData->pTsmas, &pMetaCache->pTSMAs);
}
if (TSDB_CODE_SUCCESS == code) {
code = putDbTableDataToCache(pCatalogReq->pTableUid, pMetaData->pTableMeta, &pMetaCache->pTableUid);
}
#ifdef TD_ENTERPRISE
if (TSDB_CODE_SUCCESS == code) {
code = putDbTableDataToCache(pCatalogReq->pView, pMetaData->pView, &pMetaCache->pViews);
@ -1028,13 +1031,15 @@ int32_t reserveTableUidInCache(int32_t acctId, const char* pDb, const char* pTab
}
int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta) {
char fullName[TSDB_TABLE_FNAME_LEN];
char fullName[TSDB_TABLE_FNAME_LEN];
int32_t code = tNameExtractFullName(pName, fullName);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
STableMeta* pTableMeta = NULL;
code = getMetaDataFromHash(fullName, strlen(fullName), pMetaCache->pTableMeta, (void**)&pTableMeta);
code = getMetaDataFromHash(fullName, strlen(fullName),
pMetaCache->fromTableUid ? pMetaCache->pTableUid : pMetaCache->pTableMeta,
(void**)&pTableMeta);
if (TSDB_CODE_SUCCESS == code) {
*pMeta = tableMetaDup(pTableMeta);
if (NULL == *pMeta) {