Merge pull request #13933 from taosdata/feature/TD-16524
feat: add ttl/comment function
This commit is contained in:
commit
45a247c062
|
@ -1817,6 +1817,8 @@ typedef struct SVCreateTbReq {
|
|||
tb_uid_t uid;
|
||||
int64_t ctime;
|
||||
int32_t ttl;
|
||||
int32_t commentLen;
|
||||
char* comment;
|
||||
int8_t type;
|
||||
union {
|
||||
struct {
|
||||
|
@ -1834,6 +1836,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) {
|
||||
|
@ -1930,7 +1933,7 @@ typedef struct {
|
|||
// TSDB_ALTER_TABLE_UPDATE_OPTIONS
|
||||
int8_t updateTTL;
|
||||
int32_t newTTL;
|
||||
int8_t updateComment;
|
||||
int32_t newCommentLen;
|
||||
char* newComment;
|
||||
} SVAlterTbReq;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -87,6 +87,7 @@ typedef struct SAlterDatabaseStmt {
|
|||
|
||||
typedef struct STableOptions {
|
||||
ENodeType type;
|
||||
bool commentNull;
|
||||
char comment[TSDB_TB_COMMENT_LEN];
|
||||
SNodeList* pMaxDelay;
|
||||
int64_t maxDelay1;
|
||||
|
@ -126,6 +127,7 @@ typedef struct SCreateSubTableClause {
|
|||
bool ignoreExists;
|
||||
SNodeList* pSpecificTags;
|
||||
SNodeList* pValsOfTags;
|
||||
STableOptions* pOptions;
|
||||
} SCreateSubTableClause;
|
||||
|
||||
typedef struct SCreateMultiTableStmt {
|
||||
|
|
|
@ -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},
|
||||
};
|
||||
|
||||
|
|
|
@ -524,7 +524,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 (tEncodeCStr(&encoder, pReq->comment) < 0) return -1;
|
||||
}
|
||||
if (pReq->ast1Len > 0) {
|
||||
if (tEncodeBinary(&encoder, pReq->pAst1, pReq->ast1Len) < 0) return -1;
|
||||
|
@ -589,7 +589,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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -4374,6 +4374,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;
|
||||
|
@ -4397,6 +4401,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 + 1);
|
||||
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;
|
||||
|
@ -4750,8 +4760,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;
|
||||
|
@ -4798,8 +4808,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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -77,12 +77,50 @@ 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 = rpcMallocCont(contLen);
|
||||
if (pHead == NULL) {
|
||||
mError("ttl time malloc err. contLen:%d", contLen);
|
||||
sdbRelease(pSdb, pVgroup);
|
||||
continue;
|
||||
}
|
||||
pHead->contLen = htonl(contLen);
|
||||
pHead->vgId = htonl(pVgroup->vgId);
|
||||
|
||||
int32_t t = taosGetTimestampSec();
|
||||
*(int32_t*)(POINTER_SHIFT(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);
|
||||
}
|
||||
}
|
||||
|
||||
static void *mndThreadFp(void *param) {
|
||||
SMnode *pMnode = param;
|
||||
int64_t lastTime = 0;
|
||||
setThreadName("mnode-timer");
|
||||
|
||||
while (1) {
|
||||
if (lastTime % (864000) == 0) { // sleep 1 day for ttl
|
||||
mndPushTtlTime(pMnode);
|
||||
}
|
||||
|
||||
lastTime++;
|
||||
taosMsleep(100);
|
||||
if (mndGetStop(pMnode)) break;
|
||||
|
|
|
@ -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);
|
||||
|
@ -280,8 +280,8 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
|
|||
}
|
||||
}
|
||||
|
||||
if (pOld->commentLen < pNew->commentLen) {
|
||||
void *comment = taosMemoryMalloc(pNew->commentLen);
|
||||
if (pOld->commentLen < pNew->commentLen && pNew->commentLen > 0) {
|
||||
void *comment = taosMemoryMalloc(pNew->commentLen + 1);
|
||||
if (comment != NULL) {
|
||||
taosMemoryFree(pOld->comment);
|
||||
pOld->comment = 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);
|
||||
|
@ -330,8 +331,8 @@ static int32_t mndStbActionUpdate(SSdb *pSdb, SStbObj *pOld, SStbObj *pNew) {
|
|||
pOld->numOfTags = pNew->numOfTags;
|
||||
memcpy(pOld->pTags, pNew->pTags, pOld->numOfTags * sizeof(SSchema));
|
||||
}
|
||||
if (pNew->commentLen != 0) {
|
||||
memcpy(pOld->comment, pNew->comment, pNew->commentLen);
|
||||
if (pNew->commentLen > 0) {
|
||||
memcpy(pOld->comment, pNew->comment, pNew->commentLen + 1);
|
||||
}
|
||||
if (pNew->ast1Len != 0) {
|
||||
memcpy(pOld->pAst1, pNew->pAst1, pNew->ast1Len);
|
||||
|
@ -676,12 +677,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;
|
||||
|
@ -835,7 +836,7 @@ _OVER:
|
|||
}
|
||||
|
||||
static int32_t mndCheckAlterStbReq(SMAlterStbReq *pAlter) {
|
||||
if (pAlter->commentLen != 0 || pAlter->ttl != 0) return 0;
|
||||
if (pAlter->commentLen >= 0 || pAlter->ttl != 0) return 0;
|
||||
|
||||
if (pAlter->numOfFields < 1 || pAlter->numOfFields != (int32_t)taosArrayGetSize(pAlter->pFields)) {
|
||||
terrno = TSDB_CODE_MND_INVALID_STB_OPTION;
|
||||
|
@ -890,13 +891,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;
|
||||
}
|
||||
|
@ -1206,7 +1210,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;
|
||||
|
@ -1841,17 +1844,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++;
|
||||
|
|
|
@ -210,12 +210,16 @@ struct SMetaEntry {
|
|||
struct {
|
||||
int64_t ctime;
|
||||
int32_t ttlDays;
|
||||
int32_t commentLen;
|
||||
char *comment;
|
||||
tb_uid_t suid;
|
||||
uint8_t *pTags;
|
||||
} ctbEntry;
|
||||
struct {
|
||||
int64_t ctime;
|
||||
int32_t ttlDays;
|
||||
int32_t commentLen;
|
||||
char *comment;
|
||||
int32_t ncid; // next column id
|
||||
SSchemaWrapper schemaRow;
|
||||
} ntbEntry;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -29,12 +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 (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 (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) {
|
||||
|
@ -61,12 +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 (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 (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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -320,11 +320,15 @@ 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;
|
||||
}
|
||||
|
@ -359,7 +363,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,16 +371,57 @@ 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 / 1000 + ttlDays * 24 * 60 * 60;
|
||||
// ttlKey->dtime = ctime / 1000 + ttlDays;
|
||||
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;
|
||||
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);
|
||||
|
||||
|
@ -388,15 +433,17 @@ 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)
|
||||
}
|
||||
|
||||
metaError("ttl drop table:%s", e.name);
|
||||
tDecoderClear(&dc);
|
||||
tdbFree(pData);
|
||||
|
||||
|
@ -545,16 +592,20 @@ 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);
|
||||
tDecoderClear(&dc);
|
||||
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
tDecoderClear(&dc);
|
||||
if (entry.pBuf) taosMemoryFree(entry.pBuf);
|
||||
tdbTbcClose(pTbDbc);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tDecoderClear(&dc);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -706,8 +757,87 @@ _err:
|
|||
}
|
||||
|
||||
static int metaUpdateTableOptions(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
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->newCommentLen >= 0) {
|
||||
entry.ntbEntry.commentLen = pAlterTbReq->newCommentLen;
|
||||
entry.ntbEntry.comment = pAlterTbReq->newComment;
|
||||
}
|
||||
}
|
||||
|
||||
// save to table db
|
||||
metaSaveToTbDb(pMeta, &entry);
|
||||
tdbTbcUpsert(pUidIdxc, &entry.uid, sizeof(tb_uid_t), &version, sizeof(version), 0);
|
||||
metaULock(pMeta);
|
||||
|
||||
tdbTbcClose(pTbDbc);
|
||||
tdbTbcClose(pUidIdxc);
|
||||
tDecoderClear(&dc);
|
||||
if (entry.pBuf) taosMemoryFree(entry.pBuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -786,25 +916,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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -105,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;
|
||||
|
@ -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;
|
||||
|
@ -300,6 +304,26 @@ void vnodeUpdateMetaRsp(SVnode *pVnode, STableMetaRsp *pMetaRsp) {
|
|||
pMetaRsp->precision = pVnode->config.tsdbCfg.precision;
|
||||
}
|
||||
|
||||
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 t = ntohl(*(int32_t*)pReq);
|
||||
vError("rec ttl time:%d", t);
|
||||
int32_t ret = metaTtlDropTable(pVnode->pMeta, t, tbUids);
|
||||
if(ret != 0){
|
||||
goto end;
|
||||
}
|
||||
if(taosArrayGetSize(tbUids) > 0){
|
||||
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;
|
||||
|
|
|
@ -1369,12 +1369,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
|
||||
|
@ -1391,11 +1385,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);
|
||||
|
@ -1404,7 +1412,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);
|
||||
|
@ -1418,6 +1426,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);
|
||||
|
@ -1426,11 +1448,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;
|
||||
|
|
|
@ -526,6 +526,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:
|
||||
|
|
|
@ -878,6 +878,7 @@ SNode* createDefaultTableOptions(SAstCreateContext* pCxt) {
|
|||
pOptions->watermark1 = TSDB_DEFAULT_ROLLUP_WATERMARK;
|
||||
pOptions->watermark2 = TSDB_DEFAULT_ROLLUP_WATERMARK;
|
||||
pOptions->ttl = TSDB_DEFAULT_TABLE_TTL;
|
||||
pOptions->commentNull = true; // mark null
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
|
@ -886,6 +887,7 @@ SNode* createAlterTableOptions(SAstCreateContext* pCxt) {
|
|||
STableOptions* pOptions = (STableOptions*)nodesMakeNode(QUERY_NODE_TABLE_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->ttl = -1;
|
||||
pOptions->commentNull = true; // mark null
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
|
@ -894,6 +896,7 @@ SNode* setTableOption(SAstCreateContext* pCxt, SNode* pOptions, ETableOptionType
|
|||
switch (type) {
|
||||
case TABLE_OPTION_COMMENT:
|
||||
if (checkComment(pCxt, (SToken*)pVal, true)) {
|
||||
((STableOptions*)pOptions)->commentNull = false;
|
||||
COPY_STRING_FORM_STR_TOKEN(((STableOptions*)pOptions)->comment, (SToken*)pVal);
|
||||
}
|
||||
break;
|
||||
|
@ -906,9 +909,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;
|
||||
|
@ -971,9 +980,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -3147,9 +3147,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);
|
||||
}
|
||||
|
@ -3390,17 +3387,19 @@ static int32_t buildCreateStbReq(STranslateContext* pCxt, SCreateTableStmt* pStm
|
|||
pReq->delay2 = pStmt->pOptions->maxDelay2;
|
||||
pReq->watermark1 = pStmt->pOptions->watermark1;
|
||||
pReq->watermark2 = pStmt->pOptions->watermark2;
|
||||
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);
|
||||
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;
|
||||
|
@ -3452,14 +3451,17 @@ static int32_t buildAlterSuperTableReq(STranslateContext* pCxt, SAlterTableStmt*
|
|||
pAlterReq->alterType = pStmt->alterType;
|
||||
|
||||
if (TSDB_ALTER_TABLE_UPDATE_OPTIONS == pStmt->alterType) {
|
||||
pAlterReq->ttl = pStmt->pOptions->ttl;
|
||||
if ('\0' != pStmt->pOptions->comment[0]) {
|
||||
// pAlterReq->ttl = pStmt->pOptions->ttl;
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -4715,6 +4717,16 @@ 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;
|
||||
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);
|
||||
}else{
|
||||
req.commentLen = -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));
|
||||
|
@ -4865,6 +4877,13 @@ 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;
|
||||
if (pStmt->pOptions->commentNull == false) {
|
||||
req.comment = strdup(pStmt->pOptions->comment);
|
||||
req.commentLen = strlen(pStmt->pOptions->comment);
|
||||
} else{
|
||||
req.commentLen = -1;
|
||||
}
|
||||
req.ctb.suid = suid;
|
||||
req.ctb.pTag = (uint8_t*)pTag;
|
||||
if (pStmt->ignoreExists) {
|
||||
|
@ -5436,18 +5455,20 @@ 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 && '\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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5566,6 +5587,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);
|
||||
|
|
|
@ -121,10 +121,10 @@ 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) + 1;
|
||||
expect.commentLen = strlen(pComment);
|
||||
}
|
||||
|
||||
expect.numOfFields = numOfFields;
|
||||
|
@ -180,9 +180,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'");
|
||||
|
@ -289,7 +289,7 @@ TEST_F(ParserInitialATest, alterTable) {
|
|||
expect.newTTL = ttl;
|
||||
}
|
||||
if (nullptr != pComment) {
|
||||
expect.updateComment = true;
|
||||
expect.newCommentLen = strlen(pComment);
|
||||
expect.newComment = pComment;
|
||||
}
|
||||
};
|
||||
|
@ -328,9 +328,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);
|
||||
|
|
|
@ -370,10 +370,10 @@ TEST_F(ParserInitialCTest, createStable) {
|
|||
expect.delay2 = delay2;
|
||||
expect.watermark1 = watermark1;
|
||||
expect.watermark2 = watermark2;
|
||||
expect.ttl = ttl;
|
||||
// expect.ttl = ttl;
|
||||
if (nullptr != pComment) {
|
||||
expect.comment = strdup(pComment);
|
||||
expect.commentLen = strlen(pComment) + 1;
|
||||
expect.commentLen = strlen(pComment);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -414,7 +414,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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,206 @@
|
|||
###################################################################
|
||||
# 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) 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, '')
|
||||
|
||||
|
||||
tdSql.query("show tables like 'child_table3'")
|
||||
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'")
|
||||
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')
|
||||
|
||||
|
||||
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__)
|
||||
|
||||
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
||||
|
|
@ -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 2-query/distribute_agg_count.py
|
||||
python3 ./test.py -f 2-query/distribute_agg_max.py
|
||||
python3 ./test.py -f 2-query/distribute_agg_min.py
|
||||
|
|
Loading…
Reference in New Issue