From 115d3e4adbbd1fcccfe60dfd7575cb18c9eb9c2e Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Tue, 14 Sep 2021 16:05:01 +0800 Subject: [PATCH] code optimization --- src/tsdb/inc/tsdbFS.h | 1 + src/tsdb/src/tsdbCommit.c | 4 ++-- src/tsdb/src/tsdbFS.c | 2 +- src/tsdb/src/tsdbFile.c | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/tsdb/inc/tsdbFS.h b/src/tsdb/inc/tsdbFS.h index 0ce9850b0d..2339fed52f 100644 --- a/src/tsdb/inc/tsdbFS.h +++ b/src/tsdb/inc/tsdbFS.h @@ -27,6 +27,7 @@ typedef enum { } ETsdbFsVer; #define TSDB_FVER_TYPE uint32_t +#define TSDB_LATEST_FVER TSDB_FS_VER_1 static FORCE_INLINE uint32_t tsdbGetDFSVersion(TSDB_FILE_T fType) { // latest version for DFile switch (fType) { diff --git a/src/tsdb/src/tsdbCommit.c b/src/tsdb/src/tsdbCommit.c index ad8757f006..e3839f9638 100644 --- a/src/tsdb/src/tsdbCommit.c +++ b/src/tsdb/src/tsdbCommit.c @@ -1600,7 +1600,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid SDFile *pRDataf = TSDB_READ_DATA_FILE(&(pCommith->readh)); SDFile *pWDataf = TSDB_COMMIT_DATA_FILE(pCommith); tsdbInitDFileEx(pWDataf, pRDataf); - if (tsdbOpenDFile(pWDataf, O_RDWR) < 0) { + if (tsdbOpenDFile(pWDataf, O_WRONLY) < 0) { tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWDataf), tstrerror(terrno)); @@ -1620,7 +1620,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid tsdbInitDFileEx(pWLastf, pRLastf); pCommith->isLFileSame = true; - if (tsdbOpenDFile(pWLastf, O_RDWR) < 0) { + if (tsdbOpenDFile(pWLastf, O_WRONLY) < 0) { tsdbError("vgId:%d failed to open file %s to commit since %s", REPO_ID(pRepo), TSDB_FILE_FULL_NAME(pWLastf), tstrerror(terrno)); diff --git a/src/tsdb/src/tsdbFS.c b/src/tsdb/src/tsdbFS.c index 60c73e2d27..96a0349e9d 100644 --- a/src/tsdb/src/tsdbFS.c +++ b/src/tsdb/src/tsdbFS.c @@ -1207,7 +1207,7 @@ static int tsdbRestoreDFileSet(STsdbRepo *pRepo) { TSDB_FSET_SET_INIT(&fset); // Loop to recover ONE fset - for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX - 1; ftype++) { + for (TSDB_FILE_T ftype = 0; ftype < TSDB_FILE_MAX; ftype++) { SDFile *pDFile = TSDB_DFILE_IN_SET(&fset, ftype); if (index >= taosArrayGetSize(fArray)) { diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 20d521e32e..9924a640b0 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -341,7 +341,7 @@ static int tsdbEncodeSDFileEx(void **buf, SDFile *pDFile) { static void *tsdbDecodeSDFileEx(void *buf, SDFile *pDFile) { char *aname; - + // The sync module would send DFileSet with latest verion. buf = tsdbDecodeDFInfo(buf, &(pDFile->info), tsdbGetSFSVersion()); buf = taosDecodeString(buf, &aname); strncpy(TSDB_FILE_FULL_NAME(pDFile), aname, TSDB_FILENAME_LEN); @@ -430,7 +430,7 @@ int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo) { } void *pBuf = buf; - pBuf = tsdbDecodeDFInfo(pBuf, pInfo, TSDB_FS_VER_1); + pBuf = tsdbDecodeDFInfo(pBuf, pInfo, TSDB_LATEST_FVER); return 0; } -- GitLab