dead lock after refact worker

This commit is contained in:
Shengliang Guan 2022-01-25 10:29:47 +00:00
parent 5690df9a07
commit 0797879022
3 changed files with 38 additions and 25 deletions

View File

@ -910,27 +910,27 @@ static int32_t dndInitVnodeWorkers(SDnode *pDnode) {
int32_t maxWriteThreads = TMAX(pDnode->env.numOfCores, 1); int32_t maxWriteThreads = TMAX(pDnode->env.numOfCores, 1);
int32_t maxSyncThreads = TMAX(pDnode->env.numOfCores / 2, 1); int32_t maxSyncThreads = TMAX(pDnode->env.numOfCores / 2, 1);
SQWorkerPool *pPool = &pMgmt->queryPool; SQWorkerPool *pQPool = &pMgmt->queryPool;
pPool->name = "vnode-query"; pQPool->name = "vnode-query";
pPool->min = minQueryThreads; pQPool->min = minQueryThreads;
pPool->max = maxQueryThreads; pQPool->max = maxQueryThreads;
if (tQWorkerInit(pPool) != 0) return -1; if (tQWorkerInit(pQPool) != 0) return -1;
pPool = &pMgmt->fetchPool; SFWorkerPool *pFPool = &pMgmt->fetchPool;
pPool->name = "vnode-fetch"; pFPool->name = "vnode-fetch";
pPool->min = minFetchThreads; pFPool->min = minFetchThreads;
pPool->max = maxFetchThreads; pFPool->max = maxFetchThreads;
if (tFWorkerInit(pPool) != 0) return -1; if (tFWorkerInit(pFPool) != 0) return -1;
SWWorkerPool *pMPool = &pMgmt->writePool; SWWorkerPool *pWPool = &pMgmt->writePool;
pMPool->name = "vnode-write"; pWPool->name = "vnode-write";
pMPool->max = maxWriteThreads; pWPool->max = maxWriteThreads;
if (tWWorkerInit(pMPool) != 0) return -1; if (tWWorkerInit(pWPool) != 0) return -1;
pMPool = &pMgmt->syncPool; pWPool = &pMgmt->syncPool;
pMPool->name = "vnode-sync"; pWPool->name = "vnode-sync";
pMPool->max = maxSyncThreads; pWPool->max = maxSyncThreads;
if (tWWorkerInit(pMPool) != 0) return -1; if (tWWorkerInit(pWPool) != 0) return -1;
dDebug("vnode workers is initialized"); dDebug("vnode workers is initialized");
return 0; return 0;

View File

@ -423,7 +423,9 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
queue->tail = NULL; queue->tail = NULL;
queue->numOfItems = 0; queue->numOfItems = 0;
atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems); atomic_sub_fetch_32(&qset->numOfItems, qall->numOfItems);
for (int32_t j = 1; j < qall->numOfItems; ++j) tsem_wait(&qset->sem); for (int32_t j = 1; j < qall->numOfItems; ++j) {
tsem_wait(&qset->sem);
}
} }
pthread_mutex_unlock(&queue->mutex); pthread_mutex_unlock(&queue->mutex);
@ -437,7 +439,7 @@ int32_t taosReadAllQitemsFromQset(STaosQset *qset, STaosQall *qall, void **ahand
int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **ahandle, FItem *itemFp, int32_t threadId) { int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **ahandle, FItem *itemFp, int32_t threadId) {
STaosQnode *pNode = NULL; STaosQnode *pNode = NULL;
int32_t code = 0; int32_t code = -1;
tsem_wait(&qset->sem); tsem_wait(&qset->sem);
@ -449,7 +451,10 @@ int32_t taosReadQitemFromQsetByThread(STaosQset *qset, void **ppItem, void **aha
if (queue) qset->current = queue->next; if (queue) qset->current = queue->next;
if (queue == NULL) break; if (queue == NULL) break;
if (queue->head == NULL) continue; if (queue->head == NULL) continue;
if (queue->threadId != -1 && queue->threadId != threadId) continue; if (queue->threadId != -1 && queue->threadId != threadId) {
code = 0;
continue;
}
pthread_mutex_lock(&queue->mutex); pthread_mutex_lock(&queue->mutex);
@ -485,6 +490,9 @@ void taosResetQsetThread(STaosQset *qset, void *pItem) {
pthread_mutex_lock(&qset->mutex); pthread_mutex_lock(&qset->mutex);
pNode->queue->threadId = -1; pNode->queue->threadId = -1;
for (int32_t i = 0; i < pNode->queue->numOfItems; ++i) {
tsem_post(&qset->sem);
}
pthread_mutex_unlock(&qset->mutex); pthread_mutex_unlock(&qset->mutex);
} }

View File

@ -149,8 +149,8 @@ void tFWorkerCleanup(SFWorkerPool *pool) { tQWorkerCleanup(pool); }
static void *tFWorkerThreadFp(SQWorker *worker) { static void *tFWorkerThreadFp(SQWorker *worker) {
SQWorkerPool *pool = worker->pool; SQWorkerPool *pool = worker->pool;
FItem fp = NULL;
FItem fp = NULL;
void * msg = NULL; void * msg = NULL;
void * ahandle = NULL; void * ahandle = NULL;
int32_t code = 0; int32_t code = 0;
@ -160,9 +160,14 @@ static void *tFWorkerThreadFp(SQWorker *worker) {
uDebug("worker:%s:%d is running", pool->name, worker->id); uDebug("worker:%s:%d is running", pool->name, worker->id);
while (1) { while (1) {
if (taosReadQitemFromQsetByThread(pool->qset, (void **)&msg, &ahandle, &fp, worker->id) == 0) { code = taosReadQitemFromQsetByThread(pool->qset, (void **)&msg, &ahandle, &fp, worker->id);
if (code < 0) {
uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, pool->qset); uDebug("worker:%s:%d qset:%p, got no message and exiting", pool->name, worker->id, pool->qset);
break; break;
} else if (code == 0) {
// uTrace("worker:%s:%d qset:%p, got no message and continue", pool->name, worker->id, pool->qset);
continue;
} }
if (fp != NULL) { if (fp != NULL) {
@ -231,7 +236,7 @@ void tWWorkerCleanup(SWWorkerPool *pool) {
uInfo("worker:%s is closed", pool->name); uInfo("worker:%s is closed", pool->name);
} }
static void *tWriteWorkerThreadFp(SWWorker *worker) { static void *tWWorkerThreadFp(SWWorker *worker) {
SWWorkerPool *pool = worker->pool; SWWorkerPool *pool = worker->pool;
FItems fp = NULL; FItems fp = NULL;
@ -293,7 +298,7 @@ STaosQueue *tWWorkerAllocQueue(SWWorkerPool *pool, void *ahandle, FItems fp) {
pthread_attr_init(&thAttr); pthread_attr_init(&thAttr);
pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE); pthread_attr_setdetachstate(&thAttr, PTHREAD_CREATE_JOINABLE);
if (pthread_create(&worker->thread, &thAttr, (ThreadFp)tWriteWorkerThreadFp, worker) != 0) { if (pthread_create(&worker->thread, &thAttr, (ThreadFp)tWWorkerThreadFp, worker) != 0) {
uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno)); uError("worker:%s:%d failed to create thread to process since %s", pool->name, worker->id, strerror(errno));
taosFreeQall(worker->qall); taosFreeQall(worker->qall);
taosCloseQset(worker->qset); taosCloseQset(worker->qset);