refactor error
This commit is contained in:
parent
92cb9f5317
commit
6c39f81c7b
|
@ -1370,58 +1370,68 @@ static int32_t taosCheckGlobalCfg() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t cfgInitWrapper(SConfig **pCfg) {
|
||||
if (*pCfg == NULL) {
|
||||
*pCfg = cfgInit();
|
||||
if (*pCfg == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs,
|
||||
bool tsc) {
|
||||
if (tsCfg != NULL) return 0;
|
||||
tsCfg = cfgInit();
|
||||
|
||||
int32_t code = cfgInitWrapper(&tsCfg);
|
||||
|
||||
if (tsc) {
|
||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||
if ((code = taosAddClientCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosAddClientLogCfg(tsCfg)) != 0) return code;
|
||||
} else {
|
||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
||||
if (taosAddServerLogCfg(tsCfg) != 0) return -1;
|
||||
if ((code = taosAddClientCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosAddServerCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosAddClientLogCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosAddServerLogCfg(tsCfg)) != 0) return code;
|
||||
}
|
||||
|
||||
taosAddSystemCfg(tsCfg);
|
||||
code = taosAddSystemCfg(tsCfg);
|
||||
|
||||
if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
||||
uError("failed to load cfg since %s", terrstr());
|
||||
if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) {
|
||||
uError("failed to load cfg since %s", tstrerror(code));
|
||||
cfgCleanup(tsCfg);
|
||||
tsCfg = NULL;
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (cfgLoadFromArray(tsCfg, pArgs) != 0) {
|
||||
uError("failed to load cfg from array since %s", terrstr());
|
||||
if ((code = cfgLoadFromArray(tsCfg, pArgs)) != 0) {
|
||||
uError("failed to load cfg from array since %s", tstrerror(code));
|
||||
cfgCleanup(tsCfg);
|
||||
tsCfg = NULL;
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (tsc) {
|
||||
if (taosSetClientCfg(tsCfg)) return -1;
|
||||
if ((code = taosSetClientCfg(tsCfg)) != 0) return code;
|
||||
} else {
|
||||
if (taosSetClientCfg(tsCfg)) return -1;
|
||||
if (taosUpdateServerCfg(tsCfg)) return -1;
|
||||
if (taosSetServerCfg(tsCfg)) return -1;
|
||||
if (taosSetReleaseCfg(tsCfg)) return -1;
|
||||
if (taosSetTfsCfg(tsCfg) != 0) return -1;
|
||||
if (taosSetS3Cfg(tsCfg) != 0) return -1;
|
||||
if ((code = taosSetClientCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosUpdateServerCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosSetServerCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosSetReleaseCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosSetTfsCfg(tsCfg)) != 0) return code;
|
||||
if ((code = taosSetS3Cfg(tsCfg)) != 0) return code;
|
||||
}
|
||||
|
||||
taosSetSystemCfg(tsCfg);
|
||||
|
||||
if (taosSetFileHandlesLimit() != 0) return -1;
|
||||
if ((code = taosSetFileHandlesLimit()) != 0) return code;
|
||||
|
||||
taosSetAllDebugFlag(tsCfg, cfgGetItem(tsCfg, "debugFlag")->i32);
|
||||
|
||||
cfgDumpCfg(tsCfg, tsc, false);
|
||||
|
||||
if (taosCheckGlobalCfg() != 0) {
|
||||
return -1;
|
||||
if ((code = taosCheckGlobalCfg()) != 0) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -310,6 +310,7 @@ static void taosCleanupArgs() {
|
|||
}
|
||||
|
||||
int main(int argc, char const *argv[]) {
|
||||
int32_t code = 0;
|
||||
#ifdef TD_JEMALLOC_ENABLED
|
||||
bool jeBackgroundThread = true;
|
||||
mallctl("background_thread", NULL, NULL, &jeBackgroundThread, sizeof(bool));
|
||||
|
@ -319,10 +320,10 @@ int main(int argc, char const *argv[]) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dmParseArgs(argc, argv) != 0) {
|
||||
if ((code = dmParseArgs(argc, argv)) != 0) {
|
||||
//printf("failed to start since parse args error\n");
|
||||
taosCleanupArgs();
|
||||
return -1;
|
||||
return code;
|
||||
}
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
@ -368,14 +369,15 @@ int mainWindows(int argc, char **argv) {
|
|||
#endif
|
||||
if(global.generateCode) {
|
||||
bool toLogFile = false;
|
||||
if(taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs) != 0){
|
||||
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file");
|
||||
return -1;
|
||||
if ((code = taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs)) != 0) {
|
||||
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file,reason:%s",
|
||||
tstrerror(code));
|
||||
return code;
|
||||
};
|
||||
|
||||
if(dmCheckRunning(tsDataDir) == NULL) {
|
||||
encryptError("failed to generate encrypt code since taosd is running, please stop it first");
|
||||
return -1;
|
||||
TdFilePtr pFile;
|
||||
if ((code = dmCheckRunningWrapper(tsDataDir, &pFile)) != 0) {
|
||||
encryptError("failed to generate encrypt code since taosd is running, please stop it first, reason:%s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile);
|
||||
taosCloseLog();
|
||||
|
|
|
@ -98,6 +98,7 @@ SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
|
|||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
||||
int32_t dmInitVars(SDnode *pDnode);
|
||||
int32_t dmInitVarsWrapper(SDnode *pDnode);
|
||||
void dmClearVars(SDnode *pDnode);
|
||||
int32_t dmInitModule(SDnode *pDnode);
|
||||
SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper);
|
||||
|
|
|
@ -34,10 +34,11 @@ static SDnode globalDnode = {0};
|
|||
SDnode *dmInstance() { return &globalDnode; }
|
||||
|
||||
static int32_t dmCheckRepeatInit(SDnode *pDnode) {
|
||||
int32_t code = 0;
|
||||
if (atomic_val_compare_exchange_8(&pDnode->once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
||||
dError("env is already initialized");
|
||||
terrno = TSDB_CODE_REPEAT_INIT;
|
||||
return -1;
|
||||
code = TSDB_CODE_REPEAT_INIT;
|
||||
return terrno = code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -107,7 +108,20 @@ static bool dmCheckDiskSpace() {
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
static int32_t dmCheckDiskSpaceWrapper() {
|
||||
if (!dmCheckDiskSpace()) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tfsOpenWrapper(SDiskCfg *pCfg, int32_t ndisk, STfs **tfs) {
|
||||
*tfs = tfsOpen(pCfg, ndisk);
|
||||
if (*tfs == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t dmDiskInit() {
|
||||
SDnode *pDnode = dmInstance();
|
||||
SDiskCfg dCfg = {.level = 0, .primary = 1, .disable = 0};
|
||||
|
@ -119,10 +133,10 @@ int32_t dmDiskInit() {
|
|||
numOfDisks = 1;
|
||||
}
|
||||
|
||||
pDnode->pTfs = tfsOpen(pDisks, numOfDisks);
|
||||
if (pDnode->pTfs == NULL) {
|
||||
dError("failed to init tfs since %s", terrstr());
|
||||
return -1;
|
||||
int32_t code = tfsOpenWrapper(pDisks, numOfDisks, &pDnode->pTfs);
|
||||
if (code != 0) {
|
||||
dError("failed to init tfs since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -145,6 +159,12 @@ static bool dmCheckDataDirVersion() {
|
|||
return true;
|
||||
}
|
||||
|
||||
static int32_t dmCheckDataDirVersionWrapper() {
|
||||
if (!dmCheckDataDirVersion()) {
|
||||
return TSDB_CODE_INVALID_DATA_FMT;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#if defined(USE_S3)
|
||||
|
||||
extern int32_t s3Begin();
|
||||
|
@ -155,16 +175,17 @@ extern int8_t tsS3Enabled;
|
|||
|
||||
int32_t dmInit() {
|
||||
dInfo("start to init dnode env");
|
||||
if (dmDiskInit() != 0) return -1;
|
||||
if (!dmCheckDataDirVersion()) return -1;
|
||||
if (!dmCheckDiskSpace()) return -1;
|
||||
if (dmCheckRepeatInit(dmInstance()) != 0) return -1;
|
||||
if (dmInitSystem() != 0) return -1;
|
||||
if (dmInitMonitor() != 0) return -1;
|
||||
if (dmInitAudit() != 0) return -1;
|
||||
if (dmInitDnode(dmInstance()) != 0) return -1;
|
||||
int32_t code = 0;
|
||||
if ((code = dmDiskInit()) != 0) return code;
|
||||
if ((code = dmCheckDataDirVersion()) != 0) return code;
|
||||
if ((code = dmCheckDiskSpace()) != 0) return code;
|
||||
if ((code = dmCheckRepeatInit(dmInstance())) != 0) return code;
|
||||
if ((code = dmInitSystem()) != 0) return code;
|
||||
if ((code = dmInitMonitor()) != 0) return code;
|
||||
if ((code = dmInitAudit()) != 0) return code;
|
||||
if ((code = dmInitDnode(dmInstance())) != 0) return code;
|
||||
#if defined(USE_S3)
|
||||
if (s3Begin() != 0) return -1;
|
||||
if ((code = s3Begin()) != 0) return code;
|
||||
#endif
|
||||
|
||||
dInfo("dnode env is initialized");
|
||||
|
@ -214,6 +235,7 @@ int32_t dmRun() {
|
|||
}
|
||||
|
||||
static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = dmInstance();
|
||||
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
|
@ -221,19 +243,19 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
dmReleaseWrapper(pWrapper);
|
||||
switch (ntype) {
|
||||
case MNODE:
|
||||
terrno = TSDB_CODE_MNODE_ALREADY_DEPLOYED;
|
||||
code = TSDB_CODE_MNODE_ALREADY_DEPLOYED;
|
||||
break;
|
||||
case QNODE:
|
||||
terrno = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
||||
code = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
||||
break;
|
||||
case SNODE:
|
||||
terrno = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
||||
code = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
dError("failed to create node since %s", terrstr());
|
||||
return -1;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
dInfo("start to process create-node-request");
|
||||
|
@ -241,18 +263,18 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
pWrapper = &pDnode->wrappers[ntype];
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
dmReleaseWrapper(pWrapper);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||
|
||||
dInfo("node:%s, start to create", pWrapper->name);
|
||||
int32_t code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||
code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, tstrerror(code));
|
||||
} else {
|
||||
dInfo("node:%s, has been created", pWrapper->name);
|
||||
code = dmOpenNode(pWrapper);
|
||||
|
@ -268,6 +290,7 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = dmInstance();
|
||||
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
|
@ -286,16 +309,16 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
dInfo("node:%s, checking node role:%d", pWrapper->name, role);
|
||||
if (role == TAOS_SYNC_ROLE_VOTER) {
|
||||
dError("node:%s, failed to alter node type since node already is role:%d", pWrapper->name, role);
|
||||
terrno = TSDB_CODE_MNODE_ALREADY_IS_VOTER;
|
||||
return -1;
|
||||
code = TSDB_CODE_MNODE_ALREADY_IS_VOTER;
|
||||
return terrno = code;
|
||||
}
|
||||
}
|
||||
|
||||
if (pWrapper->func.isCatchUpFp != NULL) {
|
||||
dInfo("node:%s, checking node catch up", pWrapper->name);
|
||||
if ((*pWrapper->func.isCatchUpFp)(pWrapper->pMgmt) != 1) {
|
||||
terrno = TSDB_CODE_MNODE_NOT_CATCH_UP;
|
||||
return -1;
|
||||
code = TSDB_CODE_MNODE_NOT_CATCH_UP;
|
||||
return terrno = code;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,17 +334,17 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
pWrapper = &pDnode->wrappers[ntype];
|
||||
if (taosMkDir(pWrapper->path) != 0) {
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
||||
return -1;
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||
|
||||
dInfo("node:%s, start to create", pWrapper->name);
|
||||
int32_t code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||
code = (*pWrapper->func.createFp)(&input, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, terrstr());
|
||||
dError("node:%s, failed to create since %s", pWrapper->name, tstrerror(code));
|
||||
} else {
|
||||
dInfo("node:%s, has been created", pWrapper->name);
|
||||
code = dmOpenNode(pWrapper);
|
||||
|
@ -337,35 +360,36 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
|||
}
|
||||
|
||||
static int32_t dmProcessDropNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||
int32_t code = 0;
|
||||
SDnode *pDnode = dmInstance();
|
||||
|
||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||
if (pWrapper == NULL) {
|
||||
switch (ntype) {
|
||||
case MNODE:
|
||||
terrno = TSDB_CODE_MNODE_NOT_DEPLOYED;
|
||||
code = TSDB_CODE_MNODE_NOT_DEPLOYED;
|
||||
break;
|
||||
case QNODE:
|
||||
terrno = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||
code = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||
break;
|
||||
case SNODE:
|
||||
terrno = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
||||
code = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_APP_ERROR;
|
||||
code = TSDB_CODE_APP_ERROR;
|
||||
}
|
||||
|
||||
dError("failed to drop node since %s", terrstr());
|
||||
return -1;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||
|
||||
dInfo("node:%s, start to drop", pWrapper->name);
|
||||
int32_t code = (*pWrapper->func.dropFp)(&input, pMsg);
|
||||
code = (*pWrapper->func.dropFp)(&input, pMsg);
|
||||
if (code != 0) {
|
||||
dError("node:%s, failed to drop since %s", pWrapper->name, terrstr());
|
||||
dError("node:%s, failed to drop since %s", pWrapper->name, tstrerror(code));
|
||||
} else {
|
||||
dInfo("node:%s, has been dropped", pWrapper->name);
|
||||
pWrapper->required = false;
|
||||
|
|
|
@ -42,7 +42,7 @@ int32_t dmInitDnode(SDnode *pDnode) {
|
|||
int32_t code = -1;
|
||||
char path[PATH_MAX + 100] = {0};
|
||||
|
||||
if (dmInitVars(pDnode) != 0) {
|
||||
if ((code = dmInitVarsWrapper(pDnode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -65,26 +65,31 @@ int32_t dmInitDnode(SDnode *pDnode) {
|
|||
snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name);
|
||||
pWrapper->path = taosStrdup(path);
|
||||
if (pWrapper->path == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pWrapper->required = dmRequireNode(pDnode, pWrapper);
|
||||
}
|
||||
|
||||
pDnode->lockfile = dmCheckRunning(tsDataDir);
|
||||
if (pDnode->lockfile == NULL) {
|
||||
code = dmCheckRunningWrapper(tsDataDir, &pDnode->lockfile);
|
||||
if (code != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if (dmInitModule(pDnode) != 0) {
|
||||
|
||||
if ((code = dmInitModule(pDnode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
indexInit(tsNumOfCommitThreads);
|
||||
streamMetaInit();
|
||||
|
||||
dmInitStatusClient(pDnode);
|
||||
dmInitSyncClient(pDnode);
|
||||
if ((code = dmInitStatusClient(pDnode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
if ((code = dmInitSyncClient(pDnode)) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
dmReportStartup("dnode-transport", "initialized");
|
||||
dDebug("dnode is created, ptr:%p", pDnode);
|
||||
|
@ -94,7 +99,7 @@ _OVER:
|
|||
if (code != 0 && pDnode != NULL) {
|
||||
dmClearVars(pDnode);
|
||||
pDnode = NULL;
|
||||
dError("failed to create dnode since %s", terrstr());
|
||||
dError("failed to create dnode since %s", tstrerror(code));
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -122,7 +127,15 @@ void dmCleanupDnode(SDnode *pDnode) {
|
|||
dDebug("dnode is closed, ptr:%p", pDnode);
|
||||
}
|
||||
|
||||
int32_t dmInitVarsWrapper(SDnode *pDnode) {
|
||||
int32_t code = dmInitVars(pDnode);
|
||||
if (code == -1) {
|
||||
return terrno;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int32_t dmInitVars(SDnode *pDnode) {
|
||||
int32_t code = 0;
|
||||
SDnodeData *pData = &pDnode->data;
|
||||
pData->dnodeId = 0;
|
||||
pData->clusterId = 0;
|
||||
|
@ -138,21 +151,21 @@ int32_t dmInitVars(SDnode *pDnode) {
|
|||
taosMemoryFreeClear(machineId);
|
||||
} else {
|
||||
#if defined(TD_ENTERPRISE) && !defined(GRANTS_CFG)
|
||||
terrno = TSDB_CODE_DNODE_NO_MACHINE_CODE;
|
||||
return -1;
|
||||
code = TSDB_CODE_DNODE_NO_MACHINE_CODE;
|
||||
return terrno = code;
|
||||
#endif
|
||||
}
|
||||
|
||||
pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||
if (pData->dnodeHash == NULL) {
|
||||
dError("failed to init dnode hash");
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
if (dmReadEps(pData) != 0) {
|
||||
dError("failed to read file since %s", terrstr());
|
||||
return -1;
|
||||
if ((code = dmReadEps(pData)) != 0) {
|
||||
dError("failed to read file since %s", tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
#if defined(TD_ENTERPRISE)
|
||||
|
@ -274,26 +287,25 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
|
|||
} else {
|
||||
switch (pWrapper->ntype) {
|
||||
case MNODE:
|
||||
terrno = TSDB_CODE_MNODE_NOT_FOUND;
|
||||
code = TSDB_CODE_MNODE_NOT_FOUND;
|
||||
break;
|
||||
case QNODE:
|
||||
terrno = TSDB_CODE_QNODE_NOT_FOUND;
|
||||
code = TSDB_CODE_QNODE_NOT_FOUND;
|
||||
break;
|
||||
case SNODE:
|
||||
terrno = TSDB_CODE_SNODE_NOT_FOUND;
|
||||
code = TSDB_CODE_SNODE_NOT_FOUND;
|
||||
break;
|
||||
case VNODE:
|
||||
terrno = TSDB_CODE_VND_STOPPED;
|
||||
code = TSDB_CODE_VND_STOPPED;
|
||||
break;
|
||||
default:
|
||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
||||
code = TSDB_CODE_APP_IS_STOPPING;
|
||||
break;
|
||||
}
|
||||
code = -1;
|
||||
}
|
||||
taosThreadRwlockUnlock(&pWrapper->lock);
|
||||
|
||||
return code;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper) {
|
||||
|
|
|
@ -426,7 +426,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) {
|
|||
pTrans->statusRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->statusRpc == NULL) {
|
||||
dError("failed to init dnode rpc status client");
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
dDebug("dnode rpc status client is initialized");
|
||||
|
@ -471,7 +471,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) {
|
|||
pTrans->syncRpc = rpcOpen(&rpcInit);
|
||||
if (pTrans->syncRpc == NULL) {
|
||||
dError("failed to init dnode rpc sync client");
|
||||
return -1;
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
dDebug("dnode rpc sync client is initialized");
|
||||
|
|
|
@ -206,6 +206,7 @@ void dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
|
|||
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
|
||||
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
|
||||
TdFilePtr dmCheckRunning(const char *dataDir);
|
||||
int32_t dmCheckRunningWrapper(const char *dataDir, TdFilePtr *pFile);
|
||||
|
||||
// dmodule.c
|
||||
int32_t dmInitDndInfo(SDnodeData *pData);
|
||||
|
|
|
@ -204,26 +204,26 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
content = taosMemoryMalloc(size + 1);
|
||||
if (content == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (taosReadFile(pFile, content, size) != size) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -232,12 +232,11 @@ int32_t dmReadEps(SDnodeData *pData) {
|
|||
|
||||
pJson = tjsonParse(content);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if (dmDecodeEps(pJson, pData) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
if ((code = dmDecodeEps(pJson, pData)) < 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -251,7 +250,7 @@ _OVER:
|
|||
|
||||
if (code != 0) {
|
||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
return code;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
if (taosArrayGetSize(pData->dnodeEps) == 0) {
|
||||
|
@ -261,8 +260,8 @@ _OVER:
|
|||
taosArrayPush(pData->dnodeEps, &dnodeEp);
|
||||
}
|
||||
|
||||
if (dmReadDnodePairs(pData) != 0) {
|
||||
return -1;
|
||||
if ((code = dmReadDnodePairs(pData)) != 0) {
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
dDebug("reset dnode list on startup");
|
||||
|
@ -270,8 +269,8 @@ _OVER:
|
|||
|
||||
if (pData->oldDnodeEps == NULL && dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) {
|
||||
dError("localEp %s different with %s and need to be reconfigured", tsLocalEp, file);
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_CFG;
|
||||
return terrno = code;
|
||||
}
|
||||
|
||||
return code;
|
||||
|
@ -308,7 +307,7 @@ static int32_t dmEncodeEps(SJson *pJson, SDnodeData *pData) {
|
|||
}
|
||||
|
||||
int32_t dmWriteEps(SDnodeData *pData) {
|
||||
int32_t code = -1;
|
||||
int32_t code = 0;
|
||||
char *buffer = NULL;
|
||||
SJson *pJson = NULL;
|
||||
TdFilePtr pFile = NULL;
|
||||
|
@ -317,16 +316,23 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
|||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||
snprintf(realfile, sizeof(realfile), "%s%sdnode%sdnode.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
if ((code == dmInitDndInfo(pData)) != 0) goto _OVER;
|
||||
// if ((code == dmInitDndInfo(pData)) != 0) goto _OVER;
|
||||
TAOS_CHECK_GOTO(code = dmInitDndInfo(pData), NULL, _OVER);
|
||||
|
||||
pJson = tjsonCreateObject();
|
||||
if (pJson == NULL) goto _OVER;
|
||||
if (pJson == NULL)
|
||||
TAOS_CHECK_GOTO(code = TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||
|
||||
pData->engineVer = tsVersion;
|
||||
if (dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
||||
|
||||
TAOS_CHECK_GOTO(code = dmEncodeEps(pJson, pData), NULL, _OVER);//dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
||||
|
||||
buffer = tjsonToString(pJson);
|
||||
if (buffer == NULL) goto _OVER;
|
||||
terrno = 0;
|
||||
if (buffer == NULL) {
|
||||
TAOS_CHECK_GOTO(code = TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||
}
|
||||
code = 0;
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||
if (pFile == NULL) goto _OVER;
|
||||
|
@ -349,8 +355,8 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, terrstr(), pData->dnodeVer);
|
||||
// code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, tstrerror(code), pData->dnodeVer);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -592,28 +598,29 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
|||
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||
|
||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||
dDebug("dnode file:%s not exist", file);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||
code = 0;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||
if (pFile == NULL) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
int64_t size = 0;
|
||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
code = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
content = taosMemoryMalloc(size + 1);
|
||||
if (content == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -627,12 +634,13 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
|||
|
||||
pJson = tjsonParse(content);
|
||||
if (pJson == NULL) {
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
pData->oldDnodeEps = taosArrayInit(1, sizeof(SDnodeEpPair));
|
||||
if (pData->oldDnodeEps == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
dError("failed to calloc dnodeEp array since %s", strerror(errno));
|
||||
goto _OVER;
|
||||
}
|
||||
|
@ -640,7 +648,8 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
|||
if (dmDecodeEpPairs(pJson, pData) < 0) {
|
||||
taosArrayDestroy(pData->oldDnodeEps);
|
||||
pData->oldDnodeEps = NULL;
|
||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
|
||||
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
|
@ -653,7 +662,7 @@ _OVER:
|
|||
if (pFile != NULL) taosCloseFile(&pFile);
|
||||
|
||||
if (code != 0) {
|
||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -680,8 +689,8 @@ _OVER:
|
|||
pair->oldPort, pair->newFqdn, pair->newPort, pDnodeEp->id);
|
||||
taosArrayDestroy(pData->oldDnodeEps);
|
||||
pData->oldDnodeEps = NULL;
|
||||
terrno = TSDB_CODE_INVALID_CFG;
|
||||
return -1;
|
||||
code = TSDB_CODE_INVALID_CFG;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -151,6 +151,12 @@ _OVER:
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t dmCheckRunningWrapper(const char *dataDir, TdFilePtr *pFile) {
|
||||
*pFile = dmCheckRunning(dataDir);
|
||||
if (*pFile == NULL) return terrno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
TdFilePtr dmCheckRunning(const char *dataDir) {
|
||||
char filepath[PATH_MAX] = {0};
|
||||
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||
|
|
Loading…
Reference in New Issue