From e329a159b78f5a0f945303276ec8beaa1e122371 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 20 Nov 2020 08:27:18 +0000 Subject: [PATCH] refactor --- src/inc/tfs.h | 21 +- src/tfs/inc/tfcntl.h | 28 +++ src/tfs/inc/tfslog.h | 12 +- src/tfs/inc/tfstypes.h | 28 +++ src/tfs/src/tfcntl.c | 118 +++++++++++ src/tfs/src/tfs.c | 9 + src/tfs/src/ttier.c | 2 + src/tsdb/src/tsdbFile.c | 441 +++++++++++++++++++--------------------- 8 files changed, 411 insertions(+), 248 deletions(-) create mode 100644 src/tfs/inc/tfcntl.h create mode 100644 src/tfs/inc/tfstypes.h create mode 100644 src/tfs/src/tfcntl.c diff --git a/src/inc/tfs.h b/src/inc/tfs.h index edc7e37feb..fa1c5eb930 100644 --- a/src/inc/tfs.h +++ b/src/inc/tfs.h @@ -22,16 +22,7 @@ extern "C" { #endif -typedef struct { - int level; - int id; -} SDiskID; - -typedef struct { - SDiskID did; - char fname[TSDB_FILENAME_LEN]; -} STfsFile; - +// tfs.c int tfsInit(SDiskCfg *pDiskCfg, int ndisk); void tfsDestroy(); int tfsUpdateInfo(); @@ -40,6 +31,16 @@ int tfsCreateDir(char *dirname); int tfsRemoveDir(char *dirname); int tfsRename(char *oldpath, char *newpath); +// tfcntl.c +typedef struct TFSFILE TFSFILE; +typedef struct TFSDIR TFSDIR; + +TFSDIR * tfsOpenDir(char *dir); +void tfsCloseDir(TFSDIR *tdir); +const TFSFILE *tfsReadDir(TFSDIR *tdir); + +const char *tfsGetDiskName(int level, int id); + #ifdef __cplusplus } #endif diff --git a/src/tfs/inc/tfcntl.h b/src/tfs/inc/tfcntl.h new file mode 100644 index 0000000000..7889603c62 --- /dev/null +++ b/src/tfs/inc/tfcntl.h @@ -0,0 +1,28 @@ +/* + * 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/tfslog.h index 68c2111dc9..49576d36c8 100644 --- a/src/tfs/inc/tfslog.h +++ b/src/tfs/inc/tfslog.h @@ -20,12 +20,12 @@ extern "C" { #endif -#define fFatal(...) { if (fsDebugFlag & DEBUG_FATAL) { taosPrintLog("FS FATAL ", 255, __VA_ARGS__); }} -#define fError(...) { if (fsDebugFlag & DEBUG_ERROR) { taosPrintLog("FS ERROR ", 255, __VA_ARGS__); }} -#define fWarn(...) { if (fsDebugFlag & DEBUG_WARN) { taosPrintLog("FS WARN ", 255, __VA_ARGS__); }} -#define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("FS ", 255, __VA_ARGS__); }} -#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("FS ", cqDebugFlag, __VA_ARGS__); }} -#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("FS ", cqDebugFlag, __VA_ARGS__); }} +#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__); }} +#define fInfo(...) { if (fsDebugFlag & DEBUG_INFO) { taosPrintLog("TFS ", 255, __VA_ARGS__); }} +#define fDebug(...) { if (fsDebugFlag & DEBUG_DEBUG) { taosPrintLog("TFS ", cqDebugFlag, __VA_ARGS__); }} +#define fTrace(...) { if (fsDebugFlag & DEBUG_TRACE) { taosPrintLog("TFS ", cqDebugFlag, __VA_ARGS__); }} #ifdef __cplusplus } diff --git a/src/tfs/inc/tfstypes.h b/src/tfs/inc/tfstypes.h new file mode 100644 index 0000000000..7889603c62 --- /dev/null +++ b/src/tfs/inc/tfstypes.h @@ -0,0 +1,28 @@ +/* + * 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/src/tfcntl.c b/src/tfs/src/tfcntl.c new file mode 100644 index 0000000000..f373a8f9f6 --- /dev/null +++ b/src/tfs/src/tfcntl.c @@ -0,0 +1,118 @@ +/* + * 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 . + */ + +#include "os.h" +#include "taoserror.h" +#include "tdisk.h" +#include "tfs.h" + +struct TFSFILE { + int level; + int id; + char name[TSDB_FILENAME_LEN]; +}; + +struct TFSDIR { + int level; + int id; + char name[TSDB_FILENAME_LEN]; + TFSFILE tfsfile; + DIR * dir; +}; + +TFSDIR *tfsOpenDir(char *dir) { + TFSDIR *tdir = (TFSDIR *)calloc(1, sizeof(*tdir)); + if (tdir == NULL) { + terrno = TSDB_CODE_FS_OUT_OF_MEMORY; + return NULL; + } + + if (tfsOpenDirImpl(tdir) < 0) { + tfsCloseDir(tdir); + return NULL; + } + + return tdir; +} + +void tfsCloseDir(TFSDIR *tdir) { + if (tdir) { + if (tdir->dir != NULL) { + closedir(tdir->dir); + tdir->dir = NULL; + } + free(tdir); + } +} + +const TFSFILE *tfsReadDir(TFSDIR *tdir) { + if (tdir->dir == NULL) return NULL; + + while (true) { + struct dirent *dp = readdir(tdir->dir); + if (dp != NULL) { + tdir->tfsfile.level = tdir->level; + tdir->tfsfile.id = tdir->id; + snprintf(tdir->tfsfile.name, TSDB_FILENAME_LEN, "%s/%s", tdir->name, dp->d_name); + + return &(tdir->tfsfile); + } + + closedir(tdir->dir); + + // Move to next + if (tdir->id < tfsNDisksAt(tdir->level) - 1) { + tdir->id++; + } else { + tdir->level++; + tdir->id = 0; + } + + if (tfsOpenDirImpl(tdir) < 0) { + return NULL; + } + + if (tdir->dir == NULL) return NULL; + } +} + +static int tfsOpenDirImpl(TFSDIR *tdir) { + char dirName[TSDB_FILENAME_LEN] = "\0"; + + while (tdir->level < tfsMaxLevel()) { + while (tdir->id < tfsNDisksAt(tdir->level)) { + snprintf(dirName, TSDB_FILENAME_LEN, "%s/%s", tfsGetDiskDir(tdir->level, tdir->id), tdir->name); + + tdir->dir = opendir(dirName); + if (tdir->dir == NULL) { + if (errno == ENOENT) { + tdir->id++; + } else { + fError("failed to open dir %s since %s", dirName, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; + } + } else { + return 0; + } + } + + tdir->id = 0; + tdir->level++; + } + + ASSERT(tdir->dir == NULL); + return 0; +} \ No newline at end of file diff --git a/src/tfs/src/tfs.c b/src/tfs/src/tfs.c index fe2df03473..9cd3449080 100644 --- a/src/tfs/src/tfs.c +++ b/src/tfs/src/tfs.c @@ -23,6 +23,11 @@ #define TSDB_MAX_TIER 3 +typedef struct { + int level; + int id; +} SDiskID; + typedef struct { uint64_t tsize; uint64_t avail; @@ -166,6 +171,10 @@ int tfsRename(char *oldpath, char *newpath) { return 0; } +const char *tfsGetDiskName(int level, int id) { + return DISK_AT(level, id)->dir; +} + static int tfsMount(SDiskCfg *pCfg) { SDiskID did; diff --git a/src/tfs/src/ttier.c b/src/tfs/src/ttier.c index 876a281ceb..ec5c4088ef 100644 --- a/src/tfs/src/ttier.c +++ b/src/tfs/src/ttier.c @@ -56,6 +56,8 @@ SDisk *tdMountToTier(STier *pTier, SDiskCfg *pCfg) { if (pTier->disks[id] == NULL) return -1; pTier->ndisk++; + fDebug("disk %s is mounted at level %d id %d", pCfg->dir, pCfg->level, id); + return id; } diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 7b8efa9ec1..a33d9d73b2 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -16,22 +16,15 @@ #define TAOS_RANDOM_FILE_FAIL_TEST #include #include "os.h" -#include "tglobal.h" #include "talgo.h" #include "tchecksum.h" #include "tsdbMain.h" #include "tutil.h" +#include "tfs.h" -const char * tsdbFileSuffix[] = {".head", ".data", ".last", ".stat", ".h", ".d", ".l", ".s"}; -static void tsdbDestroyFile(SFile *pFile); -static int compFGroup(const void *arg1, const void *arg2); -static int keyFGroupCompFunc(const void *key, const void *fgroup); -static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk); -static SHashObj *tsdbGetAllFids(STsdbRepo *pRepo, char *dirName); -static int tsdbRestoreFileGroup(STsdbRepo *pRepo, SDisk *pDisk, int fid, SFileGroup *pFileGroup); -static int tsdbGetFidLevel(int fid, SFidGroup *pFidGroup); -static int tsdbCreateVnodeDataDir(char *baseDir, int vid); +const char *tsdbFileSuffix[] = {".head", ".data", ".last", ".stat", ".h", ".d", ".l", ".s"}; + // ---------------- INTERNAL FUNCTIONS ---------------- STsdbFileH *tsdbNewFileH(STsdbCfg *pCfg) { @@ -75,22 +68,6 @@ int tsdbOpenFileH(STsdbRepo *pRepo) { ASSERT(pRepo != NULL && pRepo->tsdbFileH != NULL); char dataDir[TSDB_FILENAME_LEN] = "\0"; - for (int level = 0; level < tsDnodeTier->nTiers; level++) { - STier *pTier = tsDnodeTier->tiers + level; - for (int did = 0; did < pTier->nDisks; did++) { - SDisk *pDisk = pTier->disks[did]; - - tdGetTsdbDataDir(pDisk->dir, REPO_ID(pRepo), dataDir); - - if (access(dataDir, F_OK) != 0) { - // Skip those disks without data - continue; - } - - tsdbLoadFilesFromDisk(pRepo, pDisk); - } - } - return 0; } @@ -521,254 +498,254 @@ static int keyFGroupCompFunc(const void *key, const void *fgroup) { } } -static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk) { - char tsdbDataDir[TSDB_FILENAME_LEN] = "\0"; - char tsdbRootDir[TSDB_FILENAME_LEN] = "\0"; - char fname[TSDB_FILENAME_LEN] = "\0"; - SHashObj * pFids = NULL; - SHashMutableIterator *pIter = NULL; - STsdbFileH * pFileH = pRepo->tsdbFileH; - SFileGroup fgroup = {0}; - STsdbCfg * pCfg = &(pRepo->config); - SFidGroup fidGroup = {0}; - int mfid = 0; +// static int tsdbLoadFilesFromDisk(STsdbRepo *pRepo, SDisk *pDisk) { +// char tsdbDataDir[TSDB_FILENAME_LEN] = "\0"; +// char tsdbRootDir[TSDB_FILENAME_LEN] = "\0"; +// char fname[TSDB_FILENAME_LEN] = "\0"; +// SHashObj * pFids = NULL; +// SHashMutableIterator *pIter = NULL; +// STsdbFileH * pFileH = pRepo->tsdbFileH; +// SFileGroup fgroup = {0}; +// STsdbCfg * pCfg = &(pRepo->config); +// SFidGroup fidGroup = {0}; +// int mfid = 0; - tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir); - tdGetTsdbDataDir(pDisk->dir, REPO_ID(pRepo), tsdbDataDir); +// tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir); +// tdGetTsdbDataDir(pDisk->dir, REPO_ID(pRepo), tsdbDataDir); - pFids = tsdbGetAllFids(pRepo, tsdbDataDir); - if (pFids == NULL) { - goto _err; - } +// pFids = tsdbGetAllFids(pRepo, tsdbDataDir); +// if (pFids == NULL) { +// goto _err; +// } - pIter = taosHashCreateIter(pFids); - if (pIter == NULL) { - goto _err; - } +// pIter = taosHashCreateIter(pFids); +// if (pIter == NULL) { +// goto _err; +// } - tsdbGetFidGroup(pCfg, &fidGroup); - mfid = fidGroup.minFid; +// tsdbGetFidGroup(pCfg, &fidGroup); +// mfid = fidGroup.minFid; - while (taosHashIterNext(pIter)) { - int32_t fid = *(int32_t *)taosHashIterGet(pIter); +// while (taosHashIterNext(pIter)) { +// int32_t fid = *(int32_t *)taosHashIterGet(pIter); - if (fid < mfid) { - for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { - tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, type, fname); - (void)remove(fname); - } +// if (fid < mfid) { +// for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { +// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, type, fname); +// (void)remove(fname); +// } - tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NHEAD, fname); - (void)remove(fname); +// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NHEAD, fname); +// (void)remove(fname); - tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NLAST, fname); - (void)remove(fname); +// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NLAST, fname); +// (void)remove(fname); - continue; - } +// continue; +// } - tsdbRestoreFileGroup(pRepo, pDisk, fid, &fgroup); - pFileH->pFGroup[pFileH->nFGroups++] = fgroup; - qsort((void *)(pFileH->pFGroup), pFileH->nFGroups, sizeof(fgroup), compFGroup); +// tsdbRestoreFileGroup(pRepo, pDisk, fid, &fgroup); +// pFileH->pFGroup[pFileH->nFGroups++] = fgroup; +// qsort((void *)(pFileH->pFGroup), pFileH->nFGroups, sizeof(fgroup), compFGroup); - // TODO - pDisk->dmeta.nfiles++; - } +// // TODO +// pDisk->dmeta.nfiles++; +// } - taosHashDestroyIter(pIter); - taosHashCleanup(pFids); - return 0; +// taosHashDestroyIter(pIter); +// taosHashCleanup(pFids); +// return 0; -_err: - taosHashDestroyIter(pIter); - taosHashCleanup(pFids); - return -1; -} +// _err: +// taosHashDestroyIter(pIter); +// taosHashCleanup(pFids); +// return -1; +// } -static int tsdbRestoreFileGroup(STsdbRepo *pRepo, SDisk *pDisk, int fid, SFileGroup *pFileGroup) { - char tsdbRootDir[TSDB_FILENAME_LEN] = "\0"; - char nheadF[TSDB_FILENAME_LEN] = "\0"; - char nlastF[TSDB_FILENAME_LEN] = "\0"; - bool newHeadExists = false; - bool newLastExists = false; +// static int tsdbRestoreFileGroup(STsdbRepo *pRepo, SDisk *pDisk, int fid, SFileGroup *pFileGroup) { +// char tsdbRootDir[TSDB_FILENAME_LEN] = "\0"; +// char nheadF[TSDB_FILENAME_LEN] = "\0"; +// char nlastF[TSDB_FILENAME_LEN] = "\0"; +// bool newHeadExists = false; +// bool newLastExists = false; - uint32_t version = 0; +// uint32_t version = 0; - terrno = TSDB_CODE_SUCCESS; +// terrno = TSDB_CODE_SUCCESS; - memset((void *)pFileGroup, 0, sizeof(*pFileGroup)); - pFileGroup->fileId = fid; - for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { - SFile *pFile = pFileGroup->files + type; - pFile->fd = -1; - } +// memset((void *)pFileGroup, 0, sizeof(*pFileGroup)); +// pFileGroup->fileId = fid; +// for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { +// SFile *pFile = pFileGroup->files + type; +// pFile->fd = -1; +// } - tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir); - for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { - SFile *pFile = pFileGroup->files + type; - tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_HEAD, pFile->fname); - if (access(pFile->fname, F_OK) != 0) { - memset(&(pFile->info), 0, sizeof(pFile->info)); - pFile->info.magic = TSDB_FILE_INIT_MAGIC; - pFileGroup->state = 1; - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - } - } +// tdGetTsdbRootDir(pDisk->dir, REPO_ID(pRepo), tsdbRootDir); +// for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { +// SFile *pFile = pFileGroup->files + type; +// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_HEAD, pFile->fname); +// if (access(pFile->fname, F_OK) != 0) { +// memset(&(pFile->info), 0, sizeof(pFile->info)); +// pFile->info.magic = TSDB_FILE_INIT_MAGIC; +// pFileGroup->state = 1; +// terrno = TSDB_CODE_TDB_FILE_CORRUPTED; +// } +// } - tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NHEAD, nheadF); - tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NLAST, nlastF); +// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NHEAD, nheadF); +// tsdbGetDataFileName(tsdbRootDir, REPO_ID(pRepo), fid, TSDB_FILE_TYPE_NLAST, nlastF); - if (access(nheadF, F_OK) == 0) { - newHeadExists = true; - } +// if (access(nheadF, F_OK) == 0) { +// newHeadExists = true; +// } - if (access(nlastF, F_OK) == 0) { - newLastExists = true; - } +// if (access(nlastF, F_OK) == 0) { +// newLastExists = true; +// } - if (newHeadExists) { - (void)remove(nheadF); - (void)remove(nlastF); - } else { - if (newLastExists) { - (void)rename(nlastF, pFileGroup->files[TSDB_FILE_TYPE_LAST].fname); - } - } +// if (newHeadExists) { +// (void)remove(nheadF); +// (void)remove(nlastF); +// } else { +// if (newLastExists) { +// (void)rename(nlastF, pFileGroup->files[TSDB_FILE_TYPE_LAST].fname); +// } +// } - if (terrno != TSDB_CODE_SUCCESS) { - return -1; - } +// if (terrno != TSDB_CODE_SUCCESS) { +// return -1; +// } - for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { - SFile *pFile = pFileGroup->files + type; - if (tsdbOpenFile(pFile, O_RDONLY) < 0) { - memset(&(pFile->info), 0, sizeof(pFile->info)); - pFile->info.magic = TSDB_FILE_INIT_MAGIC; - pFileGroup->state = 1; - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - continue; - } +// for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) { +// SFile *pFile = pFileGroup->files + type; +// if (tsdbOpenFile(pFile, O_RDONLY) < 0) { +// memset(&(pFile->info), 0, sizeof(pFile->info)); +// pFile->info.magic = TSDB_FILE_INIT_MAGIC; +// pFileGroup->state = 1; +// terrno = TSDB_CODE_TDB_FILE_CORRUPTED; +// continue; +// } - if (tsdbLoadFileHeader(pFile, &version) < 0) { - memset(&(pFile->info), 0, sizeof(pFile->info)); - pFile->info.magic = TSDB_FILE_INIT_MAGIC; - pFileGroup->state = 1; - terrno = TSDB_CODE_TDB_FILE_CORRUPTED; - tsdbCloseFile(pFile); - continue; - } +// if (tsdbLoadFileHeader(pFile, &version) < 0) { +// memset(&(pFile->info), 0, sizeof(pFile->info)); +// pFile->info.magic = TSDB_FILE_INIT_MAGIC; +// pFileGroup->state = 1; +// terrno = TSDB_CODE_TDB_FILE_CORRUPTED; +// tsdbCloseFile(pFile); +// continue; +// } - if (version != TSDB_FILE_VERSION) { - tsdbError("vgId:%d file %s version %u is not the same as program version %u which may cause problem", - REPO_ID(pRepo), pFile->fname, version, TSDB_FILE_VERSION); - } +// if (version != TSDB_FILE_VERSION) { +// tsdbError("vgId:%d file %s version %u is not the same as program version %u which may cause problem", +// REPO_ID(pRepo), pFile->fname, version, TSDB_FILE_VERSION); +// } - tsdbCloseFile(pFile); - } +// tsdbCloseFile(pFile); +// } - if (terrno != TSDB_CODE_SUCCESS) { - return -1; - } else { - return 0; - } -} +// if (terrno != TSDB_CODE_SUCCESS) { +// return -1; +// } else { +// return 0; +// } +// } -static SHashObj *tsdbGetAllFids(STsdbRepo *pRepo, char *dirName) { - DIR * dir = NULL; - regex_t regex = {0}; - int code = 0; - int32_t vid, fid; - SHashObj *pHash = NULL; +// static SHashObj *tsdbGetAllFids(STsdbRepo *pRepo, char *dirName) { +// DIR * dir = NULL; +// regex_t regex = {0}; +// int code = 0; +// int32_t vid, fid; +// SHashObj *pHash = NULL; - code = regcomp(®ex, "^v[0-9]+f[0-9]+\\.(head|data|last|h|d|l)$", REG_EXTENDED); - if (code != 0) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - goto _err; - } +// code = regcomp(®ex, "^v[0-9]+f[0-9]+\\.(head|data|last|h|d|l)$", REG_EXTENDED); +// if (code != 0) { +// terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; +// goto _err; +// } - dir = opendir(dirName); - if (dir == NULL) { - tsdbError("vgId:%d failed to open directory %s since %s", REPO_ID(pRepo), dirName, strerror(errno)); - terrno = TAOS_SYSTEM_ERROR(errno); - goto _err; - } +// dir = opendir(dirName); +// if (dir == NULL) { +// tsdbError("vgId:%d failed to open directory %s since %s", REPO_ID(pRepo), dirName, strerror(errno)); +// terrno = TAOS_SYSTEM_ERROR(errno); +// goto _err; +// } - pHash = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); - if (pHash == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - goto _err; - } +// pHash = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); +// if (pHash == NULL) { +// terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; +// goto _err; +// } - struct dirent *dp = NULL; - while ((dp = readdir(dir)) != NULL) { - if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) continue; +// struct dirent *dp = NULL; +// while ((dp = readdir(dir)) != NULL) { +// if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) continue; - code = regexec(®ex, dp->d_name, 0, NULL, 0); - if (code == 0) { - sscanf(dp->d_name, "v%df%d", &vid, &fid); +// code = regexec(®ex, dp->d_name, 0, NULL, 0); +// if (code == 0) { +// sscanf(dp->d_name, "v%df%d", &vid, &fid); - if (vid != REPO_ID(pRepo)) { - tsdbError("vgId:%d invalid file %s exists, ignore it", REPO_ID(pRepo), dp->d_name); - continue; - } +// if (vid != REPO_ID(pRepo)) { +// tsdbError("vgId:%d invalid file %s exists, ignore it", REPO_ID(pRepo), dp->d_name); +// continue; +// } - taosHashPut(pHash, (void *)(&fid), sizeof(fid), (void *)(&fid), sizeof(fid)); - } else if (code == REG_NOMATCH) { - tsdbError("vgId:%d invalid file %s exists, ignore it", REPO_ID(pRepo), dp->d_name); - continue; - } else { - goto _err; - } - } +// taosHashPut(pHash, (void *)(&fid), sizeof(fid), (void *)(&fid), sizeof(fid)); +// } else if (code == REG_NOMATCH) { +// tsdbError("vgId:%d invalid file %s exists, ignore it", REPO_ID(pRepo), dp->d_name); +// continue; +// } else { +// goto _err; +// } +// } - closedir(dir); - regfree(®ex); - return pHash; +// closedir(dir); +// regfree(®ex); +// return pHash; -_err: - taosHashCleanup(pHash); - if (dir != NULL) closedir(dir); - regfree(®ex); - return NULL; -} +// _err: +// taosHashCleanup(pHash); +// if (dir != NULL) closedir(dir); +// regfree(®ex); +// return NULL; +// } -static int tsdbGetFidLevel(int fid, SFidGroup *pFidGroup) { - if (fid >= pFidGroup->maxFid) { - return 0; - } else if (fid >= pFidGroup->midFid && fid < pFidGroup->maxFid) { - return 1; - } else { - return 2; - } -} +// static int tsdbGetFidLevel(int fid, SFidGroup *pFidGroup) { +// if (fid >= pFidGroup->maxFid) { +// return 0; +// } else if (fid >= pFidGroup->midFid && fid < pFidGroup->maxFid) { +// return 1; +// } else { +// return 2; +// } +// } -static int tsdbCreateVnodeDataDir(char *baseDir, int vid) { - char dirName[TSDB_FILENAME_LEN] = "\0"; - char tsdbRootDir[TSDB_FILENAME_LEN] = "\0"; +// static int tsdbCreateVnodeDataDir(char *baseDir, int vid) { +// char dirName[TSDB_FILENAME_LEN] = "\0"; +// char tsdbRootDir[TSDB_FILENAME_LEN] = "\0"; - tdGetVnodeRootDir(baseDir, dirName); - if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } +// tdGetVnodeRootDir(baseDir, dirName); +// if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) { +// terrno = TAOS_SYSTEM_ERROR(errno); +// return -1; +// } - tdGetVnodeDir(baseDir, vid, dirName); - if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } +// tdGetVnodeDir(baseDir, vid, dirName); +// if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) { +// terrno = TAOS_SYSTEM_ERROR(errno); +// return -1; +// } - tdGetTsdbRootDir(baseDir, vid, tsdbRootDir); - if (taosMkDir(tsdbRootDir, 0755) < 0 && errno != EEXIST) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } +// tdGetTsdbRootDir(baseDir, vid, tsdbRootDir); +// if (taosMkDir(tsdbRootDir, 0755) < 0 && errno != EEXIST) { +// terrno = TAOS_SYSTEM_ERROR(errno); +// return -1; +// } - tdGetTsdbDataDir(baseDir, vid, dirName); - if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) { - terrno = TAOS_SYSTEM_ERROR(errno); - return -1; - } +// tdGetTsdbDataDir(baseDir, vid, dirName); +// if (taosMkDir(dirName, 0755) < 0 && errno != EEXIST) { +// terrno = TAOS_SYSTEM_ERROR(errno); +// return -1; +// } - return 0; -} \ No newline at end of file +// return 0; +// } \ No newline at end of file