diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 0f736e7068..7252929e3b 100644 --- a/include/libs/nodes/cmdnodes.h +++ b/include/libs/nodes/cmdnodes.h @@ -112,7 +112,7 @@ typedef struct SDatabaseOptions { int8_t s3Compact; int8_t withArbitrator; // for auto-compact - int8_t compactTimeOffset; // hours + int32_t compactTimeOffset; // hours int32_t compactInterval; // minutes int32_t compactStartTime; // minutes int32_t compactEndTime; // minutes diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 38dce105bb..1f018606a8 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -123,6 +123,9 @@ static const SSysDbTableSchema userDBSchema[] = { {.name = "s3_compact", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true}, {.name = "with_arbitrator", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT, .sysInfo = true}, {.name = "encrypt_algorithm", .bytes = TSDB_ENCRYPT_ALGO_STR_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, + {.name = "compact_interval", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, + {.name = "compact_time_range", .bytes = 24 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, + {.name = "compact_time_offset", .bytes = 4 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR, .sysInfo = true}, }; static const SSysDbTableSchema userFuncSchema[] = { diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index 1efbff9d53..43abc842f4 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -499,6 +499,20 @@ static int32_t mndCheckDbCfg(SMnode *pMnode, SDbCfg *pCfg) { if (pCfg->s3KeepLocal < TSDB_MIN_S3_KEEP_LOCAL || pCfg->s3KeepLocal > TSDB_MAX_S3_KEEP_LOCAL) return code; if (pCfg->s3Compact < TSDB_MIN_S3_COMPACT || pCfg->s3Compact > TSDB_MAX_S3_COMPACT) return code; + if (pCfg->compactInterval != 0 && + (pCfg->compactInterval < TSDB_MIN_COMPACT_INTERVAL || pCfg->compactInterval > pCfg->daysToKeep2)) + return code; + if (pCfg->compactStartTime != 0 && + (pCfg->compactStartTime < -pCfg->daysToKeep2 || pCfg->compactStartTime > -pCfg->daysPerFile)) + return code; + if (pCfg->compactEndTime != 0 && + (pCfg->compactEndTime < -pCfg->daysToKeep2 || pCfg->compactEndTime > -pCfg->daysPerFile)) + return code; + if (pCfg->compactStartTime != 0 && pCfg->compactEndTime != 0 && pCfg->compactStartTime >= pCfg->compactEndTime) + return code; + if (pCfg->compactTimeOffset < TSDB_MIN_COMPACT_TIME_OFFSET || pCfg->compactTimeOffset > TSDB_MAX_COMPACT_TIME_OFFSET) + return code; + code = 0; TAOS_RETURN(code); } @@ -564,6 +578,22 @@ static int32_t mndCheckInChangeDbCfg(SMnode *pMnode, SDbCfg *pOldCfg, SDbCfg *pN if (pNewCfg->s3KeepLocal < TSDB_MIN_S3_KEEP_LOCAL || pNewCfg->s3KeepLocal > TSDB_MAX_S3_KEEP_LOCAL) return code; if (pNewCfg->s3Compact < TSDB_MIN_S3_COMPACT || pNewCfg->s3Compact > TSDB_MAX_S3_COMPACT) return code; + if (pNewCfg->compactInterval != 0 && + (pNewCfg->compactInterval < TSDB_MIN_COMPACT_INTERVAL || pNewCfg->compactInterval > pNewCfg->daysToKeep2)) + return code; + if (pNewCfg->compactStartTime != 0 && + (pNewCfg->compactStartTime < -pNewCfg->daysToKeep2 || pNewCfg->compactStartTime > -pNewCfg->daysPerFile)) + return code; + if (pNewCfg->compactEndTime != 0 && + (pNewCfg->compactEndTime < -pNewCfg->daysToKeep2 || pNewCfg->compactEndTime > -pNewCfg->daysPerFile)) + return code; + if (pNewCfg->compactStartTime != 0 && pNewCfg->compactEndTime != 0 && + pNewCfg->compactStartTime >= pNewCfg->compactEndTime) + return code; + if (pNewCfg->compactTimeOffset < TSDB_MIN_COMPACT_TIME_OFFSET || + pNewCfg->compactTimeOffset > TSDB_MAX_COMPACT_TIME_OFFSET) + return code; + code = 0; TAOS_RETURN(code); } @@ -1150,20 +1180,24 @@ static int32_t mndSetDbCfgFromAlterDbReq(SDbObj *pDb, SAlterDbReq *pAlter) { code = 0; } + bool compactTimeRangeChanged = false; if (pAlter->compactStartTime != pDb->cfg.compactStartTime && (pAlter->compactStartTime == TSDB_DEFAULT_COMPACT_START_TIME || pAlter->compactStartTime <= -pDb->cfg.daysPerFile)) { pDb->cfg.compactStartTime = pAlter->compactStartTime; - pDb->vgVersion++; + compactTimeRangeChanged = true; code = 0; } if (pAlter->compactEndTime != pDb->cfg.compactEndTime && (pAlter->compactEndTime == TSDB_DEFAULT_COMPACT_END_TIME || pAlter->compactEndTime <= -pDb->cfg.daysPerFile)) { pDb->cfg.compactEndTime = pAlter->compactEndTime; - pDb->vgVersion++; + compactTimeRangeChanged = true; code = 0; } + if(compactTimeRangeChanged) { + pDb->vgVersion++; + } if (pAlter->compactTimeOffset >= TSDB_MIN_COMPACT_TIME_OFFSET && pAlter->compactTimeOffset != pDb->cfg.compactTimeOffset) { @@ -1411,14 +1445,6 @@ static void mndDumpDbCfgInfo(SDbCfgRsp *cfgRsp, SDbObj *pDb) { cfgRsp->compactInterval = pDb->cfg.compactInterval; cfgRsp->compactStartTime = pDb->cfg.compactStartTime; cfgRsp->compactEndTime = pDb->cfg.compactEndTime; - if (cfgRsp->compactInterval > 0) { - if (cfgRsp->compactStartTime == 0) { - cfgRsp->compactStartTime = -cfgRsp->daysToKeep2; - } - if (cfgRsp->compactEndTime == 0) { - cfgRsp->compactEndTime = -cfgRsp->daysPerFile; - } - } cfgRsp->compactTimeOffset = pDb->cfg.compactTimeOffset; } @@ -2435,6 +2461,7 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb, pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)strictVstr, false), &lino, _OVER); + char durationStr[128] = {0}; char durationVstr[128] = {0}; int32_t len = formatDurationOrKeep(&durationVstr[VARSTR_HEADER_SIZE], sizeof(durationVstr) - VARSTR_HEADER_SIZE, pDb->cfg.daysPerFile); @@ -2443,10 +2470,10 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb, pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER); - char keepVstr[512] = {0}; - char keep0Str[128] = {0}; - char keep1Str[128] = {0}; - char keep2Str[128] = {0}; + char keepVstr[128] = {0}; + char keep0Str[32] = {0}; + char keep1Str[32] = {0}; + char keep2Str[32] = {0}; int32_t lenKeep0 = formatDurationOrKeep(keep0Str, sizeof(keep0Str), pDb->cfg.daysToKeep0); int32_t lenKeep1 = formatDurationOrKeep(keep1Str, sizeof(keep1Str), pDb->cfg.daysToKeep1); @@ -2559,6 +2586,26 @@ static void mndDumpDbInfoData(SMnode *pMnode, SSDataBlock *pBlock, SDbObj *pDb, STR_WITH_MAXSIZE_TO_VARSTR(encryptAlgorithmVStr, encryptAlgorithmStr, 24); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)encryptAlgorithmVStr, false), &lino, _OVER); + + TAOS_UNUSED(formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactInterval)); + STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr)); + if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) { + TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER); + } + + len = formatDurationOrKeep(durationStr, sizeof(durationStr), pDb->cfg.compactStartTime); + TAOS_UNUSED(formatDurationOrKeep(durationVstr, sizeof(durationVstr), pDb->cfg.compactEndTime)); + TAOS_UNUSED(snprintf(durationStr + len, sizeof(durationStr) - len, ",%s", durationVstr)); + STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr)); + if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) { + TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER); + } + + TAOS_UNUSED(snprintf(durationStr, sizeof(durationStr), "%dh", pDb->cfg.compactTimeOffset)); + STR_WITH_MAXSIZE_TO_VARSTR(durationVstr, durationStr, sizeof(durationVstr)); + if ((pColInfo = taosArrayGet(pBlock->pDataBlock, cols++))) { + TAOS_CHECK_GOTO(colDataSetVal(pColInfo, rows, (const char *)durationVstr, false), &lino, _OVER); + } } _OVER: if (code != 0) mError("failed to retrieve at line:%d, since %s", lino, tstrerror(code)); diff --git a/source/libs/parser/inc/sql.y b/source/libs/parser/inc/sql.y index 38e93a7ce3..63a6b97bbb 100644 --- a/source/libs/parser/inc/sql.y +++ b/source/libs/parser/inc/sql.y @@ -290,8 +290,7 @@ db_options(A) ::= db_options(B) ENCRYPT_ALGORITHM NK_STRING(C). db_options(A) ::= db_options(B) DNODES NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_DNODES, &C); } db_options(A) ::= db_options(B) COMPACT_INTERVAL NK_INTEGER (C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_INTERVAL, &C); } db_options(A) ::= db_options(B) COMPACT_INTERVAL NK_VARIABLE(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_INTERVAL, &C); } -db_options(A) ::= db_options(B) COMPACT_TIME_RANGE signed_integer_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_RANGE, C); } -db_options(A) ::= db_options(B) COMPACT_TIME_RANGE signed_variable_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_RANGE, C); } +db_options(A) ::= db_options(B) COMPACT_TIME_RANGE signed_duration_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_RANGE, C); } db_options(A) ::= db_options(B) COMPACT_TIME_OFFSET NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_OFFSET, &C); } db_options(A) ::= db_options(B) COMPACT_TIME_OFFSET NK_VARIABLE(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_OFFSET, &C); } @@ -331,8 +330,7 @@ alter_db_option(A) ::= KEEP_TIME_OFFSET NK_INTEGER(B). alter_db_option(A) ::= ENCRYPT_ALGORITHM NK_STRING(B). { A.type = DB_OPTION_ENCRYPT_ALGORITHM; A.val = B; } alter_db_option(A) ::= COMPACT_INTERVAL NK_INTEGER(B). { A.type = DB_OPTION_COMPACT_INTERVAL; A.val = B; } alter_db_option(A) ::= COMPACT_INTERVAL NK_VARIABLE(B). { A.type = DB_OPTION_COMPACT_INTERVAL; A.val = B; } -alter_db_option(A) ::= COMPACT_TIME_RANGE signed_integer_list(B). { A.type = DB_OPTION_COMPACT_TIME_RANGE; A.pList = B; } -alter_db_option(A) ::= COMPACT_TIME_RANGE signed_variable_list(B). { A.type = DB_OPTION_COMPACT_TIME_RANGE; A.pList = B; } +alter_db_option(A) ::= COMPACT_TIME_RANGE signed_duration_list(B). { A.type = DB_OPTION_COMPACT_TIME_RANGE; A.pList = B; } alter_db_option(A) ::= COMPACT_TIME_OFFSET NK_INTEGER(B). { A.type = DB_OPTION_COMPACT_TIME_OFFSET; A.val = B; } alter_db_option(A) ::= COMPACT_TIME_OFFSET NK_VARIABLE(B). { A.type = DB_OPTION_COMPACT_TIME_OFFSET; A.val = B; } @@ -341,20 +339,17 @@ alter_db_option(A) ::= COMPACT_TIME_OFFSET NK_VARIABLE(B). integer_list(A) ::= NK_INTEGER(B). { A = createNodeList(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); } integer_list(A) ::= integer_list(B) NK_COMMA NK_INTEGER(C). { A = addNodeToList(pCxt, B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C)); } -%type signed_integer_list { SNodeList* } -%destructor signed_integer_list { nodesDestroyList($$); } -signed_integer_list(A) ::= signed_integer(B). { A = createNodeList(pCxt, B); } -signed_integer_list(A) ::= signed_integer_list(B) NK_COMMA signed_integer(C). { A = addNodeToList(pCxt, B, C); } - %type variable_list { SNodeList* } %destructor variable_list { nodesDestroyList($$); } variable_list(A) ::= NK_VARIABLE(B). { A = createNodeList(pCxt, createDurationValueNode(pCxt, &B)); } variable_list(A) ::= variable_list(B) NK_COMMA NK_VARIABLE(C). { A = addNodeToList(pCxt, B, createDurationValueNode(pCxt, &C)); } -%type signed_variable_list { SNodeList* } -%destructor signed_variable_list { nodesDestroyList($$); } -signed_variable_list(A) ::= signed_variable(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); } -signed_variable_list(A) ::= signed_variable_list(B) NK_COMMA signed_variable(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); } +%type signed_duration_list { SNodeList* } +%destructor signed_duration_list { nodesDestroyList($$); } +signed_duration_list(A) ::= signed_variable(B). { A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); } +signed_duration_list(A) ::= signed_integer(B). { A = createNodeList(pCxt, B); } +signed_duration_list(A) ::= signed_duration_list(B) NK_COMMA signed_integer(C). { A = addNodeToList(pCxt, B, C); } +signed_duration_list(A) ::= signed_duration_list(B) NK_COMMA signed_variable(C). { A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); } %type retention_list { SNodeList* } %destructor retention_list { nodesDestroyList($$); } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 8f3cbd6f8b..374212cc52 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2033,7 +2033,7 @@ static EDealRes translateDurationValue(STranslateContext* pCxt, SValueNode* pVal pVal->datum.i = AUTO_DURATION_VALUE; pVal->unit = getPrecisionUnit(pVal->node.resType.precision); } else if (parseNatualDuration(pVal->literal, strlen(pVal->literal), &pVal->datum.i, &pVal->unit, - pVal->node.resType.precision, false) != TSDB_CODE_SUCCESS) { + pVal->node.resType.precision, true) != TSDB_CODE_SUCCESS) { return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, pVal->literal); } *(int64_t*)&pVal->typeData = pVal->datum.i; @@ -7810,7 +7810,7 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const char* pName, int64_t val, int64_t minVal, int64_t maxVal, bool skipUndef) { - if (skipUndef ? ((val >= 0) && (val < minVal || val > maxVal)) : (val < minVal || val > maxVal)) { + if (skipUndef ? ((val >= 0 || val < -2) && (val < minVal || val > maxVal)) : (val < minVal || val > maxVal)) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, "Invalid option %s: %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]", pName, val, minVal, maxVal); @@ -8176,7 +8176,6 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) { int32_t code = 0; - int64_t interval = 0; int32_t keep2 = pOptions->keep[2]; if (NULL != pOptions->pCompactIntervalNode) { @@ -8191,23 +8190,26 @@ static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, const char* pOptions->pCompactIntervalNode->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR, TIME_UNIT_DAY); } - interval = getBigintFromValueNode(pOptions->pCompactIntervalNode); + int64_t interval = getBigintFromValueNode(pOptions->pCompactIntervalNode); if (interval != 0) { if (keep2 == -1) { // alter db TAOS_CHECK_RETURN(translateGetDbCfg(pCxt, pDbName, &pOptions->pDbCfg)); keep2 = pOptions->pDbCfg->daysToKeep2; } code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2); + TAOS_CHECK_RETURN(code); } + pOptions->compactInterval = (int32_t)interval; } else if (pOptions->compactInterval > 0) { - interval = pOptions->compactInterval * 1440; // convert to minutes - if (keep2 == -1) { // alter db + int64_t interval = (int64_t)pOptions->compactInterval * 1440; // convert to minutes + if (keep2 == -1) { // alter db TAOS_CHECK_RETURN(translateGetDbCfg(pCxt, pDbName, &pOptions->pDbCfg)); keep2 = pOptions->pDbCfg->daysToKeep2; } code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2); + TAOS_CHECK_RETURN(code); + pOptions->compactInterval = (int32_t)interval; } - if (code == 0) pOptions->compactInterval = interval; return code; } @@ -8250,6 +8252,10 @@ static int32_t checkDbCompactTimeRangeOption(STranslateContext* pCxt, const char pOptions->compactStartTime = getBigintFromValueNode(pStart); pOptions->compactEndTime = getBigintFromValueNode(pEnd); + if (pOptions->compactStartTime == 0 && pOptions->compactEndTime == 0) { + return TSDB_CODE_SUCCESS; + } + if (pOptions->compactStartTime >= pOptions->compactEndTime) { return generateSyntaxErrMsgExt( &pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, @@ -8266,7 +8272,7 @@ static int32_t checkDbCompactTimeRangeOption(STranslateContext* pCxt, const char } if (pOptions->compactStartTime < -keep2 || pOptions->compactStartTime > -days) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, - "Invalid option compact_time_range: %dm, start_time should be in range: [%dm, %dm]", + "Invalid option compact_time_range: %dm, start time should be in range: [%dm, %dm]", pOptions->compactStartTime, -keep2, -days); } if (pOptions->compactEndTime < -keep2 || pOptions->compactEndTime > -days) { diff --git a/tests/develop-test/2-query/show_create_db.py b/tests/develop-test/2-query/show_create_db.py index e59121f631..16e9b1d62c 100644 --- a/tests/develop-test/2-query/show_create_db.py +++ b/tests/develop-test/2-query/show_create_db.py @@ -47,7 +47,7 @@ class TDTestCase: tdSql.query('show create database scd2;') tdSql.checkRows(1) tdSql.checkData(0, 0, 'scd2') - tdSql.checkData(0, 1, "CREATE DATABASE `scd2` BUFFER 256 CACHESIZE 1 CACHEMODEL 'none' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 3 KEEP 3650d,3650d,3650d PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0 KEEP_TIME_OFFSET 0h ENCRYPT_ALGORITHM 'none' S3_CHUNKPAGES 131072 S3_KEEPLOCAL 525600m S3_COMPACT 1 COMPACT_INTERVAL 1d COMPACT_TIME_RANGE -3650d,-10d COMPACT_TIME_OFFSET 0h") + tdSql.checkData(0, 1, "CREATE DATABASE `scd2` BUFFER 256 CACHESIZE 1 CACHEMODEL 'none' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 3 KEEP 3650d,3650d,3650d PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0 KEEP_TIME_OFFSET 0h ENCRYPT_ALGORITHM 'none' S3_CHUNKPAGES 131072 S3_KEEPLOCAL 525600m S3_COMPACT 1 COMPACT_INTERVAL 1d COMPACT_TIME_RANGE 0d,0d COMPACT_TIME_OFFSET 0h") tdSql.query('show create database scd4') tdSql.checkRows(1) @@ -65,7 +65,7 @@ class TDTestCase: tdSql.query('show create database scd2;') tdSql.checkRows(1) tdSql.checkData(0, 0, 'scd2') - tdSql.checkData(0, 1, "CREATE DATABASE `scd2` BUFFER 256 CACHESIZE 1 CACHEMODEL 'none' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 3 KEEP 3650d,3650d,3650d PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0 KEEP_TIME_OFFSET 0h ENCRYPT_ALGORITHM 'none' S3_CHUNKPAGES 131072 S3_KEEPLOCAL 525600m S3_COMPACT 1 COMPACT_INTERVAL 1d COMPACT_TIME_RANGE -3650d,-10d COMPACT_TIME_OFFSET 0h") + tdSql.checkData(0, 1, "CREATE DATABASE `scd2` BUFFER 256 CACHESIZE 1 CACHEMODEL 'none' COMP 2 DURATION 10d WAL_FSYNC_PERIOD 3000 MAXROWS 4096 MINROWS 100 STT_TRIGGER 3 KEEP 3650d,3650d,3650d PAGES 256 PAGESIZE 4 PRECISION 'ms' REPLICA 1 WAL_LEVEL 1 VGROUPS 2 SINGLE_STABLE 0 TABLE_PREFIX 0 TABLE_SUFFIX 0 TSDB_PAGESIZE 4 WAL_RETENTION_PERIOD 3600 WAL_RETENTION_SIZE 0 KEEP_TIME_OFFSET 0h ENCRYPT_ALGORITHM 'none' S3_CHUNKPAGES 131072 S3_KEEPLOCAL 525600m S3_COMPACT 1 COMPACT_INTERVAL 1d COMPACT_TIME_RANGE 0d,0d COMPACT_TIME_OFFSET 0h") tdSql.query('show create database scd4') tdSql.checkRows(1) tdSql.checkData(0, 0, 'scd4') diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 8903ef27a4..6d52c0914b 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -414,6 +414,7 @@ ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/persisit_config.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/qmemCtrl.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact_vgroups.py +,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact_auto.py ,,n,system-test,python3 ./test.py -f 0-others/dumpsdb.py ,,y,system-test,./pytest.sh python3 ./test.py -f 0-others/compact.py -N 3 diff --git a/tests/system-test/0-others/compact_auto.py b/tests/system-test/0-others/compact_auto.py new file mode 100644 index 0000000000..813be3e9f0 --- /dev/null +++ b/tests/system-test/0-others/compact_auto.py @@ -0,0 +1,170 @@ +import taos +import sys +import time +import socket +import os +import threading +import psutil +import platform +from util.log import * +from util.sql import * +from util.cases import * +from util.dnodes import * + + +class TDTestCase: + def init(self, conn, logSql, replicaVar=1): + self.replicaVar = int(replicaVar) + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + self.default_compact_options = [ "0d", "0d,0d", "0h"] + self.compact_options = [["db00", "0m", "-0d,0", "0", "0d", "0d,0d", "0h"], + ["db01", "0m", "-2d,-1", "0", "0d", "-2d,-1d", "0h"], + ["db02", "2880m", "-61d,-1", "0", "2d", "-61d,-1d", "0h"], + ["db03", "48h", "-87840m,-60", "1h", "2d", "-61d,-60d", "1h"], + ["db04", "2d", "-87840m,-1440h", "12", "2d", "-61d,-60d", "12h"], + ["db05", "2", "-61,-1440h", "23h", "2d", "-61d,-60d", "23h"], + ] + + def create_db_compact(self): + tdLog.info("create db compact options") + for item in self.compact_options: + tdSql.execute(f'create database {item[0]} compact_interval {item[1]} compact_time_range {item[2]} compact_time_offset {item[3]} duration 1d') + tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"') + tdSql.checkEqual(tdSql.queryResult[0][34], item[4]) + tdSql.checkEqual(tdSql.queryResult[0][35], item[5]) + tdSql.checkEqual(tdSql.queryResult[0][36], item[6]) + tdSql.query(f'show create database {item[0]}') + tdSql.checkEqual(tdSql.queryResult[0][0], item[0]) + tdSql.checkEqual(True, f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}' in tdSql.queryResult[0][1]) + tdSql.execute(f'drop database {item[0]}') + + def checkShowCreateWithTimeout(self, db, expectResult, timeout=30): + result = False + for i in range(timeout): + tdSql.query(f'show create database `%s`' %(db)) + tdSql.checkEqual(tdSql.queryResult[0][0], db) + if expectResult in tdSql.queryResult[0][1]: + result = True + break + time.sleep(1) + if result == False: + raise Exception(f"Unexpected result of 'show create database `{db}`':{tdSql.queryResult[0][1]}, expect:{expectResult}") + + def alter_db_compact(self): + tdLog.info("alter db compact options together") + for item in self.compact_options: + tdSql.execute(f'create database {item[0]} duration 1d') + tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"') + tdSql.checkEqual(tdSql.queryResult[0][34], self.default_compact_options[0]) + tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1]) + tdSql.checkEqual(tdSql.queryResult[0][36], self.default_compact_options[2]) + tdSql.query(f'show create database {item[0]}') + tdSql.checkEqual(tdSql.queryResult[0][0], item[0]) + tdSql.checkEqual(True, f'COMPACT_INTERVAL {self.default_compact_options[0]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {self.default_compact_options[2]}' in tdSql.queryResult[0][1]) + tdSql.execute(f'alter database {item[0]} compact_interval {item[1]} compact_time_range {item[2]} compact_time_offset {item[3]}') + tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"') + tdSql.checkEqual(tdSql.queryResult[0][34], item[4]) + tdSql.checkEqual(tdSql.queryResult[0][35], item[5]) + tdSql.checkEqual(tdSql.queryResult[0][36], item[6]) + for item in self.compact_options: + self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}') + tdSql.execute(f'drop database {item[0]}') + + tdLog.info("alter db compact options separately") + compact_separate_options = [["db100", "0m", "-0d,0", "0", "0d", "0d,0d", "0h"], + ["db101", "10m", "-2d,-1", "1", "10m", "-2d,-1d", "1h"]] + for item in compact_separate_options: + tdSql.execute(f'create database {item[0]} duration 1d') + tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"') + tdSql.checkEqual(tdSql.queryResult[0][34], self.default_compact_options[0]) + tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1]) + tdSql.checkEqual(tdSql.queryResult[0][36], self.default_compact_options[2]) + tdSql.query(f'show create database {item[0]}') + tdSql.checkEqual(tdSql.queryResult[0][0], item[0]) + tdSql.checkEqual(True, f'COMPACT_INTERVAL {self.default_compact_options[0]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {self.default_compact_options[2]}' in tdSql.queryResult[0][1]) + tdSql.execute(f'alter database {item[0]} compact_time_offset {item[3]}', queryTimes=10) + tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"') + tdSql.checkEqual(tdSql.queryResult[0][34], self.default_compact_options[0]) + tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1]) + tdSql.checkEqual(tdSql.queryResult[0][36], item[6]) + self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {self.default_compact_options[0]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {item[6]}') + tdSql.execute(f'alter database {item[0]} compact_interval {item[1]}', queryTimes=10) + tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"') + tdSql.checkEqual(tdSql.queryResult[0][34], item[4]) + tdSql.checkEqual(tdSql.queryResult[0][35], self.default_compact_options[1]) + tdSql.checkEqual(tdSql.queryResult[0][36], item[6]) + self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {self.default_compact_options[1]} COMPACT_TIME_OFFSET {item[6]}') + tdSql.execute(f'alter database {item[0]} compact_time_range {item[2]}', queryTimes=10) + tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"') + tdSql.checkEqual(tdSql.queryResult[0][34], item[4]) + tdSql.checkEqual(tdSql.queryResult[0][35], item[5]) + tdSql.checkEqual(tdSql.queryResult[0][36], item[6]) + self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}') + tdSql.execute(f'alter database {item[0]} compact_time_offset {item[3]}', queryTimes=10) + tdSql.query(f'select * from information_schema.ins_databases where name = "{item[0]}"') + tdSql.checkEqual(tdSql.queryResult[0][34], item[4]) + tdSql.checkEqual(tdSql.queryResult[0][35], item[5]) + tdSql.checkEqual(tdSql.queryResult[0][36], item[6]) + self.checkShowCreateWithTimeout(item[0], f'COMPACT_INTERVAL {item[4]} COMPACT_TIME_RANGE {item[5]} COMPACT_TIME_OFFSET {item[6]}') + for item in compact_separate_options: + tdSql.execute(f'drop database {item[0]}', queryTimes=10) + + def compact_error(self): + compact_err_list = [["compact_time_range 86400m,61d", "Invalid option compact_time_range: 86400m, start time should be in range: [-5256000m, -14400m]"], + ["compact_time_range 60,61", "Invalid option compact_time_range: 86400m, start time should be in range: [-5256000m, -14400m]"], + ["compact_time_range 60d,61d", "Invalid option compact_time_range: 86400m, start time should be in range: [-5256000m, -14400m]"], + ["compact_time_range -60,-60", "Invalid option compact_time_range: -86400m,-86400m, start time should be less than end time"], + ["compact_time_range -60,-1440h", "Invalid option compact_time_range: -86400m,-86400m, start time should be less than end time"], + ["compact_time_range -60d,-61d", "Invalid option compact_time_range: -86400m,-87840m, start time should be less than end time"], + ["compact_time_range -5256001m,-1", "Invalid option compact_time_range: -5256001m, start time should be in range: [-5256000m, -14400m]"], + ["compact_time_range -199999999999m,-199999999998m", "start time should be in range: [-5256000m, -14400m]"], + ["compact_time_range -99999999999999999999m,-99999999999999999998m", "Invalid value type: -99999999999999999999"], + ["compact_time_range -60d,-1", "Invalid option compact_time_range: -1440m, end time should be in range: [-5256000m, -14400m]"], + ["compact_interval 24h compact_time_range -60,61", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"], + ["compact_interval 100 compact_time_range -60d,61d", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"], + ["compact_time_range -60d,87840m", "Invalid option compact_time_range: 87840m, end time should be in range: [-5256000m, -14400m]"], + ["compact_time_range -100,-90s", "Invalid option compact_time_range end unit: s, only m, h, d allowed"], + ["compact_interval 10m compact_time_range -120d,-14400m compact_time_offset -1", "syntax error near"], + ["compact_time_range -100,-99d compact_interval -1", "syntax error near"], + ["compact_time_range 0", "Invalid option compact_time_range, should have 2 value"], + ["compact_time_range -100", "Invalid option compact_time_range, should have 2 value"], + ["compact_time_range -100,-90,-80", "Invalid option compact_time_range, should have 2 value"], + ["compact_time_range -100;-90", "Invalid option compact_time_range, should have 2 value"], + ["compact_time_range -100:-90", "syntax error near"], + ["compact_time_range -100 -90", "syntax error near"], + ["compact_interval 1m", "Invalid option compact_interval: 1, valid range: [10, 5256000]"], + ["compact_interval 199999999999m", "valid range: [10, 5256000]"], + ["compact_interval 9999999999999m", "Invalid option compact_interval: 9999999999999, valid range: [10, 5256000]"], + ["compact_interval 5256001m", "Invalid option compact_interval: 5256001, valid range: [10, 5256000]"], + ["compact_interval 3651", "Invalid option compact_interval: 5257440, valid range: [10, 5256000]"], + ["compact_interval 86400s", "Invalid option compact_interval unit: s, only m, h, d allowed"], + ["compact_interval -1", "syntax error near"], + ["compact_time_offset -1", "syntax error near"], + ["compact_time_offset 3600s", "Invalid option compact_time_offset unit: s, only h allowed"], + ["compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"], + ["compact_time_offset 24", "Invalid option compact_time_offset: 24, valid range: [0, 23]"], + ["compact_time_offset 24h", "Invalid option compact_time_offset: 24, valid range: [0, 23]"], + ["compact_time_offset 9999999999999", "valid range: [0, 23]"], + ["compact_time_offset 199999999999", "valid range: [0, 23]"], + ["compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"], + ["compact_interval 10m compact_time_range -120d,-60 compact_time_offset 1d", "Invalid option compact_time_offset unit: d, only h allowed"], + ] + tdSql.execute('create database if not exists db') + for item in compact_err_list: + tdSql.error(f"create database db {item[0]}", expectErrInfo=item[1], fullMatched=False) + tdSql.error(f"alter database db {item[0]}", expectErrInfo=item[1], fullMatched=False) + tdSql.execute('drop database db') + + def run(self): + self.create_db_compact() + self.alter_db_compact() + self.compact_error() + + def stop(self): + tdSql.close() + tdLog.success(f"{__file__} successfully executed") + + +tdCases.addLinux(__file__, TDTestCase()) +tdCases.addWindows(__file__, TDTestCase()) diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index 8c25b70b76..390bf3d9dd 100644 --- a/tests/system-test/0-others/information_schema.py +++ b/tests/system-test/0-others/information_schema.py @@ -222,7 +222,7 @@ class TDTestCase: tdSql.query("select * from information_schema.ins_columns where db_name ='information_schema'") tdLog.info(len(tdSql.queryResult)) - tdSql.checkEqual(True, len(tdSql.queryResult) in range(309, 310)) + tdSql.checkEqual(True, len(tdSql.queryResult) in range(312, 313)) tdSql.query("select * from information_schema.ins_columns where db_name ='performance_schema'") tdSql.checkEqual(61, len(tdSql.queryResult)) diff --git a/tests/system-test/1-insert/alter_database.py b/tests/system-test/1-insert/alter_database.py index f58bb7517e..17a0664926 100644 --- a/tests/system-test/1-insert/alter_database.py +++ b/tests/system-test/1-insert/alter_database.py @@ -81,8 +81,8 @@ class TDTestCase: tdSql.query('select * from information_schema.ins_databases where name = "db"') db_options_items = ["replica","keep","buffer","pages","minrows","cachemodel","cachesize","wal_level","wal_fsync_period", - "wal_retention_period","wal_retention_size","stt_trigger"] - db_options_result_idx = [4,7,8,10,11,18,19,20,21,22,23,24] + "wal_retention_period","wal_retention_size","stt_trigger", "compact_interval", "compact_time_range", "compact_time_offset"] + db_options_result_idx = [4,7,8,10,11,18,19,20,21,22,23,24,34,35,36] self.option_result = [] for idx in db_options_result_idx: diff --git a/tests/system-test/2-query/elapsed.py b/tests/system-test/2-query/elapsed.py index dc89cd513d..c1191c3441 100644 --- a/tests/system-test/2-query/elapsed.py +++ b/tests/system-test/2-query/elapsed.py @@ -1542,7 +1542,7 @@ class TDTestCase: def query_precision(self): def generate_data(precision="ms"): - tdSql.execute("create database if not exists db_%s precision '%s';" %(precision, precision)) + tdSql.execute("create database if not exists db_%s keep 36500 precision '%s';" %(precision, precision)) tdSql.execute("use db_%s;" %precision) tdSql.execute("create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision) tdSql.execute("create table db_%s.tb1 using st tags(1);"%precision) diff --git a/tests/system-test/2-query/statecount.py b/tests/system-test/2-query/statecount.py index 006215956b..f5dba2df4f 100644 --- a/tests/system-test/2-query/statecount.py +++ b/tests/system-test/2-query/statecount.py @@ -395,7 +395,7 @@ class TDTestCase: def query_precision(self): def generate_data(precision="ms"): dbname = f"db_{precision}" - tdSql.execute(f"create database if not exists db_%s precision '%s';" %(precision, precision)) + tdSql.execute(f"create database if not exists db_%s keep 36500 precision '%s';" %(precision, precision)) tdSql.execute("use db_%s;" %precision) tdSql.execute(f"create stable db_%s.st (ts timestamp , id int) tags(ind int);"%precision) tdSql.execute(f"create table db_%s.tb1 using {dbname}.st tags(1);"%precision) @@ -449,7 +449,7 @@ class TDTestCase: def check_boundary_values(self, dbname="bound_test"): tdSql.execute(f"drop database if exists {dbname}") - tdSql.execute(f"create database if not exists {dbname}") + tdSql.execute(f"create database if not exists {dbname} keep 36500") tdSql.execute( f"create table {dbname}.stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);" )