From 83f9c36845bb2482f5cbe2a3646c5e890a3b9f44 Mon Sep 17 00:00:00 2001 From: hzcheng Date: Thu, 30 Apr 2020 22:53:15 +0800 Subject: [PATCH] TD-166 --- src/tsdb/src/tsdbMain.c | 19 +++++++++++-------- src/tsdb/src/tsdbMeta.c | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 22fb5036e2..c0f6030fa6 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -158,7 +158,7 @@ static int tsdbRestoreInfo(STsdbRepo *pRepo) { tsdbInitFileGroupIter(pFileH, &iter, TSDB_ORDER_ASC); while ((pFGroup = tsdbGetFileGroupNext(&iter)) != NULL) { if (tsdbSetAndOpenHelperFile(&rhelper, pFGroup) < 0) goto _err; - for (int i = 0; i < pRepo->config.maxTables; i++) { + for (int i = 1; i < pRepo->config.maxTables; i++) { STable * pTable = pMeta->tables[i]; SCompIdx *pIdx = &rhelper.pCompIdx[i]; @@ -260,7 +260,7 @@ int32_t tsdbCloseRepo(TsdbRepoT *repo) { } pRepo->commit = 1; // Loop to move pData to iData - for (int i = 0; i < pRepo->config.maxTables; i++) { + for (int i = 1; i < pRepo->config.maxTables; i++) { STable *pTable = pRepo->tsdbMeta->tables[i]; if (pTable != NULL && pTable->mem != NULL) { pTable->imem = pTable->mem; @@ -313,7 +313,7 @@ int32_t tsdbTriggerCommit(TsdbRepoT *repo) { } pRepo->commit = 1; // Loop to move pData to iData - for (int i = 0; i < pRepo->config.maxTables; i++) { + for (int i = 1; i < pRepo->config.maxTables; i++) { STable *pTable = pRepo->tsdbMeta->tables[i]; if (pTable != NULL && pTable->mem != NULL) { pTable->imem = pTable->mem; @@ -611,6 +611,10 @@ static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg) { if (pCfg->maxTables < TSDB_MIN_TABLES || pCfg->maxTables > TSDB_MAX_TABLES) return -1; } + // Since tableId starts from 1, we increase maxTables by 1 + // TODO: take a fancier way to do this + pCfg->maxTables++; + // Check daysPerFile if (pCfg->daysPerFile == -1) { pCfg->daysPerFile = TSDB_DEFAULT_DAYS_PER_FILE; @@ -833,7 +837,7 @@ static int tsdbReadRowsFromCache(SSkipListIterator *pIter, TSKEY maxKey, int max static void tsdbDestroyTableIters(SSkipListIterator **iters, int maxTables) { if (iters == NULL) return; - for (int tid = 0; tid < maxTables; tid++) { + for (int tid = 1; tid < maxTables; tid++) { if (iters[tid] == NULL) continue; tSkipListDestroyIter(iters[tid]); } @@ -845,7 +849,7 @@ static SSkipListIterator **tsdbCreateTableIters(STsdbMeta *pMeta, int maxTables) SSkipListIterator **iters = (SSkipListIterator **)calloc(maxTables, sizeof(SSkipListIterator *)); if (iters == NULL) return NULL; - for (int tid = 0; tid < maxTables; tid++) { + for (int tid = 1; tid < maxTables; tid++) { STable *pTable = pMeta->tables[tid]; if (pTable == NULL || pTable->imem == NULL) continue; @@ -912,7 +916,7 @@ _exit: free(pCache->imem); pCache->imem = NULL; pRepo->commit = 0; - for (int i = 0; i < pCfg->maxTables; i++) { + for (int i = 1; i < pCfg->maxTables; i++) { STable *pTable = pMeta->tables[i]; if (pTable && pTable->imem) { tsdbFreeMemTable(pTable->imem); @@ -946,7 +950,7 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters if (tsdbSetAndOpenHelperFile(pHelper, pGroup) < 0) goto _err; // Loop to commit data in each table - for (int tid = 0; tid < pCfg->maxTables; tid++) { + for (int tid = 1; tid < pCfg->maxTables; tid++) { STable * pTable = pMeta->tables[tid]; if (pTable == NULL) continue; @@ -984,7 +988,6 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SSkipListIterator **iters // Write the SCompBlock part if (tsdbWriteCompInfo(pHelper) < 0) goto _err; - } if (tsdbWriteCompIdx(pHelper) < 0) goto _err; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index ecd4c0225b..0fd6bc8ae6 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -129,7 +129,7 @@ int tsdbRestoreTable(void *pHandle, void *cont, int contLen) { void tsdbOrgMeta(void *pHandle) { STsdbMeta *pMeta = (STsdbMeta *)pHandle; - for (int i = 0; i < pMeta->maxTables; i++) { + for (int i = 1; i < pMeta->maxTables; i++) { STable *pTable = pMeta->tables[i]; if (pTable != NULL && pTable->type == TSDB_CHILD_TABLE) { tsdbAddTableIntoIndex(pMeta, pTable); @@ -179,7 +179,7 @@ int32_t tsdbFreeMeta(STsdbMeta *pMeta) { tsdbCloseMetaFile(pMeta->mfh); - for (int i = 0; i < pMeta->maxTables; i++) { + for (int i = 1; i < pMeta->maxTables; i++) { if (pMeta->tables[i] != NULL) { tsdbFreeTable(pMeta->tables[i]); } -- GitLab