提交 12633aa2 编写于 作者: S Shengliang Guan

[TD-993] add error code of "cluster not ready"

上级 45ec0df6
...@@ -142,9 +142,14 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) { ...@@ -142,9 +142,14 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
if (vnodes != pVgroup->numOfVnodes) { if (vnodes != pVgroup->numOfVnodes) {
mDebug("vgId:%d, db:%s need vnodes:%d, but alloc:%d, free them", pVgroup->vgId, pVgroup->dbName, mDebug("vgId:%d, db:%s need vnodes:%d, but alloc:%d, free them", pVgroup->vgId, pVgroup->dbName,
pVgroup->numOfVnodes, vnodes); pVgroup->numOfVnodes, vnodes);
balanceReleaseDnodeList(); balanceReleaseDnodeList();
balanceUnLock(); balanceUnLock();
return -1;
if (mnodeGetOnlineDnodesNum() == 0) {
return TSDB_CODE_MND_NOT_READY;
} else {
return TSDB_CODE_MND_NO_ENOUGH_DNODES;
}
} }
/* /*
...@@ -179,7 +184,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) { ...@@ -179,7 +184,7 @@ int32_t balanceAllocVnodes(SVgObj *pVgroup) {
balanceReleaseDnodeList(); balanceReleaseDnodeList();
balanceUnLock(); balanceUnLock();
return 0; return TSDB_CODE_SUCCESS;
} }
static bool balanceCheckVgroupReady(SVgObj *pVgroup, SVnodeGid *pRmVnode) { static bool balanceCheckVgroupReady(SVgObj *pVgroup, SVnodeGid *pRmVnode) {
......
...@@ -132,6 +132,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_IN_DNODE, 0, 0x0338, "vgroup not ...@@ -132,6 +132,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_NOT_IN_DNODE, 0, 0x0338, "vgroup not
TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE, 0, 0x0339, "vgroup already in dnode") TAOS_DEFINE_ERROR(TSDB_CODE_MND_VGROUP_ALREADY_IN_DNODE, 0, 0x0339, "vgroup already in dnode")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_FREE, 0, 0x033A, "dnode not avaliable") TAOS_DEFINE_ERROR(TSDB_CODE_MND_DNODE_NOT_FREE, 0, 0x033A, "dnode not avaliable")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CLUSTER_ID, 0, 0x033B, "cluster id not match") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_CLUSTER_ID, 0, 0x033B, "cluster id not match")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_NOT_READY, 0, 0x033C, "cluster not ready")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist") TAOS_DEFINE_ERROR(TSDB_CODE_MND_ACCT_ALREADY_EXIST, 0, 0x0340, "mnode accounts already exist")
TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account") TAOS_DEFINE_ERROR(TSDB_CODE_MND_INVALID_ACCT, 0, 0x0341, "mnode invalid account")
......
...@@ -41,7 +41,7 @@ void mgmtMonitorDnodeModule(); ...@@ -41,7 +41,7 @@ void mgmtMonitorDnodeModule();
int32_t mnodeGetDnodesNum(); int32_t mnodeGetDnodesNum();
int32_t mnodeGetOnlinDnodesCpuCoreNum(); int32_t mnodeGetOnlinDnodesCpuCoreNum();
int32_t mnodeGetOnlinDnodesNum(); int32_t mnodeGetOnlineDnodesNum();
void * mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode); void * mnodeGetNextDnode(void *pIter, SDnodeObj **pDnode);
void mnodeIncDnodeRef(SDnodeObj *pDnode); void mnodeIncDnodeRef(SDnodeObj *pDnode);
void mnodeDecDnodeRef(SDnodeObj *pDnode); void mnodeDecDnodeRef(SDnodeObj *pDnode);
......
...@@ -206,7 +206,7 @@ int32_t mnodeGetOnlinDnodesCpuCoreNum() { ...@@ -206,7 +206,7 @@ int32_t mnodeGetOnlinDnodesCpuCoreNum() {
return cpuCores; return cpuCores;
} }
int32_t mnodeGetOnlinDnodesNum() { int32_t mnodeGetOnlineDnodesNum() {
SDnodeObj *pDnode = NULL; SDnodeObj *pDnode = NULL;
void * pIter = NULL; void * pIter = NULL;
int32_t onlineDnodes = 0; int32_t onlineDnodes = 0;
......
...@@ -270,7 +270,7 @@ static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { ...@@ -270,7 +270,7 @@ static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) {
} }
} }
pHBRsp->onlineDnodes = htonl(mnodeGetOnlinDnodesNum()); pHBRsp->onlineDnodes = htonl(mnodeGetOnlineDnodesNum());
pHBRsp->totalDnodes = htonl(mnodeGetDnodesNum()); pHBRsp->totalDnodes = htonl(mnodeGetDnodesNum());
mnodeGetMnodeEpSetForShell(&pHBRsp->epSet); mnodeGetMnodeEpSetForShell(&pHBRsp->epSet);
......
...@@ -434,11 +434,12 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi ...@@ -434,11 +434,12 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
maxVgroupsPerDb = MAX(maxVgroupsPerDb, 2); maxVgroupsPerDb = MAX(maxVgroupsPerDb, 2);
} }
int32_t code = TSDB_CODE_MND_NO_ENOUGH_DNODES;
if (pDb->numOfVgroups < maxVgroupsPerDb) { if (pDb->numOfVgroups < maxVgroupsPerDb) {
mDebug("app:%p:%p, db:%s, try to create a new vgroup, numOfVgroups:%d maxVgroupsPerDb:%d", pMsg->rpcMsg.ahandle, mDebug("app:%p:%p, db:%s, try to create a new vgroup, numOfVgroups:%d maxVgroupsPerDb:%d", pMsg->rpcMsg.ahandle,
pMsg, pDb->name, pDb->numOfVgroups, maxVgroupsPerDb); pMsg, pDb->name, pDb->numOfVgroups, maxVgroupsPerDb);
pthread_mutex_unlock(&pDb->mutex); pthread_mutex_unlock(&pDb->mutex);
int32_t code = mnodeCreateVgroup(pMsg); code = mnodeCreateVgroup(pMsg);
if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code == TSDB_CODE_MND_ACTION_IN_PROGRESS) {
return code; return code;
} else { } else {
...@@ -449,10 +450,10 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi ...@@ -449,10 +450,10 @@ int32_t mnodeGetAvailableVgroup(SMnodeMsg *pMsg, SVgObj **ppVgroup, int32_t *pSi
SVgObj *pVgroup = pDb->vgList[0]; SVgObj *pVgroup = pDb->vgList[0];
if (pVgroup == NULL) { if (pVgroup == NULL) {
pthread_mutex_unlock(&pDb->mutex); pthread_mutex_unlock(&pDb->mutex);
return TSDB_CODE_MND_NO_ENOUGH_DNODES; return code;
} }
int32_t code = mnodeAllocVgroupIdPool(pVgroup); code = mnodeAllocVgroupIdPool(pVgroup);
if (code != TSDB_CODE_SUCCESS) { if (code != TSDB_CODE_SUCCESS) {
pthread_mutex_unlock(&pDb->mutex); pthread_mutex_unlock(&pDb->mutex);
return code; return code;
...@@ -529,10 +530,12 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) { ...@@ -529,10 +530,12 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) {
pVgroup->numOfVnodes = pDb->cfg.replications; pVgroup->numOfVnodes = pDb->cfg.replications;
pVgroup->createdTime = taosGetTimestampMs(); pVgroup->createdTime = taosGetTimestampMs();
pVgroup->accessState = TSDB_VN_ALL_ACCCESS; pVgroup->accessState = TSDB_VN_ALL_ACCCESS;
if (balanceAllocVnodes(pVgroup) != 0) { int32_t code = balanceAllocVnodes(pVgroup);
mError("db:%s, no enough dnode to alloc %d vnodes to vgroup", pDb->name, pVgroup->numOfVnodes); if (code != TSDB_CODE_SUCCESS) {
mError("db:%s, no enough dnode to alloc %d vnodes to vgroup, reason:%s", pDb->name, pVgroup->numOfVnodes,
tstrerror(code));
free(pVgroup); free(pVgroup);
return TSDB_CODE_MND_NO_ENOUGH_DNODES; return code;
} }
if (pMsg->pVgroup != NULL) { if (pMsg->pVgroup != NULL) {
...@@ -551,7 +554,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) { ...@@ -551,7 +554,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg) {
.reqFp = mnodeCreateVgroupFp .reqFp = mnodeCreateVgroupFp
}; };
int32_t code = sdbInsertRow(&oper); code = sdbInsertRow(&oper);
if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) {
pMsg->pVgroup = NULL; pMsg->pVgroup = NULL;
mnodeDestroyVgroup(pVgroup); mnodeDestroyVgroup(pVgroup);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册