enh: support drop table with uid
This commit is contained in:
parent
d7fcf21f8b
commit
28edf40c2a
|
@ -123,6 +123,11 @@ typedef struct STableMeta {
|
|||
// the schema content.
|
||||
SSchema schema[];
|
||||
} STableMeta;
|
||||
typedef struct STableMetaEx {
|
||||
STableMeta* pMeta;
|
||||
// END: KEEP THIS PART SAME WITH STableMeta
|
||||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
} STableMetaEx;
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct SViewMeta {
|
||||
|
|
|
@ -75,7 +75,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
(void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
|
||||
|
||||
if (!reqFromUid) {
|
||||
(void)sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName);
|
||||
TAOS_UNUSED(sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName));
|
||||
code = vnodeValidateTableHash(pVnode, tableFName);
|
||||
if (code) {
|
||||
goto _exit4;
|
||||
|
@ -95,6 +95,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
code = terrno;
|
||||
goto _exit3;
|
||||
}
|
||||
tstrncpy(metaRsp.tbName, tbName + VARSTR_HEADER_SIZE, TSDB_TABLE_NAME_LEN);
|
||||
if (metaGetTableEntryByName(&mer1, tbName + VARSTR_HEADER_SIZE) < 0) {
|
||||
code = terrno;
|
||||
goto _exit3;
|
||||
|
|
|
@ -2080,9 +2080,17 @@ static int32_t ctgHandleGetTbNamesRsp(SCtgTaskReq* tReq, int32_t reqType, const
|
|||
CTG_ERR_JRET(TSDB_CODE_CTG_INTERNAL_ERROR);
|
||||
}
|
||||
|
||||
pRes->code = 0;
|
||||
pRes->pRes = pOut->tbMeta;
|
||||
STableMetaEx* pMetaEx = taosMemoryMalloc(sizeof(STableMetaEx));
|
||||
if (NULL == pMetaEx) {
|
||||
CTG_ERR_JRET(TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
pMetaEx->pMeta = pOut->tbMeta;
|
||||
pOut->tbMeta = NULL;
|
||||
tstrncpy(pMetaEx->tbName, pOut->tbName, TSDB_TABLE_NAME_LEN);
|
||||
|
||||
pRes->code = 0;
|
||||
pRes->pRes = pMetaEx;
|
||||
if (0 == atomic_sub_fetch_32(&ctx->fetchNum, 1)) {
|
||||
TSWAP(pTask->res, ctx->pResList);
|
||||
taskDone = true;
|
||||
|
|
|
@ -702,7 +702,7 @@ int32_t ctgAddBatch(SCatalog* pCtg, int32_t vgId, SRequestConnInfo* pConn, SCtgT
|
|||
if (TDMT_VND_TABLE_CFG == msgType) {
|
||||
SCtgTbCfgCtx* ctx = (SCtgTbCfgCtx*)pTask->taskCtx;
|
||||
pName = ctx->pName;
|
||||
} else if (TDMT_VND_TABLE_META == msgType) {
|
||||
} else if (TDMT_VND_TABLE_META == msgType || TDMT_VND_TABLE_NAME == msgType) {
|
||||
if (CTG_TASK_GET_TB_META_BATCH == pTask->type) {
|
||||
SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx;
|
||||
SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx);
|
||||
|
@ -716,6 +716,10 @@ 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_NAME == pTask->type) {
|
||||
SCtgTbMetasCtx* ctx = (SCtgTbMetasCtx*)pTask->taskCtx;
|
||||
SCtgFetch* fetch = taosArrayGet(ctx->pFetchs, tReq->msgIdx);
|
||||
CTG_ERR_JRET(ctgGetFetchName(ctx->pNames, fetch, &pName));
|
||||
} else {
|
||||
SCtgTbMetaCtx* ctx = (SCtgTbMetaCtx*)pTask->taskCtx;
|
||||
pName = ctx->pName;
|
||||
|
|
|
@ -112,7 +112,7 @@ typedef struct SParseMetaCache {
|
|||
SHashObj* pViews; // key is viewFName, element is SViewMeta*
|
||||
SHashObj* pTableTSMAs; // key is tbFName, elements are SArray<STableTSMAInfo*>
|
||||
SHashObj* pTSMAs; // key is tsmaFName, elements are STableTSMAInfo*
|
||||
SHashObj* pTableName; // key is tbFUid, elements is tbName
|
||||
SHashObj* pTableName; // key is tbFUid, elements is STableMetaEx*
|
||||
SArray* pDnodes; // element is SEpSet
|
||||
bool dnodeRequired;
|
||||
bool qnodeRequired;
|
||||
|
|
|
@ -509,6 +509,71 @@ static int32_t getTargetName(STranslateContext* pCxt, const SName* pName, char*
|
|||
return code;
|
||||
}
|
||||
|
||||
static int32_t rewriteDropMetaCache(STranslateContext* pCxt) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SParseContext* pParCxt = pCxt->pParseCxt;
|
||||
SParseMetaCache* pMetaCache = pCxt->pMetaCache;
|
||||
int32_t tbMetaSize = taosHashGetSize(pMetaCache->pTableMeta);
|
||||
int32_t tbMetaExSize = taosHashGetSize(pMetaCache->pTableName);
|
||||
|
||||
if (tbMetaSize > 0 || tbMetaExSize <= 0) {
|
||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
}
|
||||
if (!pMetaCache->pTableMeta &&
|
||||
!(pMetaCache->pTableMeta =
|
||||
taosHashInit(tbMetaExSize, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK))) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SMetaRes** ppMetaRes = NULL;
|
||||
char dbName[TSDB_DB_NAME_LEN] = {0};
|
||||
while ((ppMetaRes = taosHashIterate(pMetaCache->pTableName, ppMetaRes))) {
|
||||
if (!(*ppMetaRes)) {
|
||||
taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes);
|
||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
}
|
||||
|
||||
char* pKey = taosHashGetKey(ppMetaRes, NULL);
|
||||
STableMetaEx* pMetaEx = (STableMetaEx*)(*ppMetaRes)->pRes;
|
||||
if (!pMetaEx || !pMetaEx->pMeta) {
|
||||
taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes);
|
||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
}
|
||||
char* pDbStart = strstr(pKey, ".");
|
||||
char* pDbEnd = pDbStart ? strstr(pDbStart + 1, ".") : NULL;
|
||||
if (!pDbEnd) {
|
||||
taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes);
|
||||
return TSDB_CODE_PAR_INTERNAL_ERROR;
|
||||
}
|
||||
tstrncpy(dbName, pDbStart + 1, pDbEnd - pDbStart);
|
||||
SName name = {0};
|
||||
toName(pParCxt->acctId, dbName, pMetaEx->tbName, &name);
|
||||
|
||||
char fullName[TSDB_TABLE_FNAME_LEN];
|
||||
code = tNameExtractFullName(&name, fullName);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes);
|
||||
return code;
|
||||
}
|
||||
|
||||
if ((code = taosHashPut(pMetaCache->pTableMeta, fullName, strlen(fullName), ppMetaRes, POINTER_BYTES))) {
|
||||
taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes);
|
||||
return code;
|
||||
}
|
||||
|
||||
SMetaRes **qqMetaRes = taosHashGet(pMetaCache->pTableMeta, fullName, strlen(fullName));
|
||||
if (!qqMetaRes) {
|
||||
taosHashCancelIterate(pMetaCache->pTableName, ppMetaRes);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
taosHashCleanup(pMetaCache->pTableName);
|
||||
if (code) {
|
||||
assert(0);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t getTargetMetaImpl(SParseContext* pParCxt, SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta,
|
||||
bool couldBeView) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -14459,8 +14524,10 @@ 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, SQuery* pQuery) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SDropTableStmt* pStmt = (SDropTableStmt*)pQuery->pRoot;
|
||||
if (!pStmt->withOpt) return code;
|
||||
|
||||
SNode* pNode = NULL;
|
||||
char pTableName[TSDB_TABLE_NAME_LEN] = {0};
|
||||
|
@ -14473,9 +14540,12 @@ static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SDropTableStmt*
|
|||
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
|
||||
tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN); // rewrite table uid to table name
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
code = rewriteDropMetaCache(pCxt);
|
||||
|
||||
TAOS_RETURN(code);
|
||||
}
|
||||
|
||||
static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
|
||||
|
@ -14484,7 +14554,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, pQuery));
|
||||
|
||||
SHashObj* pVgroupHashmap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
|
||||
if (NULL == pVgroupHashmap) {
|
||||
|
|
Loading…
Reference in New Issue