提交 a67c3fd1 编写于 作者: Y Yifan Hao

Handle memory allocation failure when open vnode

This patch fixes a few error handling of memory allocation
failure while opening vnodes.

bonus fix: also add a new error code to indicate failure
of opening vnode. Before the patch, the function would simply
return -1 when vnode open fails.
上级 f00cf118
......@@ -127,9 +127,20 @@ int32_t dnodeInitVnodes() {
int32_t threadNum = tsNumOfCores;
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
SOpenVnodeThread *threads = calloc(threadNum, sizeof(SOpenVnodeThread));
if (threads == NULL) {
return TSDB_CODE_DND_OUT_OF_MEMORY;
}
for (int32_t t = 0; t < threadNum; ++t) {
threads[t].threadIndex = t;
threads[t].vnodeList = calloc(vnodesPerThread, sizeof(int32_t));
if (threads[t].vnodeList == NULL) {
dError("vnodeList allocation failed");
status = TSDB_CODE_DND_OUT_OF_MEMORY;
goto DNODE_INIT_VNODES_OUT;
}
}
for (int32_t v = 0; v < numOfVnodes; ++v) {
......@@ -163,18 +174,24 @@ int32_t dnodeInitVnodes() {
}
openVnodes += pThread->opened;
failedVnodes += pThread->failed;
free(pThread->vnodeList);
}
free(threads);
dInfo("there are total vnodes:%d, opened:%d", numOfVnodes, openVnodes);
if (failedVnodes != 0) {
dError("there are total vnodes:%d, failed:%d", numOfVnodes, failedVnodes);
return -1;
status = TSDB_CODE_DND_VNODE_OPEN_FAILED;
}
return TSDB_CODE_SUCCESS;
DNODE_INIT_VNODES_OUT:
for (int32_t t = 0; t < threadNum; ++t) {
SOpenVnodeThread *pThread = &threads[t];
free(pThread->vnodeList);
}
free(threads);
return status;
}
void dnodeCleanupVnodes() {
......
......@@ -224,6 +224,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_DND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0404) //"Action in progress")
#define TSDB_CODE_DND_TOO_MANY_VNODES TAOS_DEF_ERROR_CODE(0, 0x0405) //"Too many vnode directories")
#define TSDB_CODE_DND_EXITING TAOS_DEF_ERROR_CODE(0, 0x0406) //"Dnode is exiting"
#define TSDB_CODE_DND_VNODE_OPEN_FAILED TAOS_DEF_ERROR_CODE(0, 0x0407) //"Vnode open failed
// vnode
#define TSDB_CODE_VND_ACTION_IN_PROGRESS TAOS_DEF_ERROR_CODE(0, 0x0500) //"Action in progress")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册