enh: support drop table with uid
This commit is contained in:
parent
a6c76329fc
commit
cd358de7ce
|
@ -72,7 +72,6 @@ typedef struct SParseContext {
|
||||||
int64_t requestRid;
|
int64_t requestRid;
|
||||||
int32_t acctId;
|
int32_t acctId;
|
||||||
const char* db;
|
const char* db;
|
||||||
bool topicQuery;
|
|
||||||
void* pTransporter;
|
void* pTransporter;
|
||||||
SEpSet mgmtEpSet;
|
SEpSet mgmtEpSet;
|
||||||
const char* pSql; // sql string
|
const char* pSql; // sql string
|
||||||
|
@ -83,6 +82,7 @@ typedef struct SParseContext {
|
||||||
SStmtCallback* pStmtCb;
|
SStmtCallback* pStmtCb;
|
||||||
const char* pUser;
|
const char* pUser;
|
||||||
const char* pEffectiveUser;
|
const char* pEffectiveUser;
|
||||||
|
bool topicQuery;
|
||||||
bool parseOnly;
|
bool parseOnly;
|
||||||
bool isSuperUser;
|
bool isSuperUser;
|
||||||
bool enableSysInfo;
|
bool enableSysInfo;
|
||||||
|
@ -92,13 +92,14 @@ typedef struct SParseContext {
|
||||||
bool isAudit;
|
bool isAudit;
|
||||||
bool nodeOffline;
|
bool nodeOffline;
|
||||||
bool isStmtBind;
|
bool isStmtBind;
|
||||||
|
bool withOpt;
|
||||||
|
int8_t biMode;
|
||||||
const char* svrVer;
|
const char* svrVer;
|
||||||
SArray* pTableMetaPos; // sql table pos => catalog data pos
|
SArray* pTableMetaPos; // sql table pos => catalog data pos
|
||||||
SArray* pTableVgroupPos; // sql table pos => catalog data pos
|
SArray* pTableVgroupPos; // sql table pos => catalog data pos
|
||||||
int64_t allocatorId;
|
int64_t allocatorId;
|
||||||
parseSqlFn parseSqlFp;
|
parseSqlFn parseSqlFp;
|
||||||
void* parseSqlParam;
|
void* parseSqlParam;
|
||||||
int8_t biMode;
|
|
||||||
SArray* pSubMetaList;
|
SArray* pSubMetaList;
|
||||||
setQueryFn setQueryFp;
|
setQueryFn setQueryFp;
|
||||||
} SParseContext;
|
} SParseContext;
|
||||||
|
|
|
@ -84,19 +84,18 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
||||||
|
|
||||||
// query meta
|
// query meta
|
||||||
metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
|
metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
|
||||||
|
|
||||||
if (reqFromUid) {
|
if (reqFromUid) {
|
||||||
uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
|
uint64_t tbUid = taosStr2UInt64(infoReq.tbName, NULL, 10);
|
||||||
if (errno == ERANGE || tbUid == 0) {
|
if (errno == ERANGE || tbUid == 0) {
|
||||||
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
code = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||||
goto _exit3;
|
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) {
|
if (metaGetTableNameByUid(pVnode, tbUid, tbName) < 0) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
goto _exit3;
|
goto _exit3;
|
||||||
}
|
}
|
||||||
if (metaGetTableEntryByName(&mer1, tbName) < 0) {
|
if (metaGetTableEntryByName(&mer1, tbName + VARSTR_HEADER_SIZE) < 0) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
goto _exit3;
|
goto _exit3;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1910,7 +1910,7 @@ static int32_t ctgHandleGetTbUidsRsp(SCtgTaskReq* tReq, int32_t reqType, const S
|
||||||
SCatalog* pCtg = pTask->pJob->pCtg;
|
SCatalog* pCtg = pTask->pJob->pCtg;
|
||||||
SRequestConnInfo* pConn = &pTask->pJob->conn;
|
SRequestConnInfo* pConn = &pTask->pJob->conn;
|
||||||
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx);
|
SCtgMsgCtx* pMsgCtx = CTG_GET_TASK_MSGCTX(pTask, tReq->msgIdx);
|
||||||
SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx;
|
SCtgTbUidsCtx* ctx = (SCtgTbUidsCtx*)pTask->taskCtx;
|
||||||
bool taskDone = false;
|
bool taskDone = false;
|
||||||
|
|
||||||
if (NULL == pMsgCtx) {
|
if (NULL == pMsgCtx) {
|
||||||
|
|
|
@ -43,6 +43,7 @@ typedef struct STranslateContext {
|
||||||
bool createStream;
|
bool createStream;
|
||||||
bool stableQuery;
|
bool stableQuery;
|
||||||
bool showRewrite;
|
bool showRewrite;
|
||||||
|
bool withOpt;
|
||||||
SNode* pPrevRoot;
|
SNode* pPrevRoot;
|
||||||
SNode* pPostRoot;
|
SNode* pPostRoot;
|
||||||
bool dual; // whether select stmt without from stmt, true for without.
|
bool dual; // whether select stmt without from stmt, true for without.
|
||||||
|
|
|
@ -116,6 +116,7 @@ typedef struct SParseMetaCache {
|
||||||
SArray* pDnodes; // element is SEpSet
|
SArray* pDnodes; // element is SEpSet
|
||||||
bool dnodeRequired;
|
bool dnodeRequired;
|
||||||
bool qnodeRequired;
|
bool qnodeRequired;
|
||||||
|
bool fromTableUid;
|
||||||
} SParseMetaCache;
|
} SParseMetaCache;
|
||||||
|
|
||||||
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
|
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
|
||||||
|
|
|
@ -483,6 +483,7 @@ int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, c
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
if (pParCxt->async) {
|
if (pParCxt->async) {
|
||||||
|
if (pParCxt->withOpt) pMetaCache->fromTableUid = true;
|
||||||
code = getTableMetaFromCache(pMetaCache, pName, pMeta);
|
code = getTableMetaFromCache(pMetaCache, pName, pMeta);
|
||||||
#ifdef TD_ENTERPRISE
|
#ifdef TD_ENTERPRISE
|
||||||
if ((TSDB_CODE_PAR_TABLE_NOT_EXIST == code || TSDB_CODE_PAR_INTERNAL_ERROR == code) && couldBeView) {
|
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;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SDropTableStmt* pStmt) {
|
static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SDropTableStmt* pStmt) {
|
||||||
// if (!pStmt->withOpt) return TSDB_CODE_SUCCESS;
|
if (!pStmt->withOpt) return TSDB_CODE_SUCCESS;
|
||||||
|
pCxt->pParseCxt->withOpt = pStmt->withOpt;
|
||||||
|
|
||||||
// SNode* pNode = NULL;
|
SNode* pNode = NULL;
|
||||||
// const char* pTableName = NULL;
|
FOREACH(pNode, pStmt->pTables) {
|
||||||
// FOREACH(pNode, pStmt->pTables) {
|
SDropTableClause* pClause = (SDropTableClause*)pNode;
|
||||||
// SDropTableClause* pClause = (SDropTableClause*)pNode;
|
|
||||||
// pTableName = "aa\u00bf\u200bstb0";
|
STableMeta* pTableMeta = NULL;
|
||||||
// if (!pTableName) {
|
SName name = {0};
|
||||||
// return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_TABLE_NOT_EXIST, "Table does not exist: '%s'",
|
toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &name);
|
||||||
// pClause->tableName);
|
int32_t code = getTargetMeta(pCxt, &name, &pTableMeta, false);
|
||||||
// }
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
// tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN);
|
return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, "Table uid does not exist: '%s'",
|
||||||
// }
|
pClause->tableName);
|
||||||
// return TSDB_CODE_SUCCESS;
|
}
|
||||||
// }
|
// 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) {
|
static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
|
||||||
SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot;
|
SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot;
|
||||||
|
@ -14451,7 +14457,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
|
||||||
SNode* pNode;
|
SNode* pNode;
|
||||||
SArray* pTsmas = NULL;
|
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);
|
SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||||
if (NULL == pVgroupHashmap) {
|
if (NULL == pVgroupHashmap) {
|
||||||
|
|
|
@ -964,6 +964,9 @@ int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMet
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = putDbTableDataToCache(pCatalogReq->pTSMAs, pMetaData->pTsmas, &pMetaCache->pTSMAs);
|
code = putDbTableDataToCache(pCatalogReq->pTSMAs, pMetaData->pTsmas, &pMetaCache->pTSMAs);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = putDbTableDataToCache(pCatalogReq->pTableUid, pMetaData->pTableMeta, &pMetaCache->pTableUid);
|
||||||
|
}
|
||||||
#ifdef TD_ENTERPRISE
|
#ifdef TD_ENTERPRISE
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = putDbTableDataToCache(pCatalogReq->pView, pMetaData->pView, &pMetaCache->pViews);
|
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) {
|
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);
|
int32_t code = tNameExtractFullName(pName, fullName);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
STableMeta* pTableMeta = NULL;
|
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) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
*pMeta = tableMetaDup(pTableMeta);
|
*pMeta = tableMetaDup(pTableMeta);
|
||||||
if (NULL == *pMeta) {
|
if (NULL == *pMeta) {
|
||||||
|
|
Loading…
Reference in New Issue