diff --git a/src/inc/twal.h b/src/inc/twal.h index 931cf5dabab4bb640d362ff71ba1bac35b58f364..05be90775fba352ae861384d61a14fb62529b0cb 100644 --- a/src/inc/twal.h +++ b/src/inc/twal.h @@ -25,6 +25,11 @@ typedef enum { TAOS_WAL_FSYNC = 2 } EWalType; +typedef enum { + TAOS_WAL_NOT_KEEP = 0, + TAOS_WAL_KEEP = 1 +} EWalKeep; + typedef struct { int8_t msgType; int8_t reserved[3]; @@ -36,11 +41,10 @@ typedef struct { } SWalHead; typedef struct { - int32_t vgId; - int32_t fsyncPeriod; // millisecond - int8_t walLevel; // wal level - int8_t wals; // number of WAL files; - int8_t keep; // keep the wal file when closed + int32_t vgId; + int32_t fsyncPeriod; // millisecond + EWalType walLevel; // wal level + EWalKeep keep; // keep the wal file when closed } SWalCfg; typedef void * twalh; // WAL HANDLE diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index 8cd8de62ad310729d44b549d4c44fc2bdc6a0f4c..6b6a49db932c6a64edc22177fe9bdd7cad1bc06d 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -175,7 +175,7 @@ static void *sdbGetTableFromId(int32_t tableId) { } static int32_t sdbInitWal() { - SWalCfg walCfg = {.vgId = 1, .walLevel = 2, .wals = 2, .keep = 1, .fsyncPeriod = 0}; + SWalCfg walCfg = {.vgId = 1, .walLevel = TAOS_WAL_FSYNC, .keep = TAOS_WAL_KEEP, .fsyncPeriod = 0}; char temp[TSDB_FILENAME_LEN]; sprintf(temp, "%s/wal", tsMnodeDir); tsSdbObj.wal = walOpen(temp, &walCfg); diff --git a/src/vnode/src/vnodeCfg.c b/src/vnode/src/vnodeCfg.c index e8dd44b48fa6b1389439711439fe864a0fbd948d..e2e57a756640339febbbe11cdc231c5a216ff2b0 100644 --- a/src/vnode/src/vnodeCfg.c +++ b/src/vnode/src/vnodeCfg.c @@ -39,8 +39,7 @@ static void vnodeLoadCfg(SVnodeObj *pVnode, SCreateVnodeMsg* vnodeMsg) { pVnode->tsdbCfg.compression = vnodeMsg->cfg.compression; pVnode->walCfg.walLevel = vnodeMsg->cfg.walLevel; pVnode->walCfg.fsyncPeriod = vnodeMsg->cfg.fsyncPeriod; - pVnode->walCfg.wals = vnodeMsg->cfg.wals; - pVnode->walCfg.keep = 0; + pVnode->walCfg.keep = TAOS_WAL_NOT_KEEP; pVnode->syncCfg.replica = vnodeMsg->cfg.replications; pVnode->syncCfg.quorum = vnodeMsg->cfg.quorum; diff --git a/src/wal/src/walMgmt.c b/src/wal/src/walMgmt.c index 2ae342244d95437b82c7131e9a9ef7f2344dab36..1f6a8f5546d6d73479b868bca13de84364a0cfe0 100644 --- a/src/wal/src/walMgmt.c +++ b/src/wal/src/walMgmt.c @@ -128,7 +128,7 @@ void walClose(void *handle) { taosClose(pWal->fd); - if (!pWal->keep) { + if (pWal->keep != TAOS_WAL_KEEP) { int64_t fileId = -1; while (walGetNextFile(pWal, &fileId) >= 0) { snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId); diff --git a/src/wal/src/walWrite.c b/src/wal/src/walWrite.c index 0d27ce1768ff4bc5ec5790ccbc889bca7a7f0418..b4769fe57b38d40fcdbfa0e1031e964aebf008cd 100644 --- a/src/wal/src/walWrite.c +++ b/src/wal/src/walWrite.c @@ -41,7 +41,7 @@ int32_t walRenew(void *handle) { wDebug("vgId:%d, file:%s, it is closed", pWal->vgId, pWal->name); } - if (pWal->keep) { + if (pWal->keep == TAOS_WAL_KEEP) { pWal->fileId = 0; } else { if (walGetNewFile(pWal, &pWal->fileId) != 0) pWal->fileId = 0; @@ -58,7 +58,7 @@ int32_t walRenew(void *handle) { wDebug("vgId:%d, file:%s, it is created", pWal->vgId, pWal->name); } - if (!pWal->keep) { + if (pWal->keep != TAOS_WAL_KEEP) { // remove the oldest wal file int64_t oldFileId = -1; if (walGetOldFile(pWal, pWal->fileId, WAL_FILE_NUM, &oldFileId) == 0) { @@ -144,12 +144,12 @@ int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) { continue; } - wDebug("vgId:%d, file:%s, restore success and keep it", pWal->vgId, walName); + wDebug("vgId:%d, file:%s, restore success", pWal->vgId, walName); count++; } - if (!pWal->keep) return TSDB_CODE_SUCCESS; + if (pWal->keep != TAOS_WAL_KEEP) return TSDB_CODE_SUCCESS; if (count == 0) { wDebug("vgId:%d, wal file not exist, renew it", pWal->vgId); @@ -173,7 +173,6 @@ int32_t walGetWalFile(void *handle, char *fileName, int64_t *fileId) { if (handle == NULL) return -1; SWal *pWal = handle; - // for keep if (*fileId == 0) *fileId = -1; pthread_mutex_lock(&(pWal->mutex)); diff --git a/src/wal/test/waltest.c b/src/wal/test/waltest.c index 14e439c0727508c603e5e0ed0a5b2eba39ab631d..7a473ed18c958afa8be3c5b94b04d2fd548a56fd 100644 --- a/src/wal/test/waltest.c +++ b/src/wal/test/waltest.c @@ -37,7 +37,6 @@ int writeToQueue(void *pVnode, void *data, int type, void *pMsg) { int main(int argc, char *argv[]) { char path[128] = "/home/jhtao/test/wal"; - int max = 3; int level = 2; int total = 5; int rows = 10000; @@ -47,8 +46,6 @@ int main(int argc, char *argv[]) { for (int i=1; i