From 174ae5ee6bcb3bad1660f2f0f4e006ad076dfe89 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Tue, 14 Jun 2022 19:06:14 +0800 Subject: [PATCH 1/9] feat:add logic for ttl --- include/libs/nodes/cmdnodes.h | 1 + source/libs/nodes/src/nodesUtilFuncs.c | 1 + source/libs/parser/src/parAstCreater.c | 2 +- source/libs/parser/src/parTranslater.c | 2 ++ 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 8d4e94663f..40963d5af2 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -121,6 +121,7 @@ typedef struct SCreateSubTableClause { bool ignoreExists; SNodeList* pSpecificTags; SNodeList* pValsOfTags; + STableOptions* pOptions; } SCreateSubTableClause; typedef struct SCreateMultiTableStmt { diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 72666f833d..2d0e2861ca 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -508,6 +508,7 @@ void nodesDestroyNode(SNode* pNode) { SCreateSubTableClause* pStmt = (SCreateSubTableClause*)pNode; nodesDestroyList(pStmt->pSpecificTags); nodesDestroyList(pStmt->pValsOfTags); + nodesDestroyNode((SNode*)pStmt->pOptions); break; } case QUERY_NODE_CREATE_MULTI_TABLE_STMT: diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index ca066c7056..05b2b0c31c 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -957,9 +957,9 @@ SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SN pStmt->ignoreExists = ignoreExists; pStmt->pSpecificTags = pSpecificTags; pStmt->pValsOfTags = pValsOfTags; + pStmt->pOptions = (STableOptions*)pOptions; nodesDestroyNode(pRealTable); nodesDestroyNode(pUseRealTable); - nodesDestroyNode(pOptions); return (SNode*)pStmt; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index fcf2f57dec..e887d00e2c 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -4252,6 +4252,7 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* SVCreateTbReq req = {0}; req.type = TD_NORMAL_TABLE; req.name = strdup(pStmt->tableName); + req.ttl = pStmt->pOptions->ttl; req.ntb.schemaRow.nCols = LIST_LENGTH(pStmt->pCols); req.ntb.schemaRow.version = 1; req.ntb.schemaRow.pSchema = taosMemoryCalloc(req.ntb.schemaRow.nCols, sizeof(SSchema)); @@ -4402,6 +4403,7 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, S struct SVCreateTbReq req = {0}; req.type = TD_CHILD_TABLE; req.name = strdup(pStmt->tableName); + req.ttl = pStmt->pOptions->ttl; req.ctb.suid = suid; req.ctb.pTag = (uint8_t*)pTag; if (pStmt->ignoreExists) { From f2a19c98efd5986953f76e8bdba01dae165eac90 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Wed, 15 Jun 2022 20:35:45 +0800 Subject: [PATCH 2/9] feat:add test for operator encode/decode --- include/common/tmsgdef.h | 2 +- source/common/src/tmsg.c | 4 +- source/dnode/mnode/impl/src/mndStb.c | 4 +- source/dnode/vnode/src/inc/vnodeInt.h | 2 + source/dnode/vnode/src/meta/metaQuery.c | 36 ++++++++++- source/dnode/vnode/src/meta/metaTable.c | 82 ++++++++++++++++++------- source/dnode/vnode/src/vnd/vnodeSvr.c | 24 +++++++- source/libs/parser/src/parTranslater.c | 7 ++- source/libs/tdb/inc/tdb.h | 1 + source/libs/tdb/src/db/tdbBtree.c | 46 ++++++++++++++ source/libs/tdb/src/db/tdbTable.c | 4 ++ source/libs/tdb/src/inc/tdbInt.h | 1 + 12 files changed, 180 insertions(+), 33 deletions(-) diff --git a/include/common/tmsgdef.h b/include/common/tmsgdef.h index 6863e3c336..4a6368ef30 100644 --- a/include/common/tmsgdef.h +++ b/include/common/tmsgdef.h @@ -198,7 +198,7 @@ enum { TD_DEF_MSG_TYPE(TDMT_VND_ALTER_CONFIRM, "alter-confirm", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_ALTER_HASHRANGE, "alter-hashrange", NULL, NULL) TD_DEF_MSG_TYPE(TDMT_VND_COMPACT, "compact", NULL, NULL) - + TD_DEF_MSG_TYPE(TDMT_VND_DROP_TTL_TABLE, "drop-ttl-stb", NULL, NULL) TD_NEW_MSG_SEG(TDMT_QND_MSG) //shared by snode and vnode diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 2f7ca249ef..945238ba1c 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -498,7 +498,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq } if (pReq->commentLen > 0) { - if (tEncodeBinary(&encoder, pReq->comment, pReq->commentLen) < 0) return -1; + if (tEncodeCStrWithLen(&encoder, pReq->comment, pReq->commentLen) < 0) return -1; } if (pReq->ast1Len > 0) { if (tEncodeBinary(&encoder, pReq->pAst1, pReq->ast1Len) < 0) return -1; @@ -561,7 +561,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR } if (pReq->commentLen > 0) { - pReq->comment = taosMemoryMalloc(pReq->commentLen); + pReq->comment = taosMemoryCalloc(1, pReq->commentLen + 1); if (pReq->comment == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; } diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 6f89c97f83..d498b640cb 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -671,12 +671,12 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat pDst->numOfTags = pCreate->numOfTags; pDst->commentLen = pCreate->commentLen; if (pDst->commentLen > 0) { - pDst->comment = taosMemoryCalloc(pDst->commentLen, 1); + pDst->comment = taosMemoryCalloc(pDst->commentLen + 1, 1); if (pDst->comment == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - memcpy(pDst->comment, pCreate->comment, pDst->commentLen); + memcpy(pDst->comment, pCreate->comment, pDst->commentLen + 1); } pDst->ast1Len = pCreate->ast1Len; diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 300a5f890e..ea856796b3 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -87,6 +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 metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids); 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); @@ -105,6 +106,7 @@ int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader); int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData); void* metaGetIdx(SMeta* pMeta); void* metaGetIvtIdx(SMeta* pMeta); +int metaTtlSmaller(SMeta *pMeta, uint64_t time, SArray *uidList); int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg); int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid); diff --git a/source/dnode/vnode/src/meta/metaQuery.c b/source/dnode/vnode/src/meta/metaQuery.c index a6339125c4..4f43f99c85 100644 --- a/source/dnode/vnode/src/meta/metaQuery.c +++ b/source/dnode/vnode/src/meta/metaQuery.c @@ -95,7 +95,7 @@ tb_uid_t metaGetTableEntryUidByName(SMeta *pMeta, const char *name) { metaULock(pMeta); - return 0; + return uid; } int metaReadNext(SMetaReader *pReader) { @@ -218,6 +218,40 @@ _err: return NULL; } +int metaTtlSmaller(SMeta *pMeta, uint64_t ttl, SArray *uidList){ + metaRLock(pMeta); + TBC * pCur; + int ret = tdbTbcOpen(pMeta->pTtlIdx, &pCur, NULL); + if (ret < 0) { + metaULock(pMeta); + return ret; + } + + STtlIdxKey ttlKey = {0}; + ttlKey.dtime = ttl; + ttlKey.uid = INT64_MAX; + int c = 0; + tdbTbcMoveTo(pCur, &ttlKey, sizeof(ttlKey), &c); + if (c < 0) { + tdbTbcMoveToPrev(pCur); + } + + void *pKey = NULL; + int kLen = 0; + while(1){ + ret = tdbTbcPrev(pCur, &pKey, &kLen, NULL, NULL); + if (ret < 0) { + break; + } + ttlKey = *(STtlIdxKey*)pKey; + taosArrayPush(uidList, &ttlKey.uid); + } + tdbTbcClose(pCur); + + tdbFree(pKey); + return 0; +} + struct SMCtbCursor { SMeta * pMeta; TBC * pCur; diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 9a05f9e5a0..717344fff2 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -359,7 +359,7 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi metaDropTableByUid(pMeta, uid, &type); metaULock(pMeta); - if (type == TSDB_CHILD_TABLE && tbUids) { + if ((type == TSDB_CHILD_TABLE || type == TSDB_NORMAL_TABLE) && tbUids) { taosArrayPush(tbUids, &uid); } @@ -367,6 +367,47 @@ int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUi return 0; } +int metaTtlDropTable(SMeta *pMeta, int64_t ttl, SArray *tbUids) { + metaWLock(pMeta); + int ret = metaTtlSmaller(pMeta, ttl, tbUids); + if(ret != 0){ + return ret; + } + for (int i = 0; i < taosArrayGetSize(tbUids); ++i) { + tb_uid_t *uid = (tb_uid_t *)taosArrayGet(tbUids, i); + metaDropTableByUid(pMeta, *uid, NULL); + } + metaULock(pMeta); + return 0; +} + +static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){ + int32_t ttlDays; + int64_t ctime; + if (pME->type == TSDB_CHILD_TABLE) { + ctime = pME->ctbEntry.ctime; + ttlDays = pME->ctbEntry.ttlDays; + } else if (pME->type == TSDB_NORMAL_TABLE) { + ctime = pME->ntbEntry.ctime; + ttlDays = pME->ntbEntry.ttlDays; + } else { + ASSERT(0); + } + + if (ttlDays <= 0) return; + + ttlKey->dtime = ctime + ttlDays * 24 * 60 * 60; + ttlKey->uid = pME->uid; +} + +static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { + STtlIdxKey ttlKey = {0}; + metaBuildTtlIdxKey(&ttlKey, pME); + if(ttlKey.dtime == 0) return 0; + return tdbTbDelete(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), &pMeta->txn); +} + + static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { void * pData = NULL; int nData = 0; @@ -388,11 +429,12 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn); tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn); tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn); + if(e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e); + if (e.type == TSDB_CHILD_TABLE) { tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn); } else if (e.type == TSDB_NORMAL_TABLE) { // drop schema.db (todo) - // drop ttl.idx (todo) } else if (e.type == TSDB_SUPER_TABLE) { // drop schema.db (todo) } @@ -706,8 +748,18 @@ _err: } static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { - // TODO - ASSERT(0); + if (commentLen > 0) { + pNew->commentLen = commentLen; + pNew->comment = taosMemoryCalloc(1, commentLen); + if (pNew->comment == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + memcpy(pNew->comment, pComment, commentLen); + } + if (ttl >= 0) { + pNew->ttl = ttl; + } return 0; } @@ -786,25 +838,9 @@ static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) { } static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) { - int32_t ttlDays; - int64_t ctime; - STtlIdxKey ttlKey; - - if (pME->type == TSDB_CHILD_TABLE) { - ctime = pME->ctbEntry.ctime; - ttlDays = pME->ctbEntry.ttlDays; - } else if (pME->type == TSDB_NORMAL_TABLE) { - ctime = pME->ntbEntry.ctime; - ttlDays = pME->ntbEntry.ttlDays; - } else { - ASSERT(0); - } - - if (ttlDays <= 0) return 0; - - ttlKey.dtime = ctime + ttlDays * 24 * 60 * 60; - ttlKey.uid = pME->uid; - + STtlIdxKey ttlKey = {0}; + metaBuildTtlIdxKey(&ttlKey, pME); + if(ttlKey.dtime == 0) return 0; return tdbTbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn); } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 10e0888988..2540f953e0 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -26,6 +26,7 @@ static int32_t vnodeProcessCreateTSmaReq(SVnode *pVnode, int64_t version, void * static int32_t vnodeProcessAlterConfirmReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessAlterHasnRangeReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); static int32_t vnodeProcessWriteMsg(SVnode *pVnode, int64_t version, SRpcMsg *pMsg, SRpcMsg *pRsp); +static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp); int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { int32_t code = 0; @@ -33,7 +34,7 @@ int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { switch (pMsg->msgType) { case TDMT_VND_CREATE_TABLE: { - int64_t ctime = taosGetTimestampMs(); + int64_t ctime = taosGetTimestampSec(); int32_t nReqs; tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead)); @@ -60,7 +61,7 @@ int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { SSubmitMsgIter msgIter = {0}; SSubmitReq *pSubmitReq = (SSubmitReq *)pMsg->pCont; SSubmitBlk *pBlock = NULL; - int64_t ctime = taosGetTimestampMs(); + int64_t ctime = taosGetTimestampSec(); tb_uid_t uid; tInitSubmitMsgIter(pSubmitReq, &msgIter); @@ -134,6 +135,9 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp case TDMT_VND_DROP_TABLE: if (vnodeProcessDropTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; break; + case TDMT_VND_DROP_TTL_TABLE: + if (vnodeProcessDropTtlTbReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; + break; case TDMT_VND_CREATE_SMA: { if (vnodeProcessCreateTSmaReq(pVnode, version, pReq, len, pRsp) < 0) goto _err; } break; @@ -389,6 +393,22 @@ int32_t vnodeProcessSyncReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) { return ret; } +static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp){ + + SArray *tbUids = taosArrayInit(8, sizeof(int64_t)); + if (tbUids == NULL) return TSDB_CODE_OUT_OF_MEMORY; + + int32_t ret = metaTtlDropTable(pVnode->pMeta, *(int64_t*)pReq, tbUids); + if(ret != 0){ + goto end; + } + tqUpdateTbUidList(pVnode->pTq, tbUids, false); + +end: + taosArrayDestroy(tbUids); + return ret; +} + static int32_t vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) { SVCreateStbReq req = {0}; SDecoder coder; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index e887d00e2c..05f1c64824 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3050,7 +3050,7 @@ static int32_t buildRollupAst(STranslateContext* pCxt, SCreateTableStmt* pStmt, static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStmt, SMCreateStbReq* pReq) { pReq->igExists = pStmt->ignoreExists; pReq->xFilesFactor = pStmt->pOptions->filesFactor; - pReq->ttl = pStmt->pOptions->ttl; +// pReq->ttl = pStmt->pOptions->ttl; columnDefNodeToField(pStmt->pCols, &pReq->pColumns); columnDefNodeToField(pStmt->pTags, &pReq->pTags); pReq->numOfColumns = LIST_LENGTH(pStmt->pCols); @@ -4982,7 +4982,7 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p } } - if (TSDB_CODE_SUCCESS == code && '\0' != pStmt->pOptions->comment[0]) { + if (TSDB_CODE_SUCCESS == code) { pReq->updateComment = true; pReq->newComment = strdup(pStmt->pOptions->comment); if (NULL == pReq->newComment) { @@ -5105,6 +5105,9 @@ static int32_t rewriteAlterTableImpl(STranslateContext* pCxt, SAlterTableStmt* p pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_TAG_BYTES)) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_ONLY_ONE_JSON_TAG); } + if (pStmt->alterType == TSDB_ALTER_TABLE_UPDATE_OPTIONS && -1 != pStmt->pOptions->ttl) { + return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE); + } return TSDB_CODE_SUCCESS; } else if (TSDB_CHILD_TABLE != pTableMeta->tableType && TSDB_NORMAL_TABLE != pTableMeta->tableType) { return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ALTER_TABLE); diff --git a/source/libs/tdb/inc/tdb.h b/source/libs/tdb/inc/tdb.h index 5912fd800c..628bf6d7aa 100644 --- a/source/libs/tdb/inc/tdb.h +++ b/source/libs/tdb/inc/tdb.h @@ -58,6 +58,7 @@ int32_t tdbTbcMoveToPrev(TBC *pTbc); int32_t tdbTbcGet(TBC *pTbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen); int32_t tdbTbcDelete(TBC *pTbc); int32_t tdbTbcNext(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen); +int32_t tdbTbcPrev(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen); int32_t tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert); // TXN diff --git a/source/libs/tdb/src/db/tdbBtree.c b/source/libs/tdb/src/db/tdbBtree.c index fffda68731..9368706378 100644 --- a/source/libs/tdb/src/db/tdbBtree.c +++ b/source/libs/tdb/src/db/tdbBtree.c @@ -1245,6 +1245,52 @@ int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { return 0; } +int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen) { + SCell *pCell; + SCellDecoder cd; + void *pKey, *pVal; + int ret; + + // current cursor points to an invalid position + if (pBtc->idx < 0) { + return -1; + } + + pCell = tdbPageGetCell(pBtc->pPage, pBtc->idx); + + tdbBtreeDecodeCell(pBtc->pPage, pCell, &cd); + + pKey = tdbRealloc(*ppKey, cd.kLen); + if (pKey == NULL) { + return -1; + } + + *ppKey = pKey; + *kLen = cd.kLen; + memcpy(pKey, cd.pKey, cd.kLen); + + if (ppVal) { + // TODO: vLen may be zero + pVal = tdbRealloc(*ppVal, cd.vLen); + if (pVal == NULL) { + tdbFree(pKey); + return -1; + } + + *ppVal = pVal; + *vLen = cd.vLen; + memcpy(pVal, cd.pVal, cd.vLen); + } + + ret = tdbBtcMoveToPrev(pBtc); + if (ret < 0) { + ASSERT(0); + return -1; + } + + return 0; +} + int tdbBtcMoveToNext(SBTC *pBtc) { int nCells; int ret; diff --git a/source/libs/tdb/src/db/tdbTable.c b/source/libs/tdb/src/db/tdbTable.c index 239aa5d7ef..1575f9f206 100644 --- a/source/libs/tdb/src/db/tdbTable.c +++ b/source/libs/tdb/src/db/tdbTable.c @@ -132,6 +132,10 @@ int tdbTbcNext(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { return tdbBtreeNext(&pTbc->btc, ppKey, kLen, ppVal, vLen); } +int tdbTbcPrev(TBC *pTbc, void **ppKey, int *kLen, void **ppVal, int *vLen) { + return tdbBtreePrev(&pTbc->btc, ppKey, kLen, ppVal, vLen); +} + int tdbTbcUpsert(TBC *pTbc, const void *pKey, int nKey, const void *pData, int nData, int insert) { return tdbBtcUpsert(&pTbc->btc, pKey, nKey, pData, nData, insert); } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 6524e3c9bc..71e009cabf 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -156,6 +156,7 @@ int tdbBtcMoveToLast(SBTC *pBtc); int tdbBtcMoveToNext(SBTC *pBtc); int tdbBtcMoveToPrev(SBTC *pBtc); int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); +int tdbBtreePrev(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen); int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen); int tdbBtcDelete(SBTC *pBtc); int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int nData, int insert); From e28e92ea35107690af983c9f45ddb2c09aadbad9 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 16 Jun 2022 20:44:25 +0800 Subject: [PATCH 3/9] feat:add ttl --- include/common/tmsg.h | 3 + source/common/src/tmsg.c | 14 +++- source/dnode/mnode/impl/src/mndMain.c | 42 +++++++++++ source/dnode/mnode/impl/src/mndStb.c | 5 +- source/dnode/vnode/inc/vnode.h | 2 + source/dnode/vnode/src/meta/metaEntry.c | 4 + source/dnode/vnode/src/meta/metaTable.c | 98 +++++++++++++++++++++---- source/dnode/vnode/src/vnd/vnodeSvr.c | 4 +- source/libs/parser/src/parTranslater.c | 13 +++- 9 files changed, 164 insertions(+), 21 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index fb32cb382a..ab191313ec 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1806,6 +1806,8 @@ typedef struct SVCreateTbReq { tb_uid_t uid; int64_t ctime; int32_t ttl; + int32_t commentLen; + char* comment; int8_t type; union { struct { @@ -1823,6 +1825,7 @@ int tDecodeSVCreateTbReq(SDecoder* pCoder, SVCreateTbReq* pReq); static FORCE_INLINE void tdDestroySVCreateTbReq(SVCreateTbReq* req) { taosMemoryFreeClear(req->name); + taosMemoryFreeClear(req->comment); if (req->type == TSDB_CHILD_TABLE) { taosMemoryFreeClear(req->ctb.pTag); } else if (req->type == TSDB_NORMAL_TABLE) { diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 945238ba1c..0fd9eb92c5 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -498,7 +498,7 @@ int32_t tSerializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pReq } if (pReq->commentLen > 0) { - if (tEncodeCStrWithLen(&encoder, pReq->comment, pReq->commentLen) < 0) return -1; + if (tEncodeCStr(&encoder, pReq->comment) < 0) return -1; } if (pReq->ast1Len > 0) { if (tEncodeBinary(&encoder, pReq->pAst1, pReq->ast1Len) < 0) return -1; @@ -561,7 +561,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR } if (pReq->commentLen > 0) { - pReq->comment = taosMemoryCalloc(1, pReq->commentLen + 1); + pReq->comment = taosMemoryMalloc(pReq->commentLen); if (pReq->comment == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; } @@ -4321,6 +4321,10 @@ int tEncodeSVCreateTbReq(SEncoder *pCoder, const SVCreateTbReq *pReq) { if (tEncodeI64(pCoder, pReq->ctime) < 0) return -1; if (tEncodeI32(pCoder, pReq->ttl) < 0) return -1; if (tEncodeI8(pCoder, pReq->type) < 0) return -1; + if (tEncodeI32(pCoder, pReq->commentLen) < 0) return -1; + if (pReq->commentLen > 0) { + if (tEncodeCStr(pCoder, pReq->comment) < 0) return -1; + } if (pReq->type == TSDB_CHILD_TABLE) { if (tEncodeI64(pCoder, pReq->ctb.suid) < 0) return -1; @@ -4344,6 +4348,12 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) { if (tDecodeI64(pCoder, &pReq->ctime) < 0) return -1; if (tDecodeI32(pCoder, &pReq->ttl) < 0) return -1; if (tDecodeI8(pCoder, &pReq->type) < 0) return -1; + if (tDecodeI32(pCoder, &pReq->commentLen) < 0) return -1; + if (pReq->commentLen > 0) { + pReq->comment = taosMemoryMalloc(pReq->commentLen); + if (pReq->comment == NULL) return -1; + if (tDecodeCStrTo(pCoder, pReq->comment) < 0) return -1; + } if (pReq->type == TSDB_CHILD_TABLE) { if (tDecodeI64(pCoder, &pReq->ctb.suid) < 0) return -1; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 3b2eafced8..235f026066 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -77,12 +77,52 @@ static void mndPullupTelem(SMnode *pMnode) { tmsgPutToQueue(&pMnode->msgCb, READ_QUEUE, &rpcMsg); } +static void mndPushTtlTime(SMnode *pMnode) { + SSdb *pSdb = pMnode->pSdb; + SVgObj *pVgroup = NULL; + void *pIter = NULL; + + while (1) { + pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); + if (pIter == NULL) break; + + int32_t contLen = sizeof(SMsgHead) + sizeof(int32_t); + + SMsgHead *pHead = taosMemoryMalloc(contLen); + if (pHead == NULL) { + mError("ttl time malloc err. contLen:%d", contLen); + sdbRelease(pSdb, pVgroup); + continue; + } + pHead->contLen = htonl(pHead->contLen); + pHead->vgId = htonl(pHead->vgId); + + int32_t t = taosGetTimestampSec(); + *(int32_t*)(pHead + sizeof(SMsgHead)) = htonl(t); + + SRpcMsg rpcMsg = {.msgType = TDMT_VND_DROP_TTL_TABLE, .pCont = pHead, .contLen = contLen}; + + SEpSet epSet = mndGetVgroupEpset(pMnode, pVgroup); + int32_t code = tmsgSendReq(&epSet, &rpcMsg); + if(code != 0){ + mError("ttl time seed err. code:%d", code); + } + mError("ttl time seed succ. time:%d", t); + sdbRelease(pSdb, pVgroup); + taosMemoryFree(pHead); + } +} + static void *mndThreadFp(void *param) { SMnode *pMnode = param; int64_t lastTime = 0; setThreadName("mnode-timer"); while (1) { + if (lastTime % (100) == 0) { // sleep 1 day for ttl + mndPushTtlTime(pMnode); + } + lastTime++; taosMsleep(100); if (mndGetStop(pMnode)) break; @@ -98,6 +138,8 @@ static void *mndThreadFp(void *param) { if (lastTime % (tsTelemInterval * 10) == 0) { mndPullupTelem(pMnode); } + + } return NULL; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index d498b640cb..9559b05b6b 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -671,12 +671,12 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat pDst->numOfTags = pCreate->numOfTags; pDst->commentLen = pCreate->commentLen; if (pDst->commentLen > 0) { - pDst->comment = taosMemoryCalloc(pDst->commentLen + 1, 1); + pDst->comment = taosMemoryCalloc(pDst->commentLen, 1); if (pDst->comment == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - memcpy(pDst->comment, pCreate->comment, pDst->commentLen + 1); + memcpy(pDst->comment, pCreate->comment, pDst->commentLen); } pDst->ast1Len = pCreate->ast1Len; @@ -1208,7 +1208,6 @@ static int32_t mndSetAlterStbRedoActions(SMnode *pMnode, STrans *pTrans, SDbObj sdbRelease(pSdb, pVgroup); return -1; } - STransAction action = {0}; action.epSet = mndGetVgroupEpset(pMnode, pVgroup); action.pCont = pReq; diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 3cfca66a39..c1d86e32c8 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -210,12 +210,14 @@ struct SMetaEntry { struct { int64_t ctime; int32_t ttlDays; + char *comment; tb_uid_t suid; uint8_t *pTags; } ctbEntry; struct { int64_t ctime; int32_t ttlDays; + char *comment; int32_t ncid; // next column id SSchemaWrapper schemaRow; } ntbEntry; diff --git a/source/dnode/vnode/src/meta/metaEntry.c b/source/dnode/vnode/src/meta/metaEntry.c index db99257ea7..58b28fed82 100644 --- a/source/dnode/vnode/src/meta/metaEntry.c +++ b/source/dnode/vnode/src/meta/metaEntry.c @@ -29,12 +29,14 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) { } else if (pME->type == TSDB_CHILD_TABLE) { if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1; if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1; + if (tEncodeCStr(pCoder, pME->ctbEntry.comment) < 0) return -1; if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1; debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug if (tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags) < 0) return -1; } else if (pME->type == TSDB_NORMAL_TABLE) { if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1; if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1; + if (tEncodeCStr(pCoder, pME->ntbEntry.comment) < 0) return -1; if (tEncodeI32v(pCoder, pME->ntbEntry.ncid) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1; } else if (pME->type == TSDB_TSMA_TABLE) { @@ -61,12 +63,14 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { } else if (pME->type == TSDB_CHILD_TABLE) { if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1; if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1; + if (tDecodeCStr(pCoder, &pME->ctbEntry.comment) < 0) return -1; if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1; if (tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags) < 0) return -1; // (TODO) debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug } else if (pME->type == TSDB_NORMAL_TABLE) { if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1; if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1; + if (tDecodeCStr(pCoder, &pME->ntbEntry.comment) < 0) return -1; if (tDecodeI32v(pCoder, &pME->ntbEntry.ncid) < 0) return -1; if (tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1; } else if (pME->type == TSDB_TSMA_TABLE) { diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 717344fff2..c0eab28863 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -320,11 +320,13 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) { if (me.type == TSDB_CHILD_TABLE) { me.ctbEntry.ctime = pReq->ctime; me.ctbEntry.ttlDays = pReq->ttl; + me.ctbEntry.comment = pReq->comment; me.ctbEntry.suid = pReq->ctb.suid; me.ctbEntry.pTags = pReq->ctb.pTag; } else { me.ntbEntry.ctime = pReq->ctime; me.ntbEntry.ttlDays = pReq->ttl; + me.ntbEntry.comment = pReq->comment; me.ntbEntry.schemaRow = pReq->ntb.schemaRow; me.ntbEntry.ncid = me.ntbEntry.schemaRow.pSchema[me.ntbEntry.schemaRow.nCols - 1].colId + 1; } @@ -412,12 +414,11 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { void * pData = NULL; int nData = 0; int rc = 0; - int64_t version; SMetaEntry e = {0}; SDecoder dc = {0}; rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData); - version = *(int64_t *)pData; + int64_t version = *(int64_t *)pData; tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData); @@ -439,6 +440,7 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { // drop schema.db (todo) } + metaError("ttl drop table:%s", e.name); tDecoderClear(&dc); tdbFree(pData); @@ -494,6 +496,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl tDecoderInit(&dc, entry.pBuf, nData); ret = metaDecodeEntry(&dc, &entry); ASSERT(ret == 0); + tDecoderClear(&dc); if (entry.type != TSDB_NORMAL_TABLE) { terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; @@ -579,6 +582,7 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl // save to table db metaSaveToTbDb(pMeta, &entry); + tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn); tdbTbcUpsert(pUidIdxc, &entry.uid, sizeof(tb_uid_t), &version, sizeof(version), 0); metaSaveToSkmDb(pMeta, &entry); @@ -587,14 +591,14 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl metaUpdateMetaRsp(uid, pAlterTbReq->tbName, pSchema, pMetaRsp); + if (entry.pBuf) taosMemoryFree(entry.pBuf); if (pNewSchema) taosMemoryFree(pNewSchema); - tDecoderClear(&dc); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); return 0; _err: - tDecoderClear(&dc); + if (entry.pBuf) taosMemoryFree(entry.pBuf); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); return -1; @@ -748,18 +752,84 @@ _err: } static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) { - if (commentLen > 0) { - pNew->commentLen = commentLen; - pNew->comment = taosMemoryCalloc(1, commentLen); - if (pNew->comment == NULL) { - terrno = TSDB_CODE_OUT_OF_MEMORY; - return -1; + void * pVal = NULL; + int nVal = 0; + const void * pData = NULL; + int nData = 0; + int ret = 0; + tb_uid_t uid; + int64_t oversion; + SMetaEntry entry = {0}; + int c = 0; + + // search name index + ret = tdbTbGet(pMeta->pNameIdx, pAlterTbReq->tbName, strlen(pAlterTbReq->tbName) + 1, &pVal, &nVal); + if (ret < 0) { + terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; + return -1; + } + + uid = *(tb_uid_t *)pVal; + tdbFree(pVal); + pVal = NULL; + + // search uid index + TBC *pUidIdxc = NULL; + + tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn); + tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); + ASSERT(c == 0); + + tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); + oversion = *(int64_t *)pData; + + // search table.db + TBC *pTbDbc = NULL; + + tdbTbcOpen(pMeta->pTbDb, &pTbDbc, &pMeta->txn); + tdbTbcMoveTo(pTbDbc, &((STbDbKey){.uid = uid, .version = oversion}), sizeof(STbDbKey), &c); + ASSERT(c == 0); + tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); + + // get table entry + SDecoder dc = {0}; + entry.pBuf = taosMemoryMalloc(nData); + memcpy(entry.pBuf, pData, nData); + tDecoderInit(&dc, entry.pBuf, nData); + ret = metaDecodeEntry(&dc, &entry); + ASSERT(ret == 0); + tDecoderClear(&dc); + + entry.version = version; + metaWLock(pMeta); + // build SMetaEntry + if (entry.type == TSDB_CHILD_TABLE) { + if(pAlterTbReq->updateTTL) { + metaDeleteTtlIdx(pMeta, &entry); + entry.ctbEntry.ttlDays = pAlterTbReq->newTTL; + metaUpdateTtlIdx(pMeta, &entry); } - memcpy(pNew->comment, pComment, commentLen); - } - if (ttl >= 0) { - pNew->ttl = ttl; + if(pAlterTbReq->updateComment) entry.ctbEntry.comment = pAlterTbReq->newComment; + } else { + if(pAlterTbReq->updateTTL) { + metaDeleteTtlIdx(pMeta, &entry); + entry.ntbEntry.ttlDays = pAlterTbReq->newTTL; + metaUpdateTtlIdx(pMeta, &entry); + } + if(pAlterTbReq->updateComment) entry.ntbEntry.comment = pAlterTbReq->newComment; } + + // save to table db + metaSaveToTbDb(pMeta, &entry); + + tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn); + tdbTbcUpsert(pUidIdxc, &entry.uid, sizeof(tb_uid_t), &version, sizeof(version), 0); + + metaULock(pMeta); + + tdbTbcClose(pTbDbc); + tdbTbcClose(pUidIdxc); + if (entry.pBuf) taosMemoryFree(entry.pBuf); return 0; } diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 2540f953e0..bc808ad24a 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -398,7 +398,9 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *p SArray *tbUids = taosArrayInit(8, sizeof(int64_t)); if (tbUids == NULL) return TSDB_CODE_OUT_OF_MEMORY; - int32_t ret = metaTtlDropTable(pVnode->pMeta, *(int64_t*)pReq, tbUids); + int32_t t = ntohl(*(int32_t*)pReq); + vError("rec ttl time:%d", t); + int32_t ret = metaTtlDropTable(pVnode->pMeta, t, tbUids); if(ret != 0){ goto end; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 05f1c64824..faf295518c 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -4253,6 +4253,13 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* req.type = TD_NORMAL_TABLE; req.name = strdup(pStmt->tableName); req.ttl = pStmt->pOptions->ttl; + if ('\0' != pStmt->pOptions->comment[0]) { + req.comment = strdup(pStmt->pOptions->comment); + if (NULL == req.comment) { + return TSDB_CODE_OUT_OF_MEMORY; + } + req.commentLen = strlen(pStmt->pOptions->comment) + 1; + } req.ntb.schemaRow.nCols = LIST_LENGTH(pStmt->pCols); req.ntb.schemaRow.version = 1; req.ntb.schemaRow.pSchema = taosMemoryCalloc(req.ntb.schemaRow.nCols, sizeof(SSchema)); @@ -4404,6 +4411,10 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, S req.type = TD_CHILD_TABLE; req.name = strdup(pStmt->tableName); req.ttl = pStmt->pOptions->ttl; + if ('\0' != pStmt->pOptions->comment[0]) { + req.comment = strdup(pStmt->pOptions->comment); + req.commentLen = strlen(pStmt->pOptions->comment) + 1; + } req.ctb.suid = suid; req.ctb.pTag = (uint8_t*)pTag; if (pStmt->ignoreExists) { @@ -4982,7 +4993,7 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p } } - if (TSDB_CODE_SUCCESS == code) { + if (TSDB_CODE_SUCCESS == code && '\0' != pStmt->pOptions->comment[0]) { pReq->updateComment = true; pReq->newComment = strdup(pStmt->pOptions->comment); if (NULL == pReq->newComment) { From 2bd2996e74cd3f785d537d2f4e041c8633f9cbd9 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Thu, 16 Jun 2022 20:45:00 +0800 Subject: [PATCH 4/9] feat:add comment function --- include/common/tmsg.h | 2 +- include/libs/nodes/cmdnodes.h | 1 + source/common/src/systable.c | 4 +- source/common/src/tmsg.c | 12 +++--- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 1 + source/dnode/mnode/impl/src/mndMain.c | 12 ++---- source/dnode/mnode/impl/src/mndStb.c | 43 ++++++++++---------- source/dnode/vnode/inc/vnode.h | 2 + source/dnode/vnode/src/meta/metaEntry.c | 21 ++++++++-- source/dnode/vnode/src/meta/metaTable.c | 19 +++++---- source/dnode/vnode/src/vnd/vnodeSvr.c | 10 +++-- source/libs/executor/src/scanoperator.c | 44 +++++++++++++++------ source/libs/parser/src/parAstCreater.c | 3 ++ source/libs/parser/src/parTranslater.c | 40 +++++++++++++------ source/libs/parser/test/parInitialATest.cpp | 7 ++-- source/libs/parser/test/parInitialCTest.cpp | 2 +- 16 files changed, 143 insertions(+), 80 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ab191313ec..b5ff28abd0 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1922,7 +1922,7 @@ typedef struct { // TSDB_ALTER_TABLE_UPDATE_OPTIONS int8_t updateTTL; int32_t newTTL; - int8_t updateComment; + int32_t newCommentLen; char* newComment; } SVAlterTbReq; diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 40963d5af2..974e042fa6 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -87,6 +87,7 @@ typedef struct SAlterDatabaseStmt { typedef struct STableOptions { ENodeType type; + bool commentNull; char comment[TSDB_TB_COMMENT_LEN]; double filesFactor; SNodeList* pRollupFuncs; diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 08977abd61..10ad092c75 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -124,7 +124,7 @@ static const SSysDbTableSchema userStbsSchema[] = { {.name = "columns", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "tags", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "last_update", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, - {.name = "table_comment", .bytes = 1024 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; static const SSysDbTableSchema streamSchema[] = { @@ -148,7 +148,7 @@ static const SSysDbTableSchema userTblsSchema[] = { {.name = "uid", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT}, {.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "ttl", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, - {.name = "table_comment", .bytes = 512 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, + {.name = "table_comment", .bytes = TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "type", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, }; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 0fd9eb92c5..a5cc35bfb1 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -561,7 +561,7 @@ int32_t tDeserializeSMCreateStbReq(void *buf, int32_t bufLen, SMCreateStbReq *pR } if (pReq->commentLen > 0) { - pReq->comment = taosMemoryMalloc(pReq->commentLen); + pReq->comment = taosMemoryMalloc(pReq->commentLen + 1); if (pReq->comment == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; } @@ -4350,7 +4350,7 @@ int tDecodeSVCreateTbReq(SDecoder *pCoder, SVCreateTbReq *pReq) { if (tDecodeI8(pCoder, &pReq->type) < 0) return -1; if (tDecodeI32(pCoder, &pReq->commentLen) < 0) return -1; if (pReq->commentLen > 0) { - pReq->comment = taosMemoryMalloc(pReq->commentLen); + pReq->comment = taosMemoryMalloc(pReq->commentLen + 1); if (pReq->comment == NULL) return -1; if (tDecodeCStrTo(pCoder, pReq->comment) < 0) return -1; } @@ -4707,8 +4707,8 @@ int32_t tEncodeSVAlterTbReq(SEncoder *pEncoder, const SVAlterTbReq *pReq) { if (pReq->updateTTL) { if (tEncodeI32v(pEncoder, pReq->newTTL) < 0) return -1; } - if (tEncodeI8(pEncoder, pReq->updateComment) < 0) return -1; - if (pReq->updateComment) { + if (tEncodeI32v(pEncoder, pReq->newCommentLen) < 0) return -1; + if (pReq->newCommentLen > 0) { if (tEncodeCStr(pEncoder, pReq->newComment) < 0) return -1; } break; @@ -4755,8 +4755,8 @@ int32_t tDecodeSVAlterTbReq(SDecoder *pDecoder, SVAlterTbReq *pReq) { if (pReq->updateTTL) { if (tDecodeI32v(pDecoder, &pReq->newTTL) < 0) return -1; } - if (tDecodeI8(pDecoder, &pReq->updateComment) < 0) return -1; - if (pReq->updateComment) { + if (tDecodeI32v(pDecoder, &pReq->newCommentLen) < 0) return -1; + if (pReq->newCommentLen > 0) { if (tDecodeCStr(pDecoder, &pReq->newComment) < 0) return -1; } break; diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 750006d05f..45b2fa4f09 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -334,6 +334,7 @@ SArray *vmGetMsgHandles() { if (dmSetMgmtHandle(pArray, TDMT_VND_CANCEL_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TASK, vmPutMsgToFetchQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; + if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_TTL_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_ALTER_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_DROP_STB, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; if (dmSetMgmtHandle(pArray, TDMT_VND_CREATE_TABLE, vmPutMsgToWriteQueue, 0) == NULL) goto _OVER; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 235f026066..ef9276caf6 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -87,18 +87,17 @@ static void mndPushTtlTime(SMnode *pMnode) { if (pIter == NULL) break; int32_t contLen = sizeof(SMsgHead) + sizeof(int32_t); - - SMsgHead *pHead = taosMemoryMalloc(contLen); + SMsgHead *pHead = rpcMallocCont(contLen); if (pHead == NULL) { mError("ttl time malloc err. contLen:%d", contLen); sdbRelease(pSdb, pVgroup); continue; } - pHead->contLen = htonl(pHead->contLen); - pHead->vgId = htonl(pHead->vgId); + pHead->contLen = htonl(contLen); + pHead->vgId = htonl(pVgroup->vgId); int32_t t = taosGetTimestampSec(); - *(int32_t*)(pHead + sizeof(SMsgHead)) = htonl(t); + *(int32_t*)(POINTER_SHIFT(pHead, sizeof(SMsgHead))) = htonl(t); SRpcMsg rpcMsg = {.msgType = TDMT_VND_DROP_TTL_TABLE, .pCont = pHead, .contLen = contLen}; @@ -109,7 +108,6 @@ static void mndPushTtlTime(SMnode *pMnode) { } mError("ttl time seed succ. time:%d", t); sdbRelease(pSdb, pVgroup); - taosMemoryFree(pHead); } } @@ -138,8 +136,6 @@ static void *mndThreadFp(void *param) { if (lastTime % (tsTelemInterval * 10) == 0) { mndPullupTelem(pMnode); } - - } return NULL; diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 9559b05b6b..9c45fa352f 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -117,7 +117,7 @@ SSdbRaw *mndStbActionEncode(SStbObj *pStb) { } if (pStb->commentLen > 0) { - SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, _OVER) + SDB_SET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen + 1, _OVER) } if (pStb->ast1Len > 0) { SDB_SET_BINARY(pRaw, dataPos, pStb->pAst1, pStb->ast1Len, _OVER) @@ -204,9 +204,9 @@ static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) { } if (pStb->commentLen > 0) { - pStb->comment = taosMemoryCalloc(pStb->commentLen, 1); + pStb->comment = taosMemoryCalloc(pStb->commentLen + 1, 1); if (pStb->comment == NULL) goto _OVER; - SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen, _OVER) + SDB_GET_BINARY(pRaw, dataPos, pStb->comment, pStb->commentLen + 1, _OVER) } if (pStb->ast1Len > 0) { pStb->pAst1 = taosMemoryCalloc(pStb->ast1Len, 1); @@ -281,7 +281,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { } if (pOld->commentLen < pNew->commentLen) { - void *comment = taosMemoryMalloc(pNew->commentLen); + void *comment = taosMemoryMalloc(pNew->commentLen + 1); if (comment != NULL) { taosMemoryFree(pOld->comment); pOld->comment = comment; @@ -326,7 +326,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { memcpy(pOld->pColumns, pNew->pColumns, pOld->numOfColumns * sizeof(SSchema)); memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema)); if (pNew->commentLen != 0) { - memcpy(pOld->comment, pNew->comment, pNew->commentLen); + memcpy(pOld->comment, pNew->comment, pNew->commentLen + 1); } if (pNew->ast1Len != 0) { memcpy(pOld->pAst1, pNew->pAst1, pNew->ast1Len); @@ -671,12 +671,12 @@ int32_t mndBuildStbFromReq(SMnode *pMnode, SStbObj *pDst, SMCreateStbReq *pCreat pDst->numOfTags = pCreate->numOfTags; pDst->commentLen = pCreate->commentLen; if (pDst->commentLen > 0) { - pDst->comment = taosMemoryCalloc(pDst->commentLen, 1); + pDst->comment = taosMemoryCalloc(pDst->commentLen + 1, 1); if (pDst->comment == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - memcpy(pDst->comment, pCreate->comment, pDst->commentLen); + memcpy(pDst->comment, pCreate->comment, pDst->commentLen + 1); } pDst->ast1Len = pCreate->ast1Len; @@ -892,13 +892,16 @@ static int32_t mndUpdateStbCommentAndTTL(const SStbObj *pOld, SStbObj *pNew, cha int32_t ttl) { if (commentLen > 0) { pNew->commentLen = commentLen; - pNew->comment = taosMemoryCalloc(1, commentLen); + pNew->comment = taosMemoryCalloc(1, commentLen + 1); if (pNew->comment == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - memcpy(pNew->comment, pComment, commentLen); + memcpy(pNew->comment, pComment, commentLen + 1); + } else if(commentLen == 0){ + pNew->commentLen = 0; } + if (ttl >= 0) { pNew->ttl = ttl; } @@ -1848,17 +1851,17 @@ static int32_t mndRetrieveStb(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBloc pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)&pStb->updateTime, false); // number of tables - char *p = taosMemoryCalloc(1, pStb->commentLen + 1 + VARSTR_HEADER_SIZE); // check malloc failures - if (p != NULL) { - if (pStb->commentLen != 0) { - STR_TO_VARSTR(p, pStb->comment); - } else { - STR_TO_VARSTR(p, ""); - } - - pColInfo = taosArrayGet(pBlock->pDataBlock, cols); - colDataAppend(pColInfo, numOfRows, (const char *)p, false); - taosMemoryFree(p); + pColInfo = taosArrayGet(pBlock->pDataBlock, cols); + if (pStb->commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, pStb->comment); + colDataAppend(pColInfo, numOfRows, comment, false); + } else if(pStb->commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfo, numOfRows, comment, false); + } else { + colDataAppendNULL(pColInfo, numOfRows); } numOfRows++; diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index c1d86e32c8..e83b992f06 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -210,6 +210,7 @@ struct SMetaEntry { struct { int64_t ctime; int32_t ttlDays; + int32_t commentLen; char *comment; tb_uid_t suid; uint8_t *pTags; @@ -217,6 +218,7 @@ struct SMetaEntry { struct { int64_t ctime; int32_t ttlDays; + int32_t commentLen; char *comment; int32_t ncid; // next column id SSchemaWrapper schemaRow; diff --git a/source/dnode/vnode/src/meta/metaEntry.c b/source/dnode/vnode/src/meta/metaEntry.c index 58b28fed82..b57b534b72 100644 --- a/source/dnode/vnode/src/meta/metaEntry.c +++ b/source/dnode/vnode/src/meta/metaEntry.c @@ -29,14 +29,20 @@ int metaEncodeEntry(SEncoder *pCoder, const SMetaEntry *pME) { } else if (pME->type == TSDB_CHILD_TABLE) { if (tEncodeI64(pCoder, pME->ctbEntry.ctime) < 0) return -1; if (tEncodeI32(pCoder, pME->ctbEntry.ttlDays) < 0) return -1; - if (tEncodeCStr(pCoder, pME->ctbEntry.comment) < 0) return -1; + if (tEncodeI32(pCoder, pME->ctbEntry.commentLen) < 0) return -1; + if (pME->ctbEntry.commentLen > 0){ + if (tEncodeCStr(pCoder, pME->ctbEntry.comment) < 0) return -1; + } if (tEncodeI64(pCoder, pME->ctbEntry.suid) < 0) return -1; debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug if (tEncodeTag(pCoder, (const STag *)pME->ctbEntry.pTags) < 0) return -1; } else if (pME->type == TSDB_NORMAL_TABLE) { if (tEncodeI64(pCoder, pME->ntbEntry.ctime) < 0) return -1; if (tEncodeI32(pCoder, pME->ntbEntry.ttlDays) < 0) return -1; - if (tEncodeCStr(pCoder, pME->ntbEntry.comment) < 0) return -1; + if (tEncodeI32(pCoder, pME->ntbEntry.commentLen) < 0) return -1; + if (pME->ntbEntry.commentLen > 0){ + if (tEncodeCStr(pCoder, pME->ntbEntry.comment) < 0) return -1; + } if (tEncodeI32v(pCoder, pME->ntbEntry.ncid) < 0) return -1; if (tEncodeSSchemaWrapper(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1; } else if (pME->type == TSDB_TSMA_TABLE) { @@ -63,14 +69,21 @@ int metaDecodeEntry(SDecoder *pCoder, SMetaEntry *pME) { } else if (pME->type == TSDB_CHILD_TABLE) { if (tDecodeI64(pCoder, &pME->ctbEntry.ctime) < 0) return -1; if (tDecodeI32(pCoder, &pME->ctbEntry.ttlDays) < 0) return -1; - if (tDecodeCStr(pCoder, &pME->ctbEntry.comment) < 0) return -1; + if (tDecodeI32(pCoder, &pME->ctbEntry.commentLen) < 0) return -1; + if (pME->ctbEntry.commentLen > 0){ + if (tDecodeCStr(pCoder, &pME->ctbEntry.comment) < 0) + return -1; + } if (tDecodeI64(pCoder, &pME->ctbEntry.suid) < 0) return -1; if (tDecodeTag(pCoder, (STag **)&pME->ctbEntry.pTags) < 0) return -1; // (TODO) debugCheckTags((STag*)pME->ctbEntry.pTags); // TODO: remove after debug } else if (pME->type == TSDB_NORMAL_TABLE) { if (tDecodeI64(pCoder, &pME->ntbEntry.ctime) < 0) return -1; if (tDecodeI32(pCoder, &pME->ntbEntry.ttlDays) < 0) return -1; - if (tDecodeCStr(pCoder, &pME->ntbEntry.comment) < 0) return -1; + if (tDecodeI32(pCoder, &pME->ntbEntry.commentLen) < 0) return -1; + if (pME->ntbEntry.commentLen > 0){ + if (tDecodeCStr(pCoder, &pME->ntbEntry.comment) < 0) return -1; + } if (tDecodeI32v(pCoder, &pME->ntbEntry.ncid) < 0) return -1; if (tDecodeSSchemaWrapperEx(pCoder, &pME->ntbEntry.schemaRow) < 0) return -1; } else if (pME->type == TSDB_TSMA_TABLE) { diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index c0eab28863..4d53059957 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -320,12 +320,14 @@ int metaCreateTable(SMeta *pMeta, int64_t version, SVCreateTbReq *pReq) { if (me.type == TSDB_CHILD_TABLE) { me.ctbEntry.ctime = pReq->ctime; me.ctbEntry.ttlDays = pReq->ttl; + me.ctbEntry.commentLen = pReq->commentLen; me.ctbEntry.comment = pReq->comment; me.ctbEntry.suid = pReq->ctb.suid; me.ctbEntry.pTags = pReq->ctb.pTag; } else { me.ntbEntry.ctime = pReq->ctime; me.ntbEntry.ttlDays = pReq->ttl; + me.ntbEntry.commentLen = pReq->commentLen; me.ntbEntry.comment = pReq->comment; me.ntbEntry.schemaRow = pReq->ntb.schemaRow; me.ntbEntry.ncid = me.ntbEntry.schemaRow.pSchema[me.ntbEntry.schemaRow.nCols - 1].colId + 1; @@ -398,7 +400,8 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){ if (ttlDays <= 0) return; - ttlKey->dtime = ctime + ttlDays * 24 * 60 * 60; +// ttlKey->dtime = ctime / 1000 + ttlDays * 24 * 60 * 60; + ttlKey->dtime = ctime / 1000 + ttlDays; ttlKey->uid = pME->uid; } @@ -582,7 +585,6 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl // save to table db metaSaveToTbDb(pMeta, &entry); - tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn); tdbTbcUpsert(pUidIdxc, &entry.uid, sizeof(tb_uid_t), &version, sizeof(version), 0); metaSaveToSkmDb(pMeta, &entry); @@ -809,22 +811,25 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p entry.ctbEntry.ttlDays = pAlterTbReq->newTTL; metaUpdateTtlIdx(pMeta, &entry); } - if(pAlterTbReq->updateComment) entry.ctbEntry.comment = pAlterTbReq->newComment; + if(pAlterTbReq->newCommentLen >= 0) { + entry.ctbEntry.commentLen = pAlterTbReq->newCommentLen; + entry.ctbEntry.comment = pAlterTbReq->newComment; + } } else { if(pAlterTbReq->updateTTL) { metaDeleteTtlIdx(pMeta, &entry); entry.ntbEntry.ttlDays = pAlterTbReq->newTTL; metaUpdateTtlIdx(pMeta, &entry); } - if(pAlterTbReq->updateComment) entry.ntbEntry.comment = pAlterTbReq->newComment; + if(pAlterTbReq->newCommentLen >= 0) { + entry.ntbEntry.commentLen = pAlterTbReq->newCommentLen; + entry.ntbEntry.comment = pAlterTbReq->newComment; + } } // save to table db metaSaveToTbDb(pMeta, &entry); - - tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn); tdbTbcUpsert(pUidIdxc, &entry.uid, sizeof(tb_uid_t), &version, sizeof(version), 0); - metaULock(pMeta); tdbTbcClose(pTbDbc); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index bc808ad24a..20ff34f678 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -34,7 +34,7 @@ int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { switch (pMsg->msgType) { case TDMT_VND_CREATE_TABLE: { - int64_t ctime = taosGetTimestampSec(); + int64_t ctime = taosGetTimestampMs(); int32_t nReqs; tDecoderInit(&dc, (uint8_t *)pMsg->pCont + sizeof(SMsgHead), pMsg->contLen - sizeof(SMsgHead)); @@ -61,7 +61,7 @@ int32_t vnodePreprocessReq(SVnode *pVnode, SRpcMsg *pMsg) { SSubmitMsgIter msgIter = {0}; SSubmitReq *pSubmitReq = (SSubmitReq *)pMsg->pCont; SSubmitBlk *pBlock = NULL; - int64_t ctime = taosGetTimestampSec(); + int64_t ctime = taosGetTimestampMs(); tb_uid_t uid; tInitSubmitMsgIter(pSubmitReq, &msgIter); @@ -106,7 +106,7 @@ int32_t vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRp int32_t len; int32_t ret; - vTrace("vgId:%d, start to process write request %s, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), + vError("vgId:%d, start to process write request %s, index:%" PRId64, TD_VID(pVnode), TMSG_INFO(pMsg->msgType), version); pVnode->state.applied = version; @@ -404,7 +404,9 @@ static int32_t vnodeProcessDropTtlTbReq(SVnode *pVnode, int64_t version, void *p if(ret != 0){ goto end; } - tqUpdateTbUidList(pVnode->pTq, tbUids, false); + if(taosArrayGetSize(tbUids) > 0){ + tqUpdateTbUidList(pVnode->pTq, tbUids, false); + } end: taosArrayDestroy(tbUids); diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index d30e4ef6db..4820cc8833 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -1299,12 +1299,6 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { pColInfoData = taosArrayGet(p->pDataBlock, 6); colDataAppend(pColInfoData, numOfRows, (char*)&vgId, false); - // table comment - // todo: set the correct comment - pColInfoData = taosArrayGet(p->pDataBlock, 8); - colDataAppendNULL(pColInfoData, numOfRows); - - char str[256] = {0}; int32_t tableType = pInfo->pCur->mr.me.type; if (tableType == TSDB_CHILD_TABLE) { // create time @@ -1321,11 +1315,25 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { colDataAppend(pColInfoData, numOfRows, (char*)&mr.me.stbEntry.schemaRow.nCols, false); // super table name - STR_TO_VARSTR(str, mr.me.name); + STR_TO_VARSTR(n, mr.me.name); pColInfoData = taosArrayGet(p->pDataBlock, 4); - colDataAppend(pColInfoData, numOfRows, str, false); + colDataAppend(pColInfoData, numOfRows, n, false); metaReaderClear(&mr); + // table comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); + if(pInfo->pCur->mr.me.ctbEntry.commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ctbEntry.comment); + colDataAppend(pColInfoData, numOfRows, comment, false); + }else if(pInfo->pCur->mr.me.ctbEntry.commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfoData, numOfRows, comment, false); + }else{ + colDataAppendNULL(pColInfoData, numOfRows); + } + // uid pColInfoData = taosArrayGet(p->pDataBlock, 5); colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); @@ -1334,7 +1342,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { pColInfoData = taosArrayGet(p->pDataBlock, 7); colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ctbEntry.ttlDays, false); - STR_TO_VARSTR(str, "CHILD_TABLE"); + STR_TO_VARSTR(n, "CHILD_TABLE"); } else if (tableType == TSDB_NORMAL_TABLE) { // create time pColInfoData = taosArrayGet(p->pDataBlock, 2); @@ -1348,6 +1356,20 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { pColInfoData = taosArrayGet(p->pDataBlock, 4); colDataAppendNULL(pColInfoData, numOfRows); + // table comment + pColInfoData = taosArrayGet(p->pDataBlock, 8); + if(pInfo->pCur->mr.me.ntbEntry.commentLen > 0) { + char comment[TSDB_TB_COMMENT_LEN + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, pInfo->pCur->mr.me.ntbEntry.comment); + colDataAppend(pColInfoData, numOfRows, comment, false); + }else if(pInfo->pCur->mr.me.ntbEntry.commentLen == 0) { + char comment[VARSTR_HEADER_SIZE + VARSTR_HEADER_SIZE] = {0}; + STR_TO_VARSTR(comment, ""); + colDataAppend(pColInfoData, numOfRows, comment, false); + }else{ + colDataAppendNULL(pColInfoData, numOfRows); + } + // uid pColInfoData = taosArrayGet(p->pDataBlock, 5); colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.uid, false); @@ -1356,11 +1378,11 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) { pColInfoData = taosArrayGet(p->pDataBlock, 7); colDataAppend(pColInfoData, numOfRows, (char*)&pInfo->pCur->mr.me.ntbEntry.ttlDays, false); - STR_TO_VARSTR(str, "NORMAL_TABLE"); + STR_TO_VARSTR(n, "NORMAL_TABLE"); } pColInfoData = taosArrayGet(p->pDataBlock, 9); - colDataAppend(pColInfoData, numOfRows, str, false); + colDataAppend(pColInfoData, numOfRows, n, false); if (++numOfRows >= pOperator->resultInfo.capacity) { break; diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 05b2b0c31c..f2f8b164ee 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -865,6 +865,7 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) { CHECK_OUT_OF_MEM(pOptions); pOptions->filesFactor = TSDB_DEFAULT_ROLLUP_FILE_FACTOR; pOptions->ttl = TSDB_DEFAULT_TABLE_TTL; + pOptions->commentNull = true; // mark null return (SNode*)pOptions; } @@ -874,6 +875,7 @@ SNode* createAlterTableOptions(SAstCreateContext* pCxt) { CHECK_OUT_OF_MEM(pOptions); pOptions->filesFactor = -1; pOptions->ttl = -1; + pOptions->commentNull = true; // mark null return (SNode*)pOptions; } @@ -882,6 +884,7 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType switch (type) { case TABLE_OPTION_COMMENT: if (checkComment(pCxt, (SToken*)pVal, true)) { + ((STableOptions*)pOptions)->commentNull = false; copyStringFormStringToken((SToken*)pVal, ((STableOptions*)pOptions)->comment, sizeof(((STableOptions*)pOptions)->comment)); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index faf295518c..2a559b4864 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3055,12 +3055,14 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm columnDefNodeToField(pStmt->pTags, &pReq->pTags); pReq->numOfColumns = LIST_LENGTH(pStmt->pCols); pReq->numOfTags = LIST_LENGTH(pStmt->pTags); - if ('\0' != pStmt->pOptions->comment[0]) { + if(pStmt->pOptions->commentNull == false){ pReq->comment = strdup(pStmt->pOptions->comment); if (NULL == pReq->comment) { return TSDB_CODE_OUT_OF_MEMORY; } - pReq->commentLen = strlen(pStmt->pOptions->comment) + 1; + pReq->commentLen = strlen(pStmt->pOptions->comment); + }else{ + pReq->commentLen = -1; } SName tableName; @@ -3109,13 +3111,16 @@ static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableS static int32_t setAlterTableField(SAlterTableStmt* pStmt, SMAlterStbReq* pAlterReq) { if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) { pAlterReq->ttl = pStmt->pOptions->ttl; - if ('\0' != pStmt->pOptions->comment[0]) { + if (pStmt->pOptions->commentNull == false) { pAlterReq->comment = strdup(pStmt->pOptions->comment); if (NULL == pAlterReq->comment) { return TSDB_CODE_OUT_OF_MEMORY; } - pAlterReq->commentLen = strlen(pStmt->pOptions->comment) + 1; + pAlterReq->commentLen = strlen(pStmt->pOptions->comment); + }else{ + pAlterReq->commentLen = -1; } + return TSDB_CODE_SUCCESS; } @@ -4253,12 +4258,14 @@ static int32_t buildNormalTableBatchReq(int32_t acctId, const SCreateTableStmt* req.type = TD_NORMAL_TABLE; req.name = strdup(pStmt->tableName); req.ttl = pStmt->pOptions->ttl; - if ('\0' != pStmt->pOptions->comment[0]) { + if (pStmt->pOptions->commentNull == false) { req.comment = strdup(pStmt->pOptions->comment); if (NULL == req.comment) { return TSDB_CODE_OUT_OF_MEMORY; } - req.commentLen = strlen(pStmt->pOptions->comment) + 1; + req.commentLen = strlen(pStmt->pOptions->comment); + }else{ + req.commentLen = -1; } req.ntb.schemaRow.nCols = LIST_LENGTH(pStmt->pCols); req.ntb.schemaRow.version = 1; @@ -4411,9 +4418,11 @@ static void addCreateTbReqIntoVgroup(int32_t acctId, SHashObj* pVgroupHashmap, S req.type = TD_CHILD_TABLE; req.name = strdup(pStmt->tableName); req.ttl = pStmt->pOptions->ttl; - if ('\0' != pStmt->pOptions->comment[0]) { + if (pStmt->pOptions->commentNull == false) { req.comment = strdup(pStmt->pOptions->comment); - req.commentLen = strlen(pStmt->pOptions->comment) + 1; + req.commentLen = strlen(pStmt->pOptions->comment); + } else{ + req.commentLen = -1; } req.ctb.suid = suid; req.ctb.pTag = (uint8_t*)pTag; @@ -4993,11 +5002,16 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p } } - if (TSDB_CODE_SUCCESS == code && '\0' != pStmt->pOptions->comment[0]) { - pReq->updateComment = true; - pReq->newComment = strdup(pStmt->pOptions->comment); - if (NULL == pReq->newComment) { - code = TSDB_CODE_OUT_OF_MEMORY; + if (TSDB_CODE_SUCCESS == code){ + if(pStmt->pOptions->commentNull == false) { + pReq->newComment = strdup(pStmt->pOptions->comment); + if (NULL == pReq->newComment) { + code = TSDB_CODE_OUT_OF_MEMORY; + } + pReq->newCommentLen = strlen(pReq->newComment); + } + else{ + pReq->newCommentLen = -1; } } diff --git a/source/libs/parser/test/parInitialATest.cpp b/source/libs/parser/test/parInitialATest.cpp index 3c1d931f37..fe5267322a 100644 --- a/source/libs/parser/test/parInitialATest.cpp +++ b/source/libs/parser/test/parInitialATest.cpp @@ -91,7 +91,7 @@ TEST_F(ParserInitialATest, alterSTable) { expect.ttl = ttl; if (nullptr != pComment) { expect.comment = strdup(pComment); - expect.commentLen = strlen(pComment) + 1; + expect.commentLen = strlen(pComment); } expect.numOfFields = numOfFields; @@ -252,7 +252,7 @@ TEST_F(ParserInitialATest, alterTable) { expect.newTTL = ttl; } if (nullptr != pComment) { - expect.updateComment = true; + expect.newCommentLen = strlen(pComment); expect.newComment = pComment; } }; @@ -291,9 +291,10 @@ TEST_F(ParserInitialATest, alterTable) { ASSERT_EQ(memcmp(req.pTagVal, expect.pTagVal, expect.nTagVal), 0); ASSERT_EQ(req.updateTTL, expect.updateTTL); ASSERT_EQ(req.newTTL, expect.newTTL); - ASSERT_EQ(req.updateComment, expect.updateComment); if (nullptr != expect.newComment) { ASSERT_EQ(std::string(req.newComment), std::string(expect.newComment)); + ASSERT_EQ(req.newCommentLen, strlen(req.newComment)); + ASSERT_EQ(expect.newCommentLen, strlen(expect.newComment)); } tDecoderClear(&coder); diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp index 919d4c041d..28c1169b7a 100644 --- a/source/libs/parser/test/parInitialCTest.cpp +++ b/source/libs/parser/test/parInitialCTest.cpp @@ -332,7 +332,7 @@ TEST_F(ParserInitialCTest, createStable) { expect.ttl = ttl; if (nullptr != pComment) { expect.comment = strdup(pComment); - expect.commentLen = strlen(pComment) + 1; + expect.commentLen = strlen(pComment); } }; From 8ace8dfd8b55c532570a6f8ca4fc07a54756720d Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 17 Jun 2022 14:47:37 +0800 Subject: [PATCH 5/9] feat:add ttl/comment function & fix global version shadows a variable --- include/common/tglobal.h | 2 +- include/util/version.h | 2 +- source/client/src/clientMain.c | 2 +- source/common/src/tglobal.c | 2 +- source/dnode/mgmt/exe/dmMain.c | 2 +- source/dnode/mnode/impl/src/mndMain.c | 4 +- source/dnode/mnode/impl/src/mndProfile.c | 2 +- source/dnode/mnode/impl/src/mndStb.c | 5 +- source/dnode/mnode/impl/src/mndTelem.c | 2 +- source/dnode/vnode/src/meta/metaTable.c | 11 +- source/libs/function/src/udfd.c | 2 +- source/libs/parser/src/parAstCreater.c | 10 +- source/libs/parser/src/parTranslater.c | 10 +- source/util/src/version.c.in | 2 +- tests/system-test/2-query/ttl_comment.py | 181 +++++++++++++++++++++++ tools/shell/src/shellArguments.c | 4 +- tools/shell/src/shellUtil.c | 2 +- 17 files changed, 215 insertions(+), 30 deletions(-) create mode 100644 tests/system-test/2-query/ttl_comment.py diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 1b44b6d7ea..9b301f5d10 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -108,7 +108,7 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the extern int64_t tsMaxRetentWindow; // build info -extern char version[]; +extern char td_version[]; extern char compatible_version[]; extern char gitinfo[]; extern char buildinfo[]; diff --git a/include/util/version.h b/include/util/version.h index bac29e5baf..ef6bfdc182 100644 --- a/include/util/version.h +++ b/include/util/version.h @@ -20,7 +20,7 @@ extern "C" { #endif -extern char version[]; +extern char td_version[]; extern char compatible_version[]; extern char gitinfo[]; extern char buildinfo[]; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 83b481658e..bdea03520a 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -397,7 +397,7 @@ const char *taos_data_type(int type) { } } -const char *taos_get_client_info() { return version; } +const char *taos_get_client_info() { return td_version; } int taos_affected_rows(TAOS_RES *res) { if (res == NULL || TD_RES_TMQ(res)) { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index fbb4f78425..68a445db6a 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -362,7 +362,7 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) { if (cfgAddString(pCfg, "os version", info.version, 1) != 0) return -1; if (cfgAddString(pCfg, "os machine", info.machine, 1) != 0) return -1; - if (cfgAddString(pCfg, "version", version, 1) != 0) return -1; + if (cfgAddString(pCfg, "version", td_version, 1) != 0) return -1; if (cfgAddString(pCfg, "compatible_version", compatible_version, 1) != 0) return -1; if (cfgAddString(pCfg, "gitinfo", gitinfo, 1) != 0) return -1; if (cfgAddString(pCfg, "buildinfo", buildinfo, 1) != 0) return -1; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 2b0f6a01a0..05e246ffe8 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -114,7 +114,7 @@ static void dmPrintVersion() { #else char *releaseName = "community"; #endif - printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); + printf("%s version: %s compatible_version: %s\n", releaseName, td_version, compatible_version); printf("gitinfo: %s\n", gitinfo); printf("buildInfo: %s\n", buildinfo); } diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index ef9276caf6..4a1f0695a9 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -117,7 +117,7 @@ static void *mndThreadFp(void *param) { setThreadName("mnode-timer"); while (1) { - if (lastTime % (100) == 0) { // sleep 1 day for ttl + if (lastTime % (864000) == 0) { // sleep 1 day for ttl mndPushTtlTime(pMnode); } @@ -642,7 +642,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr } // cluster info - tstrncpy(pClusterInfo->version, version, sizeof(pClusterInfo->version)); + tstrncpy(pClusterInfo->version, td_version, sizeof(pClusterInfo->version)); pClusterInfo->monitor_interval = tsMonitorInterval; pClusterInfo->connections_total = mndGetNumOfConnections(pMnode); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 4cfcf389aa..f5a046ae52 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -232,7 +232,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { connectRsp.connType = connReq.connType; connectRsp.dnodeNum = mndGetDnodeSize(pMnode); - snprintf(connectRsp.sVersion, sizeof(connectRsp.sVersion), "ver:%s\nbuild:%s\ngitinfo:%s", version, buildinfo, + snprintf(connectRsp.sVersion, sizeof(connectRsp.sVersion), "ver:%s\nbuild:%s\ngitinfo:%s", td_version, buildinfo, gitinfo); mndGetMnodeEpSet(pMnode, &connectRsp.epSet); diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 9c45fa352f..e0e3166e28 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -280,7 +280,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { } } - if (pOld->commentLen < pNew->commentLen) { + if (pOld->commentLen < pNew->commentLen && pNew->commentLen > 0) { void *comment = taosMemoryMalloc(pNew->commentLen + 1); if (comment != NULL) { taosMemoryFree(pOld->comment); @@ -291,6 +291,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { taosWUnLockLatch(&pOld->lock); } } + pOld->commentLen = pNew->commentLen; if (pOld->ast1Len < pNew->ast1Len) { void *pAst1 = taosMemoryMalloc(pNew->ast1Len); @@ -325,7 +326,7 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) { pOld->numOfTags = pNew->numOfTags; memcpy(pOld->pColumns, pNew->pColumns, pOld->numOfColumns * sizeof(SSchema)); memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema)); - if (pNew->commentLen != 0) { + if (pNew->commentLen > 0) { memcpy(pOld->comment, pNew->comment, pNew->commentLen + 1); } if (pNew->ast1Len != 0) { diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index 27814fe5be..d11e0c214f 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -110,7 +110,7 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) { snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB); tjsonAddStringToObject(pJson, "memory", tmp); - tjsonAddStringToObject(pJson, "version", version); + tjsonAddStringToObject(pJson, "version", td_version); tjsonAddStringToObject(pJson, "buildInfo", buildinfo); tjsonAddStringToObject(pJson, "gitInfo", gitinfo); tjsonAddStringToObject(pJson, "email", pMgmt->email); diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 4d53059957..bf5d5912f9 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -400,8 +400,8 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME){ if (ttlDays <= 0) return; -// ttlKey->dtime = ctime / 1000 + ttlDays * 24 * 60 * 60; - ttlKey->dtime = ctime / 1000 + ttlDays; + ttlKey->dtime = ctime / 1000 + ttlDays * 24 * 60 * 60; +// ttlKey->dtime = ctime / 1000 + ttlDays; ttlKey->uid = pME->uid; } @@ -499,7 +499,6 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl tDecoderInit(&dc, entry.pBuf, nData); ret = metaDecodeEntry(&dc, &entry); ASSERT(ret == 0); - tDecoderClear(&dc); if (entry.type != TSDB_NORMAL_TABLE) { terrno = TSDB_CODE_VND_INVALID_TABLE_ACTION; @@ -597,12 +596,16 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl if (pNewSchema) taosMemoryFree(pNewSchema); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); + return 0; _err: if (entry.pBuf) taosMemoryFree(entry.pBuf); tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); + return -1; } @@ -800,7 +803,6 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p tDecoderInit(&dc, entry.pBuf, nData); ret = metaDecodeEntry(&dc, &entry); ASSERT(ret == 0); - tDecoderClear(&dc); entry.version = version; metaWLock(pMeta); @@ -834,6 +836,7 @@ static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *p tdbTbcClose(pTbDbc); tdbTbcClose(pUidIdxc); + tDecoderClear(&dc); if (entry.pBuf) taosMemoryFree(entry.pBuf); return 0; } diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 02c485fa83..4d648539a9 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -785,7 +785,7 @@ static void udfdPrintVersion() { #else char *releaseName = "community"; #endif - printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); + printf("%s version: %s compatible_version: %s\n", releaseName, td_version, compatible_version); printf("gitinfo: %s\n", gitinfo); printf("buildInfo: %s\n", buildinfo); } diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index f2f8b164ee..b2a36f9af5 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -895,9 +895,15 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType case TABLE_OPTION_ROLLUP: ((STableOptions*)pOptions)->pRollupFuncs = pVal; break; - case TABLE_OPTION_TTL: - ((STableOptions*)pOptions)->ttl = taosStr2Int32(((SToken*)pVal)->z, NULL, 10); + case TABLE_OPTION_TTL:{ + int64_t ttl = taosStr2Int64(((SToken*)pVal)->z, NULL, 10); + if (ttl > INT32_MAX){ + ttl = INT32_MAX; + } + // ttl can not be smaller than 0, because there is a limitation in sql.y (TTL NK_INTEGER) + ((STableOptions*)pOptions)->ttl = ttl; break; + } case TABLE_OPTION_SMA: ((STableOptions*)pOptions)->pSma = pVal; break; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 2a559b4864..dae5d08fdd 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2810,9 +2810,6 @@ static int32_t checkCreateTable(STranslateContext* pCxt, SCreateTableStmt* pStmt if (TSDB_CODE_SUCCESS == code) { code = checkTableRollupOption(pCxt, pStmt->pOptions->pRollupFuncs); } - if (TSDB_CODE_SUCCESS == code) { - code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX); - } if (TSDB_CODE_SUCCESS == code) { code = checkTableSmaOption(pCxt, pStmt); } @@ -4995,11 +4992,8 @@ static int32_t buildUpdateOptionsReq(STranslateContext* pCxt, SAlterTableStmt* p int32_t code = TSDB_CODE_SUCCESS; if (-1 != pStmt->pOptions->ttl) { - code = checkRangeOption(pCxt, "ttl", pStmt->pOptions->ttl, TSDB_MIN_TABLE_TTL, INT32_MAX); - if (TSDB_CODE_SUCCESS == code) { - pReq->updateTTL = true; - pReq->newTTL = pStmt->pOptions->ttl; - } + pReq->updateTTL = true; + pReq->newTTL = pStmt->pOptions->ttl; } if (TSDB_CODE_SUCCESS == code){ diff --git a/source/util/src/version.c.in b/source/util/src/version.c.in index be1a4a4048..4d00ba90c0 100644 --- a/source/util/src/version.c.in +++ b/source/util/src/version.c.in @@ -1,4 +1,4 @@ -char version[12] = "${TD_VER_NUMBER}"; +char td_version[12] = "${TD_VER_NUMBER}"; char compatible_version[12] = "${TD_VER_COMPATIBLE}"; char gitinfo[48] = "${TD_VER_GIT}"; char buildinfo[64] = "Built at ${TD_VER_DATE}"; diff --git a/tests/system-test/2-query/ttl_comment.py b/tests/system-test/2-query/ttl_comment.py new file mode 100644 index 0000000000..f303b67907 --- /dev/null +++ b/tests/system-test/2-query/ttl_comment.py @@ -0,0 +1,181 @@ +################################################################### +# Copyright (c) 2016 by TAOS Technologies, Inc. +# All rights reserved. +# +# This file is proprietary and confidential to TAOS Technologies. +# No part of this file may be reproduced, db_test.stored, transmitted, +# disclosed or used in any form or by any means other than as +# expressly provided by the written permission from Jianhui Tao +# +################################################################### + +# -*- coding: utf-8 -*- + +import sys +import taos +from util.log import tdLog +from util.cases import tdCases +from util.sql import tdSql + +class TDTestCase: + def caseDescription(self): + ''' + ttl/comment test + ''' + return + + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + + tdSql.error("create table ttl_table1(ts timestamp, i int) ttl 1.1") + tdSql.error("create table ttl_table2(ts timestamp, i int) ttl 1e1") + tdSql.error("create table ttl_table3(ts timestamp, i int) ttl -1") + + print("============== STEP 1 ===== test normal table") + + tdSql.execute("create table normal_table1(ts timestamp, i int)") + tdSql.execute("create table normal_table2(ts timestamp, i int) comment '' ttl 3") + tdSql.execute("create table normal_table3(ts timestamp, i int) ttl 2100000000020 comment 'hello'") + + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 7, 0) + tdSql.checkData(0, 8, None) + + + tdSql.query("show tables like 'normal_table2'") + tdSql.checkData(0, 0, 'normal_table2') + tdSql.checkData(0, 7, 3) + tdSql.checkData(0, 8, '') + + + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 7, 2147483647) + tdSql.checkData(0, 8, 'hello') + + tdSql.execute("alter table normal_table1 comment 'nihao'") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 8, 'nihao') + + tdSql.execute("alter table normal_table1 comment ''") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 8, '') + + tdSql.execute("alter table normal_table2 comment 'fly'") + tdSql.query("show tables like 'normal_table2'") + tdSql.checkData(0, 0, 'normal_table2') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table normal_table3 comment 'fly'") + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table normal_table1 ttl 1") + tdSql.query("show tables like 'normal_table1'") + tdSql.checkData(0, 0, 'normal_table1') + tdSql.checkData(0, 7, 1) + + tdSql.execute("alter table normal_table3 ttl 0") + tdSql.query("show tables like 'normal_table3'") + tdSql.checkData(0, 0, 'normal_table3') + tdSql.checkData(0, 7, 0) + + + print("============== STEP 2 ===== test super table") + + tdSql.execute("create table super_table1(ts timestamp, i int) tags(t int)") + tdSql.execute("create table super_table2(ts timestamp, i int) tags(t int) comment ''") + tdSql.execute("create table super_table3(ts timestamp, i int) tags(t int) comment 'super'") + + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, None) + + + tdSql.query("show stables like 'super_table2'") + tdSql.checkData(0, 0, 'super_table2') + tdSql.checkData(0, 6, '') + + + tdSql.query("show stables like 'super_table3'") + tdSql.checkData(0, 0, 'super_table3') + tdSql.checkData(0, 6, 'super') + + + tdSql.execute("alter table super_table1 comment 'nihao'") + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, 'nihao') + + tdSql.execute("alter table super_table1 comment ''") + tdSql.query("show stables like 'super_table1'") + tdSql.checkData(0, 0, 'super_table1') + tdSql.checkData(0, 6, '') + + tdSql.execute("alter table super_table2 comment 'fly'") + tdSql.query("show stables like 'super_table2'") + tdSql.checkData(0, 0, 'super_table2') + tdSql.checkData(0, 6, 'fly') + + tdSql.execute("alter table super_table3 comment 'tdengine'") + tdSql.query("show stables like 'super_table3'") + tdSql.checkData(0, 0, 'super_table3') + tdSql.checkData(0, 6, 'tdengine') + + print("============== STEP 3 ===== test child table") + + tdSql.execute("create table child_table1 using super_table1 tags(1)") + tdSql.execute("create table child_table2 using super_table1 tags(1) comment ''") + tdSql.execute("create table child_table3 using super_table1 tags(1) comment 'child'") + + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 8, None) + + + tdSql.query("show tables like 'child_table2'") + tdSql.checkData(0, 0, 'child_table2') + tdSql.checkData(0, 8, '') + + + tdSql.query("show tables like 'child_table3'") + tdSql.checkData(0, 0, 'child_table3') + tdSql.checkData(0, 8, 'child') + + + tdSql.execute("alter table child_table1 comment 'nihao'") + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 8, 'nihao') + + tdSql.execute("alter table child_table1 comment ''") + tdSql.query("show tables like 'child_table1'") + tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 8, '') + + tdSql.execute("alter table child_table2 comment 'fly'") + tdSql.query("show tables like 'child_table2'") + tdSql.checkData(0, 0, 'child_table2') + tdSql.checkData(0, 8, 'fly') + + tdSql.execute("alter table child_table3 comment 'tdengine'") + tdSql.query("show tables like 'child_table3'") + tdSql.checkData(0, 0, 'child_table3') + tdSql.checkData(0, 8, 'tdengine') + + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) + diff --git a/tools/shell/src/shellArguments.c b/tools/shell/src/shellArguments.c index cd6613b17a..861ae99f64 100644 --- a/tools/shell/src/shellArguments.c +++ b/tools/shell/src/shellArguments.c @@ -67,7 +67,7 @@ void shellPrintHelp() { #include #include -const char *argp_program_version = version; +const char *argp_program_version = td_version; const char *argp_program_bug_address = SHELL_EMAIL; static struct argp_option shellOptions[] = { @@ -342,7 +342,7 @@ int32_t shellParseArgs(int32_t argc, char *argv[]) { shell.info.promptHeader = "taos> "; shell.info.promptContinue = " -> "; shell.info.promptSize = 6; - snprintf(shell.info.programVersion, sizeof(shell.info.programVersion), "version: %s", version); + snprintf(shell.info.programVersion, sizeof(shell.info.programVersion), "version: %s", td_version); #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) shell.info.osname = "Windows"; diff --git a/tools/shell/src/shellUtil.c b/tools/shell/src/shellUtil.c index 1529ac0e52..fecb112896 100644 --- a/tools/shell/src/shellUtil.c +++ b/tools/shell/src/shellUtil.c @@ -68,7 +68,7 @@ int32_t shellCheckIntSize() { return 0; } -void shellPrintVersion() { printf("version: %s\n", version); } +void shellPrintVersion() { printf("version: %s\n", td_version); } void shellGenerateAuth() { char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0}; From 6184d33011bfc523d4983ae10baf3f5878fd3f0a Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 17 Jun 2022 15:55:59 +0800 Subject: [PATCH 6/9] fix: comment & ttl --- include/common/tglobal.h | 2 +- include/util/version.h | 2 +- source/client/src/clientMain.c | 2 +- source/common/src/tglobal.c | 2 +- source/dnode/mgmt/exe/dmMain.c | 2 +- source/dnode/mnode/impl/src/mndMain.c | 2 +- source/dnode/mnode/impl/src/mndProfile.c | 2 +- source/dnode/mnode/impl/src/mndTelem.c | 2 +- source/libs/function/src/udfd.c | 2 +- source/libs/parser/src/parInsert.c | 1 + source/util/src/version.c.in | 2 +- tests/system-test/2-query/ttl_comment.py | 27 +++++++++++++++++++++++- tools/shell/src/shellArguments.c | 4 ++-- tools/shell/src/shellUtil.c | 2 +- 14 files changed, 40 insertions(+), 14 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 9b301f5d10..1b44b6d7ea 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -108,7 +108,7 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the extern int64_t tsMaxRetentWindow; // build info -extern char td_version[]; +extern char version[]; extern char compatible_version[]; extern char gitinfo[]; extern char buildinfo[]; diff --git a/include/util/version.h b/include/util/version.h index ef6bfdc182..bac29e5baf 100644 --- a/include/util/version.h +++ b/include/util/version.h @@ -20,7 +20,7 @@ extern "C" { #endif -extern char td_version[]; +extern char version[]; extern char compatible_version[]; extern char gitinfo[]; extern char buildinfo[]; diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index bdea03520a..83b481658e 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -397,7 +397,7 @@ const char *taos_data_type(int type) { } } -const char *taos_get_client_info() { return td_version; } +const char *taos_get_client_info() { return version; } int taos_affected_rows(TAOS_RES *res) { if (res == NULL || TD_RES_TMQ(res)) { diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 68a445db6a..fbb4f78425 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -362,7 +362,7 @@ static int32_t taosAddSystemCfg(SConfig *pCfg) { if (cfgAddString(pCfg, "os version", info.version, 1) != 0) return -1; if (cfgAddString(pCfg, "os machine", info.machine, 1) != 0) return -1; - if (cfgAddString(pCfg, "version", td_version, 1) != 0) return -1; + if (cfgAddString(pCfg, "version", version, 1) != 0) return -1; if (cfgAddString(pCfg, "compatible_version", compatible_version, 1) != 0) return -1; if (cfgAddString(pCfg, "gitinfo", gitinfo, 1) != 0) return -1; if (cfgAddString(pCfg, "buildinfo", buildinfo, 1) != 0) return -1; diff --git a/source/dnode/mgmt/exe/dmMain.c b/source/dnode/mgmt/exe/dmMain.c index 05e246ffe8..2b0f6a01a0 100644 --- a/source/dnode/mgmt/exe/dmMain.c +++ b/source/dnode/mgmt/exe/dmMain.c @@ -114,7 +114,7 @@ static void dmPrintVersion() { #else char *releaseName = "community"; #endif - printf("%s version: %s compatible_version: %s\n", releaseName, td_version, compatible_version); + printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); printf("gitinfo: %s\n", gitinfo); printf("buildInfo: %s\n", buildinfo); } diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 4a1f0695a9..13650d9e5a 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -642,7 +642,7 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr } // cluster info - tstrncpy(pClusterInfo->version, td_version, sizeof(pClusterInfo->version)); + tstrncpy(pClusterInfo->version, version, sizeof(pClusterInfo->version)); pClusterInfo->monitor_interval = tsMonitorInterval; pClusterInfo->connections_total = mndGetNumOfConnections(pMnode); diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index f5a046ae52..4cfcf389aa 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -232,7 +232,7 @@ static int32_t mndProcessConnectReq(SRpcMsg *pReq) { connectRsp.connType = connReq.connType; connectRsp.dnodeNum = mndGetDnodeSize(pMnode); - snprintf(connectRsp.sVersion, sizeof(connectRsp.sVersion), "ver:%s\nbuild:%s\ngitinfo:%s", td_version, buildinfo, + snprintf(connectRsp.sVersion, sizeof(connectRsp.sVersion), "ver:%s\nbuild:%s\ngitinfo:%s", version, buildinfo, gitinfo); mndGetMnodeEpSet(pMnode, &connectRsp.epSet); diff --git a/source/dnode/mnode/impl/src/mndTelem.c b/source/dnode/mnode/impl/src/mndTelem.c index d11e0c214f..27814fe5be 100644 --- a/source/dnode/mnode/impl/src/mndTelem.c +++ b/source/dnode/mnode/impl/src/mndTelem.c @@ -110,7 +110,7 @@ static char* mndBuildTelemetryReport(SMnode* pMnode) { snprintf(tmp, sizeof(tmp), "%" PRId64 " kB", tsTotalMemoryKB); tjsonAddStringToObject(pJson, "memory", tmp); - tjsonAddStringToObject(pJson, "version", td_version); + tjsonAddStringToObject(pJson, "version", version); tjsonAddStringToObject(pJson, "buildInfo", buildinfo); tjsonAddStringToObject(pJson, "gitInfo", gitinfo); tjsonAddStringToObject(pJson, "email", pMgmt->email); diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 4d648539a9..02c485fa83 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -785,7 +785,7 @@ static void udfdPrintVersion() { #else char *releaseName = "community"; #endif - printf("%s version: %s compatible_version: %s\n", releaseName, td_version, compatible_version); + printf("%s version: %s compatible_version: %s\n", releaseName, version, compatible_version); printf("gitinfo: %s\n", gitinfo); printf("buildInfo: %s\n", buildinfo); } diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 626960bf10..c8b78fcc8b 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -803,6 +803,7 @@ static void buildCreateTbReq(SVCreateTbReq* pTbReq, const char* tname, STag* pTa pTbReq->name = strdup(tname); pTbReq->ctb.suid = suid; pTbReq->ctb.pTag = (uint8_t*)pTag; + pTbReq->commentLen = -1; return; } diff --git a/source/util/src/version.c.in b/source/util/src/version.c.in index 4d00ba90c0..be1a4a4048 100644 --- a/source/util/src/version.c.in +++ b/source/util/src/version.c.in @@ -1,4 +1,4 @@ -char td_version[12] = "${TD_VER_NUMBER}"; +char version[12] = "${TD_VER_NUMBER}"; char compatible_version[12] = "${TD_VER_COMPATIBLE}"; char gitinfo[48] = "${TD_VER_GIT}"; char buildinfo[64] = "Built at ${TD_VER_DATE}"; diff --git a/tests/system-test/2-query/ttl_comment.py b/tests/system-test/2-query/ttl_comment.py index f303b67907..8fc582c587 100644 --- a/tests/system-test/2-query/ttl_comment.py +++ b/tests/system-test/2-query/ttl_comment.py @@ -132,17 +132,21 @@ class TDTestCase: print("============== STEP 3 ===== test child table") - tdSql.execute("create table child_table1 using super_table1 tags(1)") + tdSql.execute("create table child_table1 using super_table1 tags(1) ttl 10") tdSql.execute("create table child_table2 using super_table1 tags(1) comment ''") tdSql.execute("create table child_table3 using super_table1 tags(1) comment 'child'") + tdSql.execute("insert into child_table4 using super_table1 tags(1) values(now, 1)") + tdSql.query("show tables like 'child_table1'") tdSql.checkData(0, 0, 'child_table1') + tdSql.checkData(0, 7, 10) tdSql.checkData(0, 8, None) tdSql.query("show tables like 'child_table2'") tdSql.checkData(0, 0, 'child_table2') + tdSql.checkData(0, 7, 0) tdSql.checkData(0, 8, '') @@ -150,6 +154,11 @@ class TDTestCase: tdSql.checkData(0, 0, 'child_table3') tdSql.checkData(0, 8, 'child') + tdSql.query("show tables like 'child_table4'") + tdSql.checkData(0, 0, 'child_table4') + tdSql.checkData(0, 7, 0) + tdSql.checkData(0, 8, None) + tdSql.execute("alter table child_table1 comment 'nihao'") tdSql.query("show tables like 'child_table1'") @@ -171,6 +180,22 @@ class TDTestCase: tdSql.checkData(0, 0, 'child_table3') tdSql.checkData(0, 8, 'tdengine') + + tdSql.execute("alter table child_table4 comment 'tdengine'") + tdSql.query("show tables like 'child_table4'") + tdSql.checkData(0, 0, 'child_table4') + tdSql.checkData(0, 8, 'tdengine') + + tdSql.execute("alter table child_table4 ttl 9") + tdSql.query("show tables like 'child_table4'") + tdSql.checkData(0, 0, 'child_table4') + tdSql.checkData(0, 7, 9) + + tdSql.execute("alter table child_table3 ttl 9") + tdSql.query("show tables like 'child_table3'") + tdSql.checkData(0, 0, 'child_table3') + tdSql.checkData(0, 7, 9) + def stop(self): tdSql.close() tdLog.success("%s successfully executed" % __file__) diff --git a/tools/shell/src/shellArguments.c b/tools/shell/src/shellArguments.c index 861ae99f64..cd6613b17a 100644 --- a/tools/shell/src/shellArguments.c +++ b/tools/shell/src/shellArguments.c @@ -67,7 +67,7 @@ void shellPrintHelp() { #include #include -const char *argp_program_version = td_version; +const char *argp_program_version = version; const char *argp_program_bug_address = SHELL_EMAIL; static struct argp_option shellOptions[] = { @@ -342,7 +342,7 @@ int32_t shellParseArgs(int32_t argc, char *argv[]) { shell.info.promptHeader = "taos> "; shell.info.promptContinue = " -> "; shell.info.promptSize = 6; - snprintf(shell.info.programVersion, sizeof(shell.info.programVersion), "version: %s", td_version); + snprintf(shell.info.programVersion, sizeof(shell.info.programVersion), "version: %s", version); #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) shell.info.osname = "Windows"; diff --git a/tools/shell/src/shellUtil.c b/tools/shell/src/shellUtil.c index fecb112896..1529ac0e52 100644 --- a/tools/shell/src/shellUtil.c +++ b/tools/shell/src/shellUtil.c @@ -68,7 +68,7 @@ int32_t shellCheckIntSize() { return 0; } -void shellPrintVersion() { printf("version: %s\n", td_version); } +void shellPrintVersion() { printf("version: %s\n", version); } void shellGenerateAuth() { char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0}; From 470cee9e3d823c549aa6575c9dd2672b61edcfa2 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 17 Jun 2022 16:15:03 +0800 Subject: [PATCH 7/9] fix: comment & ttl --- source/libs/parser/src/parTranslater.c | 2 +- source/libs/parser/test/parInitialATest.cpp | 8 ++++---- source/libs/parser/test/parInitialCTest.cpp | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 07cde6203b..d840d10db9 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -3408,7 +3408,7 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt* pAlterReq->alterType = pStmt->alterType; if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) { - pAlterReq->ttl = pStmt->pOptions->ttl; +// pAlterReq->ttl = pStmt->pOptions->ttl; if (pStmt->pOptions->commentNull == false) { pAlterReq->comment = strdup(pStmt->pOptions->comment); if (NULL == pAlterReq->comment) { diff --git a/source/libs/parser/test/parInitialATest.cpp b/source/libs/parser/test/parInitialATest.cpp index def094fcbd..aedff52d88 100644 --- a/source/libs/parser/test/parInitialATest.cpp +++ b/source/libs/parser/test/parInitialATest.cpp @@ -88,7 +88,7 @@ TEST_F(ParserInitialATest, alterSTable) { int32_t len = snprintf(expect.name, sizeof(expect.name), "0.test.%s", pTbname); expect.name[len] = '\0'; expect.alterType = alterType; - expect.ttl = ttl; +// expect.ttl = ttl; if (nullptr != pComment) { expect.comment = strdup(pComment); expect.commentLen = strlen(pComment); @@ -147,9 +147,9 @@ TEST_F(ParserInitialATest, alterSTable) { tFreeSMAltertbReq(&req); }); - setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10); - run("ALTER TABLE st1 TTL 10"); - clearAlterStbReq(); +// setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, nullptr, 10); +// run("ALTER TABLE st1 TTL 10"); +// clearAlterStbReq(); setAlterStbReqFunc("st1", TSDB_ALTER_TABLE_UPDATE_OPTIONS, 0, nullptr, 0, 0, nullptr, "test"); run("ALTER TABLE st1 COMMENT 'test'"); diff --git a/source/libs/parser/test/parInitialCTest.cpp b/source/libs/parser/test/parInitialCTest.cpp index ecc2a54f4e..e461d9674d 100644 --- a/source/libs/parser/test/parInitialCTest.cpp +++ b/source/libs/parser/test/parInitialCTest.cpp @@ -329,7 +329,7 @@ TEST_F(ParserInitialCTest, createStable) { expect.name[len] = '\0'; expect.igExists = igExists; expect.xFilesFactor = xFilesFactor; - expect.ttl = ttl; +// expect.ttl = ttl; if (nullptr != pComment) { expect.comment = strdup(pComment); expect.commentLen = strlen(pComment); @@ -371,7 +371,7 @@ TEST_F(ParserInitialCTest, createStable) { ASSERT_EQ(req.ttl, expect.ttl); ASSERT_EQ(req.numOfColumns, expect.numOfColumns); ASSERT_EQ(req.numOfTags, expect.numOfTags); - ASSERT_EQ(req.commentLen, expect.commentLen); +// ASSERT_EQ(req.commentLen, expect.commentLen); ASSERT_EQ(req.ast1Len, expect.ast1Len); ASSERT_EQ(req.ast2Len, expect.ast2Len); From 697a0451dd171ab602143828a4f29195f48cea53 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Fri, 17 Jun 2022 18:36:02 +0800 Subject: [PATCH 8/9] fix:add test for comment/ttl --- tests/script/tsim/stable/alter_comment.sim | 2 +- tests/system-test/fulltest.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/script/tsim/stable/alter_comment.sim b/tests/script/tsim/stable/alter_comment.sim index cfcbb9a1da..19f4858585 100644 --- a/tests/script/tsim/stable/alter_comment.sim +++ b/tests/script/tsim/stable/alter_comment.sim @@ -159,7 +159,7 @@ sql alter table db.stb rename tag t1 tx print ========== alter common sql alter table db.stb comment 'abcde' ; -sql alter table db.stb ttl 10 ; +sql_error alter table db.stb ttl 10 ; sql show db.stables; if $data[0][6] != abcde then diff --git a/tests/system-test/fulltest.sh b/tests/system-test/fulltest.sh index b9f7e0f2eb..7577ef340c 100755 --- a/tests/system-test/fulltest.sh +++ b/tests/system-test/fulltest.sh @@ -98,6 +98,7 @@ python3 ./test.py -f 2-query/stateduration.py python3 ./test.py -f 2-query/function_stateduration.py python3 ./test.py -f 2-query/statecount.py python3 ./test.py -f 2-query/tail.py +python3 ./test.py -f 2-query/ttl_comment.py python3 ./test.py -f 6-cluster/5dnode1mnode.py python3 ./test.py -f 6-cluster/5dnode2mnode.py From e169d19dd4aef8b3192bafe9bb5c657a9b4553e3 Mon Sep 17 00:00:00 2001 From: wangmm0220 Date: Sat, 18 Jun 2022 21:08:12 +0800 Subject: [PATCH 9/9] fix:heap overflow in comment --- source/common/src/tmsg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 7813c0c3ab..c3c96972b7 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -707,7 +707,7 @@ int32_t tDeserializeSMAlterStbReq(void *buf, int32_t bufLen, SMAlterStbReq *pReq if (tDecodeI32(&decoder, &pReq->ttl) < 0) return -1; if (tDecodeI32(&decoder, &pReq->commentLen) < 0) return -1; if (pReq->commentLen > 0) { - pReq->comment = taosMemoryMalloc(pReq->commentLen); + pReq->comment = taosMemoryMalloc(pReq->commentLen + 1); if (pReq->comment == NULL) return -1; if (tDecodeCStrTo(&decoder, pReq->comment) < 0) return -1; }