diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index b04b0be9bad1b7cac44227a0ade32ed77175f0ea..2b6dc66e2db779083047bdb0c2089096b249c6d6 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -787,6 +787,7 @@ static int tsdbRestoreInfo(STsdbRepo *pRepo) { tsdbInitFileGroupIter(pFileH, &iter, TSDB_ORDER_DESC); while ((pFGroup = tsdbGetFileGroupNext(&iter)) != NULL) { if (tsdbSetAndOpenHelperFile(&rhelper, pFGroup) < 0) goto _err; + if (tsdbLoadCompIdx(&rhelper, NULL) < 0) goto _err; for (int i = 1; i < pMeta->maxTables; i++) { STable *pTable = pMeta->tables[i]; if (pTable == NULL) continue; diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 506f3c11c104bed4a84641f7d95538a62bdbfec7..0cb032a73058a8d321dd58e82731800241a05327 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -603,6 +603,11 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe goto _err; } + if (tsdbLoadCompIdx(pHelper, NULL) < 0) { + tsdbError("vgId:%d failed to load SCompIdx part since %s", REPO_ID(pRepo), tstrerror(terrno)); + goto _err; + } + // Loop to commit data in each table for (int tid = 1; tid < pMem->maxTables; tid++) { SCommitIter *pIter = iters + tid; diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 8d3908666ed0cd9a517fabec3b7e7ea20a0885c7..b25e5ac432979250ddf65ee30b25f95deaf19e5e 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -118,12 +118,12 @@ int tsdbSetAndOpenHelperFile(SRWHelper *pHelper, SFileGroup *pGroup) { // Open the files #ifdef TSDB_IDX - if (tsdbOpenFile(helperIdxF(pHelper), O_RDONLY) < 0) goto _err; + if (tsdbOpenFile(helperIdxF(pHelper), O_RDONLY) < 0) return -1; #endif - if (tsdbOpenFile(helperHeadF(pHelper), O_RDONLY) < 0) goto _err; + if (tsdbOpenFile(helperHeadF(pHelper), O_RDONLY) < 0) return -1; if (helperType(pHelper) == TSDB_WRITE_HELPER) { - if (tsdbOpenFile(helperDataF(pHelper), O_RDWR) < 0) goto _err; - if (tsdbOpenFile(helperLastF(pHelper), O_RDWR) < 0) goto _err; + if (tsdbOpenFile(helperDataF(pHelper), O_RDWR) < 0) return -1; + if (tsdbOpenFile(helperLastF(pHelper), O_RDWR) < 0) return -1; #ifdef TSDB_IDX // Create and open .i file @@ -144,23 +144,20 @@ int tsdbSetAndOpenHelperFile(SRWHelper *pHelper, SFileGroup *pGroup) { // Create and open .l file if should if (tsdbShouldCreateNewLast(pHelper)) { pFile = helperNewLastF(pHelper); - if (tsdbOpenFile(pFile, O_WRONLY | O_CREAT) < 0) goto _err; + if (tsdbOpenFile(pFile, O_WRONLY | O_CREAT) < 0) return -1; pFile->info.size = TSDB_FILE_HEAD_SIZE; pFile->info.magic = TSDB_FILE_INIT_MAGIC; pFile->info.len = 0; if (tsdbUpdateFileHeader(pFile, 0) < 0) return -1; } } else { - if (tsdbOpenFile(helperDataF(pHelper), O_RDONLY) < 0) goto _err; - if (tsdbOpenFile(helperLastF(pHelper), O_RDONLY) < 0) goto _err; + if (tsdbOpenFile(helperDataF(pHelper), O_RDONLY) < 0) return -1; + if (tsdbOpenFile(helperLastF(pHelper), O_RDONLY) < 0) return -1; } helperSetState(pHelper, TSDB_HELPER_FILE_SET_AND_OPEN); - return tsdbLoadCompIdx(pHelper, NULL); - -_err: - return -1; + return 0; } int tsdbCloseHelperFile(SRWHelper *pHelper, bool hasError) { diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 0e3a657fde547f186623734e9dcf24b9087e9f27..3a89ead4a891336936556de7a9ffcfe5d746a6af 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -558,11 +558,12 @@ static int32_t getFileCompInfo(STsdbQueryHandle* pQueryHandle, int32_t* numOfBlo SFileGroup* fileGroup = pQueryHandle->pFileGroup; assert(fileGroup->files[TSDB_FILE_TYPE_HEAD].fname > 0); - int32_t code = tsdbSetAndOpenHelperFile(&pQueryHandle->rhelper, fileGroup); + if (tsdbSetAndOpenHelperFile(&pQueryHandle->rhelper, fileGroup) < 0) { + return terrno; + } - //open file failed, return error code to client - if (code != TSDB_CODE_SUCCESS) { - return code; + if (tsdbLoadCompIdx(&pQueryHandle->rhelper, NULL) < 0) { + return terrno; } // load all the comp offset value for all tables in this file