diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 21fed73f6d620c5c45202135faf01540c89d1fc4..d33f6683658f197ddb58391da4eb33859f9a7bd4 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1127,6 +1127,14 @@ typedef struct { SSchema* pSchemas; } STableMetaRsp; +typedef struct { + STableMetaRsp* pMeta; +} SMAlterStbRsp; + +int32_t tEncodeSMAlterStbRsp(SEncoder *pEncoder, const SMAlterStbRsp *pRsp); +int32_t tDecodeSMAlterStbRsp(SDecoder *pDecoder, SMAlterStbRsp *pRsp); +void tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp); + int32_t tSerializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp); int32_t tDeserializeSTableMetaRsp(void* buf, int32_t bufLen, STableMetaRsp* pRsp); void tFreeSTableMetaRsp(STableMetaRsp* pRsp); @@ -1880,7 +1888,8 @@ int32_t tEncodeSVAlterTbReq(SEncoder* pEncoder, const SVAlterTbReq* pReq); int32_t tDecodeSVAlterTbReq(SDecoder* pDecoder, SVAlterTbReq* pReq); typedef struct { - int32_t code; + int32_t code; + STableMetaRsp* pMeta; } SVAlterTbRsp; int32_t tEncodeSVAlterTbRsp(SEncoder* pEncoder, const SVAlterTbRsp* pRsp); diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 8027b9394e0fd42c4c1d20a051868495130642f5..f0e642bc9af8060d0b6bc0380f2c85284f307642 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -183,7 +183,7 @@ int32_t catalogGetTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSe */ int32_t catalogGetSTableMeta(SCatalog* pCatalog, void * pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); -int32_t catalogUpdateSTableMeta(SCatalog* pCatalog, STableMetaRsp *rspMsg); +int32_t catalogUpdateTableMeta(SCatalog* pCatalog, STableMetaRsp *rspMsg); /** diff --git a/include/libs/nodes/querynodes.h b/include/libs/nodes/querynodes.h index ab5e10dc2ab632b57f9d6f313291d8cb5b04c6b0..e4af78892baaf3757ab58be41fec776e2cb7186f 100644 --- a/include/libs/nodes/querynodes.h +++ b/include/libs/nodes/querynodes.h @@ -331,8 +331,8 @@ typedef struct SQuery { int8_t precision; SCmdMsgInfo* pCmdMsg; int32_t msgType; - SArray* pDbList; SArray* pTableList; + SArray* pDbList; bool showRewrite; int32_t placeholderNum; SArray* pPlaceholderValues; diff --git a/include/libs/qcom/query.h b/include/libs/qcom/query.h index 296b18e8dea7524244dcd8ade1a1149bfe97533d..45a7e9a29f3457a68e9998659237a9e0d70d39ab 100644 --- a/include/libs/qcom/query.h +++ b/include/libs/qcom/query.h @@ -56,6 +56,11 @@ typedef struct STableComInfo { int32_t rowSize; // row size of the schema } STableComInfo; +typedef struct SQueryExecRes { + int32_t msgType; + void* res; +} SQueryExecRes; + typedef struct SIndexMeta { #ifdef WINDOWS size_t avoidCompilationErrors; @@ -192,6 +197,7 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STabl char* jobTaskStatusStr(int32_t status); SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name); +void destroyQueryExecRes(SQueryExecRes* pRes); extern int32_t (*queryBuildMsg[TDMT_MAX])(void *input, char **msg, int32_t msgSize, int32_t *msgLen, void*(*mallocFp)(int32_t)); extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t msgSize); @@ -204,7 +210,8 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t #define NEED_CLIENT_RM_TBLMETA_ERROR(_code) \ ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST || \ (_code) == TSDB_CODE_PAR_INVALID_COLUMNS_NUM || (_code) == TSDB_CODE_PAR_INVALID_COLUMN || \ - (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code == TSDB_CODE_PAR_VALUE_TOO_LONG)) + (_code) == TSDB_CODE_PAR_TAGS_NOT_MATCHED || (_code == TSDB_CODE_PAR_VALUE_TOO_LONG) || \ + (_code == TSDB_CODE_PAR_INVALID_DROP_COL)) #define NEED_CLIENT_REFRESH_VG_ERROR(_code) \ ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID) #define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED) diff --git a/include/libs/scheduler/scheduler.h b/include/libs/scheduler/scheduler.h index 0d32cce20b6e489249fa79080e6144754c17218b..331b78769029fb97764f81ce6bb646f28854918a 100644 --- a/include/libs/scheduler/scheduler.h +++ b/include/libs/scheduler/scheduler.h @@ -56,7 +56,7 @@ typedef struct SQueryProfileSummary { typedef struct SQueryResult { int32_t code; uint64_t numOfRows; - void *res; + SQueryExecRes res; } SQueryResult; typedef struct STaskInfo { diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index e541c214deba8e9b9ad3cc4e95cc2d2224f3c5a3..95af8ac30666b67b0a933477ff8ca0764d2d0a43 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -184,6 +184,7 @@ int32_t walRollback(SWal *, int64_t ver); // notify that previous logs can be pruned safely int32_t walBeginSnapshot(SWal *, int64_t ver); int32_t walEndSnapshot(SWal *); +void walRestoreFromSnapshot(SWal *, int64_t ver); // int32_t walDataCorrupted(SWal*); // read diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index 0732c7890d19063ca2f48657926d7bbe245dc59e..a2305dd45d5818b37cb0a26c0bcd1b47830b0496 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -162,6 +162,7 @@ typedef struct SResultColumn { } SResultColumn; typedef struct SReqResultInfo { + SQueryExecRes execRes; const char* pRspMsg; const char* pData; TAOS_FIELD* fields; // todo, column names are not needed. @@ -319,7 +320,7 @@ void hbMgrInitMqHbRspHandle(); SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery, void** res); int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList); -int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList, void** res); +int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList); int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest); int32_t updateQnodeList(SAppInstInfo* pInfo, SArray* pNodeList); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 669b2bc97eb3e6fab04701aebbf80402432b44c1..4f5f23b68be93ca3449ddbc2ffd3522c1d1cd27c 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -234,6 +234,8 @@ static void doDestroyRequest(void *p) { taosArrayDestroy(pRequest->tableList); taosArrayDestroy(pRequest->dbList); + destroyQueryExecRes(&pRequest->body.resInfo.execRes); + deregisterRequest(pRequest); taosMemoryFreeClear(pRequest); } diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 70b60195d261ac3551f44c43f5a0ee7c41ec8216..09c3d269c703d6e2dc78cbef49a7790c98f34245 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -120,7 +120,7 @@ static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalo return TSDB_CODE_TSC_INVALID_VALUE; } - catalogUpdateSTableMeta(pCatalog, rsp); + catalogUpdateTableMeta(pCatalog, rsp); } } diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 375e1c0da92340762b82d0dd248a42efd5a01b1e..c4bf3b50bf08a805391a0755d81e0f1d76d6459c 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -340,22 +340,23 @@ void setResPrecision(SReqResultInfo* pResInfo, int32_t precision) { pResInfo->precision = precision; } -int32_t scheduleAsyncQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList, void** pRes) { +int32_t scheduleAsyncQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) { void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter; tsem_init(&schdRspSem, 0, 0); SQueryResult res = {.code = 0, .numOfRows = 0}; int32_t code = schedulerAsyncExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, - pRequest->metric.start, schdExecCallback, &res); - while (true) { + pRequest->metric.start, schdExecCallback, &res); + + pRequest->body.resInfo.execRes = res.res; + + while (true) { if (code != TSDB_CODE_SUCCESS) { if (pRequest->body.queryJob != 0) { schedulerFreeJob(pRequest->body.queryJob); } - *pRes = res.res; - pRequest->code = code; terrno = code; return pRequest->code; @@ -378,26 +379,25 @@ int32_t scheduleAsyncQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNod } } - *pRes = res.res; - pRequest->code = res.code; terrno = res.code; return pRequest->code; } -int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList, void** pRes) { +int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) { void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter; SQueryResult res = {.code = 0, .numOfRows = 0}; int32_t code = schedulerExecJob(pTransporter, pNodeList, pDag, &pRequest->body.queryJob, pRequest->sqlstr, pRequest->metric.start, &res); + + pRequest->body.resInfo.execRes = res.res; + if (code != TSDB_CODE_SUCCESS) { if (pRequest->body.queryJob != 0) { schedulerFreeJob(pRequest->body.queryJob); } - *pRes = res.res; - pRequest->code = code; terrno = code; return pRequest->code; @@ -411,8 +411,6 @@ int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList } } - *pRes = res.res; - pRequest->code = res.code; terrno = res.code; return pRequest->code; @@ -422,80 +420,109 @@ int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList) return getPlan(pRequest, pQuery, &pRequest->body.pDag, pNodeList); } -int32_t validateSversion(SRequestObj* pRequest, void* res) { - SArray* pArray = NULL; +int32_t handleSubmitExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet *epset) { int32_t code = 0; - - if (TDMT_VND_SUBMIT == pRequest->type) { - SSubmitRsp* pRsp = (SSubmitRsp*)res; - if (pRsp->nBlocks <= 0) { - return TSDB_CODE_SUCCESS; - } - - pArray = taosArrayInit(pRsp->nBlocks, sizeof(STbSVersion)); - if (NULL == pArray) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_OUT_OF_MEMORY; + SArray* pArray = NULL; + SSubmitRsp* pRsp = (SSubmitRsp*)res; + if (pRsp->nBlocks <= 0) { + return TSDB_CODE_SUCCESS; + } + + pArray = taosArrayInit(pRsp->nBlocks, sizeof(STbSVersion)); + if (NULL == pArray) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; + } + + for (int32_t i = 0; i < pRsp->nBlocks; ++i) { + SSubmitBlkRsp* blk = pRsp->pBlocks + i; + if (NULL == blk->tblFName || 0 == blk->tblFName[0]) { + continue; } + + STbSVersion tbSver = {.tbFName = blk->tblFName, .sver = blk->sver}; + taosArrayPush(pArray, &tbSver); + } - for (int32_t i = 0; i < pRsp->nBlocks; ++i) { - SSubmitBlkRsp* blk = pRsp->pBlocks + i; - if (NULL == blk->tblFName || 0 == blk->tblFName[0]) { - continue; - } + code = catalogChkTbMetaVersion(pCatalog, pRequest->pTscObj->pAppInfo->pTransporter, epset, pArray); - STbSVersion tbSver = {.tbFName = blk->tblFName, .sver = blk->sver}; - taosArrayPush(pArray, &tbSver); - } - } else if (TDMT_VND_QUERY == pRequest->type) { - SArray* pTbArray = (SArray*)res; - int32_t tbNum = taosArrayGetSize(pTbArray); - if (tbNum <= 0) { - return TSDB_CODE_SUCCESS; - } +_return: - pArray = taosArrayInit(tbNum, sizeof(STbSVersion)); - if (NULL == pArray) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return TSDB_CODE_OUT_OF_MEMORY; - } + taosArrayDestroy(pArray); + return code; +} - for (int32_t i = 0; i < tbNum; ++i) { - STbVerInfo* tbInfo = taosArrayGet(pTbArray, i); - STbSVersion tbSver = {.tbFName = tbInfo->tbFName, .sver = tbInfo->sversion, .tver = tbInfo->tversion}; - taosArrayPush(pArray, &tbSver); - } +int32_t handleQueryExecRes(SRequestObj* pRequest, void* res, SCatalog* pCatalog, SEpSet *epset) { + int32_t code = 0; + SArray* pArray = NULL; + SArray* pTbArray = (SArray*)res; + int32_t tbNum = taosArrayGetSize(pTbArray); + if (tbNum <= 0) { + return TSDB_CODE_SUCCESS; + } + + pArray = taosArrayInit(tbNum, sizeof(STbSVersion)); + if (NULL == pArray) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; + } + + for (int32_t i = 0; i < tbNum; ++i) { + STbVerInfo* tbInfo = taosArrayGet(pTbArray, i); + STbSVersion tbSver = {.tbFName = tbInfo->tbFName, .sver = tbInfo->sversion, .tver = tbInfo->tversion}; + taosArrayPush(pArray, &tbSver); } - SCatalog* pCatalog = NULL; - CHECK_CODE_GOTO(catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog), _return); - - SEpSet epset = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp); - - code = catalogChkTbMetaVersion(pCatalog, pRequest->pTscObj->pAppInfo->pTransporter, &epset, pArray); + code = catalogChkTbMetaVersion(pCatalog, pRequest->pTscObj->pAppInfo->pTransporter, epset, pArray); _return: taosArrayDestroy(pArray); + return code; +} - return code; +int32_t handleAlterTbExecRes(void* res, SCatalog* pCatalog) { + return catalogUpdateTableMeta(pCatalog, (STableMetaRsp*)res); } -void freeRequestRes(SRequestObj* pRequest, void* res) { - if (NULL == pRequest || NULL == res) { - return; +int32_t handleExecRes(SRequestObj* pRequest) { + if (NULL == pRequest->body.resInfo.execRes.res) { + return TSDB_CODE_SUCCESS; } - - if (TDMT_VND_SUBMIT == pRequest->type) { - tFreeSSubmitRsp((SSubmitRsp*)res); - } else if (TDMT_VND_QUERY == pRequest->type) { - taosArrayDestroy((SArray*)res); + + int32_t code = 0; + SCatalog* pCatalog = NULL; + code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog); + if (code) { + return code; } + + SEpSet epset = getEpSet_s(&pRequest->pTscObj->pAppInfo->mgmtEp); + SQueryExecRes* pRes = &pRequest->body.resInfo.execRes; + + switch (pRes->msgType) { + case TDMT_VND_ALTER_TABLE: + case TDMT_MND_ALTER_STB: { + code = handleAlterTbExecRes(pRes->res, pCatalog); + break; + } + case TDMT_VND_SUBMIT: { + code = handleSubmitExecRes(pRequest, pRes->res, pCatalog, &epset); + break; + } + case TDMT_VND_QUERY: { + code = handleQueryExecRes(pRequest, pRes->res, pCatalog, &epset); + break; + } + default: + tscError("invalid exec result for request type %d", pRequest->type); + return TSDB_CODE_APP_ERROR; + } + + return code; } SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery, void** res) { - void* pRes = NULL; - if (TSDB_CODE_SUCCESS == code) { switch (pQuery->execMode) { case QUERY_EXEC_MODE_LOCAL: @@ -508,10 +535,7 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code SArray* pNodeList = NULL; code = getPlan(pRequest, pQuery, &pRequest->body.pDag, &pNodeList); if (TSDB_CODE_SUCCESS == code) { - code = scheduleQuery(pRequest, pRequest->body.pDag, pNodeList, &pRes); - if (NULL != pRes) { - code = validateSversion(pRequest, pRes); - } + code = scheduleQuery(pRequest, pRequest->body.pDag, pNodeList); } taosArrayDestroy(pNodeList); break; @@ -528,15 +552,15 @@ SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code qDestroyQuery(pQuery); } + handleExecRes(pRequest); + if (NULL != pRequest && TSDB_CODE_SUCCESS != code) { pRequest->code = terrno; } if (res) { - *res = pRes; - } else { - freeRequestRes(pRequest, pRes); - pRes = NULL; + *res = pRequest->body.resInfo.execRes.res; + pRequest->body.resInfo.execRes.res = NULL; } return pRequest; diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index f15315fe6055127f13b15849f897d8edda5a381b..9de3ee1d0f1a8a529c7177329543e3379cdc6cbb 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -223,10 +223,33 @@ int32_t processDropDbRsp(void* param, const SDataBuf* pMsg, int32_t code) { return code; } +int32_t processAlterStbRsp(void* param, const SDataBuf* pMsg, int32_t code) { + SRequestObj* pRequest = param; + if (code != TSDB_CODE_SUCCESS) { + setErrno(pRequest, code); + tsem_post(&pRequest->body.rspSem); + return code; + } + + SMAlterStbRsp alterRsp = {0}; + SDecoder coder = {0}; + tDecoderInit(&coder, pMsg->pData, pMsg->len); + tDecodeSMAlterStbRsp(&coder, &alterRsp); + tDecoderClear(&coder); + + pRequest->body.resInfo.execRes.msgType = TDMT_MND_ALTER_STB; + pRequest->body.resInfo.execRes.res = alterRsp.pMeta; + + tsem_post(&pRequest->body.rspSem); + return code; +} + + void initMsgHandleFp() { handleRequestRspFp[TMSG_INDEX(TDMT_MND_CONNECT)] = processConnectRsp; handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_DB)] = processCreateDbRsp; handleRequestRspFp[TMSG_INDEX(TDMT_MND_USE_DB)] = processUseDbRsp; handleRequestRspFp[TMSG_INDEX(TDMT_MND_CREATE_STB)] = processCreateTableRsp; handleRequestRspFp[TMSG_INDEX(TDMT_MND_DROP_DB)] = processDropDbRsp; + handleRequestRspFp[TMSG_INDEX(TDMT_MND_ALTER_STB)] = processAlterStbRsp; } diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 2962216b0cebe4841be58f2c52fd109629416d95..0f3eec01c6b3df1051e51604256dbf853d247d01 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -693,6 +693,7 @@ void tFreeSMAltertbReq(SMAlterStbReq *pReq) { pReq->pFields = NULL; } + int32_t tSerializeSEpSet(void *buf, int32_t bufLen, const SEpSet *pEpset) { SEncoder encoder = {0}; tEncoderInit(&encoder, buf, bufLen); @@ -4347,13 +4348,96 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) { int32_t tEncodeSVAlterTbRsp(SEncoder *pEncoder, const SVAlterTbRsp *pRsp) { if (tStartEncode(pEncoder) < 0) return -1; if (tEncodeI32(pEncoder, pRsp->code) < 0) return -1; + if (tEncodeI32(pEncoder, pRsp->pMeta ? 1 : 0) < 0) return -1; + if (pRsp->pMeta) { + if (tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta) < 0) return -1; + } tEndEncode(pEncoder); return 0; } int32_t tDecodeSVAlterTbRsp(SDecoder *pDecoder, SVAlterTbRsp *pRsp) { + int32_t meta = 0; if (tStartDecode(pDecoder) < 0) return -1; if (tDecodeI32(pDecoder, &pRsp->code) < 0) return -1; + if (tDecodeI32(pDecoder, &meta) < 0) return -1; + if (meta) { + pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); + if (NULL == pRsp->pMeta) return -1; + if (tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta) < 0) return -1; + } + tEndDecode(pDecoder); + return 0; +} + +int32_t tDeserializeSVAlterTbRsp(void *buf, int32_t bufLen, SVAlterTbRsp *pRsp) { + int32_t meta = 0; + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &pRsp->code) < 0) return -1; + if (tDecodeI32(&decoder, &meta) < 0) return -1; + if (meta) { + pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); + if (NULL == pRsp->pMeta) return -1; + if (tDecodeSTableMetaRsp(&decoder, pRsp->pMeta) < 0) return -1; + } + tEndDecode(&decoder); + tDecoderClear(&decoder); + return 0; +} + +int32_t tEncodeSMAlterStbRsp(SEncoder *pEncoder, const SMAlterStbRsp *pRsp) { + if (tStartEncode(pEncoder) < 0) return -1; + if (tEncodeI32(pEncoder, pRsp->pMeta->pSchemas ? 1 : 0) < 0) return -1; + if (pRsp->pMeta->pSchemas) { + if (tEncodeSTableMetaRsp(pEncoder, pRsp->pMeta) < 0) return -1; + } + tEndEncode(pEncoder); + return 0; +} + +int32_t tDecodeSMAlterStbRsp(SDecoder *pDecoder, SMAlterStbRsp *pRsp) { + int32_t meta = 0; + if (tStartDecode(pDecoder) < 0) return -1; + if (tDecodeI32(pDecoder, &meta) < 0) return -1; + if (meta) { + pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); + if (NULL == pRsp->pMeta) return -1; + if (tDecodeSTableMetaRsp(pDecoder, pRsp->pMeta) < 0) return -1; + } tEndDecode(pDecoder); return 0; } + +int32_t tDeserializeSMAlterStbRsp(void *buf, int32_t bufLen, SMAlterStbRsp *pRsp) { + int32_t meta = 0; + SDecoder decoder = {0}; + tDecoderInit(&decoder, buf, bufLen); + + if (tStartDecode(&decoder) < 0) return -1; + if (tDecodeI32(&decoder, &meta) < 0) return -1; + if (meta) { + pRsp->pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); + if (NULL == pRsp->pMeta) return -1; + if (tDecodeSTableMetaRsp(&decoder, pRsp->pMeta) < 0) return -1; + } + tEndDecode(&decoder); + tDecoderClear(&decoder); + return 0; +} + +void tFreeSMAlterStbRsp(SMAlterStbRsp* pRsp) { + if (NULL == pRsp) { + return; + } + + if (pRsp->pMeta) { + taosMemoryFree(pRsp->pMeta->pSchemas); + taosMemoryFree(pRsp->pMeta); + } +} + + + diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index acb344c8a5077ab7dca322a0b95d2a3afdfe6e25..556837f397e0d9c09546d5fa9400654b44f39401 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -1207,13 +1207,125 @@ static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj return 0; } + +static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, STableMetaRsp *pRsp) { + taosRLockLatch(&pStb->lock); + + int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; + pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema)); + if (pRsp->pSchemas == NULL) { + taosRUnLockLatch(&pStb->lock); + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + strcpy(pRsp->dbFName, pStb->db); + strcpy(pRsp->tbName, tbName); + strcpy(pRsp->stbName, tbName); + pRsp->dbId = pDb->uid; + pRsp->numOfTags = pStb->numOfTags; + pRsp->numOfColumns = pStb->numOfColumns; + pRsp->precision = pDb->cfg.precision; + pRsp->tableType = TSDB_SUPER_TABLE; + pRsp->sversion = pStb->colVer; + pRsp->tversion = pStb->tagVer; + pRsp->suid = pStb->uid; + pRsp->tuid = pStb->uid; + + for (int32_t i = 0; i < pStb->numOfColumns; ++i) { + SSchema *pSchema = &pRsp->pSchemas[i]; + SSchema *pSrcSchema = &pStb->pColumns[i]; + memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); + pSchema->type = pSrcSchema->type; + pSchema->colId = pSrcSchema->colId; + pSchema->bytes = pSrcSchema->bytes; + } + + for (int32_t i = 0; i < pStb->numOfTags; ++i) { + SSchema *pSchema = &pRsp->pSchemas[i + pStb->numOfColumns]; + SSchema *pSrcSchema = &pStb->pTags[i]; + memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); + pSchema->type = pSrcSchema->type; + pSchema->colId = pSrcSchema->colId; + pSchema->bytes = pSrcSchema->bytes; + } + + taosRUnLockLatch(&pStb->lock); + return 0; +} + +static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) { + char tbFName[TSDB_TABLE_FNAME_LEN] = {0}; + snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName); + + SDbObj *pDb = mndAcquireDb(pMnode, dbFName); + if (pDb == NULL) { + terrno = TSDB_CODE_MND_DB_NOT_SELECTED; + return -1; + } + + SStbObj *pStb = mndAcquireStb(pMnode, tbFName); + if (pStb == NULL) { + mndReleaseDb(pMnode, pDb); + terrno = TSDB_CODE_MND_INVALID_STB; + return -1; + } + + int32_t code = mndBuildStbSchemaImp(pDb, pStb, tbName, pRsp); + mndReleaseDb(pMnode, pDb); + mndReleaseStb(pMnode, pStb); + return code; +} + + +static int32_t mndBuildSMAlterStbRsp(SDbObj *pDb, const SMAlterStbReq *pAlter, SStbObj *pObj, void **pCont, int32_t *pLen) { + int ret; + SEncoder ec = {0}; + uint32_t contLen = 0; + SMAlterStbRsp alterRsp = {0}; + SName name = {0}; + tNameFromString(&name, pAlter->name, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE); + + alterRsp.pMeta = taosMemoryCalloc(1, sizeof(STableMetaRsp)); + if (NULL == alterRsp.pMeta) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + ret = mndBuildStbSchemaImp(pDb, pObj, name.tname, alterRsp.pMeta); + if (ret) { + tFreeSMAlterStbRsp(&alterRsp); + return ret; + } + + tEncodeSize(tEncodeSMAlterStbRsp, &alterRsp, contLen, ret); + if (ret) { + tFreeSMAlterStbRsp(&alterRsp); + return ret; + } + + void* cont = taosMemoryMalloc(contLen); + tEncoderInit(&ec, cont, contLen); + tEncodeSMAlterStbRsp(&ec, &alterRsp); + tEncoderClear(&ec); + + tFreeSMAlterStbRsp(&alterRsp); + + *pCont = cont; + *pLen = contLen; + + return 0; +} + static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *pAlter, SDbObj *pDb, SStbObj *pOld) { + bool needRsp = true; SStbObj stbObj = {0}; taosRLockLatch(&pOld->lock); memcpy(&stbObj, pOld, sizeof(SStbObj)); stbObj.pColumns = NULL; stbObj.pTags = NULL; stbObj.updateTime = taosGetTimestampMs(); + stbObj.lock = 0; taosRUnLockLatch(&pOld->lock); int32_t code = -1; @@ -1247,9 +1359,11 @@ static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *p code = mndAlterStbColumnBytes(pOld, &stbObj, pField0); break; case TSDB_ALTER_TABLE_UPDATE_OPTIONS: + needRsp = false; code = mndUpdateStbCommentAndTTL(pOld, &stbObj, pAlter->comment, pAlter->commentLen, pAlter->ttl); break; default: + needRsp = false; terrno = TSDB_CODE_OPS_NOT_SUPPORT; break; } @@ -1263,6 +1377,13 @@ static int32_t mndAlterStb(SMnode *pMnode, SRpcMsg *pReq, const SMAlterStbReq *p mDebug("trans:%d, used to alter stb:%s", pTrans->id, pAlter->name); mndTransSetDbName(pTrans, pDb->name); + if (needRsp) { + void* pCont = NULL; + int32_t contLen = 0; + if (mndBuildSMAlterStbRsp(pDb, pAlter, &stbObj, &pCont, &contLen)) goto _OVER; + mndTransSetRpcRsp(pTrans, pCont, contLen); + } + if (mndSetAlterStbRedoLogs(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER; if (mndSetAlterStbCommitLogs(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER; if (mndSetAlterStbRedoActions(pMnode, pTrans, pDb, &stbObj) != 0) goto _OVER; @@ -1483,75 +1604,6 @@ static int32_t mndProcessVDropStbRsp(SRpcMsg *pRsp) { return 0; } -static int32_t mndBuildStbSchemaImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, STableMetaRsp *pRsp) { - taosRLockLatch(&pStb->lock); - - int32_t totalCols = pStb->numOfColumns + pStb->numOfTags; - pRsp->pSchemas = taosMemoryCalloc(totalCols, sizeof(SSchema)); - if (pRsp->pSchemas == NULL) { - taosRUnLockLatch(&pStb->lock); - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; - } - - strcpy(pRsp->dbFName, pStb->db); - strcpy(pRsp->tbName, tbName); - strcpy(pRsp->stbName, tbName); - pRsp->dbId = pDb->uid; - pRsp->numOfTags = pStb->numOfTags; - pRsp->numOfColumns = pStb->numOfColumns; - pRsp->precision = pDb->cfg.precision; - pRsp->tableType = TSDB_SUPER_TABLE; - pRsp->sversion = pStb->colVer; - pRsp->tversion = pStb->tagVer; - pRsp->suid = pStb->uid; - pRsp->tuid = pStb->uid; - - for (int32_t i = 0; i < pStb->numOfColumns; ++i) { - SSchema *pSchema = &pRsp->pSchemas[i]; - SSchema *pSrcSchema = &pStb->pColumns[i]; - memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); - pSchema->type = pSrcSchema->type; - pSchema->colId = pSrcSchema->colId; - pSchema->bytes = pSrcSchema->bytes; - } - - for (int32_t i = 0; i < pStb->numOfTags; ++i) { - SSchema *pSchema = &pRsp->pSchemas[i + pStb->numOfColumns]; - SSchema *pSrcSchema = &pStb->pTags[i]; - memcpy(pSchema->name, pSrcSchema->name, TSDB_COL_NAME_LEN); - pSchema->type = pSrcSchema->type; - pSchema->colId = pSrcSchema->colId; - pSchema->bytes = pSrcSchema->bytes; - } - - taosRUnLockLatch(&pStb->lock); - return 0; -} - -static int32_t mndBuildStbSchema(SMnode *pMnode, const char *dbFName, const char *tbName, STableMetaRsp *pRsp) { - char tbFName[TSDB_TABLE_FNAME_LEN] = {0}; - snprintf(tbFName, sizeof(tbFName), "%s.%s", dbFName, tbName); - - SDbObj *pDb = mndAcquireDb(pMnode, dbFName); - if (pDb == NULL) { - terrno = TSDB_CODE_MND_DB_NOT_SELECTED; - return -1; - } - - SStbObj *pStb = mndAcquireStb(pMnode, tbFName); - if (pStb == NULL) { - mndReleaseDb(pMnode, pDb); - terrno = TSDB_CODE_MND_INVALID_STB; - return -1; - } - - int32_t code = mndBuildStbSchemaImp(pDb, pStb, tbName, pRsp); - mndReleaseDb(pMnode, pDb); - mndReleaseStb(pMnode, pStb); - return code; -} - static int32_t mndProcessTableMetaReq(SRpcMsg *pReq) { SMnode *pMnode = pReq->info.node; int32_t code = -1; diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 03c70b26018b48ebcb282593ceee4303a5740677..d3b5f29aac9e1ed96d8fe3569065ecaa8a1a1706 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -87,7 +87,7 @@ int metaAlterSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* p int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq); int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq); int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq, SArray* tbUids); -int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq); +int metaAlterTable(SMeta* pMeta, int64_t version, SVAlterTbReq* pReq, STableMetaRsp *pMetaRsp); SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline); STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver); int metaGetTableEntryByName(SMetaReader* pReader, const char* name); diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index a3007419422031bf3ed2c975e58ba208634d953e..9fef60b79fd9ff6cb46e86ba626802378ead3f1f 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -25,6 +25,24 @@ static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry); static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type); +static int metaUpdateMetaRsp(tb_uid_t uid, char* tbName, SSchemaWrapper *pSchema, STableMetaRsp *pMetaRsp) { + pMetaRsp->pSchemas = taosMemoryMalloc(pSchema->nCols * sizeof(SSchema)); + if (NULL == pMetaRsp->pSchemas) { + terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + return -1; + } + + strcpy(pMetaRsp->tbName, tbName); + pMetaRsp->numOfColumns = pSchema->nCols; + pMetaRsp->tableType = TSDB_NORMAL_TABLE; + pMetaRsp->sversion = pSchema->version; + pMetaRsp->tuid = uid; + + memcpy(pMetaRsp->pSchemas, pSchema->pSchema, pSchema->nCols * sizeof(SSchema)); + + return 0; +} + int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { SMetaEntry me = {0}; int kLen = 0; @@ -323,8 +341,8 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { return 0; } -static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { - void *pVal = NULL; +static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq, STableMetaRsp *pMetaRsp) { + void * pVal = NULL; int nVal = 0; const void *pData = NULL; int nData = 0; @@ -463,6 +481,8 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl metaULock(pMeta); + metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp); + if (pNewSchema) taosMemoryFree(pNewSchema); tDecoderClear(&dc); tdbTbcClose(pTbDbc); @@ -629,13 +649,13 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p return 0; } -int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq) { +int metaAlterTable(SMeta *pMeta, int64_t version, SVAlterTbReq *pReq, STableMetaRsp *pMetaRsp) { switch (pReq->action) { case TSDB_ALTER_TABLE_ADD_COLUMN: case TSDB_ALTER_TABLE_DROP_COLUMN: case TSDB_ALTER_TABLE_UPDATE_COLUMN_BYTES: case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME: - return metaAlterTableColumn(pMeta, version, pReq); + return metaAlterTableColumn(pMeta, version, pReq, pMetaRsp); case TSDB_ALTER_TABLE_UPDATE_TAG_VAL: return metaUpdateTableTagVal(pMeta, version, pReq); case TSDB_ALTER_TABLE_UPDATE_OPTIONS: diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index b66695f7c258a2b782ae666a2ac59a8a41ddc49f..ab879c5dbbbff95a663747d8c1ce09f987f5dc8f 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -251,6 +251,13 @@ void smaHandleRes(void *pVnode, int64_t smaId, const SArray *data) { tdProcessTSmaInsert(((SVnode *)pVnode)->pSma, smaId, (const char *)data); } +void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) { + strcpy(pMetaRsp->dbFName, pVnode->config.dbname); + pMetaRsp->dbId = pVnode->config.dbId; + pMetaRsp->vgId = TD_VID(pVnode); + pMetaRsp->precision = pVnode->config.tsdbCfg.precision; +} + int vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { int32_t ret = TAOS_SYNC_PROPOSE_OTHER_ERROR; @@ -520,12 +527,13 @@ _exit: } static int vnodeProcessAlterTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { - SVAlterTbReq vAlterTbReq = {0}; - SVAlterTbRsp vAlterTbRsp = {0}; - SDecoder dc = {0}; - int rcode = 0; - int ret; - SEncoder ec = {0}; + SVAlterTbReq vAlterTbReq = {0}; + SVAlterTbRsp vAlterTbRsp = {0}; + SDecoder dc = {0}; + int rcode = 0; + int ret; + SEncoder ec = {0}; + STableMetaRsp vMetaRsp = {0}; pRsp->msgType = TDMT_VND_ALTER_TABLE_RSP; pRsp->pCont = NULL; @@ -543,7 +551,7 @@ static int vnodeProcessAlterTbReq(SVnode *pVnode, int64_t version, void *pReq, i } // process - if (metaAlterTable(pVnode->pMeta, version, &vAlterTbReq) < 0) { + if (metaAlterTable(pVnode->pMeta, version, &vAlterTbReq, &vMetaRsp) < 0) { vAlterTbRsp.code = TSDB_CODE_INVALID_MSG; tDecoderClear(&dc); rcode = -1; @@ -551,6 +559,11 @@ static int vnodeProcessAlterTbReq(SVnode *pVnode, int64_t version, void *pReq, i } tDecoderClear(&dc); + if (NULL != vMetaRsp.pSchemas) { + vnodeUpdateMetaRsp(pVnode, &vMetaRsp); + vAlterTbRsp.pMeta = &vMetaRsp; + } + _exit: tEncodeSize(tEncodeSVAlterTbRsp, &vAlterTbRsp, pRsp->contLen, ret); pRsp->pCont = rpcMallocCont(pRsp->contLen); diff --git a/source/libs/catalog/inc/catalogInt.h b/source/libs/catalog/inc/catalogInt.h index 57f651ed693251b4ffd132d1c445662618ea59aa..239d719fa80eb3b4fbf9b075e165dc50051b3e52 100644 --- a/source/libs/catalog/inc/catalogInt.h +++ b/source/libs/catalog/inc/catalogInt.h @@ -302,7 +302,7 @@ typedef struct SCtgUpdateEpsetMsg { typedef struct SCtgCacheOperation { int32_t opId; void *data; - bool syncReq; + bool syncOp; uint64_t seqId; } SCtgCacheOperation; diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index a8747644683a0d77afe102bc43fe40513df9e0a5..7e0efe22dbfa2dd61a5c662c1103a1b98f579da8 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -314,6 +314,36 @@ _return: CTG_RET(code); } +int32_t ctgUpdateTbMeta(SCatalog* pCtg, STableMetaRsp *rspMsg, bool syncOp) { + STableMetaOutput *output = taosMemoryCalloc(1, sizeof(STableMetaOutput)); + if (NULL == output) { + ctgError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); + CTG_ERR_RET(TSDB_CODE_CTG_MEM_ERROR); + } + + int32_t code = 0; + + strcpy(output->dbFName, rspMsg->dbFName); + strcpy(output->tbName, rspMsg->tbName); + + output->dbId = rspMsg->dbId; + + SET_META_TYPE_TABLE(output->metaType); + + CTG_ERR_JRET(queryCreateTableMetaFromMsg(rspMsg, rspMsg->tableType == TSDB_SUPER_TABLE, &output->tbMeta)); + + CTG_ERR_JRET(ctgUpdateTbMetaEnqueue(pCtg, output, syncOp)); + + return TSDB_CODE_SUCCESS; + +_return: + + taosMemoryFreeClear(output->tbMeta); + taosMemoryFreeClear(output); + + CTG_RET(code); +} + int32_t ctgChkAuth(SCatalog* pCtg, void *pTrans, const SEpSet* pMgmtEps, const char* user, const char* dbFName, AUTH_TYPE type, bool *pass) { bool inCache = false; @@ -779,38 +809,17 @@ int32_t catalogGetSTableMeta(SCatalog* pCtg, void * pTrans, const SEpSet* pMgmtE CTG_API_LEAVE(ctgGetTbMeta(CTG_PARAMS_LIST(), &ctx, pTableMeta)); } -int32_t catalogUpdateSTableMeta(SCatalog* pCtg, STableMetaRsp *rspMsg) { +int32_t catalogUpdateTableMeta(SCatalog* pCtg, STableMetaRsp *pMsg) { CTG_API_ENTER(); - if (NULL == pCtg || NULL == rspMsg) { + if (NULL == pCtg || NULL == pMsg) { CTG_API_LEAVE(TSDB_CODE_CTG_INVALID_INPUT); } - STableMetaOutput *output = taosMemoryCalloc(1, sizeof(STableMetaOutput)); - if (NULL == output) { - ctgError("malloc %d failed", (int32_t)sizeof(STableMetaOutput)); - CTG_API_LEAVE(TSDB_CODE_CTG_MEM_ERROR); - } - int32_t code = 0; - - strcpy(output->dbFName, rspMsg->dbFName); - strcpy(output->tbName, rspMsg->tbName); - - output->dbId = rspMsg->dbId; - - SET_META_TYPE_TABLE(output->metaType); - - CTG_ERR_JRET(queryCreateTableMetaFromMsg(rspMsg, true, &output->tbMeta)); - - CTG_ERR_JRET(ctgUpdateTbMetaEnqueue(pCtg, output, false)); - - CTG_API_LEAVE(code); + CTG_ERR_JRET(ctgUpdateTbMeta(pCtg, pMsg, true)); _return: - - taosMemoryFreeClear(output->tbMeta); - taosMemoryFreeClear(output); CTG_API_LEAVE(code); } diff --git a/source/libs/catalog/src/ctgCache.c b/source/libs/catalog/src/ctgCache.c index 2fbb8b499d58de6d3fb7b968cd04fcf5d6140a0f..0f1344c3432b2540c2daa33de33c2f8c570658f0 100644 --- a/source/libs/catalog/src/ctgCache.c +++ b/source/libs/catalog/src/ctgCache.c @@ -552,7 +552,7 @@ int32_t ctgEnqueue(SCatalog* pCtg, SCtgCacheOperation *operation) { ctgDebug("action [%s] added into queue", gCtgCacheOperation[operation->opId].name); - if (operation->syncReq) { + if (operation->syncOp) { ctgWaitOpDone(operation); } @@ -591,9 +591,9 @@ _return: } -int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid, bool syncReq) { +int32_t ctgDropStbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *stbName, uint64_t suid, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_DROP_STB_META, .syncReq = syncReq}; + SCtgCacheOperation action= {.opId = CTG_OP_DROP_STB_META, .syncOp = syncOp}; SCtgRemoveStbMsg *msg = taosMemoryMalloc(sizeof(SCtgRemoveStbMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveStbMsg)); @@ -620,9 +620,9 @@ _return: -int32_t ctgDropTbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName, bool syncReq) { +int32_t ctgDropTbMetaEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, const char *tbName, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_DROP_TB_META, .syncReq = syncReq}; + SCtgCacheOperation action= {.opId = CTG_OP_DROP_TB_META, .syncOp = syncOp}; SCtgRemoveTblMsg *msg = taosMemoryMalloc(sizeof(SCtgRemoveTblMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgRemoveTblMsg)); @@ -646,9 +646,9 @@ _return: CTG_RET(code); } -int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, SDBVgInfo* dbInfo, bool syncReq) { +int32_t ctgUpdateVgroupEnqueue(SCatalog* pCtg, const char *dbFName, int64_t dbId, SDBVgInfo* dbInfo, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_VGROUP, .syncReq = syncReq}; + SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_VGROUP, .syncOp = syncOp}; SCtgUpdateVgMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateVgMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateVgMsg)); @@ -679,9 +679,9 @@ _return: CTG_RET(code); } -int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool syncReq) { +int32_t ctgUpdateTbMetaEnqueue(SCatalog* pCtg, STableMetaOutput *output, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_TB_META, .syncReq = syncReq}; + SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_TB_META, .syncOp = syncOp}; SCtgUpdateTblMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateTblMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateTblMsg)); @@ -738,9 +738,9 @@ _return: -int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syncReq) { +int32_t ctgUpdateUserEnqueue(SCatalog* pCtg, SGetUserAuthRsp *pAuth, bool syncOp) { int32_t code = 0; - SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_USER, .syncReq = syncReq}; + SCtgCacheOperation action= {.opId = CTG_OP_UPDATE_USER, .syncOp = syncOp}; SCtgUpdateUserMsg *msg = taosMemoryMalloc(sizeof(SCtgUpdateUserMsg)); if (NULL == msg) { ctgError("malloc %d failed", (int32_t)sizeof(SCtgUpdateUserMsg)); @@ -1574,7 +1574,7 @@ void* ctgUpdateThreadFunc(void* param) { gCtgMgmt.queue.seqDone = operation->seqId; - if (operation->syncReq) { + if (operation->syncOp) { tsem_post(&gCtgMgmt.queue.rspSem); } diff --git a/source/libs/catalog/test/catalogTests.cpp b/source/libs/catalog/test/catalogTests.cpp index 19c5bb6dcdd8e6d879c349633ae54d7b542af303..e4ae2c004f412e356feba406fca07f1c83863abe 100644 --- a/source/libs/catalog/test/catalogTests.cpp +++ b/source/libs/catalog/test/catalogTests.cpp @@ -1380,7 +1380,7 @@ TEST(tableMeta, updateStbMeta) { STableMetaRsp rsp = {0}; ctgTestBuildSTableMetaRsp(&rsp); - code = catalogUpdateSTableMeta(pCtg, &rsp); + code = catalogUpdateTableMeta(pCtg, &rsp); ASSERT_EQ(code, 0); taosMemoryFreeClear(rsp.pSchemas); diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 5c656b969b1cc64ff2bb86127b94c764fcb04c56..593a597a823b831bd766ffaa02195153fcb49c2b 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -60,6 +60,7 @@ typedef struct SInsertParseContext { SHashObj* pSubTableHashObj; // global SArray* pVgDataBlocks; // global SHashObj* pTableNameHashObj; // global + SHashObj* pDbFNameHashObj; // global int32_t totalNum; SVnodeModifOpStmt* pOutput; SStmtCallback* pStmtCb; @@ -1153,6 +1154,10 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, continue; } + if (TK_NK_RP == sToken.type) { + return generateSyntaxErrMsg(&pCxt->msg, TSDB_CODE_PAR_INVALID_COLUMNS_NUM); + } + if (isParseBindParam) { return buildInvalidOperationMsg(&pCxt->msg, "no mix usage for ? and values"); } @@ -1271,6 +1276,7 @@ static void destroyInsertParseContext(SInsertParseContext* pCxt) { taosHashCleanup(pCxt->pVgroupsHashObj); taosHashCleanup(pCxt->pSubTableHashObj); taosHashCleanup(pCxt->pTableNameHashObj); + taosHashCleanup(pCxt->pDbFNameHashObj); destroyBlockHashmap(pCxt->pTableBlockHashObj); destroyBlockArrayList(pCxt->pVgDataBlocks); @@ -1331,6 +1337,9 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { tNameExtractFullName(&name, tbFName); CHECK_CODE(taosHashPut(pCxt->pTableNameHashObj, tbFName, strlen(tbFName), &name, sizeof(SName))); + char dbFName[TSDB_DB_FNAME_LEN]; + tNameGetFullDbName(&name, dbFName); + CHECK_CODE(taosHashPut(pCxt->pDbFNameHashObj, dbFName, strlen(dbFName), dbFName, sizeof(dbFName))); // USING clause if (TK_USING == sToken.type) { @@ -1338,8 +1347,6 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) { NEXT_TOKEN(pCxt->pSql, sToken); autoCreateTbl = true; } else { - char dbFName[TSDB_DB_FNAME_LEN]; - tNameGetFullDbName(&name, dbFName); CHECK_CODE(getTableMeta(pCxt, &name, dbFName)); } @@ -1418,6 +1425,7 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { .pTableMeta = NULL, .pSubTableHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK), .pTableNameHashObj = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK), + .pDbFNameHashObj = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_VARCHAR), true, HASH_NO_LOCK), .totalNum = 0, .pOutput = (SVnodeModifOpStmt*)nodesMakeNode(QUERY_NODE_VNODE_MODIF_STMT), .pStmtCb = pContext->pStmtCb}; @@ -1432,7 +1440,7 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { } if (NULL == context.pVgroupsHashObj || NULL == context.pTableBlockHashObj || NULL == context.pSubTableHashObj || - NULL == context.pTableNameHashObj || NULL == context.pOutput) { + NULL == context.pTableNameHashObj || NULL == context.pDbFNameHashObj || NULL == context.pOutput) { return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -1458,6 +1466,13 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { } } + if (NULL == (*pQuery)->pDbList) { + (*pQuery)->pDbList = taosArrayInit(taosHashGetSize(context.pDbFNameHashObj), TSDB_DB_FNAME_LEN); + if (NULL == (*pQuery)->pDbList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + } + context.pOutput->payloadType = PAYLOAD_TYPE_KV; int32_t code = skipInsertInto(&context.pSql, &context.msg); @@ -1470,6 +1485,12 @@ int32_t parseInsertSql(SParseContext* pContext, SQuery** pQuery) { taosArrayPush((*pQuery)->pTableList, pTable); pTable = taosHashIterate(context.pTableNameHashObj, pTable); } + + char* pDb = taosHashIterate(context.pDbFNameHashObj, NULL); + while (NULL != pDb) { + taosArrayPush((*pQuery)->pDbList, pDb); + pDb = taosHashIterate(context.pDbFNameHashObj, pDb); + } } destroyInsertParseContext(&context); return code; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 6fc9680c09d2840313bdcac066a8b12780ac51ca..c4e63ee8807b837e4875660f400a63bf8b835ad8 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -4936,6 +4936,47 @@ static int32_t rewriteQuery(STranslateContext* pCxt, SQuery* pQuery) { return code; } +static int32_t toMsgType(ENodeType type) { + switch (type) { + case QUERY_NODE_CREATE_TABLE_STMT: + return TDMT_VND_CREATE_TABLE; + case QUERY_NODE_ALTER_TABLE_STMT: + return TDMT_VND_ALTER_TABLE; + case QUERY_NODE_DROP_TABLE_STMT: + return TDMT_VND_DROP_TABLE; + default: + break; + } + return TDMT_VND_CREATE_TABLE; +} + +static int32_t setRefreshMate(STranslateContext* pCxt, SQuery* pQuery) { + if (NULL != pCxt->pDbs) { + pQuery->pDbList = taosArrayInit(taosHashGetSize(pCxt->pDbs), TSDB_DB_FNAME_LEN); + if (NULL == pQuery->pDbList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + SFullDatabaseName* pDb = taosHashIterate(pCxt->pDbs, NULL); + while (NULL != pDb) { + taosArrayPush(pQuery->pDbList, pDb->fullDbName); + pDb = taosHashIterate(pCxt->pDbs, pDb); + } + } + + if (NULL != pCxt->pTables) { + pQuery->pTableList = taosArrayInit(taosHashGetSize(pCxt->pTables), sizeof(SName)); + if (NULL == pQuery->pTableList) { + return TSDB_CODE_OUT_OF_MEMORY; + } + SName* pTable = taosHashIterate(pCxt->pTables, NULL); + while (NULL != pTable) { + taosArrayPush(pQuery->pTableList, pTable); + pTable = taosHashIterate(pCxt->pTables, pTable); + } + } + return TSDB_CODE_SUCCESS; +} + static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { switch (nodeType(pQuery->pRoot)) { case QUERY_NODE_SELECT_STMT: @@ -4947,7 +4988,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { break; case QUERY_NODE_VNODE_MODIF_STMT: pQuery->execMode = QUERY_EXEC_MODE_SCHEDULE; - pQuery->msgType = TDMT_VND_CREATE_TABLE; + pQuery->msgType = toMsgType(((SVnodeModifOpStmt*)pQuery->pRoot)->sqlNodeType); break; case QUERY_NODE_DESCRIBE_STMT: pQuery->execMode = QUERY_EXEC_MODE_LOCAL; @@ -4975,30 +5016,6 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) { } } - if (NULL != pCxt->pDbs) { - pQuery->pDbList = taosArrayInit(taosHashGetSize(pCxt->pDbs), TSDB_DB_FNAME_LEN); - if (NULL == pQuery->pDbList) { - return TSDB_CODE_OUT_OF_MEMORY; - } - SFullDatabaseName* pDb = taosHashIterate(pCxt->pDbs, NULL); - while (NULL != pDb) { - taosArrayPush(pQuery->pDbList, pDb->fullDbName); - pDb = taosHashIterate(pCxt->pDbs, pDb); - } - } - - if (NULL != pCxt->pTables) { - pQuery->pTableList = taosArrayInit(taosHashGetSize(pCxt->pTables), sizeof(SName)); - if (NULL == pQuery->pTableList) { - return TSDB_CODE_OUT_OF_MEMORY; - } - SName* pTable = taosHashIterate(pCxt->pTables, NULL); - while (NULL != pTable) { - taosArrayPush(pQuery->pTableList, pTable); - pTable = taosHashIterate(pCxt->pTables, pTable); - } - } - return TSDB_CODE_SUCCESS; } @@ -5018,6 +5035,7 @@ int32_t translate(SParseContext* pParseCxt, SQuery* pQuery) { if (TSDB_CODE_SUCCESS == code) { code = setQuery(&cxt, pQuery); } + setRefreshMate(&cxt, pQuery); destroyTranslateContext(&cxt); return code; } diff --git a/source/libs/qcom/src/queryUtil.c b/source/libs/qcom/src/queryUtil.c index f4ba2fca8146b37a3e25bc7173488dd85c8e48d0..a5a499aaf5bc3b38998528d1550bd9b16c1d7671 100644 --- a/source/libs/qcom/src/queryUtil.c +++ b/source/libs/qcom/src/queryUtil.c @@ -199,3 +199,30 @@ SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* nam tstrncpy(s.name, name, tListLen(s.name)); return s; } + +void destroyQueryExecRes(SQueryExecRes* pRes) { + if (NULL == pRes || NULL == pRes->res) { + return; + } + + switch (pRes->msgType) { + case TDMT_VND_ALTER_TABLE: + case TDMT_MND_ALTER_STB: { + tFreeSTableMetaRsp((STableMetaRsp *)pRes->res); + taosMemoryFreeClear(pRes->res); + break; + } + case TDMT_VND_SUBMIT: { + tFreeSSubmitRsp((SSubmitRsp*)pRes->res); + break; + } + case TDMT_VND_QUERY: { + taosArrayDestroy((SArray*)pRes->res); + break; + } + default: + qError("invalid exec result for request type %d", pRes->msgType); + } +} + + diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index 810c0153b1b92cfbc490e3853ec2e188aec6f212..e77f2b0ca42e58744ea14de5286ae24d1c4ceb14 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -273,7 +273,7 @@ static int32_t queryConvertTableMetaMsg(STableMetaRsp *pMetaMsg) { return TSDB_CODE_SUCCESS; } -int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isSuperTable, STableMeta **pMeta) { +int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isStb, STableMeta **pMeta) { int32_t total = msg->numOfColumns + msg->numOfTags; int32_t metaSize = sizeof(STableMeta) + sizeof(SSchema) * total; @@ -283,14 +283,14 @@ int32_t queryCreateTableMetaFromMsg(STableMetaRsp *msg, bool isSuperTable, STabl return TSDB_CODE_TSC_OUT_OF_MEMORY; } - pTableMeta->vgId = isSuperTable ? 0 : msg->vgId; - pTableMeta->tableType = isSuperTable ? TSDB_SUPER_TABLE : msg->tableType; - pTableMeta->uid = isSuperTable ? msg->suid : msg->tuid; + pTableMeta->vgId = isStb ? 0 : msg->vgId; + pTableMeta->tableType = isStb ? TSDB_SUPER_TABLE : msg->tableType; + pTableMeta->uid = isStb ? msg->suid : msg->tuid; pTableMeta->suid = msg->suid; pTableMeta->sversion = msg->sversion; pTableMeta->tversion = msg->tversion; - if (isSuperTable) { + if (isStb) { qDebug("stable %s meta returned, suid:%" PRIx64, msg->stbName, pTableMeta->suid); } diff --git a/source/libs/scheduler/inc/schedulerInt.h b/source/libs/scheduler/inc/schedulerInt.h index 09a4f322d46758890782235a317e3ee100d06adb..44b3e6d396b8750a78ba9e414243f45686a121ec 100644 --- a/source/libs/scheduler/inc/schedulerInt.h +++ b/source/libs/scheduler/inc/schedulerInt.h @@ -204,7 +204,7 @@ typedef struct SSchJob { SSchTask *fetchTask; int32_t errCode; SRWLatch resLock; - void *queryRes; + SQueryExecRes execRes; void *resData; //TODO free it or not int32_t resNumOfRows; SSchResInfo userRes; diff --git a/source/libs/scheduler/src/schJob.c b/source/libs/scheduler/src/schJob.c index 1c60dcccfdd82c6196854ca158791de3839a2917..dbad053c65ba3572a6d4740e4b991f3760e9631b 100644 --- a/source/libs/scheduler/src/schJob.c +++ b/source/libs/scheduler/src/schJob.c @@ -773,8 +773,8 @@ _return: int32_t schSetJobQueryRes(SSchJob* pJob, SQueryResult* pRes) { pRes->code = atomic_load_32(&pJob->errCode); pRes->numOfRows = pJob->resNumOfRows; - pRes->res = pJob->queryRes; - pJob->queryRes = NULL; + pRes->res = pJob->execRes; + pJob->execRes.res = NULL; return TSDB_CODE_SUCCESS; } @@ -1107,9 +1107,9 @@ int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRs int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp) { if (rsp->tbFName[0]) { - if (NULL == pJob->queryRes) { - pJob->queryRes = taosArrayInit(pJob->taskNum, sizeof(STbVerInfo)); - if (NULL == pJob->queryRes) { + if (NULL == pJob->execRes.res) { + pJob->execRes.res = taosArrayInit(pJob->taskNum, sizeof(STbVerInfo)); + if (NULL == pJob->execRes.res) { SCH_ERR_RET(TSDB_CODE_OUT_OF_MEMORY); } } @@ -1119,7 +1119,8 @@ int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp) { tbInfo.sversion = rsp->sversion; tbInfo.tversion = rsp->tversion; - taosArrayPush((SArray *)pJob->queryRes, &tbInfo); + taosArrayPush((SArray *)pJob->execRes.res, &tbInfo); + pJob->execRes.msgType = TDMT_VND_QUERY; } return TSDB_CODE_SUCCESS; @@ -1349,11 +1350,7 @@ void schFreeJobImpl(void *job) { qExplainFreeCtx(pJob->explainCtx); - if (SCH_IS_QUERY_JOB(pJob)) { - taosArrayDestroy((SArray *)pJob->queryRes); - } else { - tFreeSSubmitRsp((SSubmitRsp*)pJob->queryRes); - } + destroyQueryExecRes(&pJob->execRes); taosMemoryFreeClear(pJob->userRes.queryRes); taosMemoryFreeClear(pJob->resData); diff --git a/source/libs/scheduler/src/schRemote.c b/source/libs/scheduler/src/schRemote.c index c15649106e499cc4de67b4e0a78a0e1ba060f46f..0ba91a1c85649463225bd5f6d82edad4b56714c9 100644 --- a/source/libs/scheduler/src/schRemote.c +++ b/source/libs/scheduler/src/schRemote.c @@ -162,6 +162,9 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch tDecoderClear(&coder); SCH_ERR_JRET(code); SCH_ERR_JRET(rsp.code); + + pJob->execRes.res = rsp.pMeta; + pJob->execRes.msgType = TDMT_VND_ALTER_TABLE; } SCH_ERR_JRET(rspCode); @@ -204,8 +207,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch SCH_TASK_DLOG("submit succeed, affectedRows:%d", rsp->affectedRows); SCH_LOCK(SCH_WRITE, &pJob->resLock); - if (pJob->queryRes) { - SSubmitRsp *sum = pJob->queryRes; + if (pJob->execRes.res) { + SSubmitRsp *sum = pJob->execRes.res; sum->affectedRows += rsp->affectedRows; sum->nBlocks += rsp->nBlocks; sum->pBlocks = taosMemoryRealloc(sum->pBlocks, sum->nBlocks * sizeof(*sum->pBlocks)); @@ -213,7 +216,8 @@ int32_t schHandleResponseMsg(SSchJob *pJob, SSchTask *pTask, int32_t msgType, ch taosMemoryFree(rsp->pBlocks); taosMemoryFree(rsp); } else { - pJob->queryRes = rsp; + pJob->execRes.res = rsp; + pJob->execRes.msgType = TDMT_VND_SUBMIT; } SCH_UNLOCK(SCH_WRITE, &pJob->resLock); } diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index d2a43c410708249983295dca44ca06f6f75a2b70..4e2270c37bc00e9055bf340dab898d842feb5ce4 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -18,6 +18,14 @@ #include "tchecksum.h" #include "walInt.h" +void walRestoreFromSnapshot(SWal *pWal, int64_t ver) { + pWal->vers.firstVer = -1; + pWal->vers.lastVer = ver; + pWal->vers.commitVer = ver - 1; + pWal->vers.snapshotVer = ver - 1; + pWal->vers.verInSnapshotting = -1; +} + int32_t walCommit(SWal *pWal, int64_t ver) { ASSERT(pWal->vers.commitVer >= pWal->vers.snapshotVer); ASSERT(pWal->vers.commitVer <= pWal->vers.lastVer); diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 9b8a63e40451a3423b88fcd27154206cae1c633a..bb446fb248602842b579817dbdbbcc02f0a0680f 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -136,4 +136,7 @@ ./test.sh -f tsim/sync/oneReplica1VgElect.sim ./test.sh -f tsim/sync/oneReplica5VgElect.sim +# --- catalog +./test.sh -f tsim/catalog/alterInCurrent.sim + #======================b1-end=============== diff --git a/tests/script/tsim/catalog/alterInCurrent.sim b/tests/script/tsim/catalog/alterInCurrent.sim new file mode 100644 index 0000000000000000000000000000000000000000..3cb337bbe1930104a21d3d31bf4d5d34a2515352 --- /dev/null +++ b/tests/script/tsim/catalog/alterInCurrent.sim @@ -0,0 +1,70 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 + +print ========= start dnode1 as LEADER +system sh/exec.sh -n dnode1 -s start +sql connect + +print ======== drop column in normal table +sql drop database if exists db1; +sql create database db1; +sql use db1; +sql create table t1 (ts timestamp, f1 int, f2 int); +sql insert into t1 values (1591060628000, 1, 2); +sql alter table t1 drop column f2; +sql insert into t1 values (1591060628001, 2); + +print ======== add column in normal table +sql drop database db1; +sql create database db1; +sql use db1; +sql create table t1 (ts timestamp, f1 int); +sql insert into t1 values (1591060628000, 1); +sql alter table t1 add column f2 int; +sql insert into t1 values (1591060628001, 2, 2); + + +print ======== drop column in super table +sql drop database db1; +sql create database db1; +sql use db1; +sql create stable st1 (ts timestamp, f1 int, f2 int) tags (t1 int); +sql create table t1 using st1 tags(1); +sql insert into t1 values (1591060628000, 1, 2); +sql alter table st1 drop column f2; +sql insert into t1 values (1591060628001, 2); + + +print ======== add column in super table +sql drop database db1; +sql create database db1; +sql use db1; +sql create stable st1 (ts timestamp, f1 int) tags (t1 int); +sql create table t1 using st1 tags(1); +sql insert into t1 values (1591060628000, 1); +sql alter table st1 add column f2 int; +sql insert into t1 values (1591060628001, 2, 2); + + +print ======== add tag in super table +sql drop database db1; +sql create database db1; +sql use db1; +sql create stable st1 (ts timestamp, f1 int) tags (t1 int); +sql create table t1 using st1 tags(1); +sql insert into t1 values (1591060628000, 1); +sql alter table st1 add tag t2 int; +sql create table t2 using st1 tags(2, 2); + + +print ======== drop tag in super table +sql drop database db1; +sql create database db1; +sql use db1; +sql create stable st1 (ts timestamp, f1 int) tags (t1 int, t2 int); +sql create table t1 using st1 tags(1, 1); +sql insert into t1 values (1591060628000, 1); +sql alter table st1 drop tag t2; +sql create table t2 using st1 tags(2); + +system sh/exec.sh -n dnode1 -s stop -x SIGINT diff --git a/tests/script/tsim/stable/column_drop.sim b/tests/script/tsim/stable/column_drop.sim index af84a3ecac28da9f6dbf41d08af707d1aa6226a4..3401465103762d523b8cb5f15585f9924db4abfa 100644 --- a/tests/script/tsim/stable/column_drop.sim +++ b/tests/script/tsim/stable/column_drop.sim @@ -129,7 +129,8 @@ endi print ========== step2 drop column c5 sql alter table db.stb drop column c5 -sql insert into db.ctb values(now+2s, 1, 2, 3, 4, 5) +sql_error insert into db.ctb values(now+2s, 1, 2, 3, 4, 5) +sql insert into db.ctb values(now+2s, 1, 2, 3, 4) sql insert into db.ctb values(now+3s, 1, 2, 3, 4) sql_error insert into db.ctb values(now+2s, 1, 2, 3, 4, 5) @@ -206,4 +207,4 @@ if $data[7][0] != t3 then return -1 endi -system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file +system sh/exec.sh -n dnode1 -s stop -x SIGINT