enh: add keep option while show stable. (#30294)

This commit is contained in:
Zhixiao Bao 2025-03-20 15:30:22 +08:00 committed by GitHub
parent a03143147f
commit 0b8bff92c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 0 deletions

View File

@ -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;

View File

@ -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:

View File

@ -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);

View File

@ -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) {

View File

@ -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())