[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:
parent
0d09f6c0b6
commit
577962ed83
|
@ -73,7 +73,7 @@ static void dnodeAllocModules() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void dnodeCleanUpModules() {
|
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) {
|
if (tsModule[module].enable && tsModule[module].stopFp) {
|
||||||
(*tsModule[module].stopFp)();
|
(*tsModule[module].stopFp)();
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,10 +120,18 @@ void *dnodeAllocateWqueue(void *pVnode) {
|
||||||
|
|
||||||
if (pWorker->qset == NULL) {
|
if (pWorker->qset == NULL) {
|
||||||
pWorker->qset = taosOpenQset();
|
pWorker->qset = taosOpenQset();
|
||||||
if (pWorker->qset == NULL) return NULL;
|
if (pWorker->qset == NULL) {
|
||||||
|
taosCloseQueue(queue);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
taosAddIntoQset(pWorker->qset, queue, pVnode);
|
taosAddIntoQset(pWorker->qset, queue, pVnode);
|
||||||
pWorker->qall = taosAllocateQall();
|
pWorker->qall = taosAllocateQall();
|
||||||
|
if (pWorker->qall == NULL) {
|
||||||
|
taosCloseQset(pWorker->qset);
|
||||||
|
taosCloseQueue(queue);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
wWorkerPool.nextId = (wWorkerPool.nextId + 1) % wWorkerPool.max;
|
wWorkerPool.nextId = (wWorkerPool.nextId + 1) % wWorkerPool.max;
|
||||||
|
|
||||||
pthread_attr_t thAttr;
|
pthread_attr_t thAttr;
|
||||||
|
@ -132,7 +140,10 @@ void *dnodeAllocateWqueue(void *pVnode) {
|
||||||
|
|
||||||
if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessWriteQueue, pWorker) != 0) {
|
if (pthread_create(&pWorker->thread, &thAttr, dnodeProcessWriteQueue, pWorker) != 0) {
|
||||||
dError("failed to create thread to process read queue, reason:%s", strerror(errno));
|
dError("failed to create thread to process read queue, reason:%s", strerror(errno));
|
||||||
|
taosFreeQall(pWorker->qall);
|
||||||
taosCloseQset(pWorker->qset);
|
taosCloseQset(pWorker->qset);
|
||||||
|
taosCloseQueue(queue);
|
||||||
|
queue = NULL;
|
||||||
} else {
|
} else {
|
||||||
dTrace("write worker:%d is launched", pWorker->workerId);
|
dTrace("write worker:%d is launched", pWorker->workerId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,6 +176,9 @@ int32_t vnodeOpen(int32_t vnode, char *rootDir) {
|
||||||
pthread_once(&vnodeModuleInit, vnodeInit);
|
pthread_once(&vnodeModuleInit, vnodeInit);
|
||||||
|
|
||||||
SVnodeObj *pVnode = calloc(sizeof(SVnodeObj), 1);
|
SVnodeObj *pVnode = calloc(sizeof(SVnodeObj), 1);
|
||||||
|
if (pVnode == NULL) {
|
||||||
|
return TSDB_CODE_NO_RESOURCE;
|
||||||
|
}
|
||||||
pVnode->vgId = vnode;
|
pVnode->vgId = vnode;
|
||||||
pVnode->status = TAOS_VN_STATUS_INIT;
|
pVnode->status = TAOS_VN_STATUS_INIT;
|
||||||
pVnode->refCount = 1;
|
pVnode->refCount = 1;
|
||||||
|
|
Loading…
Reference in New Issue