From 568799a6a3d4ba7e6d66354d4d0614b129bd4b42 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 12 Jun 2024 15:16:58 +0800 Subject: [PATCH 1/7] fix(wal/level): enable alter replica from fake walLevel 1 --- include/libs/wal/wal.h | 1 + source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 16 ++++++------ source/dnode/vnode/inc/vnode.h | 11 +++++---- source/dnode/vnode/src/vnd/vnodeCfg.c | 27 +++++++++++---------- source/dnode/vnode/src/vnd/vnodeOpen.c | 25 ++++++++++++------- source/dnode/vnode/src/vnd/vnodeSvr.c | 3 +++ source/libs/parser/src/parTranslater.c | 18 ++++++++++---- 7 files changed, 62 insertions(+), 39 deletions(-) diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 7f779609eb..155da9d116 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -60,6 +60,7 @@ typedef struct { EWalType level; // wal level int32_t encryptAlgorithm; char encryptKey[ENCRYPT_KEY_LEN + 1]; + int8_t clearFiles; } SWalCfg; typedef struct { diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index bfc9e92293..63777ab872 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -144,7 +144,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { } #if defined(TD_ENTERPRISE) pCfg->tsdbCfg.encryptAlgorithm = pCreate->encryptAlgorithm; - if(pCfg->tsdbCfg.encryptAlgorithm == DND_CA_SM4){ + if (pCfg->tsdbCfg.encryptAlgorithm == DND_CA_SM4) { strncpy(pCfg->tsdbCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); } #else @@ -160,7 +160,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { pCfg->walCfg.level = pCreate->walLevel; #if defined(TD_ENTERPRISE) pCfg->walCfg.encryptAlgorithm = pCreate->encryptAlgorithm; - if(pCfg->walCfg.encryptAlgorithm == DND_CA_SM4){ + if (pCfg->walCfg.encryptAlgorithm == DND_CA_SM4) { strncpy(pCfg->walCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); } #else @@ -169,7 +169,7 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) { #if defined(TD_ENTERPRISE) pCfg->tdbEncryptAlgorithm = pCreate->encryptAlgorithm; - if(pCfg->tdbEncryptAlgorithm == DND_CA_SM4){ + if (pCfg->tdbEncryptAlgorithm == DND_CA_SM4) { strncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); } #else @@ -278,7 +278,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { req.keepTimeOffset, req.s3ChunkSize, req.s3KeepLocal, req.s3Compact, req.isTsma, req.precision, req.compression, req.minRows, req.maxRows, req.walFsyncPeriod, req.walLevel, req.walRetentionPeriod, req.walRetentionSize, req.walRollPeriod, req.walSegmentSize, req.hashMethod, req.hashBegin, req.hashEnd, req.hashPrefix, req.hashSuffix, - req.replica, req.selfIndex, req.learnerReplica, req.learnerSelfIndex, req.strict, req.changeVersion, + req.replica, req.selfIndex, req.learnerReplica, req.learnerSelfIndex, req.strict, req.changeVersion, req.encryptAlgorithm); for (int32_t i = 0; i < req.replica; ++i) { @@ -304,8 +304,8 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return -1; } - if(req.encryptAlgorithm == DND_CA_SM4){ - if(strlen(tsEncryptKey) == 0){ + if (req.encryptAlgorithm == DND_CA_SM4) { + if (strlen(tsEncryptKey) == 0) { terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; dError("vgId:%d, failed to create vnode since encrypt key is empty", req.vgId); return -1; @@ -737,7 +737,9 @@ int32_t vmProcessAlterVnodeReplicaReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { .diskPrimary = pVnode->diskPrimary, }; tstrncpy(wrapperCfg.path, pVnode->path, sizeof(wrapperCfg.path)); - vmCloseVnode(pMgmt, pVnode, false); + + bool commitAndRemoveWal = vnodeShouldRemoveWal(pVnode->pImpl); + vmCloseVnode(pMgmt, pVnode, commitAndRemoveWal); int32_t diskPrimary = wrapperCfg.diskPrimary; char path[TSDB_FILENAME_LEN] = {0}; diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 21d967ad93..fccba91db7 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -52,6 +52,7 @@ extern const SVnodeCfg vnodeCfgDefault; int32_t vnodeInit(int32_t nthreads); void vnodeCleanup(); int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, int32_t diskPrimary, STfs *pTfs); +bool vnodeShouldRemoveWal(SVnode *pVnode); int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t diskPrimary, STfs *pTfs); int32_t vnodeAlterHashRange(const char *srcPath, const char *dstPath, SAlterVnodeHashRangeReq *pReq, int32_t diskPrimary, STfs *pTfs); @@ -181,7 +182,7 @@ void tsdbReaderSetNotifyCb(STsdbReader *pReader, TsdReaderNotifyCbFn not int32_t tsdbReuseCacherowsReader(void *pReader, void *pTableIdList, int32_t numOfTables); int32_t tsdbCacherowsReaderOpen(void *pVnode, int32_t type, void *pTableIdList, int32_t numOfTables, int32_t numOfCols, SArray *pCidList, int32_t *pSlotIds, uint64_t suid, void **pReader, const char *idstr, - SArray *pFuncTypeList, SColumnInfo* pkCol, int32_t numOfPks); + SArray *pFuncTypeList, SColumnInfo *pkCol, int32_t numOfPks); int32_t tsdbRetrieveCacheRows(void *pReader, SSDataBlock *pResBlock, const int32_t *slotIds, const int32_t *dstSlotIds, SArray *pTableUids); void *tsdbCacherowsReaderClose(void *pReader); @@ -218,8 +219,8 @@ typedef struct STqReader { STqReader *tqReaderOpen(SVnode *pVnode); void tqReaderClose(STqReader *); -bool tqGetTablePrimaryKey(STqReader* pReader); -void tqSetTablePrimaryKey(STqReader* pReader, int64_t uid); +bool tqGetTablePrimaryKey(STqReader *pReader); +void tqSetTablePrimaryKey(STqReader *pReader, int64_t uid); void tqReaderSetColIdList(STqReader *pReader, SArray *pColIdList); int32_t tqReaderSetTbUidList(STqReader *pReader, const SArray *tbUidList, const char *id); @@ -278,8 +279,8 @@ struct STsdbCfg { int32_t keep2; // just for save config, don't use in tsdbRead/tsdbCommit/..., and use STsdbKeepCfg in STsdb instead int32_t keepTimeOffset; // just for save config, use STsdbKeepCfg in STsdb instead SRetention retentions[TSDB_RETENTION_MAX]; - int32_t encryptAlgorithm; - char encryptKey[ENCRYPT_KEY_LEN + 1]; + int32_t encryptAlgorithm; + char encryptKey[ENCRYPT_KEY_LEN + 1]; }; typedef struct { diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index cd6863fd89..c7b54d36b6 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -13,9 +13,9 @@ * along with this program. If not, see . */ +#include "tglobal.h" #include "tutil.h" #include "vnd.h" -#include "tglobal.h" const SVnodeCfg vnodeCfgDefault = {.vgId = -1, .dbname = "", @@ -47,6 +47,7 @@ const SVnodeCfg vnodeCfgDefault = {.vgId = -1, .segSize = 0, .retentionSize = -1, .level = TAOS_WAL_WRITE, + .clearFiles = 0, }, .hashBegin = 0, .hashEnd = 0, @@ -142,6 +143,7 @@ int vnodeEncodeConfig(const void *pObj, SJson *pJson) { if (tjsonAddIntegerToObject(pJson, "wal.retentionSize", pCfg->walCfg.retentionSize) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "wal.segSize", pCfg->walCfg.segSize) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "wal.level", pCfg->walCfg.level) < 0) return -1; + if (tjsonAddIntegerToObject(pJson, "wal.clearFiles", pCfg->walCfg.clearFiles) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "wal.encryptAlgorithm", pCfg->walCfg.encryptAlgorithm) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "tdbEncryptAlgorithm", pCfg->tdbEncryptAlgorithm) < 0) return -1; if (tjsonAddIntegerToObject(pJson, "sstTrigger", pCfg->sttTrigger) < 0) return -1; @@ -249,12 +251,11 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { tjsonGetNumberValue(pJson, "tsdb.encryptAlgorithm", pCfg->tsdbCfg.encryptAlgorithm, code); if (code < 0) return -1; #if defined(TD_ENTERPRISE) - if(pCfg->tsdbCfg.encryptAlgorithm == DND_CA_SM4){ - if(tsEncryptKey[0] == 0){ + if (pCfg->tsdbCfg.encryptAlgorithm == DND_CA_SM4) { + if (tsEncryptKey[0] == 0) { terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; return -1; - } - else{ + } else { strncpy(pCfg->tsdbCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); } } @@ -273,15 +274,16 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { if (code < 0) return -1; tjsonGetNumberValue(pJson, "wal.level", pCfg->walCfg.level, code); if (code < 0) return -1; + tjsonGetNumberValue(pJson, "wal.clearFiles", pCfg->walCfg.clearFiles, code); + if (code < 0) return -1; tjsonGetNumberValue(pJson, "wal.encryptAlgorithm", pCfg->walCfg.encryptAlgorithm, code); if (code < 0) return -1; #if defined(TD_ENTERPRISE) - if(pCfg->walCfg.encryptAlgorithm == DND_CA_SM4){ - if(tsEncryptKey[0] == 0){ + if (pCfg->walCfg.encryptAlgorithm == DND_CA_SM4) { + if (tsEncryptKey[0] == 0) { terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; return -1; - } - else{ + } else { strncpy(pCfg->walCfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); } } @@ -289,12 +291,11 @@ int vnodeDecodeConfig(const SJson *pJson, void *pObj) { tjsonGetNumberValue(pJson, "tdbEncryptAlgorithm", pCfg->tdbEncryptAlgorithm, code); if (code < 0) return -1; #if defined(TD_ENTERPRISE) - if(pCfg->tdbEncryptAlgorithm == DND_CA_SM4){ - if(tsEncryptKey[0] == 0){ + if (pCfg->tdbEncryptAlgorithm == DND_CA_SM4) { + if (tsEncryptKey[0] == 0) { terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; return -1; - } - else{ + } else { strncpy(pCfg->tdbEncryptKey, tsEncryptKey, ENCRYPT_KEY_LEN); } } diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index da8c3a6cad..ea9209c6b4 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -81,6 +81,8 @@ int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, int32_t diskPrimary, STfs return 0; } +bool vnodeShouldRemoveWal(SVnode *pVnode) { return pVnode->config.walCfg.clearFiles == 1; } + int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t diskPrimary, STfs *pTfs) { SVnodeInfo info = {0}; char dir[TSDB_FILENAME_LEN] = {0}; @@ -129,6 +131,12 @@ int32_t vnodeAlterReplica(const char *path, SAlterVnodeReplicaReq *pReq, int32_t } pCfg->changeVersion = pReq->changeVersion; + if (info.config.walCfg.clearFiles) { + info.config.walCfg.clearFiles = 0; + + vInfo("vgId:%d, reset wal clearFiles", pReq->vgId); + } + vInfo("vgId:%d, save config while alter, replicas:%d totalReplicas:%d selfIndex:%d changeVersion:%d", pReq->vgId, pCfg->replicaNum, pCfg->totalReplicaNum, pCfg->myIndex, pCfg->changeVersion); @@ -486,15 +494,14 @@ SVnode *vnodeOpen(const char *path, int32_t diskPrimary, STfs *pTfs, SMsgCb msgC if (tsEnableMonitor && pVnode->monitor.insertCounter == NULL) { taos_counter_t *counter = NULL; - int32_t label_count = 7; - const char *sample_labels[] = {VNODE_METRIC_TAG_NAME_SQL_TYPE, VNODE_METRIC_TAG_NAME_CLUSTER_ID, - VNODE_METRIC_TAG_NAME_DNODE_ID, VNODE_METRIC_TAG_NAME_DNODE_EP, - VNODE_METRIC_TAG_NAME_VGROUP_ID, VNODE_METRIC_TAG_NAME_USERNAME, - VNODE_METRIC_TAG_NAME_RESULT}; - counter = taos_counter_new(VNODE_METRIC_SQL_COUNT, "counter for insert sql", - label_count, sample_labels); - vInfo("vgId:%d, new metric:%p",TD_VID(pVnode), counter); - if(taos_collector_registry_register_metric(counter) == 1){ + int32_t label_count = 7; + const char *sample_labels[] = {VNODE_METRIC_TAG_NAME_SQL_TYPE, VNODE_METRIC_TAG_NAME_CLUSTER_ID, + VNODE_METRIC_TAG_NAME_DNODE_ID, VNODE_METRIC_TAG_NAME_DNODE_EP, + VNODE_METRIC_TAG_NAME_VGROUP_ID, VNODE_METRIC_TAG_NAME_USERNAME, + VNODE_METRIC_TAG_NAME_RESULT}; + counter = taos_counter_new(VNODE_METRIC_SQL_COUNT, "counter for insert sql", label_count, sample_labels); + vInfo("vgId:%d, new metric:%p", TD_VID(pVnode), counter); + if (taos_collector_registry_register_metric(counter) == 1) { taos_counter_destroy(counter); counter = taos_collector_registry_get_metric(VNODE_METRIC_SQL_COUNT); vInfo("vgId:%d, get metric from registry:%p", TD_VID(pVnode), counter); diff --git a/source/dnode/vnode/src/vnd/vnodeSvr.c b/source/dnode/vnode/src/vnd/vnodeSvr.c index 002f04b8a7..02aae37315 100644 --- a/source/dnode/vnode/src/vnd/vnodeSvr.c +++ b/source/dnode/vnode/src/vnd/vnodeSvr.c @@ -2021,6 +2021,9 @@ static int32_t vnodeProcessAlterConfigReq(SVnode *pVnode, int64_t ver, void *pRe } if (pVnode->config.walCfg.level != req.walLevel) { + if (pVnode->config.walCfg.level == 0) { + pVnode->config.walCfg.clearFiles = 1; + } pVnode->config.walCfg.level = req.walLevel; walChanged = true; } diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 7e55f2cfeb..851b786308 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -6898,6 +6898,19 @@ static int32_t checkDbTbPrefixSuffixOptions(STranslateContext* pCxt, int32_t tbP } static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) { + if (pOptions->replica > 1) { + SDbCfgInfo dbCfg = {0}; + int32_t code = getDBCfg(pCxt, pDbName, &dbCfg); + if (TSDB_CODE_SUCCESS != code) { + return code; + } + + if (pOptions->walLevel == 0 || dbCfg.walLevel == 0) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, + "Invalid option, wal_level 0 should be used with replica 1"); + } + } + int32_t daysPerFile = pOptions->daysPerFile; int32_t s3KeepLocal = pOptions->s3KeepLocal; int64_t daysToKeep0 = pOptions->keep[0]; @@ -6926,11 +6939,6 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa "Invalid option, with_arbitrator should be used with replica 2"); } - if (pOptions->replica > 1 && pOptions->walLevel == 0) { - return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, - "Invalid option, wal_level 0 should be used with replica 1"); - } - return TSDB_CODE_SUCCESS; } From 4311309d510e7f7783f064e9febe0488ddd66181 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Wed, 12 Jun 2024 15:52:39 +0800 Subject: [PATCH 2/7] clear wal files for fake leve 1 --- source/dnode/mgmt/mgmt_vnode/src/vmHandle.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c index 63777ab872..4038ae1fd4 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmHandle.c @@ -482,7 +482,9 @@ int32_t vmProcessAlterVnodeTypeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { .diskPrimary = pVnode->diskPrimary, }; tstrncpy(wrapperCfg.path, pVnode->path, sizeof(wrapperCfg.path)); - vmCloseVnode(pMgmt, pVnode, false); + + bool commitAndRemoveWal = vnodeShouldRemoveWal(pVnode->pImpl); + vmCloseVnode(pMgmt, pVnode, commitAndRemoveWal); int32_t diskPrimary = wrapperCfg.diskPrimary; char path[TSDB_FILENAME_LEN] = {0}; From c13ba895ee73bce8ac88e8183c19cc6acc0d27eb Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 13 Jun 2024 09:47:14 +0800 Subject: [PATCH 3/7] fix translater rules for replica & wal level --- source/libs/parser/src/parTranslater.c | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 851b786308..60894e17cb 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -6898,19 +6898,6 @@ static int32_t checkDbTbPrefixSuffixOptions(STranslateContext* pCxt, int32_t tbP } static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbName, SDatabaseOptions* pOptions) { - if (pOptions->replica > 1) { - SDbCfgInfo dbCfg = {0}; - int32_t code = getDBCfg(pCxt, pDbName, &dbCfg); - if (TSDB_CODE_SUCCESS != code) { - return code; - } - - if (pOptions->walLevel == 0 || dbCfg.walLevel == 0) { - return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, - "Invalid option, wal_level 0 should be used with replica 1"); - } - } - int32_t daysPerFile = pOptions->daysPerFile; int32_t s3KeepLocal = pOptions->s3KeepLocal; int64_t daysToKeep0 = pOptions->keep[0]; @@ -6939,6 +6926,11 @@ static int32_t checkOptionsDependency(STranslateContext* pCxt, const char* pDbNa "Invalid option, with_arbitrator should be used with replica 2"); } + if (pOptions->replica > 1 && pOptions->walLevel == 0) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, + "Invalid option, wal_level 0 should be used with replica 1"); + } + return TSDB_CODE_SUCCESS; } @@ -7284,6 +7276,15 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm } } + if (pStmt->pOptions->replica > 1) { + SDbCfgInfo dbCfg = {0}; + int32_t code = getDBCfg(pCxt, pStmt->dbName, &dbCfg); + if (TSDB_CODE_SUCCESS == code && dbCfg.walLevel == 0) { + return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, + "Invalid option, wal_level 0 should be used with replica 1"); + } + } + int32_t code = checkDatabaseOptions(pCxt, pStmt->dbName, pStmt->pOptions); if (TSDB_CODE_SUCCESS != code) { return code; From 0adbf110d9359fb3c137f21c95b8c7ba59c486bd Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 13 Jun 2024 11:02:05 +0800 Subject: [PATCH 4/7] check wal level on mnode --- include/util/taoserror.h | 1 + source/dnode/mnode/impl/src/mndDb.c | 10 ++++++++++ source/libs/parser/src/parTranslater.c | 9 +++++---- source/util/src/terror.c | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/util/taoserror.h b/include/util/taoserror.h index 8f8434dfc1..ff327445c1 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -327,6 +327,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_MND_DB_IN_CREATING TAOS_DEF_ERROR_CODE(0, 0x0396) // #define TSDB_CODE_MND_INVALID_SYS_TABLENAME TAOS_DEF_ERROR_CODE(0, 0x039A) #define TSDB_CODE_MND_ENCRYPT_NOT_ALLOW_CHANGE TAOS_DEF_ERROR_CODE(0, 0x039B) +#define TSDB_CODE_MND_INVALID_WAL_LEVEL TAOS_DEF_ERROR_CODE(0, 0x039C) // mnode-node #define TSDB_CODE_MND_MNODE_ALREADY_EXIST TAOS_DEF_ERROR_CODE(0, 0x03A0) diff --git a/source/dnode/mnode/impl/src/mndDb.c b/source/dnode/mnode/impl/src/mndDb.c index d12f73cee6..78e3ceabce 100644 --- a/source/dnode/mnode/impl/src/mndDb.c +++ b/source/dnode/mnode/impl/src/mndDb.c @@ -495,6 +495,16 @@ static int32_t mndCheckInChangeDbCfg(SMnode *pMnode, SDbCfg *pOldCfg, SDbCfg *pN #else if (pNewCfg->replications != 1 && pNewCfg->replications != 3) return -1; #endif + + if (pNewCfg->walLevel == 0 && pOldCfg->replications > 1) { + terrno = TSDB_CODE_MND_INVALID_WAL_LEVEL; + return -1; + } + if (pNewCfg->replications > 1 && pOldCfg->walLevel == 0) { + terrno = TSDB_CODE_MND_INVALID_WAL_LEVEL; + return -1; + } + if (pNewCfg->sstTrigger < TSDB_MIN_STT_TRIGGER || pNewCfg->sstTrigger > TSDB_MAX_STT_TRIGGER) return -1; if (pNewCfg->minRows < TSDB_MIN_MINROWS_FBLOCK || pNewCfg->minRows > TSDB_MAX_MINROWS_FBLOCK) return -1; if (pNewCfg->maxRows < TSDB_MIN_MAXROWS_FBLOCK || pNewCfg->maxRows > TSDB_MAX_MAXROWS_FBLOCK) return -1; diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 60894e17cb..89d256fce0 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -7275,16 +7275,17 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm "Invalid option, wal_level 0 should be used with replica 1"); } } - - if (pStmt->pOptions->replica > 1) { + /* + if (pStmt->pOptions->replica > 1 && pStmt->pOptions->walLevel < 1) { SDbCfgInfo dbCfg = {0}; - int32_t code = getDBCfg(pCxt, pStmt->dbName, &dbCfg); + dbCfg.walLevel = -1; + int32_t code = getDBCfg(pCxt, pStmt->dbName, &dbCfg); if (TSDB_CODE_SUCCESS == code && dbCfg.walLevel == 0) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_DB_OPTION, "Invalid option, wal_level 0 should be used with replica 1"); } } - + */ int32_t code = checkDatabaseOptions(pCxt, pStmt->dbName, pStmt->pOptions); if (TSDB_CODE_SUCCESS != code) { return code; diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 0f594af0e9..96574a1a8c 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -257,6 +257,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_INDEX_NOT_EXIST, "Index not exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SYS_TABLENAME, "Invalid system table name") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_IN_CREATING, "Database in creating status") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ENCRYPT_NOT_ALLOW_CHANGE, "Encryption is not allowed to be changed after database is created") +TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_WAL_LEVEL, "Invalid option, wal_level 0 should be used with replica 1") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INCONSIST_ENCRYPT_KEY, "Inconsistent encryption key") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ENCRYPT_KEY, "The cluster has not been set properly for database encryption") From d47fe255aebe00e1d67571cd415c3d85a2c84711 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Fri, 14 Jun 2024 17:09:48 +0800 Subject: [PATCH 5/7] remova level 0's empty wals when closing vnode --- source/libs/parser/src/parTranslater.c | 4 ++-- source/libs/wal/src/walMgmt.c | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 89d256fce0..2bdee5e3bf 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -7275,7 +7275,7 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm "Invalid option, wal_level 0 should be used with replica 1"); } } - /* +#if 0 if (pStmt->pOptions->replica > 1 && pStmt->pOptions->walLevel < 1) { SDbCfgInfo dbCfg = {0}; dbCfg.walLevel = -1; @@ -7285,7 +7285,7 @@ static int32_t translateAlterDatabase(STranslateContext* pCxt, SAlterDatabaseStm "Invalid option, wal_level 0 should be used with replica 1"); } } - */ +#endif int32_t code = checkDatabaseOptions(pCxt, pStmt->dbName, pStmt->pOptions); if (TSDB_CODE_SUCCESS != code) { return code; diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 54e6abd85a..219bbd9664 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -233,6 +233,12 @@ void walClose(SWal *pWal) { taosThreadMutexUnlock(&pWal->mutex); taosRemoveRef(tsWal.refSetId, pWal->refId); + + if (pWal->cfg.level == TAOS_WAL_SKIP) { + wInfo("vgId:%d, remove all wals, path:%s", pWal->cfg.vgId, pWal->path); + taosRemoveDir(pWal->path); + taosMkDir(pWal->path); + } } static void walFreeObj(void *wal) { From 930c5d2adf48d05d45b438b4ecfbbda620fbe246 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Mon, 17 Jun 2024 08:57:53 +0800 Subject: [PATCH 6/7] cleanup wal level 0 before ref removing --- source/libs/wal/src/walMgmt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 219bbd9664..3dbaed1bc7 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -232,13 +232,13 @@ void walClose(SWal *pWal) { pWal->pRefHash = NULL; taosThreadMutexUnlock(&pWal->mutex); - taosRemoveRef(tsWal.refSetId, pWal->refId); - if (pWal->cfg.level == TAOS_WAL_SKIP) { wInfo("vgId:%d, remove all wals, path:%s", pWal->cfg.vgId, pWal->path); taosRemoveDir(pWal->path); taosMkDir(pWal->path); } + + taosRemoveRef(tsWal.refSetId, pWal->refId); } static void walFreeObj(void *wal) { From 3d3f281735f7ca645f97f0a0ff9362ba479bd770 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Tue, 18 Jun 2024 12:27:17 +0800 Subject: [PATCH 7/7] remove unused error strings --- source/util/src/terror.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 813e8011fc..fb2f4be487 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -254,8 +254,6 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_DB_IN_CREATING, "Database in creating TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_SYS_TABLENAME, "Invalid system table name") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ENCRYPT_NOT_ALLOW_CHANGE, "Encryption is not allowed to be changed after database is created") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_WAL_LEVEL, "Invalid option, wal_level 0 should be used with replica 1") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_INCONSIST_ENCRYPT_KEY, "Inconsistent encryption key") -TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ENCRYPT_KEY, "The cluster has not been set properly for database encryption") // mnode-node TAOS_DEFINE_ERROR(TSDB_CODE_MND_MNODE_ALREADY_EXIST, "Mnode already exists")