提交 32bdf913 编写于 作者: J Jeff Tao

add one more parameter in walCfg

keep the wal file when it is closed
上级 3f8a10d9
...@@ -368,6 +368,7 @@ static int32_t vnodeReadCfg(SVnodeObj *pVnode) { ...@@ -368,6 +368,7 @@ static int32_t vnodeReadCfg(SVnodeObj *pVnode) {
if (strcmp(option[0], "wals") != 0) return TSDB_CODE_INVALID_FILE_FORMAT; if (strcmp(option[0], "wals") != 0) return TSDB_CODE_INVALID_FILE_FORMAT;
if (wals == -1) return TSDB_CODE_INVALID_FILE_FORMAT; if (wals == -1) return TSDB_CODE_INVALID_FILE_FORMAT;
pVnode->walCfg.wals = (int8_t)wals; pVnode->walCfg.wals = (int8_t)wals;
pVnode->walCfg.keep = 0;
int32_t arbitratorIp = -1; int32_t arbitratorIp = -1;
num = fscanf(fp, "%s %u", option[0], &arbitratorIp); num = fscanf(fp, "%s %u", option[0], &arbitratorIp);
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
typedef struct { typedef struct {
int fd; int fd;
int keep;
int level; int level;
int max; // maximum number of wal files int max; // maximum number of wal files
uint32_t id; // increase continuously uint32_t id; // increase continuously
...@@ -61,6 +62,7 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { ...@@ -61,6 +62,7 @@ void *walOpen(const char *path, const SWalCfg *pCfg) {
pWal->id = 0; pWal->id = 0;
pWal->num = 0; pWal->num = 0;
pWal->level = pCfg->commitLog; pWal->level = pCfg->commitLog;
pWal->keep = pCfg->keep;
strcpy(pWal->path, path); strcpy(pWal->path, path);
pthread_mutex_init(&pWal->mutex, NULL); pthread_mutex_init(&pWal->mutex, NULL);
...@@ -82,18 +84,21 @@ void *walOpen(const char *path, const SWalCfg *pCfg) { ...@@ -82,18 +84,21 @@ void *walOpen(const char *path, const SWalCfg *pCfg) {
void walClose(void *handle) { void walClose(void *handle) {
if (handle == NULL) return; if (handle == NULL) return;
SWal *pWal = handle; SWal *pWal = handle;
close(pWal->fd); close(pWal->fd);
// remove all files in the directory if (pWal->keep == 0) {
for (int i=0; i<pWal->num; ++i) { // remove all files in the directory
sprintf(pWal->name, "%s/%s%d", pWal->path, walPrefix, pWal->id-i); for (int i=0; i<pWal->num; ++i) {
if (remove(pWal->name) <0) { sprintf(pWal->name, "%s/%s%d", pWal->path, walPrefix, pWal->id-i);
wError("wal:%s, failed to remove", pWal->name); if (remove(pWal->name) <0) {
} else { wError("wal:%s, failed to remove", pWal->name);
wTrace("wal:%s, it is removed", 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); pthread_mutex_destroy(&pWal->mutex);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册