diff --git a/src/tsdb/inc/tsdbReadImpl.h b/src/tsdb/inc/tsdbReadImpl.h index a06cc0f8710b955b4c4fa9a7a88262836e46bb36..35cc49f1644d7256c54ca51c9472a375e22b8e78 100644 --- a/src/tsdb/inc/tsdbReadImpl.h +++ b/src/tsdb/inc/tsdbReadImpl.h @@ -235,20 +235,4 @@ static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) { return 0; } -FORCE_INLINE int tsdbInitReadHBlkIdx(SReadH *pReadh, STsdbRepo *pRepo) { - ASSERT(pReadh != NULL && pRepo != NULL); - - memset((void *)pReadh, 0, sizeof(*pReadh)); - pReadh->pRepo = pRepo; - TSDB_FSET_SET_INIT(TSDB_READ_FSET(pReadh)); - - pReadh->aBlkIdx = taosArrayInit(1024, sizeof(SBlockIdx)); - if (pReadh->aBlkIdx == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - - return 0; -} - #endif /*_TD_TSDB_READ_IMPL_H_*/ diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index e749fdbdac407cea6f189937d2572cea0d0b78ef..ac7f6ea10b632909fc5a649b70f8ff821beed496 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -1322,7 +1322,8 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { // Loop to recover each file set SDFileSet fset = {0}; - bool isOneFSetFinish = false; + bool isOneFSetFinish = true; + int lastFType = -1; // one fileset ends when (1) the array ends or (2) encounter different fid for (size_t index = 0; index < fArraySize; ++index) { int tvid = -1, tfid = -1; @@ -1332,13 +1333,17 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { pf = taosArrayGet(fArray, index); tfsbasename(pf, bname); - tsdbParseDFilename(bname, &tvid, &tfid, &ttype, &tversion); + tsdbParseDFilename(bname, &tvid, &tfid, &ttype, &tversion); ASSERT(tvid == REPO_ID(pRepo)); SDFile *pDFile = TSDB_DFILE_IN_SET(&fset, ttype); - if (tfid < pRepo->rtn.minFid) { // skip the file expired continue; } + if ((isOneFSetFinish == false) && (lastFType == ttype)) { // only fetch the 1st file with same fid and type. + continue; + } + + lastFType = ttype; if (index == 0) { memset(&fset, 0, sizeof(SDFileSet)); @@ -1477,7 +1482,13 @@ static int tsdbComparTFILE(const void *arg1, const void *arg2) { } else if (ftype1 > ftype2) { return 1; } else { - return 0; + if (version1 < version2) { + return -1; + } else if (version1 > version2) { + return 1; + } else { + return 0; + } } } } diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 50d70804a444850fbf8e9935e37c92baf0e54afc..20d521e32e40bb4e957102ca0f60ac78ed67e104 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -454,7 +454,7 @@ static int tsdbScanAndTryFixDFile(STsdbRepo *pRepo, SDFile *pDFile) { } if (pDFile->info.size < dfstat.st_size) { - if (tsdbOpenDFile(&df, O_RDWR) < 0) { + if (tsdbOpenDFile(&df, O_WRONLY) < 0) { return -1; }