diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index b9c6b5b15efacc32c28a1eb4b49f1cfd7e2e3763..b9d4cc13d1692a9cb349ea348ca6596e3053c71f 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -5755,7 +5755,7 @@ int32_t tscCheckCreateDbParams(SSqlCmd* pCmd, SCMCreateDbMsg* pCreate) { char msg[512] = {0}; if (pCreate->walLevel != -1 && (pCreate->walLevel < TSDB_MIN_WAL_LEVEL || pCreate->walLevel > TSDB_MAX_WAL_LEVEL)) { - snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 0-2 allowed", pCreate->walLevel); + snprintf(msg, tListLen(msg), "invalid db option walLevel: %d, only 1-2 allowed", pCreate->walLevel); return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); } diff --git a/src/inc/twal.h b/src/inc/twal.h index 4fdb7aa275d539ae63129e038c4ae50f59552e1f..cf570aefdc50f26944706f4eddb1d44364986bca 100644 --- a/src/inc/twal.h +++ b/src/inc/twal.h @@ -44,6 +44,7 @@ typedef void* twalh; // WAL HANDLE typedef int (*FWalWrite)(void *ahandle, void *pHead, int type); twalh walOpen(const char *path, const SWalCfg *pCfg); +int walAlter(twalh pWal, const SWalCfg *pCfg); void walClose(twalh); int walRenew(twalh); int walWrite(twalh, SWalHead *); diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 54c049d242c504eee095120f800e023095b8eda6..8558350950de3892e30fac80514177ed3f76f886 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -910,13 +910,13 @@ static SDbCfg mnodeGetAlterDbOption(SDbObj *pDb, SCMAlterDbMsg *pAlter) { } if (walLevel > 0 && walLevel != pDb->cfg.walLevel) { - mError("db:%s, can't alter walLevel option", pDb->name); - terrno = TSDB_CODE_MND_INVALID_DB_OPTION; + mDebug("db:%s, walLevel:%d change to %d", pDb->name, pDb->cfg.walLevel, walLevel); + newCfg.walLevel = walLevel; } if (fsyncPeriod >= 0 && fsyncPeriod != pDb->cfg.fsyncPeriod) { - mError("db:%s, can't alter fsyncPeriod option", pDb->name); - terrno = TSDB_CODE_MND_INVALID_DB_OPTION; + mDebug("db:%s, fsyncPeriod:%d change to %d", pDb->name, pDb->cfg.fsyncPeriod, fsyncPeriod); + newCfg.fsyncPeriod = fsyncPeriod; } if (replications > 0 && replications != pDb->cfg.replications) { diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index a4e88fb9468e47f91e908ea669456d52b2592765..d89c383d6a4147ae6a2501fca0c73481f1a437f0 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -186,6 +186,12 @@ int32_t vnodeAlter(void *param, SMDCreateVnodeMsg *pVnodeCfg) { return code; } + code = walAlter(pVnode->wal, &pVnode->walCfg); + if (code != TSDB_CODE_SUCCESS) { + pVnode->status = TAOS_VN_STATUS_READY; + return code; + } + code = syncReconfig(pVnode->sync, &pVnode->syncCfg); if (code != TSDB_CODE_SUCCESS) { pVnode->status = TAOS_VN_STATUS_READY; @@ -390,6 +396,7 @@ void vnodeRelease(void *pVnodeRaw) { if (0 == tsEnableVnodeBak) { vInfo("vgId:%d, vnode backup not enabled", pVnode->vgId); } else { + taosRemoveDir(newDir); taosRename(rootDir, newDir); } diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index bebad69f3224e70efb795dad51e77745ea3053e4..a90c1b171c2c492a029ec0b56810518de1532f51 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -69,6 +69,13 @@ static void walModuleInitFunc() { wDebug("WAL module is initialized"); } +static inline bool walNeedFsyncTimer(SWal *pWal) { + if (pWal->fsyncPeriod > 0 && pWal->level == TAOS_WAL_FSYNC) { + return true; + } + return false; +} + void *walOpen(const char *path, const SWalCfg *pCfg) { SWal *pWal = calloc(sizeof(SWal), 1); if (pWal == NULL) { @@ -95,7 +102,7 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { tstrncpy(pWal->path, path, sizeof(pWal->path)); pthread_mutex_init(&pWal->mutex, NULL); - if (pWal->fsyncPeriod > 0 && pWal->level == TAOS_WAL_FSYNC) { + if (walNeedFsyncTimer(pWal)) { pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl); if (pWal->timer == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -127,6 +134,37 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { return pWal; } +int walAlter(twalh wal, const SWalCfg *pCfg) { + SWal *pWal = wal; + if (pWal == NULL) { + return TSDB_CODE_WAL_APP_ERROR; + } + + if (pWal->level == pCfg->walLevel && pWal->fsyncPeriod == pCfg->fsyncPeriod) { + wDebug("wal:%s, old walLevel:%d fsync:%d, new walLevel:%d fsync:%d not change", pWal->name, pWal->level, + pWal->fsyncPeriod, pCfg->walLevel, pCfg->fsyncPeriod); + return TSDB_CODE_SUCCESS; + } + + wInfo("wal:%s, change old walLevel:%d fsync:%d, new walLevel:%d fsync:%d", pWal->name, pWal->level, pWal->fsyncPeriod, + pCfg->walLevel, pCfg->fsyncPeriod); + + pthread_mutex_lock(&pWal->mutex); + pWal->level = pCfg->walLevel; + pWal->fsyncPeriod = pCfg->fsyncPeriod; + if (walNeedFsyncTimer(pWal)) { + wInfo("wal:%s, reset fsync timer, walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod); + taosTmrReset(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, &pWal->timer,walTmrCtrl); + } else { + wInfo("wal:%s, stop fsync timer, walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod); + taosTmrStop(pWal->timer); + pWal->timer = NULL; + } + pthread_mutex_unlock(&pWal->mutex); + + return TSDB_CODE_SUCCESS; +} + void walClose(void *handle) { if (handle == NULL) return; @@ -484,6 +522,12 @@ static void walProcessFsyncTimer(void *param, void *tmrId) { if (fsync(pWal->fd) < 0) { wError("wal:%s, fsync failed(%s)", pWal->name, strerror(errno)); } - - pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl); + + if (walNeedFsyncTimer(pWal)) { + pWal->timer = taosTmrStart(walProcessFsyncTimer, pWal->fsyncPeriod, pWal, walTmrCtrl); + } else { + wInfo("wal:%s, stop fsync timer for walLevel:%d fsyncPeriod:%d", pWal->name, pWal->level, pWal->fsyncPeriod); + taosTmrStop(pWal->timer); + pWal->timer = NULL; + } } diff --git a/tests/script/general/db/alter_option.sim b/tests/script/general/db/alter_option.sim index 49c75966ca12524e0ae80fcb58d7d5e710e78293..c8aa2480c509353ede3c6ce6269afa9e6efd62b5 100644 --- a/tests/script/general/db/alter_option.sim +++ b/tests/script/general/db/alter_option.sim @@ -218,7 +218,10 @@ if $data12_db != 1 then return -1 endi -sql_error alter database db wal 2 +sql alter database db wal 1 +sql alter database db wal 2 +sql alter database db wal 1 +sql alter database db wal 2 sql_error alter database db wal 0 sql_error alter database db wal 3 sql_error alter database db wal 4 @@ -226,11 +229,13 @@ sql_error alter database db wal -1 sql_error alter database db wal 1000 print ============== step fsync -sql_error alter database db fsync 2 -sql_error alter database db fsync 3 -sql_error alter database db fsync 4 +sql alter database db fsync 0 +sql alter database db fsync 1 +sql alter database db fsync 3600 +sql alter database db fsync 18000 +sql alter database db fsync 180000 +sql_error alter database db fsync 180001 sql_error alter database db fsync -1 -sql_error alter database db fsync 1000 print ============== step comp sql show databases