diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 22fb5036e21ea2028e6400e39709e102e2902760..c0f6030fa6498897e7f359c2e106b75a75c60166 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 ecd4c0225be7b513d076ee7870ebe988333df2e8..0fd6bc8ae6f927ec38c91bd32dd0c796152fad41 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]); }