enh: support drop table with uid

This commit is contained in:
kailixu 2024-09-18 19:04:44 +08:00
parent ba10e95723
commit 107ad05273
8 changed files with 62 additions and 13 deletions

View File

@ -1460,6 +1460,7 @@ typedef struct {
int32_t walFsyncPeriod;
int16_t hashPrefix;
int16_t hashSuffix;
int8_t hashMethod;
int8_t walLevel;
int8_t precision;
int8_t compression;

View File

@ -418,6 +418,8 @@ int32_t catalogGetTsma(SCatalog* pCtg, SRequestConnInfo* pConn, const SName* pTs
int32_t catalogAsyncUpdateDbTsmaVersion(SCatalog* pCtg, int32_t tsmaVersion, const char* dbFName, int64_t dbId);
int32_t ctgHashValueComp(void const* lp, void const* rp);
/**
* Destroy catalog and relase all resources
*/

View File

@ -4912,6 +4912,7 @@ int32_t tSerializeSDbCfgRspImpl(SEncoder *encoder, const SDbCfgRsp *pRsp) {
TAOS_CHECK_RETURN(tEncodeI32(encoder, pRsp->s3ChunkSize));
TAOS_CHECK_RETURN(tEncodeI32(encoder, pRsp->s3KeepLocal));
TAOS_CHECK_RETURN(tEncodeI8(encoder, pRsp->s3Compact));
TAOS_CHECK_RETURN(tEncodeI8(encoder, pRsp->hashMethod));
return 0;
}
@ -5003,6 +5004,11 @@ int32_t tDeserializeSDbCfgRspImpl(SDecoder *decoder, SDbCfgRsp *pRsp) {
TAOS_CHECK_RETURN(tDecodeI32(decoder, &pRsp->s3KeepLocal));
TAOS_CHECK_RETURN(tDecodeI8(decoder, &pRsp->s3Compact));
}
if (!tDecodeIsEnd(decoder)) {
TAOS_CHECK_RETURN(tDecodeI8(decoder, &pRsp->hashMethod));
} else {
pRsp->hashMethod = 1; // default value
}
return 0;
}

View File

@ -1321,6 +1321,7 @@ static void mndDumpDbCfgInfo(SDbCfgRsp *cfgRsp, SDbObj *pDb) {
cfgRsp->walFsyncPeriod = pDb->cfg.walFsyncPeriod;
cfgRsp->hashPrefix = pDb->cfg.hashPrefix;
cfgRsp->hashSuffix = pDb->cfg.hashSuffix;
cfgRsp->hashMethod = pDb->cfg.hashMethod;
cfgRsp->walLevel = pDb->cfg.walLevel;
cfgRsp->precision = pDb->cfg.precision;
cfgRsp->compression = pDb->cfg.compression;

View File

@ -167,6 +167,7 @@ int32_t getViewMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, ST
int32_t buildTableMetaFromViewMeta(STableMeta** pMeta, SViewMeta* pViewMeta);
int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo);
int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup);
int32_t getDbTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup);
int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
int32_t* pTableNum, int64_t* pStateTs);
int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo);

View File

@ -382,6 +382,12 @@ static int32_t collectMetaKeyFromDropTable(SCollectMetaKeyCxt* pCxt, SDropTableS
SDropTableClause* pClause = (SDropTableClause*)pNode;
if (pStmt->withOpt) {
code = reserveTableUidInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);
if (TSDB_CODE_SUCCESS == code) {
code = reserveDbVgInfoInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
}
if (TSDB_CODE_SUCCESS == code) {
code = reserveDbCfgInCache(pCxt->pParseCxt->acctId, pClause->dbName, pCxt->pMetaCache);
}
} else {
code = reserveTableMetaInCache(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, pCxt->pMetaCache);

View File

@ -509,7 +509,7 @@ static int32_t getTargetName(STranslateContext* pCxt, const SName* pName, char*
return code;
}
static int32_t rewriteDropMetaCache(STranslateContext* pCxt) {
static int32_t rewriteDropTableWithMetaCache(STranslateContext* pCxt) {
int32_t code = TSDB_CODE_SUCCESS;
SParseContext* pParCxt = pCxt->pParseCxt;
SParseMetaCache* pMetaCache = pCxt->pMetaCache;
@ -567,16 +567,6 @@ static int32_t rewriteDropMetaCache(STranslateContext* pCxt) {
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;
}
@ -720,7 +710,11 @@ static int32_t getTableHashVgroupImpl(STranslateContext* pCxt, const SName* pNam
}
if (TSDB_CODE_SUCCESS == code) {
if (pParCxt->async) {
code = getTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo);
if(pCxt->withOpt) {
code = getDbTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo);
} else {
code = getTableVgroupFromCache(pCxt->pMetaCache, pName, pInfo);
}
} else {
SRequestConnInfo conn = {.pTrans = pParCxt->pTransporter,
.requestId = pParCxt->requestId,
@ -14535,6 +14529,7 @@ 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;
SNode* pNode = NULL;
char pTableName[TSDB_TABLE_NAME_LEN] = {0};
@ -14550,7 +14545,7 @@ static int32_t rewriteDropTablewithOpt(STranslateContext* pCxt, SQuery* pQuery)
tstrncpy(pClause->tableName, pTableName, TSDB_TABLE_NAME_LEN); // rewrite table uid to table name
}
code = rewriteDropMetaCache(pCxt);
code = rewriteDropTableWithMetaCache(pCxt);
TAOS_RETURN(code);
}
@ -14581,6 +14576,7 @@ static int32_t rewriteDropTable(STranslateContext* pCxt, SQuery* pQuery) {
if (tableType == TSDB_SUPER_TABLE && LIST_LENGTH(pStmt->pTables) > 1) {
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DROP_STABLE);
}
if (pCxt->withOpt) continue;
if (pCxt->pMetaCache) code = getTableTsmasFromCache(pCxt->pMetaCache, &name, &pTsmas);
if (TSDB_CODE_SUCCESS != code) {
taosHashCleanup(pVgroupHashmap);

View File

@ -1152,6 +1152,42 @@ int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName,
return code;
}
int32_t getDbTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup) {
char fullName[TSDB_TABLE_FNAME_LEN];
int32_t code = tNameExtractFullName(pName, fullName);
if (TSDB_CODE_SUCCESS != code) {
return code;
}
const char* pDb = strstr(fullName, ".");
if (pDb == NULL) return TSDB_CODE_PAR_INTERNAL_ERROR;
pDb = strstr(pDb + 1, ".");
if (pDb == NULL) return TSDB_CODE_PAR_INTERNAL_ERROR;
int32_t fullDbLen = pDb - fullName;
int32_t fullTbLen = strlen(fullName);
SArray* pVgArray = NULL;
SDbCfgInfo* pDbCfg = NULL;
code = getMetaDataFromHash(fullName, fullDbLen, pMetaCache->pDbVgroup, (void**)&pVgArray);
if (TSDB_CODE_SUCCESS == code) {
code = getMetaDataFromHash(fullName, fullDbLen, pMetaCache->pDbCfg, (void**)&pDbCfg);
}
if (TSDB_CODE_SUCCESS == code) {
code = TSDB_CODE_PAR_INTERNAL_ERROR;
int32_t vgSize = taosArrayGetSize(pVgArray);
for (int32_t i = 0; i < vgSize; ++i) {
uint32_t hashValue =
taosGetTbHashVal(fullName, fullTbLen, pDbCfg->hashMethod, pDbCfg->hashPrefix, pDbCfg->hashSuffix);
void* pVg = taosArraySearch(pVgArray, &hashValue, ctgHashValueComp, TD_EQ);
if (pVg) {
memcpy(pVgroup, pVg, sizeof(SVgroupInfo));
code = TSDB_CODE_SUCCESS;
break;
}
}
}
return code;
}
int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache) {
return reserveDbReqInCache(acctId, pDb, &pMetaCache->pDbInfo);
}