diff --git a/src/inc/tfs.h b/src/inc/tfs.h index e10c34d7a3..94ec143a8c 100644 --- a/src/inc/tfs.h +++ b/src/inc/tfs.h @@ -35,11 +35,6 @@ void tfsPrimaryPath(char *dst); int tfsCreateDir(char *dirname); int tfsRemoveDir(char *dirname); int tfsRename(char *oldpath, char *newpath); -void tfsIncFileAt(int level, int id); -void tfsDecFileAt(int level, int id); -int tfsLock(); -int tfsUnLock(); -bool tfsIsLocked(); // tfcntl.c typedef struct TFSFILE TFSFILE; diff --git a/src/tfs/inc/tdisk.h b/src/tfs/inc/tdisk.h deleted file mode 100644 index bfbf9dc474..0000000000 --- a/src/tfs/inc/tdisk.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TD_TDISK_H -#define TD_TDISK_H - -#include "tfslog.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - uint64_t size; - uint64_t free; - uint64_t nfiles; -} SDiskMeta; - -typedef struct { - int level; - int id; - char dir[TSDB_FILENAME_LEN]; - SDiskMeta dmeta; -} SDisk; - -SDisk *tdNewDisk(int level, int id, char *dir); -void tdFreeDisk(SDisk *pDisk); -int tdUpdateDiskInfo(SDisk *pDisk); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/tfs/inc/tfcntl.h b/src/tfs/inc/tfcntl.h deleted file mode 100644 index 7889603c62..0000000000 --- a/src/tfs/inc/tfcntl.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TD_TFCNTL_H -#define TD_TFCNTL_H - -#ifdef __cplusplus -extern "C" { -#endif - - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/tfs/inc/tfslog.h b/src/tfs/inc/tfsint.h similarity index 67% rename from src/tfs/inc/tfslog.h rename to src/tfs/inc/tfsint.h index 49576d36c8..745388f5d5 100644 --- a/src/tfs/inc/tfslog.h +++ b/src/tfs/inc/tfsint.h @@ -13,13 +13,14 @@ * along with this program. If not, see . */ -#ifndef TD_TFSLOG_H -#define TD_TFSLOG_H +#ifndef TD_TFSINT_H +#define TD_TFSINT_H #ifdef __cplusplus extern "C" { #endif +// 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__); }} #define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("TFS WARN ", 255, __VA_ARGS__); }} @@ -27,6 +28,32 @@ extern "C" { #define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("TFS ", cqDebugFlag, __VA_ARGS__); }} #define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("TFS ", cqDebugFlag, __VA_ARGS__); }} +// tdisk.c +typedef struct SDisk SDisk; + +SDisk *tfsNewDisk(int level, int id, char *dir); +void tfsFreeDisk(SDisk *pDisk); +int tfsUpdateDiskInfo(SDisk *pDisk); + +// ttier.c +typedef struct STier STier; + +#define DISK_AT_TIER(pTier, id) ((pTier)->disks[id]) + +void tfsInitTier(STier *pTier, int level); +void tfsDestroyTier(STier *pTier); +SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg); +int tfsUpdateTierInfo(STier *pTier); + +// tfs.c +void tfsIncFileAt(int level, int id); +void tfsDecFileAt(int level, int id); +int tfsLock(); +int tfsUnLock(); +bool tfsIsLocked(); + +// tfcntl.c + #ifdef __cplusplus } #endif diff --git a/src/tfs/inc/tfstypes.h b/src/tfs/inc/tfstypes.h deleted file mode 100644 index 7889603c62..0000000000 --- a/src/tfs/inc/tfstypes.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TD_TFCNTL_H -#define TD_TFCNTL_H - -#ifdef __cplusplus -extern "C" { -#endif - - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/tfs/inc/ttier.h b/src/tfs/inc/ttier.h deleted file mode 100644 index b0932909bb..0000000000 --- a/src/tfs/inc/ttier.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TD_TTIER_H -#define TD_TTIER_H - -#include "tdisk.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define TSDB_MAX_DISK_PER_TIER 16 - -typedef struct { - int level; - int ndisk; - SDisk *disks[TSDB_MAX_DISK_PER_TIER]; -} STier; - -#define DISK_AT_TIER(pTier, id) ((pTier)->disks[id]) - -void tdInitTier(STier *pTier, int level); -void tdDestroyTier(STier *pTier); -SDisk *tdMountToTier(STier *pTier, SDiskCfg *pCfg); -int tdUpdateTierInfo(STier *pTier); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/tfs/src/tdisk.c b/src/tfs/src/tdisk.c index f8d7cf34dd..d5593de651 100644 --- a/src/tfs/src/tdisk.c +++ b/src/tfs/src/tdisk.c @@ -12,11 +12,26 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +#include "os.h" -#include "tdisk.h" #include "taoserror.h" +#include "tfsint.h" -SDisk *tdNewDisk(int level, int id, char *dir) { +typedef struct { + uint64_t size; + uint64_t free; + uint64_t nfiles; +} SDiskMeta; + +struct SDisk { + int level; + int id; + char dir[TSDB_FILENAME_LEN]; + SDiskMeta dmeta; +}; + +// PROTECTED ==================================== +SDisk *tfsNewDisk(int level, int id, char *dir) { SDisk *pDisk = (SDisk *)calloc(1, sizeof(*pDisk)); if (pDisk == NULL) { terrno = TSDB_CODE_FS_OUT_OF_MEMORY; @@ -30,13 +45,13 @@ SDisk *tdNewDisk(int level, int id, char *dir) { return pDisk; } -void tdFreeDisk(SDisk *pDisk) { +void tfsFreeDisk(SDisk *pDisk) { if (pDisk) { free(pDisk) } } -int tdUpdateDiskInfo(SDisk *pDisk) { +int tfsUpdateDiskInfo(SDisk *pDisk) { SysDiskSize dstat; if (taosGetDiskSize(pDisk->dir, &dstat) < 0) { fError("failed to get dir %s information since %s", pDisk->dir, strerror(errno)); diff --git a/src/tfs/src/tfcntl.c b/src/tfs/src/tfcntl.c index 0904e6027c..e15f49ba8f 100644 --- a/src/tfs/src/tfcntl.c +++ b/src/tfs/src/tfcntl.c @@ -33,6 +33,7 @@ struct TFSDIR { DIR * dir; }; +// PUBLIC ========================================== TFSDIR *tfsOpenDir(char *dir) { TFSDIR *tdir = (TFSDIR *)calloc(1, sizeof(*tdir)); if (tdir == NULL) { @@ -166,6 +167,7 @@ SDiskID tfsFileID(TFSFILE *pfile) { return did; } +// PRIVATE ============================================= static int tfsOpenDirImpl(TFSDIR *tdir) { char dirName[TSDB_FILENAME_LEN] = "\0"; diff --git a/src/tfs/src/tfs.c b/src/tfs/src/tfs.c index daceb67546..2d63371a40 100644 --- a/src/tfs/src/tfs.c +++ b/src/tfs/src/tfs.c @@ -17,17 +17,10 @@ #include "hash.h" #include "taoserror.h" -#include "tfs.h" -#include "tglobal.h" -#include "ttier.h" +#include "tfsint.h" #define TSDB_MAX_TIER 3 -typedef struct { - int level; - int id; -} SDiskID; - typedef struct { uint64_t tsize; uint64_t avail; @@ -48,6 +41,7 @@ static SFS *pfs = &tdFileSystem; #define TIER_AT(level) (pfs->tiers + (level)) #define DISK_AT(level, id) DISK_AT_TIER(TIER_AT(level), id) +// public: int tfsInit(SDiskCfg *pDiskCfg, int ndisk) { ASSERT(ndisk > 0); @@ -172,6 +166,7 @@ int tfsRename(char *oldpath, char *newpath) { return 0; } +// protected: void tfsIncFileAt(int level, int id) { ASSERT(tfsIsLocked()); DISK_AT(level, id)->dmeta.nfiles++; @@ -214,6 +209,7 @@ const char *tfsGetDiskName(int level, int id) { return DISK_AT(level, id)->dir; } +// private static int tfsMount(SDiskCfg *pCfg) { SDiskID did; diff --git a/src/tfs/src/ttier.c b/src/tfs/src/ttier.c index ec5c4088ef..d7f45d0331 100644 --- a/src/tfs/src/ttier.c +++ b/src/tfs/src/ttier.c @@ -12,24 +12,32 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +#include "os.h" -#include "ttier.h" -#include "tglobal.h" +#include "tfsint.h" #include "taoserror.h" -void tdInitTier(STier *pTier, int level) { +#define TSDB_MAX_DISK_PER_TIER 16 +struct STier { + int level; + int ndisk; + SDisk *disks[TSDB_MAX_DISK_PER_TIER]; +}; + +// PROTECTED ========================================== +void tfsInitTier(STier *pTier, int level) { pTier->level = level; } -void tdDestroyTier(STier *pTier) { +void tfsDestroyTier(STier *pTier) { for (int id = 0; id < TSDB_MAX_DISK_PER_TIER; id++) { - tdFreeDisk(DISK_AT_TIER(pTier, id)); + tfsFreeDisk(DISK_AT_TIER(pTier, id)); pTier->disks[id] = NULL; } pTier->ndisk = 0; } -SDisk *tdMountToTier(STier *pTier, SDiskCfg *pCfg) { +SDisk *tfsMountDiskToTier(STier *pTier, SDiskCfg *pCfg) { ASSERT(pTier->level == pCfg->level); int id = 0; @@ -52,19 +60,20 @@ SDisk *tdMountToTier(STier *pTier, SDiskCfg *pCfg) { id = pTier->ndisk; } - pTier->disks[id] = tdNewDisk(pCfg->level, id, pCfg->dir); - if (pTier->disks[id] == NULL) return -1; + DISK_AT_TIER(pTier, id) = tfsNewDisk(pCfg->level, id, pCfg->dir); + if (DISK_AT_TIER(pTier, id) == NULL) return -1; pTier->ndisk++; - fDebug("disk %s is mounted at level %d id %d", pCfg->dir, pCfg->level, id); + fDebug("disk %s is mounted to level %d id %d", pCfg->dir, pCfg->level, id); return id; } -int tdUpdateTierInfo(STier *pTier) { +int tfsUpdateTierInfo(STier *pTier) { for (int id = 0; id < pTier->ndisk; id++) { - if (tdUpdateDiskInfo(DISK_AT_TIER(pTier, id)) < 0) { - // TODO: deal with the error here + if (tfsUpdateDiskInfo(DISK_AT_TIER(pTier, id)) < 0) { + return -1; } } + return 0; } \ No newline at end of file