diff --git a/include/libs/nodes/cmdnodes.h b/include/libs/nodes/cmdnodes.h index 8eb30b8184..2d329ec879 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 cb08046399..8bed8d23eb 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 c28fd343f0..1d1f5744d4 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) { @@ -1408,14 +1442,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; } @@ -2432,6 +2458,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); @@ -2440,10 +2467,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); @@ -2556,6 +2583,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 63eb09d509..f52d85eea7 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($$); } @@ -594,6 +589,7 @@ cmd ::= SHOW BNODES. cmd ::= SHOW SNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SNODES_STMT); } cmd ::= SHOW CLUSTER. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CLUSTER_STMT); } cmd ::= SHOW TRANSACTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TRANSACTIONS_STMT); } +cmd ::= SHOW TRANSACTION NK_INTEGER(A). { pCxt->pRootNode = createShowTransactionDetailsStmt(pCxt, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &A)); } cmd ::= SHOW TABLE DISTRIBUTED full_table_name(A). { pCxt->pRootNode = createShowTableDistributedStmt(pCxt, A); } cmd ::= SHOW CONSUMERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONSUMERS_STMT); } cmd ::= SHOW SUBSCRIPTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_SUBSCRIPTIONS_STMT); } @@ -1709,4 +1705,4 @@ null_ordering_opt(A) ::= NULLS LAST. column_options(A) ::= . { A = createDefaultColumnOptions(pCxt); } column_options(A) ::= column_options(B) PRIMARY KEY. { A = setColumnOptionsPK(pCxt, B); } -column_options(A) ::= column_options(B) NK_ID(C) NK_STRING(D). { A = setColumnOptions(pCxt, B, &C, &D); } +column_options(A) ::= column_options(B) NK_ID(C) NK_STRING(D). { A = setColumnOptions(pCxt, B, &C, &D); } \ No newline at end of file diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 9f411c4296..178471f813 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -2005,7 +2005,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; @@ -7781,23 +7781,23 @@ 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)) { + int64_t maxVal, int8_t unit, bool skipUndef) { + 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); + "Invalid option %s: %" PRId64 "%c, valid range: [%" PRId64 "%c, %" PRId64 "%c]", + pName, val, unit, minVal, unit, maxVal, unit); } return TSDB_CODE_SUCCESS; } static int32_t checkDbRangeOption(STranslateContext* pCxt, const char* pName, int64_t val, int64_t minVal, - int64_t maxVal) { - return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_DB_OPTION, pName, val, minVal, maxVal, true); + int64_t maxVal, int8_t unit) { + return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_DB_OPTION, pName, val, minVal, maxVal, unit, true); } static int32_t checkTableRangeOption(STranslateContext* pCxt, const char* pName, int64_t val, int64_t minVal, int64_t maxVal) { - return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_TABLE_OPTION, pName, val, minVal, maxVal, true); + return checkRangeOption(pCxt, TSDB_CODE_PAR_INVALID_TABLE_OPTION, pName, val, minVal, maxVal, 0, true); } static int32_t checkDbS3KeepLocalOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) { @@ -7813,7 +7813,8 @@ static int32_t checkDbS3KeepLocalOption(STranslateContext* pCxt, SDatabaseOption } pOptions->s3KeepLocal = getBigintFromValueNode(pOptions->s3KeepLocalStr); } - return checkDbRangeOption(pCxt, "s3KeepLocal", pOptions->s3KeepLocal, TSDB_MIN_S3_KEEP_LOCAL, TSDB_MAX_S3_KEEP_LOCAL); + return checkDbRangeOption(pCxt, "s3KeepLocal", pOptions->s3KeepLocal, TSDB_MIN_S3_KEEP_LOCAL, TSDB_MAX_S3_KEEP_LOCAL, + 0); } static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) { @@ -7829,7 +7830,8 @@ static int32_t checkDbDaysOption(STranslateContext* pCxt, SDatabaseOptions* pOpt } pOptions->daysPerFile = getBigintFromValueNode(pOptions->pDaysPerFile); } - return checkDbRangeOption(pCxt, "daysPerFile", pOptions->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE); + return checkDbRangeOption(pCxt, "daysPerFile", pOptions->daysPerFile, TSDB_MIN_DAYS_PER_FILE, TSDB_MAX_DAYS_PER_FILE, + 0); } static int32_t checkDbKeepOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) { @@ -8148,7 +8150,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) { @@ -8163,23 +8164,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); + code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2, TIME_UNIT_MINUTE); + 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); + code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, keep2, TIME_UNIT_MINUTE); + TAOS_CHECK_RETURN(code); + pOptions->compactInterval = (int32_t)interval; } - if (code == 0) pOptions->compactInterval = interval; return code; } @@ -8222,13 +8226,16 @@ 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, "Invalid option compact_time_range: %dm,%dm, start time should be less than end time", pOptions->compactStartTime, pOptions->compactEndTime); } - int32_t keep2 = pOptions->keep[2]; int32_t days = pOptions->daysPerFile; if (keep2 == -1 || days == -1) { // alter db @@ -8238,7 +8245,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) { @@ -8246,7 +8253,6 @@ static int32_t checkDbCompactTimeRangeOption(STranslateContext* pCxt, const char "Invalid option compact_time_range: %dm, end time should be in range: [%dm, %dm]", pOptions->compactEndTime, -keep2, -days); } - return TSDB_CODE_SUCCESS; } @@ -8263,12 +8269,12 @@ static int32_t checkDbCompactTimeOffsetOption(STranslateContext* pCxt, SDatabase pOptions->compactTimeOffset = getBigintFromValueNode(pOptions->pCompactTimeOffsetNode) / 60; } return checkDbRangeOption(pCxt, "compact_time_offset", pOptions->compactTimeOffset, TSDB_MIN_COMPACT_TIME_OFFSET, - TSDB_MAX_COMPACT_TIME_OFFSET); + TSDB_MAX_COMPACT_TIME_OFFSET, TIME_UNIT_HOUR); } static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) { int32_t code = - checkDbRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE); + checkDbRangeOption(pCxt, "buffer", pOptions->buffer, TSDB_MIN_BUFFER_PER_VNODE, TSDB_MAX_BUFFER_PER_VNODE, 0); if (TSDB_CODE_SUCCESS == code) { code = checkDbCacheModelOption(pCxt, pOptions); } @@ -8276,26 +8282,27 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName code = checkDbEncryptAlgorithmOption(pCxt, pOptions); } if (TSDB_CODE_SUCCESS == code) { - code = - checkDbRangeOption(pCxt, "cacheSize", pOptions->cacheLastSize, TSDB_MIN_DB_CACHE_SIZE, TSDB_MAX_DB_CACHE_SIZE); + code = checkDbRangeOption(pCxt, "cacheSize", pOptions->cacheLastSize, TSDB_MIN_DB_CACHE_SIZE, + TSDB_MAX_DB_CACHE_SIZE, 0); } if (TSDB_CODE_SUCCESS == code) { - code = - checkDbRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL); + code = checkDbRangeOption(pCxt, "compression", pOptions->compressionLevel, TSDB_MIN_COMP_LEVEL, TSDB_MAX_COMP_LEVEL, + 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbDaysOption(pCxt, pOptions); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbRangeOption(pCxt, "fsyncPeriod", pOptions->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD); + code = + checkDbRangeOption(pCxt, "fsyncPeriod", pOptions->fsyncPeriod, TSDB_MIN_FSYNC_PERIOD, TSDB_MAX_FSYNC_PERIOD, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbRangeOption(pCxt, "maxRowsPerBlock", pOptions->maxRowsPerBlock, TSDB_MIN_MAXROWS_FBLOCK, - TSDB_MAX_MAXROWS_FBLOCK); + TSDB_MAX_MAXROWS_FBLOCK, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbRangeOption(pCxt, "minRowsPerBlock", pOptions->minRowsPerBlock, TSDB_MIN_MINROWS_FBLOCK, - TSDB_MAX_MINROWS_FBLOCK); + TSDB_MAX_MINROWS_FBLOCK, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbPrecisionOption(pCxt, pOptions); @@ -8307,18 +8314,18 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName code = checkDbKeepTimeOffsetOption(pCxt, pOptions); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbRangeOption(pCxt, "pages", pOptions->pages, TSDB_MIN_PAGES_PER_VNODE, TSDB_MAX_PAGES_PER_VNODE); + code = checkDbRangeOption(pCxt, "pages", pOptions->pages, TSDB_MIN_PAGES_PER_VNODE, TSDB_MAX_PAGES_PER_VNODE, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbRangeOption(pCxt, "pagesize", pOptions->pagesize, TSDB_MIN_PAGESIZE_PER_VNODE, - TSDB_MAX_PAGESIZE_PER_VNODE); + TSDB_MAX_PAGESIZE_PER_VNODE, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbRangeOption(pCxt, "tsdbPagesize", pOptions->tsdbPageSize, TSDB_MIN_TSDB_PAGESIZE, - TSDB_MAX_TSDB_PAGESIZE); + TSDB_MAX_TSDB_PAGESIZE, 0); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbRangeOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA); + code = checkDbRangeOption(pCxt, "replications", pOptions->replica, TSDB_MIN_DB_REPLICA, TSDB_MAX_DB_REPLICA, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbStrictOption(pCxt, pOptions); @@ -8328,7 +8335,8 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName TSDB_MAX_WAL_LEVEL); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbRangeOption(pCxt, "vgroups", pOptions->numOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB); + code = + checkDbRangeOption(pCxt, "vgroups", pOptions->numOfVgroups, TSDB_MIN_VNODES_PER_DB, TSDB_MAX_VNODES_PER_DB, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbEnumOption(pCxt, "singleStable", pOptions->singleStable, TSDB_DB_SINGLE_STABLE_ON, @@ -8342,21 +8350,22 @@ static int32_t checkDatabaseOptions(STranslateContext* pCxt, const char* pDbName } if (TSDB_CODE_SUCCESS == code) { code = checkDbRangeOption(pCxt, "walRetentionPeriod", pOptions->walRetentionPeriod, - TSDB_DB_MIN_WAL_RETENTION_PERIOD, INT32_MAX); + TSDB_DB_MIN_WAL_RETENTION_PERIOD, INT32_MAX, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbRangeOption(pCxt, "walRetentionSize", pOptions->walRetentionSize, TSDB_DB_MIN_WAL_RETENTION_SIZE, - INT32_MAX); - } - if (TSDB_CODE_SUCCESS == code) { - code = checkDbRangeOption(pCxt, "walRollPeriod", pOptions->walRollPeriod, TSDB_DB_MIN_WAL_ROLL_PERIOD, INT32_MAX); + INT32_MAX, 0); } if (TSDB_CODE_SUCCESS == code) { code = - checkDbRangeOption(pCxt, "walSegmentSize", pOptions->walSegmentSize, TSDB_DB_MIN_WAL_SEGMENT_SIZE, INT32_MAX); + checkDbRangeOption(pCxt, "walRollPeriod", pOptions->walRollPeriod, TSDB_DB_MIN_WAL_ROLL_PERIOD, INT32_MAX, 0); } if (TSDB_CODE_SUCCESS == code) { - code = checkDbRangeOption(pCxt, "sstTrigger", pOptions->sstTrigger, TSDB_MIN_STT_TRIGGER, TSDB_MAX_STT_TRIGGER); + code = checkDbRangeOption(pCxt, "walSegmentSize", pOptions->walSegmentSize, TSDB_DB_MIN_WAL_SEGMENT_SIZE, INT32_MAX, + 0); + } + if (TSDB_CODE_SUCCESS == code) { + code = checkDbRangeOption(pCxt, "sstTrigger", pOptions->sstTrigger, TSDB_MIN_STT_TRIGGER, TSDB_MAX_STT_TRIGGER, 0); } if (TSDB_CODE_SUCCESS == code) { code = checkDbEnumOption(pCxt, "withArbitrator", pOptions->withArbitrator, TSDB_MIN_DB_WITH_ARBITRATOR, @@ -9933,7 +9942,7 @@ static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* p static int32_t translateCreateUser(STranslateContext* pCxt, SCreateUserStmt* pStmt) { int32_t code = 0; SCreateUserReq createReq = {0}; - if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, false))) { + if ((code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, 0, false))) { return code; } tstrncpy(createReq.user, pStmt->userName, TSDB_USER_LEN); @@ -9962,13 +9971,13 @@ static int32_t checkAlterUser(STranslateContext* pCxt, SAlterUserStmt* pStmt) { int32_t code = 0; switch (pStmt->alterType) { case TSDB_ALTER_USER_ENABLE: - code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1, false); + code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "enable", pStmt->enable, 0, 1, 0, false); break; case TSDB_ALTER_USER_SYSINFO: - code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, false); + code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "sysinfo", pStmt->sysinfo, 0, 1, 0, false); break; case TSDB_ALTER_USER_CREATEDB: - code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1, false); + code = checkRangeOption(pCxt, TSDB_CODE_INVALID_OPTION, "createdb", pStmt->createdb, 0, 1, 0, false); break; } return code; diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index ed73a2742c..0f82efc61b 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -411,6 +411,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..27c24087c1 --- /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: 1m, valid range: [10m, 5256000m]"], + ["compact_interval 199999999999m", "valid range: [10m, 5256000m]"], + ["compact_interval 9999999999999m", "Invalid option compact_interval: 9999999999999m, valid range: [10m, 5256000m]"], + ["compact_interval 5256001m", "Invalid option compact_interval: 5256001m, valid range: [10m, 5256000m]"], + ["compact_interval 3651", "Invalid option compact_interval: 5257440m, valid range: [10m, 5256000m]"], + ["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: 24h, valid range: [0h, 23h]"], + ["compact_time_offset 24h", "Invalid option compact_time_offset: 24h, valid range: [0h, 23h]"], + ["compact_time_offset 9999999999999", "valid range: [0h, 23h]"], + ["compact_time_offset 199999999999", "valid range: [0h, 23h]"], + ["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()) \ No newline at end of file diff --git a/tests/system-test/0-others/information_schema.py b/tests/system-test/0-others/information_schema.py index af0dd6d949..130085b91d 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(303, 304)) + 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(60, 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: