From 683494295e6d811c0a89949b483088df2cbb6556 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 23 Nov 2020 05:09:48 +0000 Subject: [PATCH] refactor --- src/inc/tfs.h | 2 +- src/tfs/inc/tfsint.h | 5 +++++ src/tfs/src/tdisk.c | 2 +- src/tfs/src/tfcntl.c | 8 ++++++-- src/tfs/src/tfs.c | 10 ++++++++-- src/tsdb/inc/tsdbMain.h | 4 ++-- src/tsdb/src/tsdbFile.c | 2 +- 7 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/inc/tfs.h b/src/inc/tfs.h index 8c57c09b83..e0a86fa062 100644 --- a/src/inc/tfs.h +++ b/src/inc/tfs.h @@ -50,7 +50,7 @@ const char *tfsRelName(TFSFILE *pfile); void tfsDirName(TFSFILE *pfile, char dest[]); void tfsBaseName(TFSFILE *pfile, char dest[]); -int tfsopen(TFSFILE *pfile); +int tfsopen(TFSFILE *pfile, int flags); int tfsclose(int fd); TFSFILE *tfsCreateFiles(int level, int nfile, ...); diff --git a/src/tfs/inc/tfsint.h b/src/tfs/inc/tfsint.h index 25b5467fef..1a92868a5d 100644 --- a/src/tfs/inc/tfsint.h +++ b/src/tfs/inc/tfsint.h @@ -16,10 +16,15 @@ #ifndef TD_TFSINT_H #define TD_TFSINT_H +#include "tlog.h" +#include "tglobal.h" + #ifdef __cplusplus extern "C" { #endif +extern int fsDebugFlag; + // For debug purpose #define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("TFS FATAL ", 255, __VA_ARGS__); }} #define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("TFS ERROR ", 255, __VA_ARGS__); }} diff --git a/src/tfs/src/tdisk.c b/src/tfs/src/tdisk.c index 5a611d45d9..b73f33caab 100644 --- a/src/tfs/src/tdisk.c +++ b/src/tfs/src/tdisk.c @@ -47,7 +47,7 @@ SDisk *tfsNewDisk(int level, int id, char *dir) { void tfsFreeDisk(SDisk *pDisk) { if (pDisk) { - free(pDisk) + free(pDisk); } } diff --git a/src/tfs/src/tfcntl.c b/src/tfs/src/tfcntl.c index ee85ed4dc8..3b3da8e275 100644 --- a/src/tfs/src/tfcntl.c +++ b/src/tfs/src/tfcntl.c @@ -15,8 +15,8 @@ #include "os.h" #include "taoserror.h" -#include "tdisk.h" #include "tfs.h" +#include "tfsint.h" struct TFSFILE { int level; @@ -33,6 +33,10 @@ struct TFSDIR { DIR * dir; }; +static int tfsOpenDirImpl(TFSDIR *tdir); +static void tfsInitFile(TFSFILE *pfile, int level, int id, char *rname); +static TFSFILE *tfsNewFile(int level, int id, char *rname); + // PUBLIC ========================================== TFSDIR *tfsOpenDir(char *dir) { TFSDIR *tdir = (TFSDIR *)calloc(1, sizeof(*tdir)); @@ -123,7 +127,7 @@ int tfsclose(int fd) { return -1; } - return 0 + return 0; } TFSFILE *tfsCreateFiles(int level, int nfile, ...) { diff --git a/src/tfs/src/tfs.c b/src/tfs/src/tfs.c index 41335646f4..f3abb26241 100644 --- a/src/tfs/src/tfs.c +++ b/src/tfs/src/tfs.c @@ -41,6 +41,12 @@ static SFS *pfs = &tdFileSystem; #define TIER_AT(level) (pfs->tiers + (level)) #define DISK_AT(level, id) DISK_AT_TIER(TIER_AT(level), id) +static int tfsMount(SDiskCfg *pCfg); +static int tfsCheckAndFormatCfg(SDiskCfg *pCfg); +static int tfsFormatDir(char *idir, char *odir); +static int tfsCheck(); +static tfsGetDiskByName(char *dirName); + // public: int tfsInit(SDiskCfg *pDiskCfg, int ndisk) { ASSERT(ndisk > 0); @@ -84,7 +90,7 @@ void tfsDestroy() { pthread_mutex_destroy(&(pfs->lock)); for (int level = 0; level < TSDB_MAX_TIER; level++) { - tdDestroyTier(TIER_AT(level)); + tfsDestroyTier(TIER_AT(level)); } } @@ -92,7 +98,7 @@ int tfsUpdateInfo() { tfsLock(); for (int level = 0; level < pfs->nlevel; level++) { - if (tdUpdateTierInfo(TIER_AT(level)) < 0) { + if (tfsUpdateTierInfo(TIER_AT(level)) < 0) { // TODO: deal with the error here } } diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index bc6b3a2517..7a2ad7760a 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -196,7 +196,7 @@ typedef struct { typedef struct { int fileId; - int state; // 0 for health, 1 for problem + int state; // 0 for health, 1 for problem SFile files[TSDB_FILE_TYPE_MAX]; } SFileGroup; @@ -518,7 +518,7 @@ void tsdbSeekFileGroupIter(SFileGroupIter* pIter, int fid); SFileGroup* tsdbGetFileGroupNext(SFileGroupIter* pIter); int tsdbOpenFile(SFile* pFile, int oflag); void tsdbCloseFile(SFile* pFile); -int tsdbCreateFile(SFile* pFile, STsdbRepo* pRepo, int fid, int type, SDisk* pDisk); +int tsdbCreateFile(SFile* pFile, STsdbRepo* pRepo, int fid, int type); SFileGroup* tsdbSearchFGroup(STsdbFileH* pFileH, int fid, int flags); void tsdbRemoveFilesBeyondRetention(STsdbRepo* pRepo, SFidGroup* pFidGroup); int tsdbUpdateFileHeader(SFile* pFile); diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 922d0d93ed..ba50a5526d 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -262,7 +262,7 @@ void tsdbCloseFile(SFile *pFile) { } } -int tsdbCreateFile(SFile *pFile, STsdbRepo *pRepo, int fid, int type, SDisk *pDisk) { +int tsdbCreateFile(SFile *pFile, STsdbRepo *pRepo, int fid, int type) { memset((void *)pFile, 0, sizeof(SFile)); pFile->fd = -1;