[Dnode / Vnode] More error handling.

This patch adds more error handling code:
1. In dnodeAllocateWqueue(), if the allocation of pWorker fails, any
allocated memory should be unwound and returns a NULL queue. This is
a better function contract where either all allocation succeeds or none
succeeds.
2. In vnodeOpen(), handle allocation failure for pVnode.
This commit is contained in:
yifan hao 2020-05-04 23:25:08 -06:00
parent 0d09f6c0b6
commit 577962ed83
3 changed files with 34 additions and 20 deletions

View File

@ -73,7 +73,7 @@ static void dnodeAllocModules() {
}
void dnodeCleanUpModules() {
for (int32_t module = 1; module < TSDB_MOD_MAX; ++module) {
for (EModuleType module = 1; module < TSDB_MOD_MAX; ++module) {
if (tsModule[module].enable && tsModule[module].stopFp) {
(*tsModule[module].stopFp)();
}

View File

@ -120,10 +120,18 @@ void *dnodeAllocateWqueue(void *pVnode) {
if (pWorker->qset == NULL) {
pWorker->qset = taosOpenQset();
if (pWorker->qset == NULL) return NULL;
if (pWorker->qset == NULL) {
taosCloseQueue(queue);
return NULL;
}
taosAddIntoQset(pWorker->qset, queue, pVnode);
pWorker->qall = taosAllocateQall();
if (pWorker->qall == NULL) {
taosCloseQset(pWorker->qset);
taosCloseQueue(queue);
return NULL;
}
wWorkerPool.nextId = (wWorkerPool.nextId + 1) % wWorkerPool.max;
pthread_attr_t thAttr;
@ -132,7 +140,10 @@ void *dnodeAllocateWqueue(void *pVnode) {
if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessWriteQueue, pWorker) != 0) {
dError("failed to create thread to process read queue, reason:%s", strerror(errno));
taosFreeQall(pWorker->qall);
taosCloseQset(pWorker->qset);
taosCloseQueue(queue);
queue = NULL;
} else {
dTrace("write worker:%d is launched", pWorker->workerId);
}

View File

@ -176,6 +176,9 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
pthread_once(&vnodeModuleInit, vnodeInit);
SVnodeObj *pVnode = calloc(sizeof(SVnodeObj), 1);
if (pVnode == NULL) {
return TSDB_CODE_NO_RESOURCE;
}
pVnode->vgId = vnode;
pVnode->status = TAOS_VN_STATUS_INIT;
pVnode->refCount = 1;