feat: support auto compact

This commit is contained in:
kailixu 2024-11-26 19:46:48 +08:00
parent 9a9f73273c
commit 67924ee55b
11 changed files with 173 additions and 70 deletions

View File

@ -1344,9 +1344,9 @@ typedef struct {
char dnodeListStr[TSDB_DNODE_LIST_LEN];
// 1. add auto-compact parameters
int32_t compactInterval;
int32_t compactStartTime;
int32_t compactEndTime;
int32_t compactTimeOffset;
int64_t compactStartTime;
int64_t compactEndTime;
int8_t compactTimeOffset;
} SCreateDbReq;
int32_t tSerializeSCreateDbReq(void* buf, int32_t bufLen, SCreateDbReq* pReq);
@ -1380,9 +1380,9 @@ typedef struct {
int8_t withArbitrator;
// 1. add auto-compact parameters
int32_t compactInterval;
int32_t compactStartTime;
int32_t compactEndTime;
int32_t compactTimeOffset;
int64_t compactStartTime;
int64_t compactEndTime;
int8_t compactTimeOffset;
} SAlterDbReq;
int32_t tSerializeSAlterDbReq(void* buf, int32_t bufLen, SAlterDbReq* pReq);

View File

@ -111,12 +111,12 @@ typedef struct SDatabaseOptions {
int8_t withArbitrator;
// for auto-compact
SValueNode* pCompactIntervalNode;
int32_t compactInterval;
int32_t compactInterval; // minutes
SNodeList* pCompactTimeRangeList;
int32_t compactStartTime;
int32_t compactEndTime;
int32_t compactStartTime; // minutes
int32_t compactEndTime; // minutes
SValueNode* pCompactTimeOffsetNode;
int32_t compactTimeOffset;
int32_t compactTimeOffset; // hours
} SDatabaseOptions;
typedef struct SCreateDatabaseStmt {

View File

@ -506,8 +506,12 @@ typedef enum ELogicConditionType {
#define TSDB_DEFAULT_TABLE_TTL 0
#define TSDB_DEFAULT_COMPACT_INTERVAL 0
#define TSDB_MIN_COMPACT_INTERVAL 10 // unit minute
#define TSDB_MAX_COMPACT_INTERVAL TSDB_MAX_KEEP // unit minute
#define TSDB_DEFAULT_COMPACT_START_TIME 0
#define TSDB_DEFAULT_COMPACT_END_TIME 0
#define TSDB_MIN_COMPACT_TIME_OFFSET 0
#define TSDB_MAX_COMPACT_TIME_OFFSET 23
#define TSDB_DEFAULT_COMPACT_TIME_OFFSET 0
#define TSDB_MIN_EXPLAIN_RATIO 0

View File

@ -3939,9 +3939,9 @@ int32_t tSerializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq) {
// auto-compact parameters
TAOS_CHECK_EXIT(tEncodeI32v(&encoder, pReq->compactInterval));
TAOS_CHECK_EXIT(tEncodeI32v(&encoder, pReq->compactStartTime));
TAOS_CHECK_EXIT(tEncodeI32v(&encoder, pReq->compactEndTime));
TAOS_CHECK_EXIT(tEncodeI32v(&encoder, pReq->compactTimeOffset));
TAOS_CHECK_EXIT(tEncodeI64v(&encoder, pReq->compactStartTime));
TAOS_CHECK_EXIT(tEncodeI64v(&encoder, pReq->compactEndTime));
TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->compactTimeOffset));
tEndEncode(&encoder);
@ -4036,9 +4036,9 @@ int32_t tDeserializeSCreateDbReq(void *buf, int32_t bufLen, SCreateDbReq *pReq)
if (!tDecodeIsEnd(&decoder)) {
TAOS_CHECK_EXIT(tDecodeI32v(&decoder, &pReq->compactInterval));
TAOS_CHECK_EXIT(tDecodeI32v(&decoder, &pReq->compactStartTime));
TAOS_CHECK_EXIT(tDecodeI32v(&decoder, &pReq->compactEndTime));
TAOS_CHECK_EXIT(tDecodeI32v(&decoder, &pReq->compactTimeOffset));
TAOS_CHECK_EXIT(tDecodeI64v(&decoder, &pReq->compactStartTime));
TAOS_CHECK_EXIT(tDecodeI64v(&decoder, &pReq->compactEndTime));
TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->compactTimeOffset));
} else {
pReq->compactInterval = 0;
pReq->compactStartTime = 0;
@ -4098,9 +4098,9 @@ int32_t tSerializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) {
TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->withArbitrator));
// auto compact config
TAOS_CHECK_EXIT(tEncodeI32v(&encoder, pReq->compactInterval));
TAOS_CHECK_EXIT(tEncodeI32v(&encoder, pReq->compactStartTime));
TAOS_CHECK_EXIT(tEncodeI32v(&encoder, pReq->compactEndTime));
TAOS_CHECK_EXIT(tEncodeI32v(&encoder, pReq->compactTimeOffset));
TAOS_CHECK_EXIT(tEncodeI64v(&encoder, pReq->compactStartTime));
TAOS_CHECK_EXIT(tEncodeI64v(&encoder, pReq->compactEndTime));
TAOS_CHECK_EXIT(tEncodeI8(&encoder, pReq->compactTimeOffset));
tEndEncode(&encoder);
_exit:
@ -4172,9 +4172,9 @@ int32_t tDeserializeSAlterDbReq(void *buf, int32_t bufLen, SAlterDbReq *pReq) {
// auto compact config
if (!tDecodeIsEnd(&decoder)) {
TAOS_CHECK_EXIT(tDecodeI32v(&decoder, &pReq->compactInterval));
TAOS_CHECK_EXIT(tDecodeI32v(&decoder, &pReq->compactStartTime));
TAOS_CHECK_EXIT(tDecodeI32v(&decoder, &pReq->compactEndTime));
TAOS_CHECK_EXIT(tDecodeI32v(&decoder, &pReq->compactTimeOffset));
TAOS_CHECK_EXIT(tDecodeI64v(&decoder, &pReq->compactStartTime));
TAOS_CHECK_EXIT(tDecodeI64v(&decoder, &pReq->compactEndTime));
TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pReq->compactTimeOffset));
} else {
pReq->compactInterval = 0;
pReq->compactStartTime = 0;

View File

@ -423,10 +423,10 @@ typedef struct {
int8_t s3Compact;
int8_t withArbitrator;
int8_t encryptAlgorithm;
int8_t compactTimeOffset;
int32_t compactInterval;
int32_t compactStartTime;
int32_t compactEndTime;
int32_t compactTimeOffset;
int64_t compactStartTime;
int64_t compactEndTime;
} SDbCfg;
typedef struct {

View File

@ -858,7 +858,7 @@ static int32_t mndSaveCompactProgress(SMnode *pMnode, int32_t compactId) {
return 0;
}
void mndCompactPullup(SMnode *pMnode) {
static void mndCompactPullup(SMnode *pMnode) {
int32_t code = 0;
SSdb *pSdb = pMnode->pSdb;
SArray *pArray = taosArrayInit(sdbGetSize(pSdb, SDB_COMPACT), sizeof(int32_t));
@ -891,8 +891,58 @@ void mndCompactPullup(SMnode *pMnode) {
taosArrayDestroy(pArray);
}
static int32_t mndProcessAutoCompact(SRpcMsg *pReq) {
int32_t code = 0, lino = 0;
SMnode *pMnode = pReq->info.node;
SSdb *pSdb = pMnode->pSdb;
int64_t now = taosGetTimestampMs();
void *pDbIter = NULL;
while (1) {
SDbObj *pDb = NULL;
pDbIter = sdbFetch(pSdb, SDB_DB, pDbIter, (void **)&pDb);
if (pDbIter == NULL) break;
if ((pDb->cfg.compactInterval == 0) || (pDb->cfg.compactStartTime == pDb->cfg.compactEndTime)) {
sdbRelease(pSdb, pDb);
continue;
}
if (pDb->cfg.compactStartTime > pDb->cfg.compactEndTime) {
mWarn("db:%s compact start time is greater than end time", pDb->name);
sdbRelease(pSdb, pDb);
continue;
}
// check if there is an unfinished compact task for this db
bool hasCompact = false;
void *pCompactIter = NULL;
while (1) {
SCompactObj *pCompact = NULL;
pCompactIter = sdbFetch(pSdb, SDB_COMPACT, pCompactIter, (void **)&pCompact);
if (pCompactIter == NULL) break;
if (0 == strncmp(pCompact->dbname, pDb->name, TSDB_DB_FNAME_LEN) == 0) {
hasCompact = true;
sdbRelease(pSdb, pCompact);
break;
}
sdbRelease(pSdb, pCompact);
}
if (hasCompact) {
mInfo("db:%s skip auto compact since unfinished compact task", pDb->name);
sdbRelease(pSdb, pDb);
continue;
}
sdbRelease(pSdb, pDb);
}
return 0;
}
static int32_t mndProcessCompactTimer(SRpcMsg *pReq) {
mTrace("start to process compact timer");
mndCompactPullup(pReq->info.node);
TAOS_UNUSED(mndProcessAutoCompact(pReq));
return 0;
}

View File

@ -37,7 +37,7 @@
#include "tjson.h"
#define DB_VER_NUMBER 1
#define DB_RESERVE_SIZE 27
#define DB_RESERVE_SIZE 6
static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw);
static int32_t mndDbActionInsert(SSdb *pSdb, SDbObj *pDb);
@ -151,6 +151,10 @@ SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.withArbitrator, _OVER)
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.encryptAlgorithm, _OVER)
SDB_SET_INT32(pRaw, dataPos, pDb->tsmaVersion, _OVER);
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.compactTimeOffset, _OVER)
SDB_SET_INT64(pRaw, dataPos, pDb->cfg.compactStartTime, _OVER)
SDB_SET_INT64(pRaw, dataPos, pDb->cfg.compactEndTime, _OVER)
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.compactInterval, _OVER)
SDB_SET_RESERVE(pRaw, dataPos, DB_RESERVE_SIZE, _OVER)
SDB_SET_DATALEN(pRaw, dataPos, _OVER)
@ -250,6 +254,10 @@ static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.withArbitrator, _OVER)
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.encryptAlgorithm, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pDb->tsmaVersion, _OVER);
SDB_GET_INT8(pRaw, dataPos, &pDb->cfg.compactTimeOffset, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pDb->cfg.compactStartTime, _OVER)
SDB_GET_INT64(pRaw, dataPos, &pDb->cfg.compactEndTime, _OVER)
SDB_GET_INT32(pRaw, dataPos, &pDb->cfg.compactInterval, _OVER)
SDB_GET_RESERVE(pRaw, dataPos, DB_RESERVE_SIZE, _OVER)
taosInitRWLatch(&pDb->lock);
@ -365,6 +373,10 @@ static int32_t mndDbActionUpdate(SSdb *pSdb, SDbObj *pOld, SDbObj *pNew) {
pOld->cfg.s3KeepLocal = pNew->cfg.s3KeepLocal;
pOld->cfg.s3Compact = pNew->cfg.s3Compact;
pOld->cfg.withArbitrator = pNew->cfg.withArbitrator;
pOld->cfg.compactInterval = pNew->cfg.compactInterval;
pOld->cfg.compactStartTime = pNew->cfg.compactStartTime;
pOld->cfg.compactEndTime = pNew->cfg.compactEndTime;
pOld->cfg.compactTimeOffset = pNew->cfg.compactTimeOffset;
pOld->compactStartTime = pNew->compactStartTime;
pOld->tsmaVersion = pNew->tsmaVersion;
taosWUnLockLatch(&pOld->lock);

View File

@ -288,8 +288,11 @@ db_options(A) ::= db_options(B) S3_COMPACT NK_INTEGER(C).
db_options(A) ::= db_options(B) KEEP_TIME_OFFSET NK_INTEGER(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_KEEP_TIME_OFFSET, &C); }
db_options(A) ::= db_options(B) ENCRYPT_ALGORITHM NK_STRING(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_ENCRYPT_ALGORITHM, &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 integer_list(C). { A = setDatabaseOption(pCxt, B, DB_OPTION_COMPACT_TIME_RANGE, &C); }
db_options(A) ::= db_options(B) COMPACT_TIME_RANGE variable_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); }
alter_db_options(A) ::= alter_db_option(B). { A = createAlterDatabaseOptions(pCxt); A = setAlterDatabaseOption(pCxt, A, &B); }
@ -328,7 +331,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_VARIABLE(B). { A.type = DB_OPTION_COMPACT_INTERVAL; A.val = B; }
alter_db_option(A) ::= COMPACT_TIME_RANGE variable_list(B). { A.type = DB_OPTION_COMPACT_TIME_RANGE; A.pList = B; }
alter_db_option(A) ::= COMPACT_TIME_OFFSET NK_VARIABLE(B). { A.type = DB_OPTION_COMPACT_TIME_OFFSET; A.val = B; }
alter_db_option(A) ::= COMPACT_TIME_OFFSET NK_INTEGER(B). { A.type = DB_OPTION_COMPACT_TIME_OFFSET; A.val = B; }
%type integer_list { SNodeList* }
%destructor integer_list { nodesDestroyList($$); }

View File

@ -2001,14 +2001,17 @@ static SNode* setDatabaseOptionImpl(SAstCreateContext* pCxt, SNode* pOptions, ED
}
break;
case DB_OPTION_COMPACT_INTERVAL:
pDbOptions->pCompactIntervalNode = (SValueNode*)createDurationValueNode(pCxt, (SToken*)pVal);
if (TK_NK_INTEGER == ((SToken*)pVal)->type) {
pDbOptions->compactInterval = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
} else {
pDbOptions->pCompactIntervalNode = (SValueNode*)createDurationValueNode(pCxt, (SToken*)pVal);
}
break;
case DB_OPTION_COMPACT_TIME_RANGE:
pDbOptions->pCompactTimeRangeList = pVal;
break;
case DB_OPTION_COMPACT_TIME_OFFSET:
pDbOptions->pCompactTimeOffsetNode = (SValueNode*)createDurationValueNode(pCxt, (SToken*)pVal);
;
pDbOptions->compactTimeOffset = taosStr2Int32(((SToken*)pVal)->z, NULL, 10);
break;
default:
break;
@ -2019,6 +2022,8 @@ _err:
return NULL;
}
SNode* setDatabaseOption(SAstCreateContext* pCxt, SNode* pOptions, EDatabaseOptionType type, void* pVal) {
return setDatabaseOptionImpl(pCxt, pOptions, type, pVal, false);
}

View File

@ -72,6 +72,9 @@ static SKeyword keywordTable[] = {
{"COMP", TK_COMP},
{"COMPACT", TK_COMPACT},
{"COMPACTS", TK_COMPACTS},
{"COMPACT_INTERVAL", TK_COMPACT_INTERVAL},
{"COMPACT_TIME_OFFSET", TK_COMPACT_TIME_OFFSET},
{"COMPACT_TIME_RANGE", TK_COMPACT_TIME_RANGE},
{"CONNECTION", TK_CONNECTION},
{"CONNECTIONS", TK_CONNECTIONS},
{"CONNS", TK_CONNS},

View File

@ -7577,8 +7577,8 @@ static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const cha
return TSDB_CODE_SUCCESS;
}
static int32_t checkDbRangeOption(STranslateContext* pCxt, const char* pName, int32_t val, int32_t minVal,
int32_t maxVal) {
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);
}
@ -7928,21 +7928,31 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa
}
static int32_t checkDbCompactIntervalOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
if (NULL == pOptions->pCompactIntervalNode) return TSDB_CODE_SUCCESS;
if (DEAL_RES_ERROR == translateValue(pCxt, pOptions->pCompactIntervalNode)) {
return pCxt->errCode;
int32_t code = 0;
int64_t interval = 0;
if (NULL != pOptions->pCompactIntervalNode) {
if (DEAL_RES_ERROR == translateValue(pCxt, pOptions->pCompactIntervalNode)) {
return pCxt->errCode;
}
if (TIME_UNIT_MINUTE != pOptions->pCompactIntervalNode->unit &&
TIME_UNIT_HOUR != pOptions->pCompactIntervalNode->unit &&
TIME_UNIT_DAY != pOptions->pCompactIntervalNode->unit) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_interval unit: %c, only %c, %c, %c allowed",
pOptions->pCompactIntervalNode->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR,
TIME_UNIT_DAY);
}
interval = getBigintFromValueNode(pOptions->pCompactIntervalNode);
if (interval != 0) {
code = checkDbRangeOption(pCxt, "compact_interval", pOptions->compactInterval, TSDB_MIN_COMPACT_INTERVAL,
pOptions->keep[2]);
}
} else if (pOptions->compactInterval != 0) {
interval = pOptions->compactInterval * 1440; // convert to minutes
code = checkDbRangeOption(pCxt, "compact_interval", interval, TSDB_MIN_COMPACT_INTERVAL, pOptions->keep[2]);
}
if (TIME_UNIT_MINUTE != pOptions->pCompactIntervalNode->unit &&
TIME_UNIT_HOUR != pOptions->pCompactIntervalNode->unit) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_interval unit: %c, only %c, %c allowed",
pOptions->pCompactIntervalNode->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR);
}
pOptions->compactInterval = getBigintFromValueNode(pOptions->pCompactIntervalNode);
// TODO: check the semantic of compact_interval
return TSDB_CODE_SUCCESS;
if (code == 0) pOptions->compactInterval = interval;
return code;
}
static int32_t checkDbCompactTimeRangeOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
@ -7963,40 +7973,56 @@ static int32_t checkDbCompactTimeRangeOption(STranslateContext* pCxt, SDatabaseO
if (DEAL_RES_ERROR == translateValue(pCxt, pEnd)) {
return pCxt->errCode;
}
if (TIME_UNIT_MINUTE != pStart->unit && TIME_UNIT_HOUR != pStart->unit && TIME_UNIT_DAY != pStart->unit) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_time_range start unit: %c, only %c, %c, %c allowed",
pStart->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR, TIME_UNIT_DAY);
if (IS_DURATION_VAL(pStart->flag)) {
if (TIME_UNIT_MINUTE != pStart->unit && TIME_UNIT_HOUR != pStart->unit && TIME_UNIT_DAY != pStart->unit) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_time_range start unit: %c, only %c, %c, %c allowed",
pStart->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR, TIME_UNIT_DAY);
}
} else {
pStart->datum.i *= 1440;
}
if (TIME_UNIT_MINUTE != pEnd->unit && TIME_UNIT_HOUR != pEnd->unit && TIME_UNIT_DAY != pEnd->unit) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_time_range end unit: %c, only %c, %c, %c allowed",
pEnd->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR, TIME_UNIT_DAY);
if (IS_DURATION_VAL(pEnd->flag)) {
if (TIME_UNIT_MINUTE != pEnd->unit && TIME_UNIT_HOUR != pEnd->unit && TIME_UNIT_DAY != pEnd->unit) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_time_range end unit: %c, only %c, %c, %c allowed",
pEnd->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR, TIME_UNIT_DAY);
}
} else {
pStart->datum.i *= 1440;
}
pOptions->compactStartTime = getBigintFromValueNode(pStart);
pOptions->compactEndTime = getBigintFromValueNode(pEnd);
// TODO: check the semantic of compact_time_range
if (pOptions->compactStartTime >= pOptions->compactEndTime) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_time_range, start time should be less than end time");
}
if (pOptions->compactStartTime < -pOptions->keep[2] || pOptions->compactStartTime > -pOptions->daysPerFile) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_time_range, start_time should be in range: [%" PRIi64
"m, %" PRId64 "m]",
-pOptions->keep[2], -pOptions->daysPerFile);
}
if (pOptions->compactEndTime < -pOptions->keep[2] || pOptions->compactEndTime > -pOptions->daysPerFile) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_time_range, end time should be in range: [%" PRIi64
"m, %" PRId64 "m]",
-pOptions->keep[2], -pOptions->daysPerFile);
}
return TSDB_CODE_SUCCESS;
}
static int32_t checkDbCompactTimeOffsetOption(STranslateContext* pCxt, SDatabaseOptions* pOptions) {
if (NULL == pOptions->pCompactTimeOffsetNode) {
return TSDB_CODE_SUCCESS;
}
if (DEAL_RES_ERROR == translateValue(pCxt, pOptions->pCompactTimeOffsetNode)) {
return pCxt->errCode;
}
if (TIME_UNIT_MINUTE != pOptions->pCompactTimeOffsetNode->unit &&
TIME_UNIT_HOUR != pOptions->pCompactTimeOffsetNode->unit) {
if (pOptions->compactTimeOffset < TSDB_MIN_COMPACT_TIME_OFFSET ||
pOptions->compactTimeOffset > TSDB_MAX_COMPACT_TIME_OFFSET) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION,
"Invalid option compact_time_offset unit: %c, only %c, %c allowed",
pOptions->pCompactTimeOffsetNode->unit, TIME_UNIT_MINUTE, TIME_UNIT_HOUR);
"Invalid option compact_time_offset: %d"
" valid range: [%d, %d]",
pOptions->compactTimeOffset, TSDB_MIN_COMPACT_TIME_OFFSET,
TSDB_MAX_COMPACT_TIME_OFFSET);
}
pOptions->compactTimeOffset = getBigintFromValueNode(pOptions->pCompactTimeOffsetNode);
// TODO: check the semantic of compact_time_offset
return TSDB_CODE_SUCCESS;
}