more code

This commit is contained in:
Hongze Cheng 2025-02-08 11:24:45 +08:00
parent 708fa269b5
commit f2dafd9362
3 changed files with 17 additions and 30 deletions

View File

@ -92,9 +92,9 @@ int32_t tfsGetLevel(STfs *pTfs);
* @param pDiskId The disk ID after allocation. * @param pDiskId The disk ID after allocation.
* @return int32_t 0 for success, -1 for failure. * @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. * @brief Get the primary path.

View File

@ -1811,7 +1811,7 @@ int32_t tsdbAllocateDisk(STsdb *tsdb, int32_t fid, const char *label, SDiskID *d
STfs *tfs = tsdb->pVnode->pTfs; STfs *tfs = tsdb->pVnode->pTfs;
int32_t expectedLevel = tsdbFidLevel(fid, &tsdb->keepCfg, taosGetTimestampSec()); int32_t expectedLevel = tsdbFidLevel(fid, &tsdb->keepCfg, taosGetTimestampSec());
code = tfsAllocDisk(tfs, expectedLevel, &did); code = tfsAllocDisk(tfs, expectedLevel, label, &did);
if (code) { if (code) {
tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code)); tsdbError("vgId:%d %s failed at %s:%d since %s", TD_VID(tsdb->pVnode), __func__, __FILE__, lino, tstrerror(code));
return 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; STfs *tfs = tsdb->pVnode->pTfs;
code = tfsAllocDiskAtLevel(tfs, level, &did); code = tfsAllocDiskAtLevel(tfs, level, label, &did);
if (code) { if (code) {
return 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) { if (diskId) {
*diskId = did; *diskId = did;
} }

View File

@ -152,18 +152,10 @@ int32_t tfsGetDisksAtLevel(STfs *pTfs, int32_t level) {
int32_t tfsGetLevel(STfs *pTfs) { return pTfs->nlevel; } 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->level = level;
pDiskId->id = -1; 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]); pDiskId->id = tfsAllocDiskOnTier(&pTfs->tiers[pDiskId->level]);
if (pDiskId->id < 0) { if (pDiskId->id < 0) {
TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK); TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK);
@ -172,27 +164,18 @@ int32_t tfsAllocDiskAtLevel(STfs *pTfs, int32_t level, SDiskID *pDiskId) {
TAOS_RETURN(0); TAOS_RETURN(0);
} }
int32_t tfsAllocDisk(STfs *pTfs, int32_t expLevel, SDiskID *pDiskId) { int32_t tfsAllocDisk(STfs *pTfs, int32_t expLevel, const char *label, SDiskID *pDiskId) {
pDiskId->level = expLevel; if (expLevel >= pTfs->nlevel) {
pDiskId->id = -1; expLevel = pTfs->nlevel - 1;
} else if (expLevel < 0) {
if (pDiskId->level >= pTfs->nlevel) { expLevel = 0;
pDiskId->level = pTfs->nlevel - 1;
}
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); TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK);
} }