From 25148268e69c96a02ffb11bde1867f98d86aebe9 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 9 Nov 2022 18:10:30 +0800 Subject: [PATCH] enh: support wider range for future timestamp --- include/common/tglobal.h | 1 + include/util/tdef.h | 2 +- source/common/src/tglobal.c | 9 +++++++++ source/dnode/vnode/src/tsdb/tsdbCommit.c | 4 ++++ source/dnode/vnode/src/tsdb/tsdbUtil.c | 4 ++-- source/dnode/vnode/src/tsdb/tsdbWrite.c | 2 +- 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 681d1beb79..bb1c0709b4 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -43,6 +43,7 @@ extern int32_t tsMaxNumOfDistinctResults; extern int32_t tsCompatibleModel; extern bool tsPrintAuth; extern int64_t tsTickPerMin[3]; +extern int64_t tsMaxKeyByPrecision[3]; extern int32_t tsCountAlwaysReturnValue; // queue & threads diff --git a/include/util/tdef.h b/include/util/tdef.h index 6e1fa87854..ff1b26c21a 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -26,7 +26,7 @@ extern "C" { #define TSKEY int64_t #define TSKEY_MIN INT64_MIN -#define TSKEY_MAX (INT64_MAX - 1) +#define TSKEY_MAX INT64_MAX #define TSKEY_INITIAL_VAL TSKEY_MIN #define TD_VER_MAX UINT64_MAX // TODO: use the real max version from query handle diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 1be77077b6..695ffbefef 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -141,6 +141,15 @@ bool tsDeployOnSnode = true; */ int64_t tsTickPerMin[] = {60000L, 60000000L, 60000000000L}; +/** + * @brief max key by precision + * approximately calculation: + * ms: 3600*1000*8765*1000 // 1970 + 1000 years + * us: 3600*1000000*8765*1000 // 1970 + 1000 years + * ns: 3600*1000000000*8765*292 // 1970 + 292 years + */ +int64_t tsMaxKeyByPrecision[] = {31556995200000L, 31556995200000000L, 9214646400000000000L}; + // lossy compress 6 char tsLossyColumns[32] = ""; // "float|double" means all float and double columns can be lossy compressed. set empty // can close lossy compress. diff --git a/source/dnode/vnode/src/tsdb/tsdbCommit.c b/source/dnode/vnode/src/tsdb/tsdbCommit.c index 874fe3c958..65a46331aa 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCommit.c +++ b/source/dnode/vnode/src/tsdb/tsdbCommit.c @@ -495,6 +495,10 @@ static int32_t tsdbCommitFileDataStart(SCommitter *pCommitter) { pCommitter->commitFid = tsdbKeyFid(pCommitter->nextKey, pCommitter->minutes, pCommitter->precision); tsdbFidKeyRange(pCommitter->commitFid, pCommitter->minutes, pCommitter->precision, &pCommitter->minKey, &pCommitter->maxKey); +#if 0 + ASSERT(pCommitter->minKey <= pCommitter->nextKey && pCommitter->maxKey >= pCommitter->nextKey); +#endif + pCommitter->nextKey = TSKEY_MAX; // Reader diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 52b74aea3f..37367bd838 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -505,8 +505,8 @@ int32_t tsdbKeyFid(TSKEY key, int32_t minutes, int8_t precision) { } void tsdbFidKeyRange(int32_t fid, int32_t minutes, int8_t precision, TSKEY *minKey, TSKEY *maxKey) { - *minKey = fid * minutes * tsTickPerMin[precision]; - *maxKey = *minKey + minutes * tsTickPerMin[precision] - 1; + *minKey = tsTickPerMin[precision] * fid * minutes; + *maxKey = *minKey + tsTickPerMin[precision] * minutes - 1; } int32_t tsdbFidLevel(int32_t fid, STsdbKeepCfg *pKeepCfg, int64_t now) { diff --git a/source/dnode/vnode/src/tsdb/tsdbWrite.c b/source/dnode/vnode/src/tsdb/tsdbWrite.c index f38802aee7..1935d688f0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbWrite.c +++ b/source/dnode/vnode/src/tsdb/tsdbWrite.c @@ -97,7 +97,7 @@ int tsdbScanAndConvertSubmitMsg(STsdb *pTsdb, SSubmitReq *pMsg) { STsdbKeepCfg *pCfg = &pTsdb->keepCfg; TSKEY now = taosGetTimestamp(pCfg->precision); TSKEY minKey = now - tsTickPerMin[pCfg->precision] * pCfg->keep2; - TSKEY maxKey = now + tsTickPerMin[pCfg->precision] * pCfg->days; + TSKEY maxKey = tsMaxKeyByPrecision[pCfg->precision]; terrno = TSDB_CODE_SUCCESS; // pMsg->length = htonl(pMsg->length); -- GitLab