From c3920c4697e0bd6fca125fb97476576adcfedefc Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 9 Mar 2022 20:44:15 +0800 Subject: [PATCH] reset smsStatWindow --- source/dnode/vnode/src/inc/tsdbFile.h | 3 ++- source/dnode/vnode/src/tsdb/tsdbSma.c | 24 ++++++++++++++++++++++++ source/dnode/vnode/test/tsdbSmaTest.cpp | 3 ++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/inc/tsdbFile.h b/source/dnode/vnode/src/inc/tsdbFile.h index 1034ae015a..b58bfe77ab 100644 --- a/source/dnode/vnode/src/inc/tsdbFile.h +++ b/source/dnode/vnode/src/inc/tsdbFile.h @@ -58,8 +58,9 @@ typedef enum { TSDB_FILE_META, // meta TSDB_FILE_TSMA, // .tsma.${sma_index_name}, Time-range-wise SMA TSDB_FILE_RSMA, // .rsma.${sma_index_name}, Time-range-wise Rollup SMA -} TSDB_FILE_T; +} E_TSDB_FILE_T; +typedef int32_t TSDB_FILE_T; typedef enum { TSDB_FS_VER_0 = 0, TSDB_FS_VER_MAX, diff --git a/source/dnode/vnode/src/tsdb/tsdbSma.c b/source/dnode/vnode/src/tsdb/tsdbSma.c index c5f1261282..aa9fb7c7ed 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSma.c +++ b/source/dnode/vnode/src/tsdb/tsdbSma.c @@ -203,6 +203,23 @@ int32_t tsdbUpdateExpiredWindow(STsdb *pTsdb, char *msg) { return TSDB_CODE_SUCCESS; } +static int32_t tsdbResetExpiredWindow(STsdb *pTsdb, const char *indexName, void *timeWindow) { + SSmaStatItem *pItem = NULL; + + if (pTsdb->pSmaStat && pTsdb->pSmaStat->smaStatItems) { + pItem = (SSmaStatItem *)taosHashGet(pTsdb->pSmaStat->smaStatItems, indexName, strlen(indexName)); + } + + if (pItem != NULL) { + // TODO: reset time windows for the sma data blocks + while (true) { + TSKEY thisWindow = 0; + taosHashRemove(pItem->expiredWindows, &thisWindow, sizeof(thisWindow)); + } + } + return TSDB_CODE_SUCCESS; +} + /** * @brief Judge the tSma storage level * @@ -495,6 +512,9 @@ int32_t tsdbInsertTSmaDataImpl(STsdb *pTsdb, STSma *param, STSmaData *pData) { return terrno; } + // reset the SSmaStat + tsdbResetExpiredWindow(pTsdb, param->indexName, &pData->tsWindow); + return TSDB_CODE_SUCCESS; } @@ -542,6 +562,10 @@ int32_t tsdbInsertRSmaDataImpl(STsdb *pTsdb, SRSma *param, STSmaData *pData) { TASSERT(0); return TSDB_CODE_INVALID_PARA; } + + // reset the SSmaStat + tsdbResetExpiredWindow(pTsdb, param->tsma.indexName, &pData->tsWindow); + // Step 4: finish return TSDB_CODE_SUCCESS; } diff --git a/source/dnode/vnode/test/tsdbSmaTest.cpp b/source/dnode/vnode/test/tsdbSmaTest.cpp index f3a61bdfa4..bf3e67cdf5 100644 --- a/source/dnode/vnode/test/tsdbSmaTest.cpp +++ b/source/dnode/vnode/test/tsdbSmaTest.cpp @@ -20,6 +20,7 @@ #include #include +#include #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wwrite-strings" @@ -209,7 +210,7 @@ TEST(testCase, tSma_DB_Put_Get_Del_Test) { metaClose(pMeta); } -#if 0 +#if 1 TEST(testCase, tSmaInsertTest) { STSma tSma = {0}; STSmaData* pSmaData = NULL;