From 0adbf110d9359fb3c137f21c95b8c7ba59c486bd Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 13 Jun 2024 11:02:05 +0800 Subject: [PATCH] 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")