From e9d4948e84a4babe23c718947a97c294353095bd Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 12 Jul 2022 14:46:52 +0800 Subject: [PATCH] enh: transfer leader before close vnode and mnode --- include/dnode/mnode/mnode.h | 1 + source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 1 + source/dnode/mgmt/mgmt_vnode/src/vmInt.c | 4 +++- source/dnode/mnode/impl/src/mndMain.c | 6 ++++++ source/dnode/vnode/inc/vnode.h | 1 + source/dnode/vnode/src/vnd/vnodeOpen.c | 6 ++++++ 6 files changed, 18 insertions(+), 1 deletion(-) diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 70056783ea..3bed77d682 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -52,6 +52,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption); * @param pMnode The mnode object to close. */ void mndClose(SMnode *pMnode); +void mndPreClose(SMnode *pMnode); /** * @brief Start mnode diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 012e61d239..84491a82b0 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -150,6 +150,7 @@ static void mmStop(SMnodeMgmt *pMgmt) { dDebug("mnode-mgmt start to stop"); taosThreadRwlockWrlock(&pMgmt->lock); pMgmt->stopped = 1; + mndPreClose(pMgmt->pMnode); taosThreadRwlockUnlock(&pMgmt->lock); mndStop(pMgmt->pMnode); diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index 051e5defb0..eac9052289 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -75,11 +75,13 @@ int32_t vmOpenVnode(SVnodeMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) { void vmCloseVnode(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { char path[TSDB_FILENAME_LEN] = {0}; + vnodePreClose(pVnode->pImpl); + taosThreadRwlockWrlock(&pMgmt->lock); taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t)); taosThreadRwlockUnlock(&pMgmt->lock); - vmReleaseVnode(pMgmt, pVnode); + while (pVnode->refCount > 0) taosMsleep(10); dTrace("vgId:%d, wait for vnode queue is empty", pVnode->vgId); diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index 861aa82a93..df8dc42d17 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -366,6 +366,12 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { return pMnode; } +void mndPreClose(SMnode *pMnode) { + if (pMnode != NULL) { + syncLeaderTransfer(pMnode->syncMgmt.sync); + } +} + void mndClose(SMnode *pMnode) { if (pMnode != NULL) { mDebug("start to close mnode"); diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index bba4bdb2b1..8f2d3bde09 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -51,6 +51,7 @@ void vnodeCleanup(); int32_t vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs); void vnodeDestroy(const char *path, STfs *pTfs); SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb); +void vnodePreClose(SVnode *pVnode); void vnodeClose(SVnode *pVnode); int32_t vnodeStart(SVnode *pVnode); diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index cf95040585..0914827950 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -175,6 +175,12 @@ _err: return NULL; } +void vnodePreClose(SVnode *pVnode) { + if (pVnode) { + syncLeaderTransfer(pVnode->sync); + } +} + void vnodeClose(SVnode *pVnode) { if (pVnode) { vnodeCommit(pVnode);