diff --git a/src/vnode/main/src/vnodeMain.c b/src/vnode/main/src/vnodeMain.c index 210063ecf5eac89c9d29cddeb181af8556364f89..ea7a003d3d8836105e390e26e7d2c6a66bfe8f54 100644 --- a/src/vnode/main/src/vnodeMain.c +++ b/src/vnode/main/src/vnodeMain.c @@ -368,6 +368,7 @@ static int32_t vnodeReadCfg(SVnodeObj *pVnode) { if (strcmp(option[0], "wals") != 0) return TSDB_CODE_INVALID_FILE_FORMAT; if (wals == -1) return TSDB_CODE_INVALID_FILE_FORMAT; pVnode->walCfg.wals = (int8_t)wals; + pVnode->walCfg.keep = 0; int32_t arbitratorIp = -1; num = fscanf(fp, "%s %u", option[0], &arbitratorIp); diff --git a/src/vnode/wal/src/walMain.c b/src/vnode/wal/src/walMain.c index e799bfd63a1c049bf7a7b5de06ea767266460708..edca4e371cdbc09cfe98f26e7b7972348c1e8098 100644 --- a/src/vnode/wal/src/walMain.c +++ b/src/vnode/wal/src/walMain.c @@ -36,6 +36,7 @@ typedef struct { int fd; + int keep; int level; int max; // maximum number of wal files uint32_t id; // increase continuously @@ -61,6 +62,7 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { pWal->id = 0; pWal->num = 0; pWal->level = pCfg->commitLog; + pWal->keep = pCfg->keep; strcpy(pWal->path, path); pthread_mutex_init(&pWal->mutex, NULL); @@ -82,18 +84,21 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { void walClose(void *handle) { if (handle == NULL) return; - SWal *pWal = handle; - + SWal *pWal = handle; close(pWal->fd); - // remove all files in the directory - for (int i=0; inum; ++i) { - sprintf(pWal->name, "%s/%s%d", pWal->path, walPrefix, pWal->id-i); - if (remove(pWal->name) <0) { - wError("wal:%s, failed to remove", pWal->name); - } else { - wTrace("wal:%s, it is removed", pWal->name); + if (pWal->keep == 0) { + // remove all files in the directory + for (int i=0; inum; ++i) { + sprintf(pWal->name, "%s/%s%d", pWal->path, walPrefix, pWal->id-i); + if (remove(pWal->name) <0) { + wError("wal:%s, failed to remove", pWal->name); + } else { + wTrace("wal:%s, it is removed", pWal->name); + } } + } else { + wTrace("wal:%s, it is closed and kept", pWal->name); } pthread_mutex_destroy(&pWal->mutex);