From f2dafd93626b74c32cf29f30aeccc46a36115e9a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 8 Feb 2025 11:24:45 +0800 Subject: [PATCH] more code --- include/libs/tfs/tfs.h | 4 +-- source/dnode/vnode/src/tsdb/tsdbUtil.c | 8 ++++-- source/libs/tfs/src/tfs.c | 35 +++++++------------------- 3 files changed, 17 insertions(+), 30 deletions(-) diff --git a/include/libs/tfs/tfs.h b/include/libs/tfs/tfs.h index f4e9048388..8a8484f61e 100644 --- a/include/libs/tfs/tfs.h +++ b/include/libs/tfs/tfs.h @@ -92,9 +92,9 @@ int32_t tfsGetLevel(STfs *pTfs); * @param pDiskId The disk ID after allocation. * @return int32_t 0 for success, -1 for failure. */ -int32_t tfsAllocDisk(STfs *pTfs, int32_t expLevel, SDiskID *pDiskId); +int32_t tfsAllocDisk(STfs *pTfs, int32_t expLevel, const char *label, SDiskID *pDiskId); -int32_t tfsAllocDiskAtLevel(STfs *pTfs, int32_t level, SDiskID *pDiskId); +int32_t tfsAllocDiskAtLevel(STfs *pTfs, int32_t level, const char *label, SDiskID *pDiskId); /** * @brief Get the primary path. diff --git a/source/dnode/vnode/src/tsdb/tsdbUtil.c b/source/dnode/vnode/src/tsdb/tsdbUtil.c index 11d8373296..62afba0a38 100644 --- a/source/dnode/vnode/src/tsdb/tsdbUtil.c +++ b/source/dnode/vnode/src/tsdb/tsdbUtil.c @@ -1811,7 +1811,7 @@ int32_t tsdbAllocateDisk(STsdb *tsdb, int32_t fid, const char *label, SDiskID *d STfs *tfs = tsdb->pVnode->pTfs; int32_t expectedLevel = tsdbFidLevel(fid, &tsdb->keepCfg, taosGetTimestampSec()); - code = tfsAllocDisk(tfs, expectedLevel, &did); + code = tfsAllocDisk(tfs, expectedLevel, label, &did); if (code) { tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); return code; @@ -1834,11 +1834,15 @@ int32_t tsdbAllocateDiskAtLevel(STsdb *tsdb, int32_t fid, int32_t level, const c }; STfs *tfs = tsdb->pVnode->pTfs; - code = tfsAllocDiskAtLevel(tfs, level, &did); + code = tfsAllocDiskAtLevel(tfs, level, label, &did); if (code) { return code; } + if (tfsMkdirRecurAt(tfs, tsdb->path, did) != 0) { + tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); + } + if (diskId) { *diskId = did; } diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index eb7d6d3d27..7634bd59b4 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -152,18 +152,10 @@ int32_t tfsGetDisksAtLevel(STfs *pTfs, int32_t level) { int32_t tfsGetLevel(STfs *pTfs) { return pTfs->nlevel; } -int32_t tfsAllocDiskAtLevel(STfs *pTfs, int32_t level, SDiskID *pDiskId) { +int32_t tfsAllocDiskAtLevel(STfs *pTfs, int32_t level, const char *label, SDiskID *pDiskId) { pDiskId->level = level; pDiskId->id = -1; - if (pDiskId->level >= pTfs->nlevel) { - pDiskId->level = pTfs->nlevel - 1; - } - - if (pDiskId->level < 0) { - pDiskId->level = 0; - } - pDiskId->id = tfsAllocDiskOnTier(&pTfs->tiers[pDiskId->level]); if (pDiskId->id < 0) { TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK); @@ -172,26 +164,17 @@ int32_t tfsAllocDiskAtLevel(STfs *pTfs, int32_t level, SDiskID *pDiskId) { TAOS_RETURN(0); } -int32_t tfsAllocDisk(STfs *pTfs, int32_t expLevel, SDiskID *pDiskId) { - pDiskId->level = expLevel; - pDiskId->id = -1; - - if (pDiskId->level >= pTfs->nlevel) { - pDiskId->level = pTfs->nlevel - 1; +int32_t tfsAllocDisk(STfs *pTfs, int32_t expLevel, const char *label, SDiskID *pDiskId) { + if (expLevel >= pTfs->nlevel) { + expLevel = pTfs->nlevel - 1; + } else if (expLevel < 0) { + expLevel = 0; } - if (pDiskId->level < 0) { - pDiskId->level = 0; - } - - while (pDiskId->level >= 0) { - pDiskId->id = tfsAllocDiskOnTier(&pTfs->tiers[pDiskId->level]); - if (pDiskId->id < 0) { - pDiskId->level--; - continue; + for (; expLevel >= 0; expLevel--) { + if (tfsAllocDiskAtLevel(pTfs, expLevel, label, pDiskId) == 0) { + TAOS_RETURN(0); } - - TAOS_RETURN(0); } TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK);