From 3e31cdbeae415c1311fb374dd5794f338411ee92 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 29 Jan 2021 15:17:18 +0800 Subject: [PATCH] refact --- src/tsdb/inc/tsdbFS.h | 1 + src/tsdb/src/tsdbFS.c | 38 ++++++++++++++++++-------------------- src/tsdb/src/tsdbFile.c | 1 + 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/tsdb/inc/tsdbFS.h b/src/tsdb/inc/tsdbFS.h index ef0e0800c5..d63aeb14ac 100644 --- a/src/tsdb/inc/tsdbFS.h +++ b/src/tsdb/inc/tsdbFS.h @@ -51,6 +51,7 @@ typedef struct { #define FS_CURRENT_STATUS(pfs) ((pfs)->cstatus) #define FS_NEW_STATUS(pfs) ((pfs)->nstatus) #define FS_IN_TXN(pfs) (pfs)->intxn +#define FS_VERSION(pfs) ((pfs)->cstatus->meta.version) #define FS_TXN_VERSION(pfs) ((pfs)->nstatus->meta.version) typedef struct { diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index a758aebfaa..9196fecfcd 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -159,27 +159,24 @@ static void tsdbResetFSStatus(SFSStatus *pStatus) { } static void tsdbSetStatusMFile(SFSStatus *pStatus, const SMFile *pMFile) { - ASSERT(pStatus->pmf == NULL && TSDB_FILE_CLOSED(pMFile)); + ASSERT(pStatus->pmf == NULL); pStatus->pmf = &(pStatus->mf); - *(pStatus->pmf) = *pMFile; + tsdbInitMFileEx(pStatus->pmf, pMFile); } static int tsdbAddDFileSetToStatus(SFSStatus *pStatus, const SDFileSet *pSet) { - ASSERT(TSDB_FILE_CLOSED(&(pSet->files[0]))); - ASSERT(TSDB_FILE_CLOSED(&(pSet->files[1]))); - ASSERT(TSDB_FILE_CLOSED(&(pSet->files[2]))); - if (taosArrayPush(pStatus->df, (void *)pSet) == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } + TSDB_FSET_SET_CLOSED(((SDFileSet *)taosArrayGetLast(pStatus->df))); + return 0; } // ================== STsdbFS -// TODO STsdbFS *tsdbNewFS(STsdbCfg *pCfg) { int keep = pCfg->keep; int days = pCfg->daysPerFile; @@ -221,7 +218,6 @@ STsdbFS *tsdbNewFS(STsdbCfg *pCfg) { return pfs; } -// TODO void *tsdbFreeFS(STsdbFS *pfs) { if (pfs) { pfs->nstatus = tsdbFreeFSStatus(pfs->nstatus); @@ -235,8 +231,8 @@ void *tsdbFreeFS(STsdbFS *pfs) { } int tsdbOpenFS(STsdbRepo *pRepo) { - STsdbFS * pfs = REPO_FS(pRepo); - char current[TSDB_FILENAME_LEN] = "\0"; + STsdbFS *pfs = REPO_FS(pRepo); + char current[TSDB_FILENAME_LEN] = "\0"; ASSERT(pfs != NULL); @@ -247,11 +243,16 @@ int tsdbOpenFS(STsdbRepo *pRepo) { tsdbError("vgId:%d failed to open FS since %s", REPO_ID(pRepo), tstrerror(terrno)); return -1; } - } else { - if (tsdbRestoreCurrent(pRepo) < 0) { - tsdbError("vgId:%d failed to restore current file since %s", REPO_ID(pRepo), tstrerror(terrno)); - return -1; - } + } else { + if (tsdbRestoreCurrent(pRepo) < 0) { + tsdbError("vgId:%d failed to restore current file since %s", REPO_ID(pRepo), tstrerror(terrno)); + return -1; + } + } + + if (tsdbScanAndTryFixFS(pRepo) < 0) { + tsdbError("vgId:%d failed to scan and fix FS since %s", REPO_ID(pRepo), tstrerror(terrno)); + return -1; } // Load meta cache if has meta file @@ -264,7 +265,7 @@ int tsdbOpenFS(STsdbRepo *pRepo) { } void tsdbCloseFS(STsdbRepo *pRepo) { - // TODO + // Do nothing } // Start a new transaction to modify the file system @@ -651,10 +652,6 @@ static int tsdbOpenFSFromCurrent(STsdbRepo *pRepo) { taosTZfree(buffer); close(fd); - if (tsdbScanAndTryFixFS(pRepo) < 0) { - return -1; - } - return 0; _err: @@ -965,6 +962,7 @@ static int tsdbRestoreMeta(STsdbRepo *pRepo) { if (tsdbLoadMFileHeader(pfs->cstatus->pmf, &(pfs->cstatus->pmf->info)) < 0) { tsdbError("vgId:%d failed to restore meta since %s", REPO_ID(pRepo), tstrerror(terrno)); + tsdbCloseMFile(pfs->cstatus->pmf); tfsClosedir(tdir); regfree(®ex); return -1; diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 433ef7c825..9a53bf4577 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -581,6 +581,7 @@ void *tsdbDecodeDFileSet(void *buf, SDFileSet *pSet) { int32_t fid; buf = taosDecodeFixedI32(buf, &(fid)); + pSet->state = 0; pSet->fid = fid; for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { buf = tsdbDecodeSDFile(buf, TSDB_DFILE_IN_SET(pSet, ftype)); -- GitLab