diff --git a/src/inc/twal.h b/src/inc/twal.h index 94bdcacfce69e63f3bb1775f47a06c702f587c10..3a229ed8350624e1c69772abbe9b2f30ac232b80 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 2dfa4962a21fa95ea2a83bca2399b9f3efa382b1..8c53c6629bd2eeeec82e3ab1d08dd82596a37cf5 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 7e731d44db8506cead8d052ae8ce2476a207c86e..0bdaf64d058356492df1937f9d50b88da1f3f321 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 272f44b93af90ec3946433373399f65bc85f8b38..346e3fe5b85ca11317f053df94fb8920a1c1a520 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 00dc3f474427b3669d4504ed5eeffcba95b64009..214642cdf45ba7ab4c9435f12d42db68be09f84c 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