From c202b418616693ef7d602c0ac22a42264553fb1b Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Wed, 18 Dec 2024 14:03:10 +0800 Subject: [PATCH 1/4] Parse alter dataDir config. --- source/common/src/tglobal.c | 4 +++ source/util/src/tconfig.c | 65 ++++++++++++++++++++++++++++++++++--- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 905dcb4fda..774c062a23 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -2381,6 +2381,10 @@ static int32_t taosCfgDynamicOptionsForServer(SConfig *pCfg, const char *name) { code = TSDB_CODE_SUCCESS; goto _exit; } + if (strcasecmp(name, "dataDir") == 0) { + code = TSDB_CODE_SUCCESS; + goto _exit; + } { // 'bool/int32_t/int64_t/float/double' variables with general modification function static OptionNameAndVar debugOptions[] = { diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index ee88996c29..d293883f92 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -432,6 +432,56 @@ _err: TAOS_RETURN(code); } +int32_t cfgUpdateTfsItemDisable(SConfigItem *pItem, const char *value) { + int32_t code = 0; + int32_t len = strlen(value) + 1; + int8_t disable = 0; + char *dataDirStr = taosMemoryMalloc(PATH_MAX); + char *disableStr = taosMemoryMalloc(1 + 1); + const char *p = value; + while (*p) { + if (*p == ' ') { + break; + } + p++; + } + + size_t optLen = p - value; + tstrncpy(dataDirStr, value, PATH_MAX); + dataDirStr[optLen] = 0; + + if (' ' == value[optLen] && strlen(value) > optLen + 1) { + disableStr[0] = value[optLen + 1]; + disableStr[1] = 0; + if ((taosStr2int8(dataDirStr, &disable)) < 0) { + code = TSDB_CODE_INVALID_CFG_VALUE; + goto _exit; + } + } else { + code = TSDB_CODE_INVALID_CFG_VALUE; + goto _exit; + } + + int32_t sz = taosArrayGetSize(pItem->array); + for (int32_t i = 0; i < sz; ++i) { + SDiskCfg *cfg = taosArrayGet(pItem->array, i); + if (strcmp(cfg->dir, dataDirStr) == 0) { + cfg->disable = disable; + break; + uInfo("update tfs item:%s disable:%d", cfg->dir, cfg->disable); + } + } + code = TSDB_CODE_INVALID_CFG_VALUE; + +_exit: + if (code != TSDB_CODE_SUCCESS) { + uError("failed to update tfs item:%s disable:%d", dataDirStr, disable); + } + taosMemoryFree(dataDirStr); + taosMemoryFree(disableStr); + TAOS_RETURN(code); +} + static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool resetArray) { SConfigItem *pDebugFlagItem = cfgGetItem(pCfg, "debugFlag"); if (resetArray) { @@ -501,15 +551,22 @@ int32_t cfgGetAndSetItem(SConfig *pCfg, SConfigItem **pItem, const char *name, c *pItem = cfgGetItem(pCfg, name); if (*pItem == NULL) { - (void)taosThreadMutexUnlock(&pCfg->lock); - TAOS_RETURN(TSDB_CODE_CFG_NOT_FOUND); + code = TSDB_CODE_CFG_NOT_FOUND; + goto _exit; } - TAOS_CHECK_RETURN(cfgSetItemVal(*pItem, name, value, stype)); + if (strcasecmp(name, "dataDir") == 0) { + code = cfgUpdateTfsItemDisable(*pItem, value); + goto _exit; + } + + TAOS_CHECK_GOTO(cfgSetItemVal(*pItem, name, value, stype), NULL, _exit); + +_exit: if (lock) { (void)taosThreadMutexUnlock(&pCfg->lock); } - + TAOS_RETURN(code); } From 93500cf96ed6dae3ef29f0833980851acd80883d Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 20 Dec 2024 09:16:54 +0800 Subject: [PATCH 2/4] Feat support alter dataDir disable. --- include/common/tglobal.h | 2 + include/libs/tfs/tfs.h | 9 ++++ source/common/src/tglobal.c | 10 ++++ source/dnode/mgmt/mgmt_dnode/inc/dmInt.h | 1 + source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 9 ++-- source/dnode/mgmt/mgmt_dnode/src/dmInt.c | 1 + source/libs/tfs/src/tfs.c | 19 +++++++ source/util/src/tconfig.c | 57 +-------------------- 8 files changed, 49 insertions(+), 59 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index e6333d2ddc..8f9e9b2bf0 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -323,6 +323,8 @@ void printConfigNotMatch(SArray *array); int32_t compareSConfigItemArrays(SArray *mArray, const SArray *dArray, SArray *diffArray); bool isConifgItemLazyMode(SConfigItem *item); +int32_t taosUpdateTfsItemDisable(SConfig *pCfg, const char *value, void *pTfs); + #ifdef __cplusplus } #endif diff --git a/include/libs/tfs/tfs.h b/include/libs/tfs/tfs.h index 446c1d6fd7..a6a3c63a50 100644 --- a/include/libs/tfs/tfs.h +++ b/include/libs/tfs/tfs.h @@ -319,6 +319,15 @@ bool tfsDiskSpaceAvailable(STfs *pTfs, int32_t level); */ bool tfsDiskSpaceSufficient(STfs *pTfs, int32_t level, int32_t disk); +/** + * @brief Update disk size of tfs. + * + * @param pTfs The fs object. + * @param dir The directory. + * @param disable The disable flag. + */ +int32_t tfsUpdateDiskDisable(STfs *pTfs, const char *dir, int8_t disable); + #ifdef __cplusplus } #endif diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 774c062a23..3259f392f0 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -390,6 +390,16 @@ int32_t taosSetTfsCfg(SConfig *pCfg) { int32_t taosSetTfsCfg(SConfig *pCfg); #endif +#ifndef _STORAGE +int32_t cfgUpdateTfsItemDisable(SConfig *pCfg, const char *value, void *pTfs) { return TSDB_CODE_INVALID_CFG; } +#else +int32_t cfgUpdateTfsItemDisable(SConfig *pCfg, const char *value, void *pTfs); +#endif + +int32_t taosUpdateTfsItemDisable(SConfig *pCfg, const char *value, void *pTfs) { + return cfgUpdateTfsItemDisable(pCfg, value, pTfs); +} + static int32_t taosSplitS3Cfg(SConfig *pCfg, const char *name, char gVarible[TSDB_MAX_EP_NUM][TSDB_FQDN_LEN], int8_t *pNum) { int32_t code = TSDB_CODE_SUCCESS; diff --git a/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h b/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h index 2108a097ee..05a423436a 100644 --- a/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h +++ b/source/dnode/mgmt/mgmt_dnode/inc/dmInt.h @@ -25,6 +25,7 @@ extern "C" { typedef struct SDnodeMgmt { SDnodeData *pData; SMsgCb msgCb; + STfs *pTfs; const char *path; const char *name; TdThread statusThread; diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index ccc6439b5d..0e1b388ead 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -499,9 +499,15 @@ static int32_t dmAlterMaxCompactTask(const char *value) { int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { int32_t code = 0; SDCfgDnodeReq cfgReq = {0}; + SConfig *pCfg = taosGetCfg(); + SConfigItem *pItem = NULL; + if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) { return TSDB_CODE_INVALID_MSG; } + if (strcasecmp(cfgReq.config, "dataDir") == 0) { + return taosUpdateTfsItemDisable(pCfg, cfgReq.value, pMgmt->pTfs); + } if (strncmp(cfgReq.config, tsAlterCompactTaskKeywords, strlen(tsAlterCompactTaskKeywords) + 1) == 0) { return dmAlterMaxCompactTask(cfgReq.value); @@ -509,9 +515,6 @@ int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) { dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value); - SConfig *pCfg = taosGetCfg(); - SConfigItem *pItem = NULL; - code = cfgGetAndSetItem(pCfg, &pItem, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_SERVER_CMD, true); if (code != 0) { if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) { diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmInt.c b/source/dnode/mgmt/mgmt_dnode/src/dmInt.c index b58c1a216d..be9e7b5136 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmInt.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmInt.c @@ -68,6 +68,7 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) { pMgmt->pData = pInput->pData; pMgmt->msgCb = pInput->msgCb; + pMgmt->pTfs = pInput->pTfs; pMgmt->path = pInput->path; pMgmt->name = pInput->name; pMgmt->processCreateNodeFp = pInput->processCreateNodeFp; diff --git a/source/libs/tfs/src/tfs.c b/source/libs/tfs/src/tfs.c index 4ac72e8918..ecc55517b3 100644 --- a/source/libs/tfs/src/tfs.c +++ b/source/libs/tfs/src/tfs.c @@ -726,3 +726,22 @@ int32_t tfsGetMonitorInfo(STfs *pTfs, SMonDiskInfo *pInfo) { TAOS_RETURN(0); } + +int32_t tfsUpdateDiskDisable(STfs *pTfs, const char *dir, int8_t disable) { + TAOS_UNUSED(tfsLock(pTfs)); + for (int32_t level = 0; level < pTfs->nlevel; level++) { + STfsTier *pTier = &pTfs->tiers[level]; + for (int32_t disk = 0; disk < pTier->ndisk; ++disk) { + STfsDisk *pDisk = pTier->disks[disk]; + if (strcmp(pDisk->path, dir) == 0) { + pDisk->disable = disable; + TAOS_UNUSED(tfsUnLock(pTfs)); + fInfo("disk %s is %s", dir, disable ? "disabled" : "enabled"); + TAOS_RETURN(TSDB_CODE_SUCCESS); + } + } + } + TAOS_UNUSED(tfsUnLock(pTfs)); + fError("failed to update disk disable since %s not found", dir); + TAOS_RETURN(TSDB_CODE_FS_NO_VALID_DISK); +} \ No newline at end of file diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index d293883f92..52794af4dd 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -432,56 +432,6 @@ _err: TAOS_RETURN(code); } -int32_t cfgUpdateTfsItemDisable(SConfigItem *pItem, const char *value) { - int32_t code = 0; - int32_t len = strlen(value) + 1; - int8_t disable = 0; - char *dataDirStr = taosMemoryMalloc(PATH_MAX); - char *disableStr = taosMemoryMalloc(1 + 1); - const char *p = value; - while (*p) { - if (*p == ' ') { - break; - } - p++; - } - - size_t optLen = p - value; - tstrncpy(dataDirStr, value, PATH_MAX); - dataDirStr[optLen] = 0; - - if (' ' == value[optLen] && strlen(value) > optLen + 1) { - disableStr[0] = value[optLen + 1]; - disableStr[1] = 0; - if ((taosStr2int8(dataDirStr, &disable)) < 0) { - code = TSDB_CODE_INVALID_CFG_VALUE; - goto _exit; - } - } else { - code = TSDB_CODE_INVALID_CFG_VALUE; - goto _exit; - } - - int32_t sz = taosArrayGetSize(pItem->array); - for (int32_t i = 0; i < sz; ++i) { - SDiskCfg *cfg = taosArrayGet(pItem->array, i); - if (strcmp(cfg->dir, dataDirStr) == 0) { - cfg->disable = disable; - break; - uInfo("update tfs item:%s disable:%d", cfg->dir, cfg->disable); - } - } - code = TSDB_CODE_INVALID_CFG_VALUE; - -_exit: - if (code != TSDB_CODE_SUCCESS) { - uError("failed to update tfs item:%s disable:%d", dataDirStr, disable); - } - taosMemoryFree(dataDirStr); - taosMemoryFree(disableStr); - TAOS_RETURN(code); -} - static int32_t cfgUpdateDebugFlagItem(SConfig *pCfg, const char *name, bool resetArray) { SConfigItem *pDebugFlagItem = cfgGetItem(pCfg, "debugFlag"); if (resetArray) { @@ -555,18 +505,13 @@ int32_t cfgGetAndSetItem(SConfig *pCfg, SConfigItem **pItem, const char *name, c goto _exit; } - if (strcasecmp(name, "dataDir") == 0) { - code = cfgUpdateTfsItemDisable(*pItem, value); - goto _exit; - } - TAOS_CHECK_GOTO(cfgSetItemVal(*pItem, name, value, stype), NULL, _exit); _exit: if (lock) { (void)taosThreadMutexUnlock(&pCfg->lock); } - + TAOS_RETURN(code); } From 2458badeab5d4533a63fdb22085056e11fa79061 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 20 Dec 2024 11:35:16 +0800 Subject: [PATCH 3/4] Add py test. --- tests/system-test/0-others/multilevel.py | 55 ++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/tests/system-test/0-others/multilevel.py b/tests/system-test/0-others/multilevel.py index 3ed4002fcd..243e811532 100644 --- a/tests/system-test/0-others/multilevel.py +++ b/tests/system-test/0-others/multilevel.py @@ -287,6 +287,55 @@ class TDTestCase: checkFiles('/mnt/data3/vnode/*/tsdb/v*',0) checkFiles('/mnt/data4/vnode/*/tsdb/v*',1) + def test_alter_disable_err_case(self): + tdLog.info("============== test_alter_disable_err_case test ===============") + tdDnodes.stop(1) + cfg={ + '/mnt/data1 0 1 1' : 'dataDir', + '/mnt/data2 0 0 0' : 'dataDir' + } + tdSql.createDir('/mnt/data1') + tdSql.createDir('/mnt/data2') + tdDnodes.deploy(1,cfg) + tdDnodes.start(1) + + tdSql.execute('alter dnode 1 "dataDir /mnt/data2 1"') + tdSql.error('alter dnode 1 "dataDir /mnt/errpath 1"') + tdSql.error('alter dnode 1 "dataDir /mnt/data2 3"') + tdSql.error('alter dnode 1 "dataDir /mnt/data2 ee"') + + def test_alter_disable_case(self): + tdLog.info("============== test_alter_disable_case test ===============") + tdDnodes.stop(1) + cfg={ + '/mnt/data1 0 1 1' : 'dataDir', + '/mnt/data2 0 0 0' : 'dataDir', + '/mnt/data3 0 0 0' : 'dataDir' + } + tdSql.createDir('/mnt/data1') + tdSql.createDir('/mnt/data2') + tdSql.createDir('/mnt/data3') + tdDnodes.deploy(1,cfg) + tdDnodes.start(1) + + tdSql.execute('create database dbtest duration 3') + tdSql.execute('use dbtest') + tdSql.execute('create table stb (ts timestamp,c0 int) tags(t0 int)') + tdSql.execute('create table tb1 using stb tags(1)') + for i in range(1,600, 30): + tdSql.execute(f'insert into tb1 values(now-{i}d,10)') + tdSql.execute('flush database dbtest') + + tdSql.execute('alter dnode 1 "dataDir /mnt/data2 1"') + + tdSql.execute('create database dbtest1 duration 3') + tdSql.execute('use dbtest1') + tdSql.execute('create table stb (ts timestamp,c0 int) tags(t0 int)') + tdSql.execute('create table tb1 using stb tags(1)') + for i in range(1,600, 30): + tdSql.execute(f'insert into tb1 values(now-{i}d,10)') + tdSql.execute('flush database dbtest1') + def run(self): self.basic() self.dir_not_exist() @@ -297,12 +346,12 @@ class TDTestCase: self.trim_database() self.missing_middle_level() self.disable_create_new_file() - - + self.test_alter_disable_err_case() + self.test_alter_disable_case() def stop(self): tdSql.close() - tdLog.success("%s successfully executed" % __file__) + # tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase()) From e29ddfcd3dda13639a819b79d46dabbce1460322 Mon Sep 17 00:00:00 2001 From: xiao-77 Date: Fri, 20 Dec 2024 12:34:45 +0800 Subject: [PATCH 4/4] Fix ci case. --- tests/system-test/0-others/multilevel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system-test/0-others/multilevel.py b/tests/system-test/0-others/multilevel.py index 243e811532..971451a023 100644 --- a/tests/system-test/0-others/multilevel.py +++ b/tests/system-test/0-others/multilevel.py @@ -351,7 +351,7 @@ class TDTestCase: def stop(self): tdSql.close() - # tdLog.success("%s successfully executed" % __file__) + tdLog.success("%s successfully executed" % __file__) tdCases.addWindows(__file__, TDTestCase()) tdCases.addLinux(__file__, TDTestCase())