diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 9117ab03af539605838192dbadda04d6e157fff9..eb43fba0798085d84c793a145b082325e6d56a15 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -416,15 +416,12 @@ void vnodeDestroy(SVnodeObj *pVnode) { } void vnodeCleanUp(SVnodeObj *pVnode) { - if (!vnodeInInitStatus(pVnode)) { - // it may be in updateing or reset state, then it shall wait - int32_t i = 0; - while (!vnodeSetClosingStatus(pVnode)) { - if (++i % 1000 == 0) { - sched_yield(); - } - } - } + vDebug("vgId:%d, vnode will cleanup, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode); + + vnodeSetClosingStatus(pVnode); + + // release local resources only after cutting off outside connections + qQueryMgmtNotifyClosed(pVnode->qMgmt); // stop replication module if (pVnode->sync > 0) { @@ -433,10 +430,7 @@ void vnodeCleanUp(SVnodeObj *pVnode) { syncStop(sync); } - vDebug("vgId:%d, vnode will cleanup, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode); - - // release local resources only after cutting off outside connections - qQueryMgmtNotifyClosed(pVnode->qMgmt); + vDebug("vgId:%d, vnode is cleaned, refCount:%d pVnode:%p", pVnode->vgId, pVnode->refCount, pVnode); vnodeRelease(pVnode); } diff --git a/src/vnode/src/vnodeStatus.c b/src/vnode/src/vnodeStatus.c index d09a6a86631837db6799aca5b4df87ae22e07853..76618ffca792f02a0e47addb9dd9494348cc04f5 100644 --- a/src/vnode/src/vnodeStatus.c +++ b/src/vnode/src/vnodeStatus.c @@ -15,6 +15,8 @@ #define _DEFAULT_SOURCE #include "os.h" +#include "taosmsg.h" +#include "query.h" #include "vnodeStatus.h" char* vnodeStatus[] = { @@ -44,11 +46,13 @@ bool vnodeSetReadyStatus(SVnodeObj* pVnode) { vDebug("vgId:%d, cannot set status:ready, old:%s", pVnode->vgId, vnodeStatus[pVnode->status]); } + qQueryMgmtReOpen(pVnode->qMgmt); + pthread_mutex_unlock(&pVnode->statusMutex); return set; } -bool vnodeSetClosingStatus(SVnodeObj* pVnode) { +static bool vnodeSetClosingStatusImp(SVnodeObj* pVnode) { bool set = false; pthread_mutex_lock(&pVnode->statusMutex); @@ -63,6 +67,20 @@ bool vnodeSetClosingStatus(SVnodeObj* pVnode) { return set; } +bool vnodeSetClosingStatus(SVnodeObj* pVnode) { + if (!vnodeInInitStatus(pVnode)) { + // it may be in updating or reset state, then it shall wait + int32_t i = 0; + while (!vnodeSetClosingStatusImp(pVnode)) { + if (++i % 1000 == 0) { + sched_yield(); + } + } + } + + return true; +} + bool vnodeSetUpdatingStatus(SVnodeObj* pVnode) { bool set = false; pthread_mutex_lock(&pVnode->statusMutex);