fix(stream): add lock, and fix race condition.
This commit is contained in:
parent
f23a8a37bc
commit
e261023ee6
|
@ -501,6 +501,10 @@ int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, b
|
|||
}
|
||||
|
||||
// extract the required source task for a given stream, identified by streamId
|
||||
streamMetaRLock(pMeta);
|
||||
|
||||
numOfTasks = taosArrayGetSize(pMeta->pTaskList);
|
||||
|
||||
for (int32_t i = 0; i < numOfTasks; ++i) {
|
||||
STaskId* pId = taosArrayGet(pMeta->pTaskList, i);
|
||||
if (pId->streamId != streamId) {
|
||||
|
@ -552,5 +556,7 @@ int32_t tqGetStreamExecInfo(SVnode* pVnode, int64_t streamId, int64_t* pDelay, b
|
|||
walCloseReader(pReader);
|
||||
}
|
||||
|
||||
streamMetaRUnLock(pMeta);
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -733,15 +733,12 @@ bool streamTaskIsAllUpstreamClosed(SStreamTask* pTask) {
|
|||
bool streamTaskSetSchedStatusWait(SStreamTask* pTask) {
|
||||
bool ret = false;
|
||||
|
||||
// double check
|
||||
taosThreadMutexLock(&pTask->lock);
|
||||
if (pTask->status.schedStatus == TASK_SCHED_STATUS__INACTIVE) {
|
||||
taosThreadMutexLock(&pTask->lock);
|
||||
if (pTask->status.schedStatus == TASK_SCHED_STATUS__INACTIVE) {
|
||||
pTask->status.schedStatus = TASK_SCHED_STATUS__WAITING;
|
||||
ret = true;
|
||||
}
|
||||
taosThreadMutexUnlock(&pTask->lock);
|
||||
pTask->status.schedStatus = TASK_SCHED_STATUS__WAITING;
|
||||
ret = true;
|
||||
}
|
||||
taosThreadMutexUnlock(&pTask->lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue