diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 9fd0ad057c..c295c40c1e 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1430,6 +1430,7 @@ typedef struct { int64_t watermark1; int64_t watermark2; int32_t ttl; + int32_t keep; SArray* pFuncs; int32_t commentLen; char* pComment; diff --git a/source/common/src/msg/tmsg.c b/source/common/src/msg/tmsg.c index e60da401d1..5d99ef8fea 100644 --- a/source/common/src/msg/tmsg.c +++ b/source/common/src/msg/tmsg.c @@ -3970,6 +3970,8 @@ int32_t tSerializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) { } } + TAOS_CHECK_EXIT(tEncodeI32(&encoder, pRsp->keep)); + tEndEncode(&encoder); _exit: @@ -4070,6 +4072,13 @@ int32_t tDeserializeSTableCfgRsp(void *buf, int32_t bufLen, STableCfgRsp *pRsp) pRsp->pColRefs = NULL; } } + + if (!tDecodeIsEnd(&decoder)) { + TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pRsp->keep)); + } else { + pRsp->keep = 0; + } + tEndDecode(&decoder); _exit: diff --git a/source/dnode/mnode/impl/src/mndStb.c b/source/dnode/mnode/impl/src/mndStb.c index 136b6c527c..35c753022b 100644 --- a/source/dnode/mnode/impl/src/mndStb.c +++ b/source/dnode/mnode/impl/src/mndStb.c @@ -2326,6 +2326,7 @@ static int32_t mndBuildStbCfgImp(SDbObj *pDb, SStbObj *pStb, const char *tbName, pRsp->watermark1 = pStb->watermark[0]; pRsp->watermark2 = pStb->watermark[1]; pRsp->ttl = pStb->ttl; + pRsp->keep = pStb->keep; pRsp->commentLen = pStb->commentLen; if (pStb->commentLen > 0) { pRsp->pComment = taosStrdup(pStb->comment); diff --git a/source/libs/command/src/command.c b/source/libs/command/src/command.c index 027c87909b..c83cb19d7a 100644 --- a/source/libs/command/src/command.c +++ b/source/libs/command/src/command.c @@ -784,6 +784,11 @@ static void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STab if (pCfg->ttl > 0) { *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), " TTL %d", pCfg->ttl); + } + + if (pCfg->keep > 0) { + *len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), + " KEEP %dm", pCfg->keep); } if (TSDB_SUPER_TABLE == pCfg->tableType || TSDB_NORMAL_TABLE == pCfg->tableType) { diff --git a/tests/army/create/create_stb_keep.py b/tests/army/create/create_stb_keep.py index c6c2807024..87a0dd0b8e 100644 --- a/tests/army/create/create_stb_keep.py +++ b/tests/army/create/create_stb_keep.py @@ -100,6 +100,16 @@ class TDTestCase(TBase): tdSql.error("CREATE TABLE ntb (ts TIMESTAMP, a INT, b FLOAT, c BINARY(10)) KEEP 1d",expectErrInfo="KEEP parameter is not allowed when creating normal table") tdSql.execute("CREATE TABLE ntb (ts TIMESTAMP, a INT, b FLOAT, c BINARY(10))") tdSql.error("ALTER TABLE ntb keep 1d",expectErrInfo="only super table can alter keep duration") + + def chceck_stb_keep_show_create(self): + tdLog.info(f"check stb keep show create") + tdSql.execute("USE test") + tdSql.execute("CREATE STABLE stb (ts TIMESTAMP, a INT, b FLOAT, c BINARY(10)) TAGS (e_id INT) KEEP 10d") + tdSql.query("SHOW CREATE TABLE stb") + tdSql.checkData(0, 1, "CREATE STABLE `stb` (`ts` TIMESTAMP ENCODE 'delta-i' COMPRESS 'lz4' LEVEL 'medium', `a` INT ENCODE 'simple8b' COMPRESS 'lz4' LEVEL 'medium', `b` FLOAT ENCODE 'delta-d' COMPRESS 'lz4' LEVEL 'medium', `c` VARCHAR(10) ENCODE 'disabled' COMPRESS 'zstd' LEVEL 'medium') TAGS (`e_id` INT) KEEP 14400m") + tdSql.execute("ALTER TABLE stb KEEP 5d") + tdSql.query("SHOW CREATE TABLE stb") + tdSql.checkData(0, 1, "CREATE STABLE `stb` (`ts` TIMESTAMP ENCODE 'delta-i' COMPRESS 'lz4' LEVEL 'medium', `a` INT ENCODE 'simple8b' COMPRESS 'lz4' LEVEL 'medium', `b` FLOAT ENCODE 'delta-d' COMPRESS 'lz4' LEVEL 'medium', `c` VARCHAR(10) ENCODE 'disabled' COMPRESS 'zstd' LEVEL 'medium') TAGS (`e_id` INT) KEEP 7200m") # run def run(self): @@ -126,6 +136,9 @@ class TDTestCase(TBase): # check normal table with keep self.check_normal_table_with_keep() + # check stb keep show create + self.chceck_stb_keep_show_create() + tdLog.success(f"{__file__} successfully executed") tdCases.addLinux(__file__, TDTestCase())