diff --git a/include/common/tmsg.h b/include/common/tmsg.h index ab191313ec0f5845ff445d9af3e3f1a6cfa5c44e..b5ff28abd003d59ebe8a912fcfb77133a26c8de7 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 40963d5af220ecd3c4f802a807f04f53b4d2dbd3..974e042fa67ab686e5dcaf231ea87356f1b95e2b 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 08977abd61aeefc64ffca9702c6a04b7cd529858..10ad092c75e73ec6daa5013273f3875438d7005c 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 0fd9eb92c5553daf4ee31aa6aedafa4f09fcacd6..a5cc35bfb17a0e0ddd5b6ec71261dff38978d270 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 750006d05fea6940c1b580accf6c0ad20140c97c..45b2fa4f0911b9a2c2a27fb4d27e399f10d31e7e 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 235f026066dd1d63931693aab1fa180ce76f4b9c..ef9276caf6e0d664f0fe97d251bba98ab4fe2310 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 9559b05b6bcb7a59ada2786348a251585848b8ef..9c45fa352fc163ed39066b5606fd93fb5481bef0 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 c1d86e32c87bf67ab7b9c7c2955e7fd9d9f385b2..e83b992f06c39250b5e5b48a37b60843c4504823 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 58b28fed82ccd9e7e5037ecd7864447f2748305d..b57b534b7284a61178908e81dc62c48b304e0459 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 c0eab28863c04efea8ff615b141f7432eb668f00..4d53059957b6f04fafe622e0cdfd9bb5f745f701 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 bc808ad24a97637d0f9c59ab45e8fd83e2c06d25..20ff34f678bf120873fa3a8b3bb78c23183818ad 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 d30e4ef6db5c6beabcd1251efea8d36b7b7f267b..4820cc8833f32045b4efe5d645b945565f96d42f 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 05b2b0c31cb806d29819512f0828cdabe55cf8a4..f2f8b164ee07351911d3430b8941dc8941aed76d 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 faf295518c57076150dab6f32c080c433a8ada01..2a559b4864076e8f5b7e94cc524fc0105aca164d 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 3c1d931f37c51436067acc315e8bc57ea49cd8ca..fe5267322a1451d45939dc1f5697aa3e645cd507 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 919d4c041d685826498f7fa87952ab03621abe7e..28c1169b7a34a812d25643b1b4b1cde6076c443b 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); } };