From bbf58d2d9d88c3c9beb59aa1bb955e8697f2a8c1 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 12 Jul 2023 12:49:32 +0800 Subject: [PATCH 1/6] enh: unify handling of vnode primary dir in vnodeCreate and metaOpen --- source/dnode/vnode/src/inc/vnd.h | 3 ++ source/dnode/vnode/src/meta/metaOpen.c | 26 ++++++++--------- source/dnode/vnode/src/vnd/vnodeOpen.c | 39 +++++++++----------------- 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index a67f246e73..c52bc29590 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -86,6 +86,9 @@ void vnodeBufPoolReset(SVBufPool* pPool); void vnodeBufPoolAddToFreeList(SVBufPool* pPool); int32_t vnodeBufPoolRecycle(SVBufPool* pPool); +// vnodeOpen.c +int32_t vnodeGetAbsDir(const char* relPath, STfs* pTfs, char* buf, size_t bufLen); + // vnodeQuery.c int32_t vnodeQueryOpen(SVnode* pVnode); void vnodeQueryPreClose(SVnode* pVnode); diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index 511cc8d6ec..b896b73e40 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -14,6 +14,7 @@ */ #include "meta.h" +#include "vnd.h" static int tbDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); static int skmDbKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2); @@ -34,30 +35,27 @@ static void metaCleanup(SMeta **ppMeta); int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) { SMeta *pMeta = NULL; int ret; - int slen; + int offset; + char path[TSDB_FILENAME_LEN] = {0}; *ppMeta = NULL; // create handle - if (pVnode->pTfs) { - slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_META_DIR) + 3; - } else { - slen = strlen(pVnode->path) + strlen(VNODE_META_DIR) + 2; - } - if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + slen)) == NULL) { + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, path, TSDB_FILENAME_LEN); + offset = strlen(path); + snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VNODE_META_DIR); + + if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + strlen(path) + 1)) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } metaInitLock(pMeta); + pMeta->path = (char *)&pMeta[1]; - if (pVnode->pTfs) { - sprintf(pMeta->path, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, - VNODE_META_DIR); - } else { - sprintf(pMeta->path, "%s%s%s", pVnode->path, TD_DIRSEP, VNODE_META_DIR); - } - taosRealPath(pMeta->path, NULL, slen); + strcpy(pMeta->path, path); + taosRealPath(pMeta->path, NULL, strlen(path) + 1); + pMeta->pVnode = pVnode; // create path if not created yet diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 8967e9dc62..648dadcade 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -15,6 +15,16 @@ #include "vnd.h" +int32_t vnodeGetAbsDir(const char *relPath, STfs *pTfs, char *buf, size_t bufLen) { + if (pTfs) { + snprintf(buf, bufLen - 1, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, relPath); + } else { + snprintf(buf, bufLen - 1, "%s", relPath); + } + buf[bufLen - 1] = '\0'; + return 0; +} + int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN] = {0}; @@ -26,17 +36,9 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { } // create vnode env - if (pTfs) { - if (tfsMkdirAt(pTfs, path, (SDiskID){0}) < 0) { - vError("vgId:%d, failed to create vnode since:%s", pCfg->vgId, tstrerror(terrno)); - return -1; - } - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path); - } else { - if (taosMkDir(path)) { - return TAOS_SYSTEM_ERROR(errno); - } - snprintf(dir, TSDB_FILENAME_LEN, "%s", path); + vnodeGetAbsDir(path, pTfs, dir, TSDB_FILENAME_LEN); + if (taosMkDir(dir)) { + return TAOS_SYSTEM_ERROR(errno); } if (pCfg) { @@ -63,11 +65,7 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, STfs *p char dir[TSDB_FILENAME_LEN] = {0}; int32_t ret = 0; - if (pTfs) { - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path); - } else { - snprintf(dir, TSDB_FILENAME_LEN, "%s", path); - } + vnodeGetAbsDir(path, pTfs, dir, TSDB_FILENAME_LEN); ret = vnodeLoadInfo(dir, &info); if (ret < 0) { @@ -185,15 +183,6 @@ int32_t vnodeRenameVgroupId(const char *srcPath, const char *dstPath, int32_t sr return ret; } -int32_t vnodeGetAbsDir(const char *relPath, STfs *pTfs, char *buf, size_t bufLen) { - if (pTfs) { - snprintf(buf, bufLen, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, relPath); - } else { - snprintf(buf, bufLen, "%s", relPath); - } - return 0; -} - int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnodeHashRangeReq *pReq, STfs *pTfs) { SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN] = {0}; From 4c3bf41178ba77806d3f8247c12e7b739415c720 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 12 Jul 2023 12:58:34 +0800 Subject: [PATCH 2/6] enh: unify handling of vnode primary dir for sma --- source/dnode/vnode/src/inc/sma.h | 14 +-- source/dnode/vnode/src/sma/smaFS.c | 41 ++++----- source/dnode/vnode/src/sma/smaRollup.c | 7 +- source/dnode/vnode/src/sma/smaSnapshot.c | 12 +-- source/dnode/vnode/src/sma/smaUtil.c | 108 ++++++++++------------- 5 files changed, 75 insertions(+), 107 deletions(-) diff --git a/source/dnode/vnode/src/inc/sma.h b/source/dnode/vnode/src/inc/sma.h index c3e8d7ef1d..07cce1fdf3 100644 --- a/source/dnode/vnode/src/inc/sma.h +++ b/source/dnode/vnode/src/inc/sma.h @@ -229,11 +229,11 @@ int32_t tdRSmaProcessCreateImpl(SSma *pSma, SRSmaParam *param, int64_t suid, con int32_t tdRSmaProcessExecImpl(SSma *pSma, ERsmaExecType type); int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash); int32_t tdRSmaProcessRestoreImpl(SSma *pSma, int8_t type, int64_t qtaskFileVer, int8_t rollback); -void tdRSmaQTaskInfoGetFileName(int32_t vgId, int64_t suid, int8_t level, int64_t version, char *outputName); -void tdRSmaQTaskInfoGetFullName(int32_t vgId, int64_t suid, int8_t level, int64_t version, const char *path, +void tdRSmaQTaskInfoGetFileName(SVnode *pVnode, int64_t suid, int8_t level, int64_t version, char *outputName); +void tdRSmaQTaskInfoGetFullName(SVnode *pVnode, int64_t suid, int8_t level, int64_t version, STfs *pTfs, char *outputName); -void tdRSmaQTaskInfoGetFullPath(int32_t vgId, int8_t level, const char *path, char *outputName); -void tdRSmaQTaskInfoGetFullPathEx(int32_t vgId, tb_uid_t suid, int8_t level, const char *path, char *outputName); +void tdRSmaQTaskInfoGetFullPath(SVnode *pVnode, int8_t level, STfs *pTfs, char *outputName); +void tdRSmaQTaskInfoGetFullPathEx(SVnode *pVnode, tb_uid_t suid, int8_t level, STfs *pTfs, char *outputName); static FORCE_INLINE void tdRefRSmaInfo(SSma *pSma, SRSmaInfo *pRSmaInfo) { int32_t ref = T_REF_INC(pRSmaInfo); @@ -244,9 +244,9 @@ static FORCE_INLINE void tdUnRefRSmaInfo(SSma *pSma, SRSmaInfo *pRSmaInfo) { smaTrace("vgId:%d, unref rsma info:%p, val:%d", SMA_VID(pSma), pRSmaInfo, ref); } -void tdRSmaGetFileName(int32_t vgId, const char *pdname, const char *dname, const char *fname, int64_t suid, - int8_t level, int64_t version, char *outputName); -void tdRSmaGetDirName(int32_t vgId, const char *pdname, const char *dname, bool endWithSep, char *outputName); +void tdRSmaGetFileName(SVnode *pVnode, STfs *pTfs, const char *fname, int64_t suid, int8_t level, int64_t version, + char *outputName); +void tdRSmaGetDirName(SVnode *pVnode, STfs *pTfs, bool endWithSep, char *outputName); #ifdef __cplusplus } diff --git a/source/dnode/vnode/src/sma/smaFS.c b/source/dnode/vnode/src/sma/smaFS.c index 1211ef9405..1742d983a6 100644 --- a/source/dnode/vnode/src/sma/smaFS.c +++ b/source/dnode/vnode/src/sma/smaFS.c @@ -14,6 +14,7 @@ */ #include "sma.h" +#include "vnd.h" // ================================================================================================= @@ -157,25 +158,15 @@ _exit: static void tdRSmaGetCurrentFName(SSma *pSma, char *current, char *current_t) { SVnode *pVnode = pSma->pVnode; - if (pVnode->pTfs) { - if (current) { - snprintf(current, TSDB_FILENAME_LEN - 1, "%s%svnode%svnode%d%srsma%sPRESENT", tfsGetPrimaryPath(pVnode->pTfs), - TD_DIRSEP, TD_DIRSEP, TD_VID(pVnode), TD_DIRSEP, TD_DIRSEP); - } - if (current_t) { - snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%svnode%svnode%d%srsma%sPRESENT.t", tfsGetPrimaryPath(pVnode->pTfs), - TD_DIRSEP, TD_DIRSEP, TD_VID(pVnode), TD_DIRSEP, TD_DIRSEP); - } - } else { -#if 0 - if (current) { - snprintf(current, TSDB_FILENAME_LEN - 1, "%s%sPRESENT", pTsdb->path, TD_DIRSEP); - } - if (current_t) { - snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%sPRESENT.t", pTsdb->path, TD_DIRSEP); - } -#endif - } + int32_t offset = 0; + + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, current, TSDB_FILENAME_LEN); + offset = strlen(current); + snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%srsma%sPRESENT", TD_DIRSEP, TD_DIRSEP); + + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); + offset = strlen(current_t); + snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%srsma%sPRESENT.t", TD_DIRSEP, TD_DIRSEP); } static int32_t tdRSmaLoadFSFromFile(const char *fname, SRSmaFS *pFS) { @@ -309,8 +300,7 @@ static int32_t tdRSmaFSApplyChange(SSma *pSma, SRSmaFS *pFSNew) { nRef = atomic_sub_fetch_32(&preTaskF->nRef, 1); if (nRef <= 0) { - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), preTaskF->suid, preTaskF->level, preTaskF->version, - tfsGetPrimaryPath(pVnode->pTfs), fname); + tdRSmaQTaskInfoGetFullName(pVnode, preTaskF->suid, preTaskF->level, preTaskF->version, pVnode->pTfs, fname); (void)taosRemoveFile(fname); taosArrayRemove(pFSOld->aQTaskInf, idx); } @@ -341,9 +331,9 @@ static int32_t tdRSmaFSScanAndTryFix(SSma *pSma) { SQTaskFile *pTaskF = (SQTaskFile *)taosArrayGet(pFS->aQTaskInf, i); // main.tdb ========= - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, pTaskF->level, pTaskF->version, - tfsGetPrimaryPath(pVnode->pTfs), fnameVer); - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, pTaskF->level, -1, tfsGetPrimaryPath(pVnode->pTfs), fname); + tdRSmaQTaskInfoGetFullName(pVnode, pTaskF->suid, pTaskF->level, pTaskF->version, + pVnode->pTfs, fnameVer); + tdRSmaQTaskInfoGetFullName(pVnode, pTaskF->suid, pTaskF->level, -1, pVnode->pTfs, fname); if (taosCheckExistFile(fnameVer)) { if (taosRenameFile(fnameVer, fname) < 0) { @@ -597,8 +587,7 @@ void tdRSmaFSUnRef(SSma *pSma, SRSmaFS *pFS) { nRef = atomic_sub_fetch_32(&pTaskF->nRef, 1); if (nRef == 0) { - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, pTaskF->level, pTaskF->version, - tfsGetPrimaryPath(pVnode->pTfs), fname); + tdRSmaQTaskInfoGetFullName(pVnode, pTaskF->suid, pTaskF->level, pTaskF->version, pVnode->pTfs, fname); if (taosRemoveFile(fname) < 0) { smaWarn("vgId:%d, failed to remove %s since %s", TD_VID(pVnode), fname, tstrerror(TAOS_SYSTEM_ERROR(errno))); } else { diff --git a/source/dnode/vnode/src/sma/smaRollup.c b/source/dnode/vnode/src/sma/smaRollup.c index d393f4b6bc..02f08d0ee3 100644 --- a/source/dnode/vnode/src/sma/smaRollup.c +++ b/source/dnode/vnode/src/sma/smaRollup.c @@ -260,7 +260,7 @@ static int32_t tdSetRSmaInfoItemParams(SSma *pSma, SRSmaParam *param, SRSmaStat void *pStreamState = NULL; // set the backend of stream state - tdRSmaQTaskInfoGetFullPathEx(TD_VID(pVnode), pRSmaInfo->suid, idx + 1, tfsGetPrimaryPath(pVnode->pTfs), taskInfDir); + tdRSmaQTaskInfoGetFullPathEx(pVnode, pRSmaInfo->suid, idx + 1, pVnode->pTfs, taskInfDir); if (!taosCheckExistFile(taskInfDir)) { char *s = taosStrdup(taskInfDir); if (taosMulMkDir(taosDirName(s)) != 0) { @@ -1258,9 +1258,8 @@ int32_t tdRSmaPersistExecImpl(SRSmaStat *pRSmaStat, SHashObj *pInfoHash) { pRSmaInfo->suid, i + 1); // qTaskInfo file - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pRSmaInfo->suid, i + 1, -1, tfsGetPrimaryPath(pVnode->pTfs), fname); - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pRSmaInfo->suid, i + 1, version, tfsGetPrimaryPath(pVnode->pTfs), - fnameVer); + tdRSmaQTaskInfoGetFullName(pVnode, pRSmaInfo->suid, i + 1, -1, pVnode->pTfs, fname); + tdRSmaQTaskInfoGetFullName(pVnode, pRSmaInfo->suid, i + 1, version, pVnode->pTfs, fnameVer); if (taosCheckExistFile(fnameVer)) { smaWarn("vgId:%d, rsma persist, duplicate file %s exist", TD_VID(pVnode), fnameVer); } diff --git a/source/dnode/vnode/src/sma/smaSnapshot.c b/source/dnode/vnode/src/sma/smaSnapshot.c index c00e96a066..5511ce006d 100644 --- a/source/dnode/vnode/src/sma/smaSnapshot.c +++ b/source/dnode/vnode/src/sma/smaSnapshot.c @@ -117,8 +117,7 @@ static int32_t rsmaSnapReadQTaskInfo(SRSmaSnapReader* pReader, uint8_t** ppBuf) continue; } - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), qTaskF->suid, qTaskF->level, version, tfsGetPrimaryPath(pVnode->pTfs), - fname); + tdRSmaQTaskInfoGetFullName(pVnode, qTaskF->suid, qTaskF->level, version, pVnode->pTfs, fname); if (!taosCheckExistFile(fname)) { smaError("vgId:%d, vnode snapshot rsma reader for qtaskinfo, table %" PRIi64 ", level %" PRIi8 ", version %" PRIi64 " failed since %s not exist", @@ -340,7 +339,6 @@ int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback) { SSmaEnv* pEnv = NULL; SRSmaStat* pStat = NULL; SRSmaSnapWriter* pWriter = *ppWriter; - const char* primaryPath = NULL; char fname[TSDB_FILENAME_LEN] = {0}; char fnameVer[TSDB_FILENAME_LEN] = {0}; TdFilePtr pOutFD = NULL; @@ -354,7 +352,6 @@ int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback) { pVnode = pSma->pVnode; pEnv = SMA_RSMA_ENV(pSma); pStat = (SRSmaStat*)SMA_ENV_STAT(pEnv); - primaryPath = tfsGetPrimaryPath(pVnode->pTfs); // rsma1/rsma2 for (int32_t i = 0; i < TSDB_RETENTION_L2; ++i) { @@ -375,8 +372,8 @@ int32_t rsmaSnapWriterClose(SRSmaSnapWriter** ppWriter, int8_t rollback) { for (int32_t i = 0; i < size; ++i) { SQTaskFile* pTaskF = TARRAY_GET_ELEM(pFS->aQTaskInf, i); if (pTaskF->version == pWriter->ever) { - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, pTaskF->level, pTaskF->version, primaryPath, fnameVer); - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pTaskF->suid, pTaskF->level, -1, primaryPath, fname); + tdRSmaQTaskInfoGetFullName(pVnode, pTaskF->suid, pTaskF->level, pTaskF->version, pVnode->pTfs, fnameVer); + tdRSmaQTaskInfoGetFullName(pVnode, pTaskF->suid, pTaskF->level, -1, pVnode->pTfs, fname); pInFD = taosOpenFile(fnameVer, TD_FILE_READ); if (pInFD == NULL) { @@ -486,8 +483,7 @@ static int32_t rsmaSnapWriteQTaskInfo(SRSmaSnapWriter* pWriter, uint8_t* pData, SQTaskFile qTaskFile = { .nRef = 1, .level = pHdr->flag, .suid = pHdr->index, .version = pWriter->ever, .size = pHdr->size}; - tdRSmaQTaskInfoGetFullName(TD_VID(pVnode), pHdr->index, pHdr->flag, qTaskFile.version, - tfsGetPrimaryPath(pVnode->pTfs), fname); + tdRSmaQTaskInfoGetFullName(pVnode, pHdr->index, pHdr->flag, qTaskFile.version, pVnode->pTfs, fname); fp = taosCreateFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (!fp) { diff --git a/source/dnode/vnode/src/sma/smaUtil.c b/source/dnode/vnode/src/sma/smaUtil.c index 7c538280e5..7f5f593e36 100644 --- a/source/dnode/vnode/src/sma/smaUtil.c +++ b/source/dnode/vnode/src/sma/smaUtil.c @@ -14,88 +14,72 @@ */ #include "sma.h" +#include "vnd.h" #define TD_QTASKINFO_FNAME_PREFIX "main.tdb" -void tdRSmaQTaskInfoGetFileName(int32_t vgId, int64_t suid, int8_t level, int64_t version, char *outputName) { - tdRSmaGetFileName(vgId, NULL, VNODE_RSMA_DIR, TD_QTASKINFO_FNAME_PREFIX, suid, level, version, outputName); +void tdRSmaQTaskInfoGetFileName(SVnode *pVnode, int64_t suid, int8_t level, int64_t version, char *outputName) { + tdRSmaGetFileName(pVnode, NULL, TD_QTASKINFO_FNAME_PREFIX, suid, level, version, outputName); } -void tdRSmaQTaskInfoGetFullName(int32_t vgId, int64_t suid, int8_t level, int64_t version, const char *path, +void tdRSmaQTaskInfoGetFullName(SVnode *pVnode, int64_t suid, int8_t level, int64_t version, STfs *pTfs, char *outputName) { - tdRSmaGetFileName(vgId, path, VNODE_RSMA_DIR, TD_QTASKINFO_FNAME_PREFIX, suid, level, version, outputName); + tdRSmaGetFileName(pVnode, pTfs, TD_QTASKINFO_FNAME_PREFIX, suid, level, version, outputName); } -void tdRSmaQTaskInfoGetFullPath(int32_t vgId, int8_t level, const char *path, char *outputName) { - tdRSmaGetDirName(vgId, path, VNODE_RSMA_DIR, true, outputName); +void tdRSmaQTaskInfoGetFullPath(SVnode *pVnode, int8_t level, STfs *pTfs, char *outputName) { + tdRSmaGetDirName(pVnode, pTfs, true, outputName); int32_t rsmaLen = strlen(outputName); snprintf(outputName + rsmaLen, TSDB_FILENAME_LEN - rsmaLen, "%" PRIi8, level); } -void tdRSmaQTaskInfoGetFullPathEx(int32_t vgId, tb_uid_t suid, int8_t level, const char *path, char *outputName) { - tdRSmaGetDirName(vgId, path, VNODE_RSMA_DIR, true, outputName); +void tdRSmaQTaskInfoGetFullPathEx(SVnode *pVnode, tb_uid_t suid, int8_t level, STfs *pTfs, char *outputName) { + tdRSmaGetDirName(pVnode, pTfs, true, outputName); int32_t rsmaLen = strlen(outputName); snprintf(outputName + rsmaLen, TSDB_FILENAME_LEN - rsmaLen, "%" PRIi8 "%s%" PRIi64, level, TD_DIRSEP, suid); } -void tdRSmaGetFileName(int32_t vgId, const char *pdname, const char *dname, const char *fname, int64_t suid, - int8_t level, int64_t version, char *outputName) { +void tdRSmaGetFileName(SVnode *pVnode, STfs *pTfs, const char *fname, int64_t suid, int8_t level, int64_t version, + char *outputName) { + int32_t offset = 0; + + // vnode + vnodeGetAbsDir(pVnode->path, pTfs, outputName, TSDB_FILENAME_LEN); + offset = strlen(outputName); + + // rsma + snprintf(outputName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VNODE_RSMA_DIR); + offset = strlen(outputName); + + // level & suid || vgid if (level >= 0 && suid > 0) { - if (version >= 0) { - if (pdname) { - snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%s%" PRIi8 "%s%" PRIi64 "%s%s.%" PRIi64, pdname, - TD_DIRSEP, TD_DIRSEP, vgId, TD_DIRSEP, dname, TD_DIRSEP, level, TD_DIRSEP, suid, TD_DIRSEP, fname, - version); - } else { - snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%s%" PRIi8 "%s%" PRIi64 "%s%s.%" PRIi64, TD_DIRSEP, - vgId, TD_DIRSEP, dname, TD_DIRSEP, level, TD_DIRSEP, suid, TD_DIRSEP, fname, version); - } - } else { - if (pdname) { - snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%s%" PRIi8 "%s%" PRIi64 "%s%s", pdname, - TD_DIRSEP, TD_DIRSEP, vgId, TD_DIRSEP, dname, TD_DIRSEP, level, TD_DIRSEP, suid, TD_DIRSEP, fname); - } else { - snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%s%" PRIi8 "%s%" PRIi64 "%s%s", TD_DIRSEP, vgId, - TD_DIRSEP, dname, TD_DIRSEP, level, TD_DIRSEP, suid, TD_DIRSEP, fname); - } - } + snprintf(outputName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%" PRIi8 "%s%" PRIi64 "%s", TD_DIRSEP, level, + TD_DIRSEP, suid, TD_DIRSEP); } else { - if (version >= 0) { - if (pdname) { - snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%sv%d%s%" PRIi64, pdname, TD_DIRSEP, TD_DIRSEP, - vgId, TD_DIRSEP, dname, TD_DIRSEP, vgId, fname, version); - } else { - snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%sv%d%s%" PRIi64, TD_DIRSEP, vgId, TD_DIRSEP, dname, - TD_DIRSEP, vgId, fname, version); - } - } else { - if (pdname) { - snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%sv%d%s", pdname, TD_DIRSEP, TD_DIRSEP, vgId, - TD_DIRSEP, dname, TD_DIRSEP, vgId, fname); - } else { - snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%sv%d%s", TD_DIRSEP, vgId, TD_DIRSEP, dname, - TD_DIRSEP, vgId, fname); - } - } + snprintf(outputName + offset, TSDB_FILENAME_LEN - offset - 1, "%sv%d", TD_DIRSEP, TD_VID(pVnode)); + } + offset = strlen(outputName); + + // fname + snprintf(outputName + offset, TSDB_FILENAME_LEN - offset - 1, "%s", fname); + offset = strlen(outputName); + + // version + if (version >= 0) { + snprintf(outputName + offset, TSDB_FILENAME_LEN - offset - 1, ".%" PRIi64, version); } } -void tdRSmaGetDirName(int32_t vgId, const char *pdname, const char *dname, bool endWithSep, char *outputName) { - if (pdname) { - if (endWithSep) { - snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s%s", pdname, TD_DIRSEP, TD_DIRSEP, vgId, TD_DIRSEP, - dname, TD_DIRSEP); - } else { - snprintf(outputName, TSDB_FILENAME_LEN, "%s%svnode%svnode%d%s%s", pdname, TD_DIRSEP, TD_DIRSEP, vgId, TD_DIRSEP, - dname); - } - } else { - if (endWithSep) { - snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s%s", TD_DIRSEP, vgId, TD_DIRSEP, dname, TD_DIRSEP); - } else { - snprintf(outputName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, dname); - } - } +void tdRSmaGetDirName(SVnode *pVnode, STfs *pTfs, bool endWithSep, char *outputName) { + int32_t offset = 0; + + // vnode + vnodeGetAbsDir(pVnode->path, pTfs, outputName, TSDB_FILENAME_LEN); + offset = strlen(outputName); + + // rsma + snprintf(outputName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s%s", TD_DIRSEP, VNODE_RSMA_DIR, + (endWithSep ? TD_DIRSEP : "")); } // smaXXXUtil ================ @@ -117,4 +101,4 @@ int32_t tdReleaseSmaRef(int32_t rsetId, int64_t refId) { smaTrace("rsma release ref for rsetId:%d refId:%" PRIi64 " success", rsetId, refId); return TSDB_CODE_SUCCESS; -} \ No newline at end of file +} From 05e8af483734f482a3ab21a64202d220e80e0eb1 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 12 Jul 2023 15:17:52 +0800 Subject: [PATCH 3/6] enh: unify handling of vnode primary dir for vnd and tsdb --- source/dnode/vnode/src/tsdb/tsdbCache.c | 15 ++++------ source/dnode/vnode/src/tsdb/tsdbFS.c | 33 ++++++++++----------- source/dnode/vnode/src/tsdb/tsdbFile.c | 9 ++++-- source/dnode/vnode/src/vnd/vnodeCommit.c | 26 ++++++++-------- source/dnode/vnode/src/vnd/vnodeOpen.c | 6 +--- source/dnode/vnode/src/vnd/vnodeRetention.c | 14 ++------- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 24 +++++---------- 7 files changed, 51 insertions(+), 76 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index cde0e6f1b7..cb4ee8fca7 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -13,6 +13,7 @@ * along with this program. If not, see . */ #include "tsdb.h" +#include "vnd.h" #define ROCKS_BATCH_SIZE (4096) @@ -58,16 +59,10 @@ typedef struct { static void tsdbGetRocksPath(STsdb *pTsdb, char *path) { SVnode *pVnode = pTsdb->pVnode; - if (pVnode->pTfs) { - if (path) { - snprintf(path, TSDB_FILENAME_LEN, "%s%s%s%scache.rdb", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP, - pTsdb->path, TD_DIRSEP); - } - } else { - if (path) { - snprintf(path, TSDB_FILENAME_LEN, "%s%scache.rdb", pTsdb->path, TD_DIRSEP); - } - } + vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, path, TSDB_FILENAME_LEN); + + int32_t offset = strlen(path); + snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%scache.rdb", TD_DIRSEP); } static const char *myCmpName(void *state) { diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 5519d43012..8d2932b417 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -14,6 +14,7 @@ */ #include "tsdb.h" +#include "vnd.h" // ================================================================================================= static int32_t tsdbFSToBinary(uint8_t *p, STsdbFS *pFS) { @@ -271,22 +272,20 @@ int32_t tDFileSetCmprFn(const void *p1, const void *p2) { static void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) { SVnode *pVnode = pTsdb->pVnode; - if (pVnode->pTfs) { - if (current) { - snprintf(current, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP, - pTsdb->path, TD_DIRSEP); - } - if (current_t) { - snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%s%s%sCURRENT.t", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), TD_DIRSEP, - pTsdb->path, TD_DIRSEP); - } - } else { - if (current) { - snprintf(current, TSDB_FILENAME_LEN - 1, "%s%sCURRENT", pTsdb->path, TD_DIRSEP); - } - if (current_t) { - snprintf(current_t, TSDB_FILENAME_LEN - 1, "%s%sCURRENT.t", pTsdb->path, TD_DIRSEP); - } + int32_t offset = 0; + + // CURRENT + if (current) { + vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, current, TSDB_FILENAME_LEN); + offset = strlen(current); + snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT", TD_DIRSEP); + } + + // CURRENT.t + if (current_t) { + vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); + offset = strlen(current_t); + snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT.t", TD_DIRSEP); } } @@ -1142,4 +1141,4 @@ void tsdbFSUnref(STsdb *pTsdb, STsdbFS *pFS) { } taosArrayDestroy(pFS->aDFileSet); -} \ No newline at end of file +} diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index d91475376b..bf58b1d7c6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -14,6 +14,7 @@ */ #include "tsdb.h" +#include "vnd.h" int32_t tPutHeadFile(uint8_t *p, SHeadFile *pHeadFile) { int32_t n = 0; @@ -282,8 +283,12 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) { // SDelFile =============================================== void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]) { - snprintf(fname, TSDB_FILENAME_LEN - 1, "%s%s%s%sv%dver%" PRId64 "%s", tfsGetPrimaryPath(pTsdb->pVnode->pTfs), - TD_DIRSEP, pTsdb->path, TD_DIRSEP, TD_VID(pTsdb->pVnode), pFile->commitID, ".del"); + int32_t offset = 0; + + vnodeGetAbsDir(pTsdb->path, pTsdb->pVnode->pTfs, fname, TSDB_FILENAME_LEN); + offset = strlen(fname); + snprintf((char *)fname + offset, TSDB_FILENAME_LEN - offset - 1, "%sv%dver%" PRId64 ".del", TD_DIRSEP, + TD_VID(pTsdb->pVnode), pFile->commitID); } int32_t tPutDelFile(uint8_t *p, SDelFile *pDelFile) { diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 77453fd894..f7c8411b32 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -290,11 +290,7 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) { pInfo->txn = metaGetTxn(pVnode->pMeta); // save info - if (pVnode->pTfs) { - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path); - } else { - snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path); - } + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); vDebug("vgId:%d, save config while prepare commit", TD_VID(pVnode)); if (vnodeSaveInfo(dir, &pInfo->info) < 0) { @@ -427,11 +423,7 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) { return -1; } - if (pVnode->pTfs) { - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path); - } else { - snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path); - } + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); syncBeginSnapshot(pVnode->sync, pInfo->info.state.committed); @@ -493,16 +485,22 @@ _exit: bool vnodeShouldRollback(SVnode *pVnode) { char tFName[TSDB_FILENAME_LEN] = {0}; - snprintf(tFName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, - VND_INFO_FNAME_TMP); + int32_t offset = 0; + + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); + offset = strlen(tFName); + snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP); return taosCheckExistFile(tFName); } void vnodeRollback(SVnode *pVnode) { char tFName[TSDB_FILENAME_LEN] = {0}; - snprintf(tFName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, - VND_INFO_FNAME_TMP); + int32_t offset = 0; + + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); + offset = strlen(tFName); + snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP); (void)taosRemoveFile(tFName); } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 648dadcade..37ff2ebae3 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -291,11 +291,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { char tdir[TSDB_FILENAME_LEN * 2] = {0}; int32_t ret = 0; - if (pTfs) { - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path); - } else { - snprintf(dir, TSDB_FILENAME_LEN, "%s", path); - } + vnodeGetAbsDir(path, pTfs, dir, TSDB_FILENAME_LEN); info.config = vnodeCfgDefault; diff --git a/source/dnode/vnode/src/vnd/vnodeRetention.c b/source/dnode/vnode/src/vnd/vnodeRetention.c index 170deb4286..6b092cc346 100644 --- a/source/dnode/vnode/src/vnd/vnodeRetention.c +++ b/source/dnode/vnode/src/vnd/vnodeRetention.c @@ -35,11 +35,7 @@ static int32_t vnodePrepareRentention(SVnode *pVnode, SRetentionInfo *pInfo) { pInfo->commitID = ++pVnode->state.commitID; char dir[TSDB_FILENAME_LEN] = {0}; - if (pVnode->pTfs) { - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path); - } else { - snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path); - } + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); if (vnodeLoadInfo(dir, &pInfo->info) < 0) { code = terrno; @@ -64,11 +60,7 @@ static int32_t vnodeRetentionTask(void *param) { SVnode *pVnode = pInfo->pVnode; char dir[TSDB_FILENAME_LEN] = {0}; - if (pVnode->pTfs) { - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path); - } else { - snprintf(dir, TSDB_FILENAME_LEN, "%s", pVnode->path); - } + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); // save info pInfo->info.state.commitID = pInfo->commitID; @@ -127,4 +119,4 @@ _exit: vInfo("vgId:%d %s done", TD_VID(pInfo->pVnode), __func__); } return 0; -} \ No newline at end of file +} diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 052e4ab2c1..eaa79fbcfb 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -91,12 +91,11 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) // FIXME: if commit multiple times and the config changed? if (!pReader->cfgDone) { char fName[TSDB_FILENAME_LEN]; - if (pReader->pVnode->pTfs) { - snprintf(fName, TSDB_FILENAME_LEN, "%s%s%s%s%s", tfsGetPrimaryPath(pReader->pVnode->pTfs), TD_DIRSEP, - pReader->pVnode->path, TD_DIRSEP, VND_INFO_FNAME); - } else { - snprintf(fName, TSDB_FILENAME_LEN, "%s%s%s", pReader->pVnode->path, TD_DIRSEP, VND_INFO_FNAME); - } + int32_t offset = 0; + + vnodeGetAbsDir(pReader->pVnode->path, pReader->pVnode->pTfs, fName, TSDB_FILENAME_LEN); + offset = strlen(fName); + snprintf(fName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME); TdFilePtr pFile = taosOpenFile(fName, TD_FILE_READ); if (NULL == pFile) { @@ -344,11 +343,7 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot * .applyTerm = pWriter->info.state.commitTerm}; pVnode->statis = pWriter->info.statis; char dir[TSDB_FILENAME_LEN] = {0}; - if (pWriter->pVnode->pTfs) { - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path); - } else { - snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path); - } + vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); vnodeCommitInfo(dir); } else { @@ -400,12 +395,7 @@ static int32_t vnodeSnapWriteInfo(SVSnapWriter *pWriter, uint8_t *pData, uint32_ // modify info as needed char dir[TSDB_FILENAME_LEN] = {0}; - if (pWriter->pVnode->pTfs) { - snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pWriter->pVnode->pTfs), TD_DIRSEP, - pWriter->pVnode->path); - } else { - snprintf(dir, TSDB_FILENAME_LEN, "%s", pWriter->pVnode->path); - } + vnodeGetAbsDir(pWriter->pVnode->path, pWriter->pVnode->pTfs, dir, TSDB_FILENAME_LEN); SVnodeStats vndStats = pWriter->info.config.vndStats; SVnode *pVnode = pWriter->pVnode; From b7e134af209f5e96b71fbe9513de6c1afbe6608f Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Wed, 12 Jul 2023 17:53:09 +0800 Subject: [PATCH 4/6] enh: remove unused code in vmProcessCreateVnodeReq --- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 69fe4f22b5..7e9f1f795f 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -265,22 +265,6 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, vnodeCfg.vgId); -#if 0 - if (pMgmt->pTfs) { - if (tfsDirExistAt(pMgmt->pTfs, path, (SDiskID){0})) { - terrno = TSDB_CODE_VND_DIR_ALREADY_EXIST; - dError("vgId:%d, failed to restore vnode since %s", req.vgId, terrstr()); - return -1; - } - } else { - if (taosDirExist(path)) { - terrno = TSDB_CODE_VND_DIR_ALREADY_EXIST; - dError("vgId:%d, failed to restore vnode since %s", req.vgId, terrstr()); - return -1; - } - } -#endif - if (vnodeCreate(path, &vnodeCfg, pMgmt->pTfs) < 0) { tFreeSCreateVnodeReq(&req); dError("vgId:%d, failed to create vnode since %s", req.vgId, terrstr()); From e209b487c618675f5afbf3d6d1cccd1c27b8e688 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Thu, 13 Jul 2023 10:38:05 +0800 Subject: [PATCH 5/6] enh: rename func name vnodeGetPrimaryDir --- source/dnode/vnode/src/inc/vnd.h | 2 +- source/dnode/vnode/src/meta/metaOpen.c | 2 +- source/dnode/vnode/src/sma/smaFS.c | 4 ++-- source/dnode/vnode/src/sma/smaUtil.c | 4 ++-- source/dnode/vnode/src/tsdb/tsdbCache.c | 2 +- source/dnode/vnode/src/tsdb/tsdbFS.c | 4 ++-- source/dnode/vnode/src/tsdb/tsdbFile.c | 2 +- source/dnode/vnode/src/vnd/vnodeCommit.c | 8 ++++---- source/dnode/vnode/src/vnd/vnodeOpen.c | 14 +++++++------- source/dnode/vnode/src/vnd/vnodeRetention.c | 4 ++-- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 6 +++--- 11 files changed, 26 insertions(+), 26 deletions(-) diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index c52bc29590..ac352e764c 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -87,7 +87,7 @@ void vnodeBufPoolAddToFreeList(SVBufPool* pPool); int32_t vnodeBufPoolRecycle(SVBufPool* pPool); // vnodeOpen.c -int32_t vnodeGetAbsDir(const char* relPath, STfs* pTfs, char* buf, size_t bufLen); +int32_t vnodeGetPrimaryDir(const char* relPath, STfs* pTfs, char* buf, size_t bufLen); // vnodeQuery.c int32_t vnodeQueryOpen(SVnode* pVnode); diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c index b896b73e40..e2253e26db 100644 --- a/source/dnode/vnode/src/meta/metaOpen.c +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -41,7 +41,7 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) { *ppMeta = NULL; // create handle - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, path, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, path, TSDB_FILENAME_LEN); offset = strlen(path); snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VNODE_META_DIR); diff --git a/source/dnode/vnode/src/sma/smaFS.c b/source/dnode/vnode/src/sma/smaFS.c index 1742d983a6..9bd71748e9 100644 --- a/source/dnode/vnode/src/sma/smaFS.c +++ b/source/dnode/vnode/src/sma/smaFS.c @@ -160,11 +160,11 @@ static void tdRSmaGetCurrentFName(SSma *pSma, char *current, char *current_t) { SVnode *pVnode = pSma->pVnode; int32_t offset = 0; - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, current, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, current, TSDB_FILENAME_LEN); offset = strlen(current); snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%srsma%sPRESENT", TD_DIRSEP, TD_DIRSEP); - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); offset = strlen(current_t); snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%srsma%sPRESENT.t", TD_DIRSEP, TD_DIRSEP); } diff --git a/source/dnode/vnode/src/sma/smaUtil.c b/source/dnode/vnode/src/sma/smaUtil.c index 7f5f593e36..efdf7aa2bb 100644 --- a/source/dnode/vnode/src/sma/smaUtil.c +++ b/source/dnode/vnode/src/sma/smaUtil.c @@ -44,7 +44,7 @@ void tdRSmaGetFileName(SVnode *pVnode, STfs *pTfs, const char *fname, int64_t su int32_t offset = 0; // vnode - vnodeGetAbsDir(pVnode->path, pTfs, outputName, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pTfs, outputName, TSDB_FILENAME_LEN); offset = strlen(outputName); // rsma @@ -74,7 +74,7 @@ void tdRSmaGetDirName(SVnode *pVnode, STfs *pTfs, bool endWithSep, char *outputN int32_t offset = 0; // vnode - vnodeGetAbsDir(pVnode->path, pTfs, outputName, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pTfs, outputName, TSDB_FILENAME_LEN); offset = strlen(outputName); // rsma diff --git a/source/dnode/vnode/src/tsdb/tsdbCache.c b/source/dnode/vnode/src/tsdb/tsdbCache.c index cb4ee8fca7..4e69063941 100644 --- a/source/dnode/vnode/src/tsdb/tsdbCache.c +++ b/source/dnode/vnode/src/tsdb/tsdbCache.c @@ -59,7 +59,7 @@ typedef struct { static void tsdbGetRocksPath(STsdb *pTsdb, char *path) { SVnode *pVnode = pTsdb->pVnode; - vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, path, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pTsdb->path, pVnode->pTfs, path, TSDB_FILENAME_LEN); int32_t offset = strlen(path); snprintf(path + offset, TSDB_FILENAME_LEN - offset - 1, "%scache.rdb", TD_DIRSEP); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 8d2932b417..1b4461c07b 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -276,14 +276,14 @@ static void tsdbGetCurrentFName(STsdb *pTsdb, char *current, char *current_t) { // CURRENT if (current) { - vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, current, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pTsdb->path, pVnode->pTfs, current, TSDB_FILENAME_LEN); offset = strlen(current); snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT", TD_DIRSEP); } // CURRENT.t if (current_t) { - vnodeGetAbsDir(pTsdb->path, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pTsdb->path, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); offset = strlen(current_t); snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%sCURRENT.t", TD_DIRSEP); } diff --git a/source/dnode/vnode/src/tsdb/tsdbFile.c b/source/dnode/vnode/src/tsdb/tsdbFile.c index bf58b1d7c6..8577a42417 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/tsdbFile.c @@ -285,7 +285,7 @@ int32_t tGetDFileSet(uint8_t *p, SDFileSet *pSet) { void tsdbDelFileName(STsdb *pTsdb, SDelFile *pFile, char fname[]) { int32_t offset = 0; - vnodeGetAbsDir(pTsdb->path, pTsdb->pVnode->pTfs, fname, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pTsdb->path, pTsdb->pVnode->pTfs, fname, TSDB_FILENAME_LEN); offset = strlen(fname); snprintf((char *)fname + offset, TSDB_FILENAME_LEN - offset - 1, "%sv%dver%" PRId64 ".del", TD_DIRSEP, TD_VID(pTsdb->pVnode), pFile->commitID); diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index f7c8411b32..f8b9451100 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -290,7 +290,7 @@ static int32_t vnodePrepareCommit(SVnode *pVnode, SCommitInfo *pInfo) { pInfo->txn = metaGetTxn(pVnode->pMeta); // save info - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); vDebug("vgId:%d, save config while prepare commit", TD_VID(pVnode)); if (vnodeSaveInfo(dir, &pInfo->info) < 0) { @@ -423,7 +423,7 @@ static int vnodeCommitImpl(SCommitInfo *pInfo) { return -1; } - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); syncBeginSnapshot(pVnode->sync, pInfo->info.state.committed); @@ -487,7 +487,7 @@ bool vnodeShouldRollback(SVnode *pVnode) { char tFName[TSDB_FILENAME_LEN] = {0}; int32_t offset = 0; - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); offset = strlen(tFName); snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP); @@ -498,7 +498,7 @@ void vnodeRollback(SVnode *pVnode) { char tFName[TSDB_FILENAME_LEN] = {0}; int32_t offset = 0; - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, tFName, TSDB_FILENAME_LEN); offset = strlen(tFName); snprintf(tFName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME_TMP); diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index 37ff2ebae3..5ca96c2a0b 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -15,7 +15,7 @@ #include "vnd.h" -int32_t vnodeGetAbsDir(const char *relPath, STfs *pTfs, char *buf, size_t bufLen) { +int32_t vnodeGetPrimaryDir(const char *relPath, STfs *pTfs, char *buf, size_t bufLen) { if (pTfs) { snprintf(buf, bufLen - 1, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, relPath); } else { @@ -36,7 +36,7 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) { } // create vnode env - vnodeGetAbsDir(path, pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(path, pTfs, dir, TSDB_FILENAME_LEN); if (taosMkDir(dir)) { return TAOS_SYSTEM_ERROR(errno); } @@ -65,7 +65,7 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, STfs *p char dir[TSDB_FILENAME_LEN] = {0}; int32_t ret = 0; - vnodeGetAbsDir(path, pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(path, pTfs, dir, TSDB_FILENAME_LEN); ret = vnodeLoadInfo(dir, &info); if (ret < 0) { @@ -188,7 +188,7 @@ int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnod char dir[TSDB_FILENAME_LEN] = {0}; int32_t ret = 0; - vnodeGetAbsDir(srcPath, pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(srcPath, pTfs, dir, TSDB_FILENAME_LEN); ret = vnodeLoadInfo(dir, &info); if (ret < 0) { @@ -247,7 +247,7 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN] = {0}; - vnodeGetAbsDir(dstPath, pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(dstPath, pTfs, dir, TSDB_FILENAME_LEN); if (vnodeLoadInfo(dir, &info) == 0) { if (info.config.vgId != dstVgId) { vError("vgId:%d, unexpected vnode config.vgId:%d", dstVgId, info.config.vgId); @@ -256,7 +256,7 @@ int32_t vnodeRestoreVgroupId(const char *srcPath, const char *dstPath, int32_t s return dstVgId; } - vnodeGetAbsDir(srcPath, pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(srcPath, pTfs, dir, TSDB_FILENAME_LEN); if (vnodeLoadInfo(dir, &info) < 0) { vError("vgId:%d, failed to read vnode config from %s since %s", srcVgId, srcPath, tstrerror(terrno)); return -1; @@ -291,7 +291,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { char tdir[TSDB_FILENAME_LEN * 2] = {0}; int32_t ret = 0; - vnodeGetAbsDir(path, pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(path, pTfs, dir, TSDB_FILENAME_LEN); info.config = vnodeCfgDefault; diff --git a/source/dnode/vnode/src/vnd/vnodeRetention.c b/source/dnode/vnode/src/vnd/vnodeRetention.c index 6b092cc346..71878ae4f4 100644 --- a/source/dnode/vnode/src/vnd/vnodeRetention.c +++ b/source/dnode/vnode/src/vnd/vnodeRetention.c @@ -35,7 +35,7 @@ static int32_t vnodePrepareRentention(SVnode *pVnode, SRetentionInfo *pInfo) { pInfo->commitID = ++pVnode->state.commitID; char dir[TSDB_FILENAME_LEN] = {0}; - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); if (vnodeLoadInfo(dir, &pInfo->info) < 0) { code = terrno; @@ -60,7 +60,7 @@ static int32_t vnodeRetentionTask(void *param) { SVnode *pVnode = pInfo->pVnode; char dir[TSDB_FILENAME_LEN] = {0}; - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); // save info pInfo->info.state.commitID = pInfo->commitID; diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index eaa79fbcfb..c80792490a 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -93,7 +93,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) char fName[TSDB_FILENAME_LEN]; int32_t offset = 0; - vnodeGetAbsDir(pReader->pVnode->path, pReader->pVnode->pTfs, fName, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pReader->pVnode->path, pReader->pVnode->pTfs, fName, TSDB_FILENAME_LEN); offset = strlen(fName); snprintf(fName + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s", TD_DIRSEP, VND_INFO_FNAME); @@ -343,7 +343,7 @@ int32_t vnodeSnapWriterClose(SVSnapWriter *pWriter, int8_t rollback, SSnapshot * .applyTerm = pWriter->info.state.commitTerm}; pVnode->statis = pWriter->info.statis; char dir[TSDB_FILENAME_LEN] = {0}; - vnodeGetAbsDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, dir, TSDB_FILENAME_LEN); vnodeCommitInfo(dir); } else { @@ -395,7 +395,7 @@ static int32_t vnodeSnapWriteInfo(SVSnapWriter *pWriter, uint8_t *pData, uint32_ // modify info as needed char dir[TSDB_FILENAME_LEN] = {0}; - vnodeGetAbsDir(pWriter->pVnode->path, pWriter->pVnode->pTfs, dir, TSDB_FILENAME_LEN); + vnodeGetPrimaryDir(pWriter->pVnode->path, pWriter->pVnode->pTfs, dir, TSDB_FILENAME_LEN); SVnodeStats vndStats = pWriter->info.config.vndStats; SVnode *pVnode = pWriter->pVnode; From dc75f7ce2187e93a9d940f22ff04980e143a0b58 Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Thu, 13 Jul 2023 11:27:31 +0800 Subject: [PATCH 6/6] enh: use VNODE_RSMA_DIR in tdRSmaGetCurrentFName --- source/dnode/vnode/src/sma/smaFS.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/sma/smaFS.c b/source/dnode/vnode/src/sma/smaFS.c index 9bd71748e9..c9d0230921 100644 --- a/source/dnode/vnode/src/sma/smaFS.c +++ b/source/dnode/vnode/src/sma/smaFS.c @@ -162,11 +162,11 @@ static void tdRSmaGetCurrentFName(SSma *pSma, char *current, char *current_t) { vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, current, TSDB_FILENAME_LEN); offset = strlen(current); - snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%srsma%sPRESENT", TD_DIRSEP, TD_DIRSEP); + snprintf(current + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s%sPRESENT", TD_DIRSEP, VNODE_RSMA_DIR, TD_DIRSEP); vnodeGetPrimaryDir(pVnode->path, pVnode->pTfs, current_t, TSDB_FILENAME_LEN); offset = strlen(current_t); - snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%srsma%sPRESENT.t", TD_DIRSEP, TD_DIRSEP); + snprintf(current_t + offset, TSDB_FILENAME_LEN - offset - 1, "%s%s%sPRESENT.t", TD_DIRSEP, VNODE_RSMA_DIR, TD_DIRSEP); } static int32_t tdRSmaLoadFSFromFile(const char *fname, SRSmaFS *pFS) {