From a1f2ad0daee8ff120dc3965e0eb40fe3b707a880 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 3 Nov 2020 15:27:25 +0800 Subject: [PATCH] TD-1894 --- src/inc/twal.h | 1 + src/vnode/src/vnodeMain.c | 4 ++++ src/wal/inc/walInt.h | 1 + src/wal/src/walMgmt.c | 10 ++++++++++ src/wal/src/walWrite.c | 7 ++++++- 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/inc/twal.h b/src/inc/twal.h index 94bdcacfce..3a229ed835 100644 --- a/src/inc/twal.h +++ b/src/inc/twal.h @@ -51,6 +51,7 @@ void walCleanUp(); twalh walOpen(char *path, SWalCfg *pCfg); int32_t walAlter(twalh pWal, SWalCfg *pCfg); +void walStop(twalh); void walClose(twalh); int32_t walRenew(twalh); int32_t walWrite(twalh, SWalHead *); diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 2dfa4962a2..8c53c6629b 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -386,6 +386,10 @@ void vnodeRelease(void *pVnodeRaw) { pVnode->qMgmt = NULL; } + if (pVnode->wal) { + walStop(pVnode->wal); + } + if (pVnode->tsdb) { tsdbCloseRepo(pVnode->tsdb, 1); pVnode->tsdb = NULL; diff --git a/src/wal/inc/walInt.h b/src/wal/inc/walInt.h index 7e731d44db..0bdaf64d05 100644 --- a/src/wal/inc/walInt.h +++ b/src/wal/inc/walInt.h @@ -49,6 +49,7 @@ typedef struct { int32_t level; int32_t fsyncPeriod; int32_t fsyncSeq; + int8_t stop; char path[WAL_PATH_LEN]; char name[WAL_FILE_LEN]; pthread_mutex_t mutex; diff --git a/src/wal/src/walMgmt.c b/src/wal/src/walMgmt.c index 272f44b93a..346e3fe5b8 100644 --- a/src/wal/src/walMgmt.c +++ b/src/wal/src/walMgmt.c @@ -110,6 +110,16 @@ int32_t walAlter(void *handle, SWalCfg *pCfg) { return TSDB_CODE_SUCCESS; } +void walStop(void *handle) { + if (handle == NULL) return; + SWal *pWal = handle; + + pthread_mutex_lock(&pWal->mutex); + pWal->stop = 1; + pthread_mutex_unlock(&pWal->mutex); + wDebug("vgId:%d, stop write wal", pWal->vgId); +} + void walClose(void *handle) { if (handle == NULL) return; diff --git a/src/wal/src/walWrite.c b/src/wal/src/walWrite.c index 00dc3f4744..214642cdf4 100644 --- a/src/wal/src/walWrite.c +++ b/src/wal/src/walWrite.c @@ -29,6 +29,11 @@ int32_t walRenew(void *handle) { SWal * pWal = handle; int32_t code = 0; + if (pWal->stop) { + wDebug("vgId:%d, do not create a new wal file", pWal->vgId); + return 0; + } + pthread_mutex_lock(&pWal->mutex); if (pWal->fd >= 0) { @@ -151,7 +156,7 @@ int32_t walRestore(void *handle, void *pVnode, int32_t (*writeFp)(void *, void * if (!pWal->keep) return TSDB_CODE_SUCCESS; if (count == 0) { - wDebug("vgId:%d, file:%s not exist, renew it", pWal->vgId, pWal->name); + wDebug("vgId:%d, wal file not exist, renew it", pWal->vgId); return walRenew(pWal); } else { // open the existing WAL file in append mode -- GitLab