提交 353109cd 编写于 作者: S Shengliang Guan

fix: deadlock of vnode if its state changed

上级 4f905782
......@@ -308,7 +308,7 @@ struct SVnode {
SSink* pSink;
tsem_t canCommit;
int64_t sync;
SRWLatch lock;
TdThreadMutex lock;
bool blocked;
bool restored;
tsem_t syncSem;
......
......@@ -28,14 +28,14 @@ static inline bool vnodeIsMsgWeak(tmsg_t type) { return false; }
static inline void vnodeWaitBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) {
if (vnodeIsMsgBlock(pMsg->msgType)) {
const STraceId *trace = &pMsg->info.traceId;
taosWLockLatch(&pVnode->lock);
taosThreadMutexLock(&pVnode->lock);
if (!pVnode->blocked) {
vGTrace("vgId:%d, msg:%p wait block, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
pVnode->blocked = true;
taosWUnLockLatch(&pVnode->lock);
taosThreadMutexUnlock(&pVnode->lock);
tsem_wait(&pVnode->syncSem);
} else {
taosWUnLockLatch(&pVnode->lock);
taosThreadMutexUnlock(&pVnode->lock);
}
}
}
......@@ -43,13 +43,13 @@ static inline void vnodeWaitBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) {
static inline void vnodePostBlockMsg(SVnode *pVnode, const SRpcMsg *pMsg) {
if (vnodeIsMsgBlock(pMsg->msgType)) {
const STraceId *trace = &pMsg->info.traceId;
taosWLockLatch(&pVnode->lock);
taosThreadMutexLock(&pVnode->lock);
if (pVnode->blocked) {
vGTrace("vgId:%d, msg:%p post block, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
pVnode->blocked = false;
tsem_post(&pVnode->syncSem);
}
taosWUnLockLatch(&pVnode->lock);
taosThreadMutexUnlock(&pVnode->lock);
}
}
......@@ -685,12 +685,12 @@ static void vnodeBecomeFollower(struct SSyncFSM *pFsm) {
vDebug("vgId:%d, become follower", pVnode->config.vgId);
// clear old leader resource
taosWLockLatch(&pVnode->lock);
taosThreadMutexLock(&pVnode->lock);
if (pVnode->blocked) {
pVnode->blocked = false;
tsem_post(&pVnode->syncSem);
}
taosWUnLockLatch(&pVnode->lock);
taosThreadMutexUnlock(&pVnode->lock);
}
static void vnodeBecomeLeader(struct SSyncFSM *pFsm) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册