From 3041354e8d9d835e0b4cd07bab22ad2a20e11361 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 16 Jun 2020 09:33:19 +0000 Subject: [PATCH] TD-353 --- src/tsdb/inc/tsdbMain.h | 2 ++ src/tsdb/src/tsdbFile.c | 20 ++++++-------------- src/tsdb/src/tsdbMain.c | 13 +++++++++++++ 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index 1deb66c0a3..aaa84884a1 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -111,6 +111,7 @@ typedef struct { } SMemTable; // ------------------ tsdbFile.c +extern const char* tsdbFileSuffix[]; typedef enum { TSDB_FILE_TYPE_HEAD = 0, TSDB_FILE_TYPE_DATA, @@ -340,6 +341,7 @@ void tsdbFreeFileH(STsdbFileH* pFileH); #define IS_REPO_LOCKED(r) (r)->repoLocked char* tsdbGetMetaFileName(char* rootDir); +char* tsdbGetDataFileName(STsdbRepo* pRepo, int fid, int type); int tsdbLockRepo(STsdbRepo* pRepo); int tsdbUnlockRepo(STsdbRepo* pRepo); diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index f48c72dd8f..59bc2f53bb 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -99,7 +99,13 @@ int *tsdbOpenFileH(STsdbRepo *pRepo) { SFileGroup fileGroup = {0}; if (tsdbSearchFGroup(pFileH, fid, TD_EQ) != NULL) continue; + fileGroup.fileId = fid; for (int type = TSDB_FILE_TYPE_HEAD; type <= TSDB_FILE_TYPE_LAST; type++) { + fileGroup.headF.fname = tsdbGetDataFileName(pRepo, fid, type); + if (fileGroup.headF.fname == NULL) goto _err; + if (tsdbInitFile(fileGroup.headF)) + + } for (int type = TSDB_FILE_TYPE_NHEAD; type <= TSDB_FILE_TYPE_NLAST; type++) { @@ -238,20 +244,6 @@ SFileGroup *tsdbGetFileGroupNext(SFileGroupIter *pIter) { return ret; } -char *tsdbGetFileName(char *dataDir, int fileId, int type) { - int tlen = strlen(dataDir) + strlen(tsdbFileSuffix[type]) + 24; - - char *fname = (char *)malloc(tlen); - if (fname == NULL) { - terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; - return -1; - } - - sprintf(fname, "%s/v%df%d%s", dataDir, fileId, tsdbFileSuffix[type]); - - return 0; -} - int tsdbOpenFile(SFile *pFile, int oflag) { ASSERT(!TSDB_IS_FILE_OPENED(pFile)); diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index c459f766d9..4ecd87b250 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -296,6 +296,19 @@ char *tsdbGetMetaFileName(char *rootDir) { return fname; } +char *tsdbGetDataFileName(STsdbRepo *pRepo, int fid, int type) { + int tlen = strlen(pRepo->rootDir) + strlen(tsdbFileSuffix[type]) + 24; + + char *fname = malloc(tlen); + if (fname == NULL) { + terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; + return -1; + } + + sprintf(fname, "%s/%s/v%df%d.%s", pRepo->rootDir, TSDB_DATA_DIR_NAME, REPO_ID(pRepo), fid, tsdbFileSuffix[type]); + return fname; +} + int tsdbLockRepo(STsdbRepo *pRepo) { int code = pthread_mutex_lock(&pRepo->mutex); if (code != 0) {