From dc5d4d5285fb365bfc7d9ba1af89d96b6a6ad0d5 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Wed, 13 Oct 2021 09:50:39 +0800 Subject: [PATCH] code optimization --- src/tsdb/inc/tsdbFile.h | 16 +++++----------- src/tsdb/src/tsdbCommit.c | 2 +- src/tsdb/src/tsdbCompact.c | 2 +- src/tsdb/src/tsdbFS.c | 8 ++++---- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/tsdb/inc/tsdbFile.h b/src/tsdb/inc/tsdbFile.h index fcd435728d..776b24870b 100644 --- a/src/tsdb/inc/tsdbFile.h +++ b/src/tsdb/inc/tsdbFile.h @@ -325,11 +325,11 @@ static FORCE_INLINE uint8_t tsdbGetNFiles(SDFileSet* pSet) { #define TSDB_DFILE_IN_SET(s, t) ((s)->files + (t)) #define TSDB_FSET_LEVEL(s) TSDB_FILE_LEVEL(TSDB_DFILE_IN_SET(s, 0)) #define TSDB_FSET_ID(s) TSDB_FILE_ID(TSDB_DFILE_IN_SET(s, 0)) -#define TSDB_FSET_SET_CLOSED(s) \ - do { \ - for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < tsdbGetNFiles(s); ftype++) { \ - TSDB_FILE_SET_CLOSED(TSDB_DFILE_IN_SET(s, ftype)); \ - } \ +#define TSDB_FSET_SET_CLOSED(s) \ + do { \ + for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ + TSDB_FILE_SET_CLOSED(TSDB_DFILE_IN_SET(s, ftype)); \ + } \ } while (0); #define TSDB_FSET_FSYNC(s) \ do { \ @@ -337,12 +337,6 @@ static FORCE_INLINE uint8_t tsdbGetNFiles(SDFileSet* pSet) { TSDB_FILE_FSYNC(TSDB_DFILE_IN_SET(s, ftype)); \ } \ } while (0); -#define TSDB_FSET_SET_INIT(s) \ - do { \ - for (TSDB_FILE_T ftype = TSDB_FILE_HEAD; ftype < TSDB_FILE_MAX; ftype++) { \ - TSDB_FILE_SET_CLOSED(TSDB_DFILE_IN_SET(s, ftype)); \ - } \ - } while (0); void tsdbInitDFileSet(SDFileSet* pSet, SDiskID did, int vid, int fid, uint32_t ver, uint8_t fsetVer); void tsdbInitDFileSetEx(SDFileSet* pSet, SDFileSet* pOSet); diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index 27945ca66d..539713d4fa 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -844,7 +844,7 @@ static int tsdbInitCommitH(SCommitH *pCommith, STsdbRepo *pRepo) { memset(pCommith, 0, sizeof(*pCommith)); tsdbGetRtnSnap(pRepo, &(pCommith->rtn)); - TSDB_FSET_SET_INIT(TSDB_COMMIT_WRITE_FSET(pCommith)); + TSDB_FSET_SET_CLOSED(TSDB_COMMIT_WRITE_FSET(pCommith)); // Init read handle if (tsdbInitReadH(&(pCommith->readh), pRepo) < 0) { diff --git a/src/tsdb/src/tsdbCompact.c b/src/tsdb/src/tsdbCompact.c index fbd5622c13..4722b0e420 100644 --- a/src/tsdb/src/tsdbCompact.c +++ b/src/tsdb/src/tsdbCompact.c @@ -274,7 +274,7 @@ static int tsdbCompactMeta(STsdbRepo *pRepo) { memset(pComph, 0, sizeof(*pComph)); - TSDB_FSET_SET_INIT(TSDB_COMPACT_WSET(pComph)); + TSDB_FSET_SET_CLOSED(TSDB_COMPACT_WSET(pComph)); tsdbGetRtnSnap(pRepo, &(pComph->rtn)); tsdbFSIterInit(&(pComph->fsIter), REPO_FS(pRepo), TSDB_FS_ITER_FORWARD); diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index 1edf216448..a559ddb0d1 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -1200,7 +1200,7 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { SDFileSet fset = {0}; - TSDB_FSET_SET_INIT(&fset); + TSDB_FSET_SET_CLOSED(&fset); // Loop to recover ONE fset for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { @@ -1355,7 +1355,7 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { if (index == 0) { memset(&fset, 0, sizeof(SDFileSet)); - TSDB_FSET_SET_INIT(&fset); + TSDB_FSET_SET_CLOSED(&fset); nDFiles = 1; fset.fid = tfid; pDFile->f = *pf; @@ -1377,7 +1377,7 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { } else { // next FSet memset(&fset, 0, sizeof(SDFileSet)); - TSDB_FSET_SET_INIT(&fset); + TSDB_FSET_SET_CLOSED(&fset); nDFiles = 1; fset.fid = tfid; pDFile->f = *pf; @@ -1437,7 +1437,7 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { // next FSet memset(&fset, 0, sizeof(SDFileSet)); - TSDB_FSET_SET_INIT(&fset); + TSDB_FSET_SET_CLOSED(&fset); nDFiles = 1; fset.fid = tfid; pDFile->f = *pf; -- GitLab