diff --git a/packaging/cfg/taos.cfg b/packaging/cfg/taos.cfg index 46e27b98e9339cb0cb0cb0d8fe0d038bde926148..9a88a0679d50e0eedb861cdc1628b7678bf719a5 100644 --- a/packaging/cfg/taos.cfg +++ b/packaging/cfg/taos.cfg @@ -307,3 +307,6 @@ keepColumnName 1 # unit MB. Flush vnode wal file if walSize > walFlushSize and walSize > cache*0.5*blocks # walFlushSize 1024 + +# unit Hour. Latency of data migration +# keepTimeOffset 0 diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 13bcdd7eca4d7c655892b448a6799c55c8b4e097..fd72a501a75375fd20d4b95bb0382d7d083ee187 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -7715,6 +7715,7 @@ int32_t validateDNodeConfig(SMiscInfo* pOptions) { const int tokenDebugFlag = 4; const int tokenDebugFlagEnd = 20; const int tokenOfflineInterval = 21; + const int tokenKeepTimeOffset = 22; const SDNodeDynConfOption cfgOptions[] = { {"resetLog", 8}, {"resetQueryCache", 15}, {"balance", 7}, {"monitor", 7}, {"debugFlag", 9}, {"monDebugFlag", 12}, {"vDebugFlag", 10}, {"mDebugFlag", 10}, @@ -7723,6 +7724,7 @@ int32_t validateDNodeConfig(SMiscInfo* pOptions) { {"dDebugFlag", 10}, {"mqttDebugFlag", 13}, {"wDebugFlag", 10}, {"tmrDebugFlag", 12}, {"cqDebugFlag", 11}, {"offlineInterval", 15}, + {"keepTimeOffset", 14}, }; SStrToken* pOptionToken = taosArrayGet(pOptions->a, 1); @@ -7762,6 +7764,14 @@ int32_t validateDNodeConfig(SMiscInfo* pOptions) { return TSDB_CODE_TSC_INVALID_OPERATION; // options value is invalid } return TSDB_CODE_SUCCESS; + } else if ((strncasecmp(cfgOptions[tokenKeepTimeOffset].name, pOptionToken->z, pOptionToken->n) == 0) && + (cfgOptions[tokenKeepTimeOffset].len == pOptionToken->n)) { + SStrToken* pValToken = taosArrayGet(pOptions->a, 2); + int32_t val = strtol(pValToken->z, NULL, 10); + if (val < -23 || val > 23) { + return TSDB_CODE_TSC_INVALID_OPERATION; // options value is invalid + } + return TSDB_CODE_SUCCESS; } else { SStrToken* pValToken = taosArrayGet(pOptions->a, 2); diff --git a/src/common/inc/tglobal.h b/src/common/inc/tglobal.h index 06ed93b110281756ade98d5e99dd4b57b4924fc3..edf5ada6c9f4f5a075ce620d8c47381c7042f96a 100644 --- a/src/common/inc/tglobal.h +++ b/src/common/inc/tglobal.h @@ -193,6 +193,7 @@ extern float tsReservedTmpDirectorySpace; extern float tsMinimalDataDirGB; extern int32_t tsTotalMemoryMB; extern uint32_t tsVersion; +extern int32_t tsKeepTimeOffset; // build info extern char version[]; diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c index 922ae1dedc806c8939a142d737e4661f3fe4561d..7f7f9e4d20012a0e5845b7be516770df3d99482d 100644 --- a/src/common/src/tglobal.c +++ b/src/common/src/tglobal.c @@ -217,6 +217,7 @@ char tsMnodeBakDir[PATH_MAX] = {0}; char tsDataDir[PATH_MAX] = {0}; char tsScriptDir[PATH_MAX] = {0}; char tsTempDir[PATH_MAX] = "/tmp/"; +int32_t tsKeepTimeOffset = 0; int32_t tsDiskCfgNum = 0; int32_t tsTopicBianryLen = 16000; @@ -665,6 +666,16 @@ static void doInitGlobalConfig(void) { cfg.unitType = TAOS_CFG_UTYPE_NONE; taosInitConfigOption(cfg); + cfg.option = "keepTimeOffset"; + cfg.ptr = &tsKeepTimeOffset; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = -23; + cfg.maxValue = 23; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + // 0-any; 1-mnode; 2-vnode cfg.option = "role"; cfg.ptr = &tsAlternativeRole; diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index d432c951dd1d91e12c7338aeda9b0619bd949b6d..911eb5e2792bd7321d2a6ed1ed45b2d89636ce80 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -44,6 +44,14 @@ typedef struct { SDataCols * pDataCols; } SCommitH; +/* + * millisecond by default + * for TSDB_TIME_PRECISION_MILLI: 3600000L + * TSDB_TIME_PRECISION_MICRO: 3600000000L + * TSDB_TIME_PRECISION_NANO: 3600000000000L + */ +static int64_t tsTickPerHour[] = {3600000L, 3600000000L, 3600000000000L}; + #define TSDB_COMMIT_REPO(ch) TSDB_READ_REPO(&(ch->readh)) #define TSDB_COMMIT_REPO_ID(ch) REPO_ID(TSDB_READ_REPO(&(ch->readh))) #define TSDB_COMMIT_WRITE_FSET(ch) (&((ch)->wSet)) @@ -397,7 +405,7 @@ void tsdbGetRtnSnap(STsdbRepo *pRepo, SRtn *pRtn) { STsdbCfg *pCfg = REPO_CFG(pRepo); TSKEY minKey, midKey, maxKey, now; - now = taosGetTimestamp(pCfg->precision); + now = taosGetTimestamp(pCfg->precision) - tsKeepTimeOffset * tsTickPerHour[pCfg->precision]; minKey = now - pCfg->keep * tsTickPerDay[pCfg->precision]; midKey = now - pCfg->keep2 * tsTickPerDay[pCfg->precision]; maxKey = now - pCfg->keep1 * tsTickPerDay[pCfg->precision]; diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h index c0a4986936f7d43d48aa4fac0be6f427f5db32f5..872da82a8e16549facd03fb3249b03b150a8f842 100644 --- a/src/util/inc/tconfig.h +++ b/src/util/inc/tconfig.h @@ -20,7 +20,7 @@ extern "C" { #endif -#define TSDB_CFG_MAX_NUM 133 +#define TSDB_CFG_MAX_NUM 134 #define TSDB_CFG_PRINT_LEN 23 #define TSDB_CFG_OPTION_LEN 24 #define TSDB_CFG_VALUE_LEN 41