提交 115d67e0 编写于 作者: S slguan

TBASE-1442 #1025

上级 14111fbd
...@@ -91,7 +91,7 @@ extern "C" { ...@@ -91,7 +91,7 @@ extern "C" {
#define TSDB_CODE_INVALID_QHANDLE 70 #define TSDB_CODE_INVALID_QHANDLE 70
#define TSDB_CODE_RELATED_TABLES_EXIST 71 #define TSDB_CODE_RELATED_TABLES_EXIST 71
#define TSDB_CODE_MONITOR_DB_FORBEIDDEN 72 #define TSDB_CODE_MONITOR_DB_FORBEIDDEN 72
#define TSDB_CODE_VG_COMMITLOG_INIT_FAILED 73 #define TSDB_CODE_NO_DISK_PERMISSIONS 73
#define TSDB_CODE_VG_INIT_FAILED 74 #define TSDB_CODE_VG_INIT_FAILED 74
#define TSDB_CODE_DATA_ALREADY_IMPORTED 75 #define TSDB_CODE_DATA_ALREADY_IMPORTED 75
#define TSDB_CODE_OPS_NOT_SUPPORT 76 #define TSDB_CODE_OPS_NOT_SUPPORT 76
......
...@@ -16,16 +16,20 @@ ...@@ -16,16 +16,20 @@
#ifndef TDENGINE_TSTATUS_H #ifndef TDENGINE_TSTATUS_H
#define TDENGINE_TSTATUS_H #define TDENGINE_TSTATUS_H
#include "taoserror.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
enum _TSDB_VG_STATUS { enum _TSDB_VG_STATUS {
TSDB_VG_STATUS_READY, TSDB_VG_STATUS_READY = TSDB_CODE_SUCCESS,
TSDB_VG_STATUS_IN_PROGRESS, TSDB_VG_STATUS_IN_PROGRESS = TSDB_CODE_ACTION_IN_PROGRESS,
TSDB_VG_STATUS_COMMITLOG_INIT_FAILED, TSDB_VG_STATUS_NO_DISK_PERMISSIONS = TSDB_CODE_NO_DISK_PERMISSIONS,
TSDB_VG_STATUS_INIT_FAILED, TSDB_VG_STATUS_SERVER_NO_PACE = TSDB_CODE_SERVER_NO_SPACE,
TSDB_VG_STATUS_FULL TSDB_VG_STATUS_SERV_OUT_OF_MEMORY = TSDB_CODE_SERV_OUT_OF_MEMORY,
TSDB_VG_STATUS_INIT_FAILED = TSDB_CODE_VG_INIT_FAILED,
TSDB_VG_STATUS_FULL = TSDB_CODE_NO_ENOUGH_DNODES,
}; };
enum _TSDB_DB_STATUS { enum _TSDB_DB_STATUS {
......
...@@ -197,7 +197,7 @@ char *tsError[] = {"success", ...@@ -197,7 +197,7 @@ char *tsError[] = {"success",
"invalid query handle", // 70 "invalid query handle", // 70
"tables related to metric exist", "tables related to metric exist",
"can't drop monitor database or tables", "can't drop monitor database or tables",
"commit log init failed", "no disk permissions",
"vgroup init failed", "vgroup init failed",
"data is already imported", // 75 "data is already imported", // 75
"not supported operation", "not supported operation",
...@@ -234,7 +234,7 @@ char *tsError[] = {"success", ...@@ -234,7 +234,7 @@ char *tsError[] = {"success",
"timestamp disordered in cache block", "timestamp disordered in cache block",
"timestamp disordered in file block", "timestamp disordered in file block",
"invalid commit log", "invalid commit log",
"server no disk space", //110 "no disk space on server", //110
"only super table has metric meta info", "only super table has metric meta info",
"tags value not unique for join", "tags value not unique for join",
"invalid submit message", "invalid submit message",
......
...@@ -152,19 +152,15 @@ int mgmtProcessVPeersRsp(char *msg, int msgLen, SDnodeObj *pObj) { ...@@ -152,19 +152,15 @@ int mgmtProcessVPeersRsp(char *msg, int msgLen, SDnodeObj *pObj) {
return 0; return 0;
} }
if (pRsp->code == 0) { if (pRsp->code == TSDB_CODE_SUCCESS) {
pDb->vgStatus = TSDB_VG_STATUS_READY; pDb->vgStatus = TSDB_VG_STATUS_READY;
mTrace("dnode:%s, db:%s vgroup is created in dnode", taosIpStr(pObj->privateIp), pRsp->more); mTrace("dnode:%s, db:%s vgroup is created in dnode", taosIpStr(pObj->privateIp), pRsp->more);
return 0; return 0;
} }
if (pRsp->code == TSDB_CODE_VG_COMMITLOG_INIT_FAILED) { pDb->vgStatus = pRsp->code;
pDb->vgStatus = TSDB_VG_STATUS_COMMITLOG_INIT_FAILED; mError("dnode:%s, db:%s vgroup init failed, code:%d %s",
mError("dnode:%s, db:%s vgroup commit log init failed, code:%d", taosIpStr(pObj->privateIp), pRsp->more, pRsp->code); taosIpStr(pObj->privateIp), pRsp->more, pRsp->code, taosGetVgroupStatusStr(pDb->vgStatus));
} else {
pDb->vgStatus = TSDB_VG_STATUS_INIT_FAILED;
mError("dnode:%s, db:%s vgroup init failed, code:%d", taosIpStr(pObj->privateIp), pRsp->more, pRsp->code);
}
return 0; return 0;
} }
......
...@@ -657,16 +657,10 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) { ...@@ -657,16 +657,10 @@ int mgmtCreateMeter(SDbObj *pDb, SCreateTableMsg *pCreate) {
return TSDB_CODE_NO_ENOUGH_DNODES; return TSDB_CODE_NO_ENOUGH_DNODES;
} }
if (pDb->vgStatus == TSDB_VG_STATUS_COMMITLOG_INIT_FAILED) { if (pDb->vgStatus < TSDB_VG_STATUS_FULL && pDb->vgStatus > TSDB_CODE_ACTION_IN_PROGRESS) {
mgmtDestroyMeter(pMeter); mgmtDestroyMeter(pMeter);
mError("table:%s, commit log init failed", pCreate->meterId); mError("table:%s, vgroup init failed, reason:%d %s", pCreate->meterId, pDb->vgStatus, taosGetVgroupStatusStr(pDb->vgStatus));
return TSDB_CODE_VG_COMMITLOG_INIT_FAILED; return pDb->vgStatus;
}
if (pDb->vgStatus == TSDB_VG_STATUS_INIT_FAILED) {
mgmtDestroyMeter(pMeter);
mError("table:%s, vgroup init failed", pCreate->meterId);
return TSDB_CODE_VG_INIT_FAILED;
} }
if (pVgroup == NULL) { if (pVgroup == NULL) {
......
...@@ -1823,7 +1823,7 @@ int vnodeUpdateFileMagic(int vnode, int fileId) { ...@@ -1823,7 +1823,7 @@ int vnodeUpdateFileMagic(int vnode, int fileId) {
} }
int vnodeInitFile(int vnode) { int vnodeInitFile(int vnode) {
int code = 0; int code = TSDB_CODE_SUCCESS;
SVnodeObj *pVnode = vnodeList + vnode; SVnodeObj *pVnode = vnodeList + vnode;
pVnode->maxFiles = pVnode->cfg.daysToKeep / pVnode->cfg.daysPerFile + 1; pVnode->maxFiles = pVnode->cfg.daysToKeep / pVnode->cfg.daysPerFile + 1;
......
...@@ -79,8 +79,14 @@ int vnodeCreateMeterObjFile(int vnode) { ...@@ -79,8 +79,14 @@ int vnodeCreateMeterObjFile(int vnode) {
sprintf(fileName, "%s/vnode%d/meterObj.v%d", tsDirectory, vnode, vnode); sprintf(fileName, "%s/vnode%d/meterObj.v%d", tsDirectory, vnode, vnode);
fp = fopen(fileName, "w+"); fp = fopen(fileName, "w+");
if (fp == NULL) { if (fp == NULL) {
dError("failed to create vnode:%d file:%s", vnode, fileName); dError("failed to create vnode:%d file:%s, reason:%s", vnode, fileName, strerror(errno));
return -1; if (errno == EACCES) {
return TSDB_CODE_NO_DISK_PERMISSIONS;
} else if (errno == ENOSPC) {
return TSDB_CODE_SERVER_NO_SPACE;
} else {
return TSDB_CODE_VG_INIT_FAILED;
}
} else { } else {
vnodeCreateFileHeader(fp); vnodeCreateFileHeader(fp);
vnodeUpdateVnodeFileHeader(fp, vnodeList + vnode); vnodeUpdateVnodeFileHeader(fp, vnodeList + vnode);
...@@ -95,7 +101,7 @@ int vnodeCreateMeterObjFile(int vnode) { ...@@ -95,7 +101,7 @@ int vnodeCreateMeterObjFile(int vnode) {
fclose(fp); fclose(fp);
} }
return 0; return TSDB_CODE_SUCCESS;
} }
FILE *vnodeOpenMeterObjFile(int vnode) { FILE *vnodeOpenMeterObjFile(int vnode) {
...@@ -273,7 +279,7 @@ int vnodeSaveVnodeCfg(int vnode, SVnodeCfg *pCfg, SVPeerDesc *pDesc) { ...@@ -273,7 +279,7 @@ int vnodeSaveVnodeCfg(int vnode, SVnodeCfg *pCfg, SVPeerDesc *pDesc) {
/* vnodeUpdateFileCheckSum(fp); */ /* vnodeUpdateFileCheckSum(fp); */
fclose(fp); fclose(fp);
return 0; return TSDB_CODE_SUCCESS;
} }
int vnodeSaveVnodeInfo(int vnode) { int vnodeSaveVnodeInfo(int vnode) {
......
...@@ -45,24 +45,24 @@ static int vnodeInitStoreVnode(int vnode) { ...@@ -45,24 +45,24 @@ static int vnodeInitStoreVnode(int vnode) {
pVnode->pCachePool = vnodeOpenCachePool(vnode); pVnode->pCachePool = vnodeOpenCachePool(vnode);
if (pVnode->pCachePool == NULL) { if (pVnode->pCachePool == NULL) {
dError("vid:%d, cache pool init failed.", pVnode->vnode); dError("vid:%d, cache pool init failed.", pVnode->vnode);
return -1; return TSDB_CODE_SERV_OUT_OF_MEMORY;
} }
if (vnodeInitFile(vnode) < 0) { if (vnodeInitFile(vnode) != TSDB_CODE_SUCCESS) {
dError("vid:%d, files init failed.", pVnode->vnode); dError("vid:%d, files init failed.", pVnode->vnode);
return -1; return TSDB_CODE_VG_INIT_FAILED;
} }
if (vnodeInitCommit(vnode) < 0) { if (vnodeInitCommit(vnode) != TSDB_CODE_SUCCESS) {
dError("vid:%d, commit init failed.", pVnode->vnode); dError("vid:%d, commit init failed.", pVnode->vnode);
return -1; return TSDB_CODE_VG_INIT_FAILED;
} }
pthread_mutex_init(&(pVnode->vmutex), NULL); pthread_mutex_init(&(pVnode->vmutex), NULL);
dPrint("vid:%d, storage initialized, version:%ld fileId:%d numOfFiles:%d", vnode, pVnode->version, pVnode->fileId, dPrint("vid:%d, storage initialized, version:%ld fileId:%d numOfFiles:%d", vnode, pVnode->version, pVnode->fileId,
pVnode->numOfFiles); pVnode->numOfFiles);
return 0; return TSDB_CODE_SUCCESS;
} }
int vnodeOpenVnode(int vnode) { int vnodeOpenVnode(int vnode) {
...@@ -192,16 +192,19 @@ int vnodeCreateVnode(int vnode, SVnodeCfg *pCfg, SVPeerDesc *pDesc) { ...@@ -192,16 +192,19 @@ int vnodeCreateVnode(int vnode, SVnodeCfg *pCfg, SVPeerDesc *pDesc) {
mkdir(fileName, 0755); mkdir(fileName, 0755);
vnodeList[vnode].cfg = *pCfg; vnodeList[vnode].cfg = *pCfg;
if (vnodeCreateMeterObjFile(vnode) != 0) { int code = vnodeCreateMeterObjFile(vnode);
return TSDB_CODE_VG_INIT_FAILED; if (code != TSDB_CODE_SUCCESS) {
return code;
} }
if (vnodeSaveVnodeCfg(vnode, pCfg, pDesc) != 0) { code = vnodeSaveVnodeCfg(vnode, pCfg, pDesc);
if (code != TSDB_CODE_SUCCESS) {
return TSDB_CODE_VG_INIT_FAILED; return TSDB_CODE_VG_INIT_FAILED;
} }
if (vnodeInitStoreVnode(vnode) < 0) { code = vnodeInitStoreVnode(vnode);
return TSDB_CODE_VG_COMMITLOG_INIT_FAILED; if (code != TSDB_CODE_SUCCESS) {
return code;
} }
return vnodeOpenVnode(vnode); return vnodeOpenVnode(vnode);
...@@ -294,7 +297,8 @@ int vnodeInitStore() { ...@@ -294,7 +297,8 @@ int vnodeInitStore() {
if (vnodeInitInfo() < 0) return -1; if (vnodeInitInfo() < 0) return -1;
for (vnode = 0; vnode < TSDB_MAX_VNODES; ++vnode) { for (vnode = 0; vnode < TSDB_MAX_VNODES; ++vnode) {
if (vnodeInitStoreVnode(vnode) < 0) { int code = vnodeInitStoreVnode(vnode);
if (code != TSDB_CODE_SUCCESS) {
// one vnode is failed to recover from commit log, continue for remain // one vnode is failed to recover from commit log, continue for remain
return -1; return -1;
} }
......
...@@ -19,11 +19,13 @@ ...@@ -19,11 +19,13 @@
const char* taosGetVgroupStatusStr(int vgroupStatus) { const char* taosGetVgroupStatusStr(int vgroupStatus) {
switch (vgroupStatus) { switch (vgroupStatus) {
case TSDB_VG_STATUS_READY: return "ready"; case TSDB_VG_STATUS_READY: return tsError[vgroupStatus];
case TSDB_VG_STATUS_IN_PROGRESS: return "inprogress"; case TSDB_VG_STATUS_IN_PROGRESS: return tsError[vgroupStatus];
case TSDB_VG_STATUS_COMMITLOG_INIT_FAILED: return "commitlog_init_failed"; case TSDB_VG_STATUS_NO_DISK_PERMISSIONS: return tsError[vgroupStatus];
case TSDB_VG_STATUS_INIT_FAILED: return "init_failed"; case TSDB_VG_STATUS_SERVER_NO_PACE: return tsError[vgroupStatus];
case TSDB_VG_STATUS_FULL: return "full"; case TSDB_VG_STATUS_SERV_OUT_OF_MEMORY: return tsError[vgroupStatus];
case TSDB_VG_STATUS_INIT_FAILED: return tsError[vgroupStatus];
case TSDB_VG_STATUS_FULL: return tsError[vgroupStatus];
default: return "undefined"; default: return "undefined";
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册