From 6d2b8fe2bf3be692ac675c5267611e82636627e0 Mon Sep 17 00:00:00 2001 From: kailixu Date: Tue, 18 Jun 2024 19:08:00 +0800 Subject: [PATCH] tfs: support disable create new file --- include/util/tdef.h | 4 ++-- source/libs/tfs/inc/tfsInt.h | 3 ++- source/libs/tfs/src/tfs.c | 5 ----- source/libs/tfs/src/tfsDisk.c | 3 ++- source/libs/tfs/src/tfsTier.c | 10 +++++++-- tests/system-test/0-others/multilevel.py | 26 ++++++++++++------------ 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/include/util/tdef.h b/include/util/tdef.h index a7ebb4da22..9e61ec8fe6 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -548,8 +548,8 @@ enum { ENCRYPT_KEY_STAT_UNKNOWN = 0, ENCRYPT_KEY_STAT_UNSET, ENCRYPT_KEY_STAT_SE typedef struct { char dir[TSDB_FILENAME_LEN]; int32_t level; - int8_t primary; - int8_t disable; // disable create new file + int32_t primary; + int8_t disable; // disable create new file } SDiskCfg; typedef struct { diff --git a/source/libs/tfs/inc/tfsInt.h b/source/libs/tfs/inc/tfsInt.h index 713f548e9e..b3bde3abba 100644 --- a/source/libs/tfs/inc/tfsInt.h +++ b/source/libs/tfs/inc/tfsInt.h @@ -38,6 +38,7 @@ typedef struct { int32_t level; int32_t id; + int8_t disable; // disable create new file char *path; SDiskSize size; } STfsDisk; @@ -73,7 +74,7 @@ typedef struct STfs { SHashObj *hash; // name to did map } STfs; -STfsDisk *tfsNewDisk(int32_t level, int32_t id, const char *dir); +STfsDisk *tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *dir); STfsDisk *tfsFreeDisk(STfsDisk *pDisk); int32_t tfsUpdateDiskSize(STfsDisk *pDisk); diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index ac1fe40f24..4110652f6f 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -494,11 +494,6 @@ static int32_t tfsMount(STfs *pTfs, SDiskCfg *pCfg) { return -1; } - if (pCfg->disable == 1 && pCfg->primary != 1) { - fInfo("skip to mount disk %s to level %d since disable is %" PRIi8, pCfg->dir, pCfg->level, pCfg->disable); - return 0; - } - SDiskID did = {.level = pCfg->level}; STfsDisk *pDisk = tfsMountDiskToTier(TFS_TIER_AT(pTfs, did.level), pCfg); if (pDisk == NULL) { diff --git a/source/libs/tfs/src/tfsDisk.c b/source/libs/tfs/src/tfsDisk.c index 3717bf1a6d..06eb1cd42e 100644 --- a/source/libs/tfs/src/tfsDisk.c +++ b/source/libs/tfs/src/tfsDisk.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "tfsInt.h" -STfsDisk *tfsNewDisk(int32_t level, int32_t id, const char *path) { +STfsDisk *tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *path) { STfsDisk *pDisk = taosMemoryCalloc(1, sizeof(STfsDisk)); if (pDisk == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -32,6 +32,7 @@ STfsDisk *tfsNewDisk(int32_t level, int32_t id, const char *path) { pDisk->level = level; pDisk->id = id; + pDisk->disable = disable; taosGetDiskSize(pDisk->path, &pDisk->size); return pDisk; } diff --git a/source/libs/tfs/src/tfsTier.c b/source/libs/tfs/src/tfsTier.c index 911fdc52b7..cb79c334bf 100644 --- a/source/libs/tfs/src/tfsTier.c +++ b/source/libs/tfs/src/tfsTier.c @@ -65,7 +65,7 @@ STfsDisk *tfsMountDiskToTier(STfsTier *pTier, SDiskCfg *pCfg) { return NULL; } - STfsDisk *pDisk = tfsNewDisk(pCfg->level, id, pCfg->dir); + STfsDisk *pDisk = tfsNewDisk(pCfg->level, id, pCfg->disable, pCfg->dir); if (pDisk == NULL) return NULL; pTier->disks[id] = pDisk; @@ -89,7 +89,7 @@ void tfsUpdateTierSize(STfsTier *pTier) { size.total += pDisk->size.total; size.used += pDisk->size.used; size.avail += pDisk->size.avail; - nAvailDisks++; + if (pDisk->disable == 0) nAvailDisks++; } pTier->size = size; @@ -118,6 +118,12 @@ int32_t tfsAllocDiskOnTier(STfsTier *pTier) { if (pDisk == NULL) continue; + if (pDisk->disable == 1) { + uTrace("disk %s is disabled and skip it, level:%d id:%d disable:%" PRIi8, pDisk->path, pDisk->level, pDisk->id, + pDisk->disable); + continue; + } + if (pDisk->size.avail < tsMinDiskFreeSize) { uInfo("disk %s is full and skip it, level:%d id:%d free size:%" PRId64 " min free size:%" PRId64, pDisk->path, pDisk->level, pDisk->id, pDisk->size.avail, tsMinDiskFreeSize); diff --git a/tests/system-test/0-others/multilevel.py b/tests/system-test/0-others/multilevel.py index aaecbae50e..7e657fd3ba 100644 --- a/tests/system-test/0-others/multilevel.py +++ b/tests/system-test/0-others/multilevel.py @@ -52,7 +52,7 @@ class TDTestCase: tdLog.info("============== basic test ===============") cfg={ '/mnt/data1' : 'dataDir', - '/mnt/data2 0 0' : 'dataDir' + '/mnt/data2 0 0 0' : 'dataDir' } tdSql.createDir('/mnt/data1') tdSql.createDir('/mnt/data2') @@ -112,9 +112,9 @@ class TDTestCase: cfg={ '/mnt/data00 0 1' : 'dataDir', '/mnt/data01 0 0' : 'dataDir', - '/mnt/data02 0 0' : 'dataDir', + '/mnt/data02 0 0 0' : 'dataDir', '/mnt/data03 0 0' : 'dataDir', - '/mnt/data04 0 0' : 'dataDir' + '/mnt/data04 0 0 0' : 'dataDir' } dir_list = ['/mnt/data00','/mnt/data01','/mnt/data02','/mnt/data03','/mnt/data04'] for i in dir_list: @@ -160,15 +160,15 @@ class TDTestCase: tdDnodes.stop(1) # Test1 1 dataDir cfg={ - '/mnt/data000 0 1' : 'dataDir', + '/mnt/data000 0 1 0' : 'dataDir', '/mnt/data001 0 0' : 'dataDir', - '/mnt/data002 0 0' : 'dataDir', + '/mnt/data002 0 0 0' : 'dataDir', '/mnt/data010 1 0' : 'dataDir', - '/mnt/data011 1 0' : 'dataDir', + '/mnt/data011 1 0 0' : 'dataDir', '/mnt/data012 1 0' : 'dataDir', - '/mnt/data020 2 0' : 'dataDir', - '/mnt/data021 2 0' : 'dataDir', - '/mnt/data022 2 0' : 'dataDir' + '/mnt/data020 2 0 0' : 'dataDir', + '/mnt/data021 2 0 0' : 'dataDir', + '/mnt/data022 2 0 0' : 'dataDir' } dir_list = ['/mnt/data000','/mnt/data001','/mnt/data002','/mnt/data010','/mnt/data011','/mnt/data012','/mnt/data020','/mnt/data021''/mnt/data022'] for i in dir_list: @@ -189,7 +189,7 @@ class TDTestCase: if i == 0 : datadir = '/mnt/data%d 0 1' % (i+1) else: - datadir = '/mnt/data%d 0 0' % (i+1) + datadir = '/mnt/data%d 0 0 0' % (i+1) cfg.update({ datadir : 'dataDir' }) tdSql.createDir('/mnt/data%d' % (i+1)) @@ -250,9 +250,9 @@ class TDTestCase: tdDnodes.stop(1) cfg={ '/mnt/data1 0 1' : 'dataDir', - '/mnt/data2 1 0 1' : 'dataDir', - '/mnt/data3 1 0 0' : 'dataDir', - '/mnt/data4 1 0' : 'dataDir', + '/mnt/data2 1 0 0' : 'dataDir', + '/mnt/data3 1 0 1' : 'dataDir', + '/mnt/data4 2 0' : 'dataDir', } tdSql.createDir('/mnt/data2') tdSql.createDir('/mnt/data3')