enh: support drop table with uid
This commit is contained in:
parent
270d485da7
commit
1b6694af20
|
@ -462,6 +462,7 @@ typedef enum ENodeType {
|
|||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
uint8_t option; // 0x01 tableUid
|
||||
const char* dbFName;
|
||||
const char* tbName;
|
||||
} SBuildTableInput;
|
||||
|
@ -2048,6 +2049,7 @@ typedef struct {
|
|||
SMsgHead header;
|
||||
char dbFName[TSDB_DB_FNAME_LEN];
|
||||
char tbName[TSDB_TABLE_NAME_LEN];
|
||||
uint8_t option; // 0x01 for table uid
|
||||
} STableInfoReq;
|
||||
|
||||
int32_t tSerializeSTableInfoReq(void* buf, int32_t bufLen, STableInfoReq* pReq);
|
||||
|
|
|
@ -5720,6 +5720,7 @@ int32_t tSerializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq)
|
|||
TAOS_CHECK_EXIT(tStartEncode(&encoder));
|
||||
TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->dbFName));
|
||||
TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pReq->tbName));
|
||||
TAOS_CHECK_EXIT(tEncodeU8(&encoder, pReq->option));
|
||||
tEndEncode(&encoder);
|
||||
|
||||
_exit:
|
||||
|
@ -5754,6 +5755,11 @@ int32_t tDeserializeSTableInfoReq(void *buf, int32_t bufLen, STableInfoReq *pReq
|
|||
TAOS_CHECK_EXIT(tStartDecode(&decoder));
|
||||
TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->dbFName));
|
||||
TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pReq->tbName));
|
||||
if (tDecodeIsEnd(&decoder)) {
|
||||
pReq->option = 0;
|
||||
} else {
|
||||
TAOS_CHECK_EXIT(tDecodeU8(&decoder, &pReq->option));
|
||||
}
|
||||
|
||||
tEndDecode(&decoder);
|
||||
_exit:
|
||||
|
|
|
@ -55,6 +55,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
SMetaReader mer1 = {0};
|
||||
SMetaReader mer2 = {0};
|
||||
char tableFName[TSDB_TABLE_FNAME_LEN];
|
||||
bool tbUidReq = false;
|
||||
SRpcMsg rpcMsg = {0};
|
||||
int32_t code = 0;
|
||||
int32_t rspLen = 0;
|
||||
|
@ -68,20 +69,38 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
goto _exit4;
|
||||
}
|
||||
|
||||
if (infoReq.option == 0x01) tbUidReq = true;
|
||||
metaRsp.dbId = pVnode->config.dbId;
|
||||
(void)strcpy(metaRsp.tbName, infoReq.tbName);
|
||||
(void)memcpy(metaRsp.dbFName, infoReq.dbFName, sizeof(metaRsp.dbFName));
|
||||
|
||||
(void)sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName);
|
||||
code = vnodeValidateTableHash(pVnode, tableFName);
|
||||
if (code) {
|
||||
goto _exit4;
|
||||
if (!tbUidReq) {
|
||||
(void)sprintf(tableFName, "%s.%s", infoReq.dbFName, infoReq.tbName);
|
||||
code = vnodeValidateTableHash(pVnode, tableFName);
|
||||
if (code) {
|
||||
goto _exit4;
|
||||
}
|
||||
}
|
||||
|
||||
// query meta
|
||||
metaReaderDoInit(&mer1, pVnode->pMeta, META_READER_LOCK);
|
||||
|
||||
if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
|
||||
if (tbUidReq) {
|
||||
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};
|
||||
if (metaGetTableNameByUid(&mer1, tbUid, tbName) < 0) {
|
||||
code = terrno;
|
||||
goto _exit3;
|
||||
}
|
||||
if (metaGetTableEntryByName(&mer1, tbName) < 0) {
|
||||
code = terrno;
|
||||
goto _exit3;
|
||||
}
|
||||
} else if (metaGetTableEntryByName(&mer1, infoReq.tbName) < 0) {
|
||||
code = terrno;
|
||||
goto _exit3;
|
||||
}
|
||||
|
@ -107,7 +126,7 @@ int32_t vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg, bool direct) {
|
|||
schema = mer1.me.ntbEntry.schemaRow;
|
||||
} else {
|
||||
vError("vnodeGetTableMeta get invalid table type:%d", mer1.me.type);
|
||||
return TSDB_CODE_APP_ERROR;
|
||||
goto _exit3;
|
||||
}
|
||||
|
||||
metaRsp.numOfTags = schemaTag.nCols;
|
||||
|
@ -175,7 +194,7 @@ _exit4:
|
|||
rpcMsg.msgType = pMsg->msgType;
|
||||
|
||||
if (code) {
|
||||
qError("get table %s meta failed cause of %s", infoReq.tbName, tstrerror(code));
|
||||
qError("get table %s meta with %" PRIu8 " failed cause of %s", infoReq.tbName, infoReq.option, tstrerror(code));
|
||||
}
|
||||
|
||||
if (direct) {
|
||||
|
|
|
@ -806,7 +806,8 @@ 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_VIEW == (_taskType)) || (CTG_TASK_GET_TB_TSMA == (_taskType)) || \
|
||||
(CTG_TASK_GET_TB_UID == (_taskType)))
|
||||
|
||||
#define CTG_GET_TASK_MSGCTX(_task, _id) \
|
||||
(CTG_IS_BATCH_TASK((_task)->type) ? taosArrayGet((_task)->msgCtxs, (_id)) : &(_task)->msgCtx)
|
||||
|
|
|
@ -600,7 +600,7 @@ static int32_t ctgInitGetTbUidTask(SCtgJob* pJob, int32_t taskId, void* param) {
|
|||
}
|
||||
task.taskCtx = pTaskCtx;
|
||||
pTaskCtx->pNames = param;
|
||||
pTaskCtx->pResList = taosArrayInit(pJob->tsmaNum, sizeof(SMetaRes));
|
||||
pTaskCtx->pResList = taosArrayInit(pJob->tbUidNum, sizeof(SMetaRes));
|
||||
if (NULL == pTaskCtx->pResList) {
|
||||
qError("qid:0x%" PRIx64 " taosArrayInit %d SMetaRes %d failed", pJob->queryId, pJob->tbUidNum,
|
||||
(int32_t)sizeof(SMetaRes));
|
||||
|
@ -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, ctgHandleGetTbMetasRsp, ctgDumpTbUidsRes, NULL, NULL},
|
||||
{ctgInitGetTbUidTask, ctgLaunchGetTbUidTask, ctgHandleGetTbUidsRsp, ctgDumpTbUidsRes, NULL, NULL},
|
||||
};
|
||||
|
||||
int32_t ctgMakeAsyncRes(SCtgJob* pJob) {
|
||||
|
|
|
@ -614,6 +614,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_UID == pTask->type) {
|
||||
SCtgTbUidsCtx* ctx = (SCtgTbUidsCtx*)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;
|
||||
|
@ -1346,10 +1350,12 @@ int32_t ctgGetTbMetaFromVnode(SCatalog* pCtg, SRequestConnInfo* pConn, const SNa
|
|||
ctgDebug("try to get table meta from vnode, vgId:%d, ep num:%d, ep %s:%d, tbFName:%s", vgroupInfo->vgId,
|
||||
vgroupInfo->epSet.numOfEps, pEp->fqdn, pEp->port, tbFName);
|
||||
|
||||
SBuildTableInput bInput = {
|
||||
.vgId = vgroupInfo->vgId, .dbFName = dbFName, .tbName = (char*)tNameGetTableName(pTableName)};
|
||||
char* msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
SBuildTableInput bInput = {.vgId = vgroupInfo->vgId,
|
||||
.option = pTask && pTask->type == CTG_TASK_GET_TB_UID ? 0x01 : 0x00,
|
||||
.dbFName = dbFName,
|
||||
.tbName = (char*)tNameGetTableName(pTableName)};
|
||||
char* msg = NULL;
|
||||
int32_t msgLen = 0;
|
||||
|
||||
int32_t code = queryBuildMsg[TMSG_INDEX(reqType)](&bInput, &msg, 0, &msgLen, mallocFp);
|
||||
if (code) {
|
||||
|
|
|
@ -111,6 +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]";
|
||||
default:
|
||||
return "unknown";
|
||||
}
|
||||
|
@ -844,6 +846,15 @@ void ctgFreeTaskRes(CTG_TASK_TYPE type, void** pRes) {
|
|||
*pRes = NULL;
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_TB_UID: {
|
||||
SArray* pArray = (SArray*)*pRes;
|
||||
int32_t num = taosArrayGetSize(pArray);
|
||||
for (int32_t i = 0; i < num; ++i) {
|
||||
ctgFreeBatchMeta(taosArrayGet(pArray, i));
|
||||
}
|
||||
*pRes = NULL; // no need to free it
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qError("invalid task type %d", type);
|
||||
break;
|
||||
|
@ -906,6 +917,11 @@ void ctgFreeSubTaskRes(CTG_TASK_TYPE type, void** pRes) {
|
|||
*pRes = NULL;
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_TB_UID: {
|
||||
taosArrayDestroyEx(*pRes, ctgFreeBatchMeta);
|
||||
*pRes = NULL;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qError("invalid task type %d", type);
|
||||
break;
|
||||
|
@ -1016,6 +1032,21 @@ void ctgFreeTaskCtx(SCtgTask* pTask) {
|
|||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
break;
|
||||
}
|
||||
case CTG_TASK_GET_TB_UID: {
|
||||
SCtgTbUidsCtx* taskCtx = (SCtgTbUidsCtx*)pTask->taskCtx;
|
||||
taosArrayDestroyEx(taskCtx->pResList, ctgFreeBatchMeta);
|
||||
taosArrayDestroy(taskCtx->pFetchs);
|
||||
// NO NEED TO FREE pNames
|
||||
|
||||
taosArrayDestroyEx(pTask->msgCtxs, (FDelete)ctgFreeTbMetasMsgCtx);
|
||||
|
||||
if (pTask->msgCtx.lastOut) {
|
||||
ctgFreeSTableMetaOutput((STableMetaOutput*)pTask->msgCtx.lastOut);
|
||||
pTask->msgCtx.lastOut = NULL;
|
||||
}
|
||||
taosMemoryFreeClear(pTask->taskCtx);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
qError("invalid task type %d", pTask->type);
|
||||
break;
|
||||
|
|
|
@ -76,7 +76,7 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
STableInfoReq infoReq = {0};
|
||||
STableInfoReq infoReq = {.option = pInput->option};
|
||||
infoReq.header.vgId = pInput->vgId;
|
||||
if (pInput->dbFName) {
|
||||
tstrncpy(infoReq.dbFName, pInput->dbFName, TSDB_DB_FNAME_LEN);
|
||||
|
@ -85,8 +85,7 @@ int32_t queryBuildTableMetaReqMsg(void *input, char **msg, int32_t msgSize, int3
|
|||
|
||||
int32_t bufLen = tSerializeSTableInfoReq(NULL, 0, &infoReq);
|
||||
void *pBuf = (*mallcFp)(bufLen);
|
||||
if(tSerializeSTableInfoReq(pBuf, bufLen, &infoReq) < 0)
|
||||
{
|
||||
if (tSerializeSTableInfoReq(pBuf, bufLen, &infoReq) < 0) {
|
||||
return TSDB_CODE_TSC_INVALID_INPUT;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue