Merge pull request #26616 from taosdata/fix/addErrorToMgmt
Fix/addErrorToMgmt
This commit is contained in:
commit
e8c24c236a
|
@ -1370,58 +1370,68 @@ static int32_t taosCheckGlobalCfg() {
|
||||||
return 0;
|
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,
|
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs,
|
||||||
bool tsc) {
|
bool tsc) {
|
||||||
if (tsCfg != NULL) return 0;
|
if (tsCfg != NULL) return 0;
|
||||||
tsCfg = cfgInit();
|
|
||||||
|
int32_t code = cfgInitWrapper(&tsCfg);
|
||||||
|
|
||||||
if (tsc) {
|
if (tsc) {
|
||||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddClientCfg(tsCfg)) != 0) return code;
|
||||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddClientLogCfg(tsCfg)) != 0) return code;
|
||||||
} else {
|
} else {
|
||||||
if (taosAddClientCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddClientCfg(tsCfg)) != 0) return code;
|
||||||
if (taosAddServerCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddServerCfg(tsCfg)) != 0) return code;
|
||||||
if (taosAddClientLogCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddClientLogCfg(tsCfg)) != 0) return code;
|
||||||
if (taosAddServerLogCfg(tsCfg) != 0) return -1;
|
if ((code = taosAddServerLogCfg(tsCfg)) != 0) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosAddSystemCfg(tsCfg);
|
code = taosAddSystemCfg(tsCfg);
|
||||||
|
|
||||||
if (taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl) != 0) {
|
if ((code = taosLoadCfg(tsCfg, envCmd, cfgDir, envFile, apolloUrl)) != 0) {
|
||||||
uError("failed to load cfg since %s", terrstr());
|
uError("failed to load cfg since %s", tstrerror(code));
|
||||||
cfgCleanup(tsCfg);
|
cfgCleanup(tsCfg);
|
||||||
tsCfg = NULL;
|
tsCfg = NULL;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfgLoadFromArray(tsCfg, pArgs) != 0) {
|
if ((code = cfgLoadFromArray(tsCfg, pArgs)) != 0) {
|
||||||
uError("failed to load cfg from array since %s", terrstr());
|
uError("failed to load cfg from array since %s", tstrerror(code));
|
||||||
cfgCleanup(tsCfg);
|
cfgCleanup(tsCfg);
|
||||||
tsCfg = NULL;
|
tsCfg = NULL;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tsc) {
|
if (tsc) {
|
||||||
if (taosSetClientCfg(tsCfg)) return -1;
|
if ((code = taosSetClientCfg(tsCfg)) != 0) return code;
|
||||||
} else {
|
} else {
|
||||||
if (taosSetClientCfg(tsCfg)) return -1;
|
if ((code = taosSetClientCfg(tsCfg)) != 0) return code;
|
||||||
if (taosUpdateServerCfg(tsCfg)) return -1;
|
if ((code = taosUpdateServerCfg(tsCfg)) != 0) return code;
|
||||||
if (taosSetServerCfg(tsCfg)) return -1;
|
if ((code = taosSetServerCfg(tsCfg)) != 0) return code;
|
||||||
if (taosSetReleaseCfg(tsCfg)) return -1;
|
if ((code = taosSetReleaseCfg(tsCfg)) != 0) return code;
|
||||||
if (taosSetTfsCfg(tsCfg) != 0) return -1;
|
if ((code = taosSetTfsCfg(tsCfg)) != 0) return code;
|
||||||
if (taosSetS3Cfg(tsCfg) != 0) return -1;
|
if ((code = taosSetS3Cfg(tsCfg)) != 0) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosSetSystemCfg(tsCfg);
|
taosSetSystemCfg(tsCfg);
|
||||||
|
|
||||||
if (taosSetFileHandlesLimit() != 0) return -1;
|
if ((code = taosSetFileHandlesLimit()) != 0) return code;
|
||||||
|
|
||||||
taosSetAllDebugFlag(tsCfg, cfgGetItem(tsCfg, "debugFlag")->i32);
|
taosSetAllDebugFlag(tsCfg, cfgGetItem(tsCfg, "debugFlag")->i32);
|
||||||
|
|
||||||
cfgDumpCfg(tsCfg, tsc, false);
|
cfgDumpCfg(tsCfg, tsc, false);
|
||||||
|
|
||||||
if (taosCheckGlobalCfg() != 0) {
|
if ((code = taosCheckGlobalCfg()) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -167,23 +167,23 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||||
printf("config file path overflow");
|
printf("config file path overflow");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
tstrncpy(configDir, argv[i], PATH_MAX);
|
tstrncpy(configDir, argv[i], PATH_MAX);
|
||||||
} else {
|
} else {
|
||||||
printf("'-c' requires a parameter, default is %s\n", configDir);
|
printf("'-c' requires a parameter, default is %s\n", configDir);
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-a") == 0) {
|
} else if (strcmp(argv[i], "-a") == 0) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||||
printf("apollo url overflow");
|
printf("apollo url overflow");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
tstrncpy(global.apolloUrl, argv[i], PATH_MAX);
|
tstrncpy(global.apolloUrl, argv[i], PATH_MAX);
|
||||||
} else {
|
} else {
|
||||||
printf("'-a' requires a parameter\n");
|
printf("'-a' requires a parameter\n");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-s") == 0) {
|
} else if (strcmp(argv[i], "-s") == 0) {
|
||||||
global.dumpSdb = true;
|
global.dumpSdb = true;
|
||||||
|
@ -191,12 +191,12 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
if (strlen(argv[++i]) >= PATH_MAX) {
|
if (strlen(argv[++i]) >= PATH_MAX) {
|
||||||
printf("env file path overflow");
|
printf("env file path overflow");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
tstrncpy(global.envFile, argv[i], PATH_MAX);
|
tstrncpy(global.envFile, argv[i], PATH_MAX);
|
||||||
} else {
|
} else {
|
||||||
printf("'-E' requires a parameter\n");
|
printf("'-E' requires a parameter\n");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-k") == 0) {
|
} else if (strcmp(argv[i], "-k") == 0) {
|
||||||
global.generateGrant = true;
|
global.generateGrant = true;
|
||||||
|
@ -206,16 +206,16 @@ static int32_t dmParseArgs(int32_t argc, char const *argv[]) {
|
||||||
int32_t len = strlen(argv[++i]);
|
int32_t len = strlen(argv[++i]);
|
||||||
if (len < ENCRYPT_KEY_LEN_MIN) {
|
if (len < ENCRYPT_KEY_LEN_MIN) {
|
||||||
printf("ERROR: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN);
|
printf("ERROR: Encrypt key should be at least %d characters\n", ENCRYPT_KEY_LEN_MIN);
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
if (len > ENCRYPT_KEY_LEN) {
|
if (len > ENCRYPT_KEY_LEN) {
|
||||||
printf("ERROR: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN);
|
printf("ERROR: Encrypt key overflow, it should be at most %d characters\n", ENCRYPT_KEY_LEN);
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
tstrncpy(global.encryptKey, argv[i], ENCRYPT_KEY_LEN);
|
tstrncpy(global.encryptKey, argv[i], ENCRYPT_KEY_LEN);
|
||||||
} else {
|
} else {
|
||||||
printf("'-y' requires a parameter\n");
|
printf("'-y' requires a parameter\n");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_CFG;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "-C") == 0) {
|
} else if (strcmp(argv[i], "-C") == 0) {
|
||||||
global.dumpConfig = true;
|
global.dumpConfig = true;
|
||||||
|
@ -310,6 +310,7 @@ static void taosCleanupArgs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char const *argv[]) {
|
int main(int argc, char const *argv[]) {
|
||||||
|
int32_t code = 0;
|
||||||
#ifdef TD_JEMALLOC_ENABLED
|
#ifdef TD_JEMALLOC_ENABLED
|
||||||
bool jeBackgroundThread = true;
|
bool jeBackgroundThread = true;
|
||||||
mallctl("background_thread", NULL, NULL, &jeBackgroundThread, sizeof(bool));
|
mallctl("background_thread", NULL, NULL, &jeBackgroundThread, sizeof(bool));
|
||||||
|
@ -319,10 +320,10 @@ int main(int argc, char const *argv[]) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmParseArgs(argc, argv) != 0) {
|
if ((code = dmParseArgs(argc, argv)) != 0) {
|
||||||
// printf("failed to start since parse args error\n");
|
// printf("failed to start since parse args error\n");
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
@ -335,6 +336,7 @@ int main(int argc, char const *argv[]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int mainWindows(int argc, char **argv) {
|
int mainWindows(int argc, char **argv) {
|
||||||
|
int32_t code = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (global.generateGrant) {
|
if (global.generateGrant) {
|
||||||
|
@ -357,7 +359,7 @@ int mainWindows(int argc, char **argv) {
|
||||||
|
|
||||||
#if defined(LINUX)
|
#if defined(LINUX)
|
||||||
if (global.memDbg) {
|
if (global.memDbg) {
|
||||||
int32_t code = taosMemoryDbgInit();
|
code = taosMemoryDbgInit();
|
||||||
if (code) {
|
if (code) {
|
||||||
printf("failed to init memory dbg, error:%s\n", tstrerror(code));
|
printf("failed to init memory dbg, error:%s\n", tstrerror(code));
|
||||||
return code;
|
return code;
|
||||||
|
@ -368,14 +370,16 @@ int mainWindows(int argc, char **argv) {
|
||||||
#endif
|
#endif
|
||||||
if (global.generateCode) {
|
if (global.generateCode) {
|
||||||
bool toLogFile = false;
|
bool toLogFile = false;
|
||||||
if(taosReadDataFolder(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs) != 0){
|
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");
|
encryptError("failed to generate encrypt code since dataDir can not be set from cfg file,reason:%s",
|
||||||
return -1;
|
tstrerror(code));
|
||||||
|
return code;
|
||||||
};
|
};
|
||||||
|
TdFilePtr pFile;
|
||||||
if(dmCheckRunning(tsDataDir) == NULL) {
|
if ((code = dmCheckRunning(tsDataDir, &pFile)) != 0) {
|
||||||
encryptError("failed to generate encrypt code since taosd is running, please stop it first");
|
encryptError("failed to generate encrypt code since taosd is running, please stop it first, reason:%s",
|
||||||
return -1;
|
tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile);
|
int ret = dmUpdateEncryptKey(global.encryptKey, toLogFile);
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
|
@ -383,30 +387,30 @@ int mainWindows(int argc, char **argv) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmInitLog() != 0) {
|
if ((code = dmInitLog()) != 0) {
|
||||||
printf("failed to start since init log error\n");
|
printf("failed to start since init log error\n");
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dmPrintArgs(argc, argv);
|
dmPrintArgs(argc, argv);
|
||||||
|
|
||||||
if (taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0) != 0) {
|
if ((code = taosInitCfg(configDir, global.envCmd, global.envFile, global.apolloUrl, global.pArgs, 0)) != 0) {
|
||||||
dError("failed to start since read config error");
|
dError("failed to start since read config error");
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosConvInit() != 0) {
|
if ((code = taosConvInit()) != 0) {
|
||||||
dError("failed to init conv");
|
dError("failed to init conv");
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (global.checkS3) {
|
if (global.checkS3) {
|
||||||
int32_t code = dmCheckS3();
|
code = dmCheckS3();
|
||||||
taosCleanupCfg();
|
taosCleanupCfg();
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
|
@ -435,31 +439,32 @@ int mainWindows(int argc, char **argv) {
|
||||||
osSetProcPath(argc, (char **)argv);
|
osSetProcPath(argc, (char **)argv);
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
|
|
||||||
if(dmGetEncryptKey() != 0){
|
if ((code = dmGetEncryptKey()) != 0) {
|
||||||
dError("failed to start since failed to get encrypt key");
|
dError("failed to start since failed to get encrypt key");
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return -1;
|
return code;
|
||||||
};
|
};
|
||||||
|
|
||||||
if (dmInit() != 0) {
|
if ((code = dmInit()) != 0) {
|
||||||
if (terrno == TSDB_CODE_NOT_FOUND) {
|
if (code == TSDB_CODE_NOT_FOUND) {
|
||||||
dError("failed to init dnode since unsupported platform, please visit https://www.taosdata.com for support");
|
dError("failed to init dnode since unsupported platform, please visit https://www.taosdata.com for support");
|
||||||
} else {
|
} else {
|
||||||
dError("failed to init dnode since %s", terrstr());
|
dError("failed to init dnode since %s", tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
taosCleanupCfg();
|
taosCleanupCfg();
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosConvDestroy();
|
taosConvDestroy();
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("start to init service");
|
dInfo("start to init service");
|
||||||
dmSetSignalHandle();
|
dmSetSignalHandle();
|
||||||
tsDndStart = taosGetTimestampMs();
|
tsDndStart = taosGetTimestampMs();
|
||||||
tsDndStartOsUptime = taosGetOsUptime();
|
tsDndStartOsUptime = taosGetOsUptime();
|
||||||
int32_t code = dmRun();
|
|
||||||
|
code = dmRun();
|
||||||
dInfo("shutting down the service");
|
dInfo("shutting down the service");
|
||||||
|
|
||||||
dmCleanup();
|
dmCleanup();
|
||||||
|
|
|
@ -207,18 +207,26 @@ int32_t dmProcessGrantRsp(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t dmProcessConfigReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDCfgDnodeReq cfgReq = {0};
|
SDCfgDnodeReq cfgReq = {0};
|
||||||
if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
|
if (tDeserializeSDCfgDnodeReq(pMsg->pCont, pMsg->contLen, &cfgReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
dInfo("start to config, option:%s, value:%s", cfgReq.config, cfgReq.value);
|
||||||
|
|
||||||
SConfig *pCfg = taosGetCfg();
|
SConfig *pCfg = taosGetCfg();
|
||||||
cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true);
|
|
||||||
taosCfgDynamicOptions(pCfg, cfgReq.config, true);
|
code = cfgSetItem(pCfg, cfgReq.config, cfgReq.value, CFG_STYPE_ALTER_CMD, true);
|
||||||
return 0;
|
if (code != 0) {
|
||||||
|
if (strncasecmp(cfgReq.config, "resetlog", strlen("resetlog")) == 0) {
|
||||||
|
code = 0;
|
||||||
|
} else {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return taosCfgDynamicOptions(pCfg, cfgReq.config, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
@ -276,32 +284,49 @@ static void dmGetServerRunStatus(SDnodeMgmt *pMgmt, SServerStatusRsp *pStatus) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t dmProcessServerRunStatus(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
dDebug("server run status req is received");
|
dDebug("server run status req is received");
|
||||||
SServerStatusRsp statusRsp = {0};
|
SServerStatusRsp statusRsp = {0};
|
||||||
dmGetServerRunStatus(pMgmt, &statusRsp);
|
dmGetServerRunStatus(pMgmt, &statusRsp);
|
||||||
|
|
||||||
|
pMsg->info.rsp = NULL;
|
||||||
|
pMsg->info.rspLen = 0;
|
||||||
|
|
||||||
SRpcMsg rspMsg = {.info = pMsg->info};
|
SRpcMsg rspMsg = {.info = pMsg->info};
|
||||||
int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
|
int32_t rspLen = tSerializeSServerStatusRsp(NULL, 0, &statusRsp);
|
||||||
if (rspLen < 0) {
|
if (rspLen < 0) {
|
||||||
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
// rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
// return rspMsg.code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pRsp = rpcMallocCont(rspLen);
|
void *pRsp = rpcMallocCont(rspLen);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
// rspMsg.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
// return rspMsg.code;
|
||||||
|
}
|
||||||
|
|
||||||
|
rspLen = tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
|
||||||
|
if (rspLen < 0) {
|
||||||
|
return TSDB_CODE_INVALID_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
tSerializeSServerStatusRsp(pRsp, rspLen, &statusRsp);
|
|
||||||
pMsg->info.rsp = pRsp;
|
pMsg->info.rsp = pRsp;
|
||||||
pMsg->info.rspLen = rspLen;
|
pMsg->info.rspLen = rspLen;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock *dmBuildVariablesBlock(void) {
|
int32_t dmBuildVariablesBlock(SSDataBlock **ppBlock) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
SSDataBlock *pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
|
||||||
|
if (pBlock == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
const SSysTableMeta *pMeta = NULL;
|
const SSysTableMeta *pMeta = NULL;
|
||||||
getInfosDbMeta(&pMeta, &size);
|
getInfosDbMeta(&pMeta, &size);
|
||||||
|
|
||||||
|
@ -314,52 +339,74 @@ SSDataBlock *dmBuildVariablesBlock(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
|
pBlock->pDataBlock = taosArrayInit(pMeta[index].colNum, sizeof(SColumnInfoData));
|
||||||
|
if (pBlock->pDataBlock == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
|
for (int32_t i = 0; i < pMeta[index].colNum; ++i) {
|
||||||
SColumnInfoData colInfoData = {0};
|
SColumnInfoData colInfoData = {0};
|
||||||
colInfoData.info.colId = i + 1;
|
colInfoData.info.colId = i + 1;
|
||||||
colInfoData.info.type = pMeta[index].schema[i].type;
|
colInfoData.info.type = pMeta[index].schema[i].type;
|
||||||
colInfoData.info.bytes = pMeta[index].schema[i].bytes;
|
colInfoData.info.bytes = pMeta[index].schema[i].bytes;
|
||||||
taosArrayPush(pBlock->pDataBlock, &colInfoData);
|
if (taosArrayPush(pBlock->pDataBlock, &colInfoData) == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pBlock->info.hasVarCol = true;
|
pBlock->info.hasVarCol = true;
|
||||||
|
_exit:
|
||||||
return pBlock;
|
if (code != 0) {
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
|
} else {
|
||||||
|
*ppBlock = pBlock;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
|
int32_t dmAppendVariablesToBlock(SSDataBlock *pBlock, int32_t dnodeId) {
|
||||||
/*int32_t code = */dumpConfToDataBlock(pBlock, 1);
|
int32_t code = dumpConfToDataBlock(pBlock, 1);
|
||||||
|
if (code != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, 0);
|
||||||
colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
|
if (pColInfo == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return colDataSetNItems(pColInfo, 0, (const char *)&dnodeId, pBlock->info.rows, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
int32_t size = 0;
|
int32_t size = 0;
|
||||||
int32_t rowsRead = 0;
|
int32_t rowsRead = 0;
|
||||||
|
int32_t code = 0;
|
||||||
SRetrieveTableReq retrieveReq = {0};
|
SRetrieveTableReq retrieveReq = {0};
|
||||||
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
|
if (tDeserializeSRetrieveTableReq(pMsg->pCont, pMsg->contLen, &retrieveReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
|
if (strcmp(retrieveReq.user, TSDB_DEFAULT_USER) != 0) {
|
||||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
code = TSDB_CODE_MND_NO_RIGHTS;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
|
if (strcasecmp(retrieveReq.tb, TSDB_INS_TABLE_DNODE_VARIABLES)) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SSDataBlock *pBlock = dmBuildVariablesBlock();
|
SSDataBlock *pBlock = NULL;
|
||||||
|
if ((code = dmBuildVariablesBlock(&pBlock)) != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
|
code = dmAppendVariablesToBlock(pBlock, pMgmt->pData->dnodeId);
|
||||||
|
if (code != 0) {
|
||||||
|
blockDataDestroy(pBlock);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
size_t numOfCols = taosArrayGetSize(pBlock->pDataBlock);
|
||||||
size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols +
|
size = sizeof(SRetrieveMetaTableRsp) + sizeof(int32_t) + sizeof(SSysTableSchema) * numOfCols +
|
||||||
|
@ -367,10 +414,10 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
|
||||||
SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
|
SRetrieveMetaTableRsp *pRsp = rpcMallocCont(size);
|
||||||
if (pRsp == NULL) {
|
if (pRsp == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
dError("failed to retrieve data since %s", terrstr());
|
dError("failed to retrieve data since %s", tstrerror(code));
|
||||||
blockDataDestroy(pBlock);
|
blockDataDestroy(pBlock);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *pStart = pRsp->data;
|
char *pStart = pRsp->data;
|
||||||
|
@ -404,7 +451,9 @@ int32_t dmProcessRetrieve(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
SArray *dmGetMsgHandles() {
|
SArray *dmGetMsgHandles() {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
|
SArray *pArray = taosArrayInit(16, sizeof(SMgmtHandle));
|
||||||
if (pArray == NULL) goto _OVER;
|
if (pArray == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Requests handled by DNODE
|
// Requests handled by DNODE
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_DND_CREATE_MNODE, dmPutNodeMsgToMgmtQueue, 0) == NULL) goto _OVER;
|
||||||
|
|
|
@ -18,22 +18,23 @@
|
||||||
#include "libs/function/tudf.h"
|
#include "libs/function/tudf.h"
|
||||||
|
|
||||||
static int32_t dmStartMgmt(SDnodeMgmt *pMgmt) {
|
static int32_t dmStartMgmt(SDnodeMgmt *pMgmt) {
|
||||||
if (dmStartStatusThread(pMgmt) != 0) {
|
int32_t code = 0;
|
||||||
return -1;
|
if ((code = dmStartStatusThread(pMgmt)) != 0) {
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
#if defined(TD_ENTERPRISE)
|
#if defined(TD_ENTERPRISE)
|
||||||
if (dmStartNotifyThread(pMgmt) != 0) {
|
if ((code = dmStartNotifyThread(pMgmt)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (dmStartMonitorThread(pMgmt) != 0) {
|
if ((code = dmStartMonitorThread(pMgmt)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
if (dmStartAuditThread(pMgmt) != 0) {
|
if ((code = dmStartAuditThread(pMgmt)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
if (dmStartCrashReportThread(pMgmt) != 0) {
|
if ((code = dmStartCrashReportThread(pMgmt)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -50,10 +51,10 @@ static void dmStopMgmt(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
|
SDnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SDnodeMgmt));
|
||||||
if (pMgmt == NULL) {
|
if (pMgmt == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
|
@ -70,12 +71,11 @@ static int32_t dmOpenMgmt(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
pMgmt->getMnodeLoadsFp = pInput->getMnodeLoadsFp;
|
pMgmt->getMnodeLoadsFp = pInput->getMnodeLoadsFp;
|
||||||
pMgmt->getQnodeLoadsFp = pInput->getQnodeLoadsFp;
|
pMgmt->getQnodeLoadsFp = pInput->getQnodeLoadsFp;
|
||||||
|
|
||||||
// pMgmt->pData->ipWhiteVer = 0;
|
if ((code = dmStartWorker(pMgmt)) != 0) {
|
||||||
if (dmStartWorker(pMgmt) != 0) {
|
return code;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (udfStartUdfd(pMgmt->pData->dnodeId) != 0) {
|
if ((code = udfStartUdfd(pMgmt->pData->dnodeId)) != 0) {
|
||||||
dError("failed to start udfd");
|
dError("failed to start udfd");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -264,12 +264,14 @@ static void *dmCrashReportThreadFp(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartStatusThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->statusThread, &thAttr, dmStatusThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create status thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create status thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
@ -285,12 +287,14 @@ void dmStopStatusThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartNotifyThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->notifyThread, &thAttr, dmNotifyThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create notify thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create notify thread since %s", strerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
@ -308,12 +312,14 @@ void dmStopNotifyThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->monitorThread, &thAttr, dmMonitorThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create monitor thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create monitor thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
@ -322,12 +328,14 @@ int32_t dmStartMonitorThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartAuditThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->auditThread, &thAttr, dmAuditThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create audit thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create audit thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
@ -350,6 +358,7 @@ void dmStopAuditThread(SDnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
if (!tsEnableCrashReport) {
|
if (!tsEnableCrashReport) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -358,8 +367,9 @@ int32_t dmStartCrashReportThread(SDnodeMgmt *pMgmt) {
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->crashReportThread, &thAttr, dmCrashReportThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create crashReport thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create crashReport thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
@ -431,8 +441,8 @@ static void dmProcessMgmtQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
|
code = dmProcessCreateEncryptKeyReq(pMgmt, pMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
dGError("msg:%p, not processed in mgmt queue", pMsg);
|
dGError("msg:%p, not processed in mgmt queue, reason:%s", pMsg, tstrerror(code));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,11 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
tjsonGetInt32ValueFromDouble(pJson, "deployed", pOption->deploy, code);
|
tjsonGetInt32ValueFromDouble(pJson, "deployed", pOption->deploy, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
tjsonGetInt32ValueFromDouble(pJson, "selfIndex", pOption->selfIndex, code);
|
tjsonGetInt32ValueFromDouble(pJson, "selfIndex", pOption->selfIndex, code);
|
||||||
if (code < 0) return 0;
|
if (code < 0) return code;
|
||||||
tjsonGetInt32ValueFromDouble(pJson, "lastIndex", pOption->lastIndex, code);
|
tjsonGetInt32ValueFromDouble(pJson, "lastIndex", pOption->lastIndex, code);
|
||||||
if (code < 0) return 0;
|
if (code < 0) return code;
|
||||||
|
|
||||||
SJson *replicas = tjsonGetObjectItem(pJson, "replicas");
|
SJson *replicas = tjsonGetObjectItem(pJson, "replicas");
|
||||||
if (replicas == NULL) return 0;
|
if (replicas == NULL) return 0;
|
||||||
|
@ -35,17 +35,17 @@ static int32_t mmDecodeOption(SJson *pJson, SMnodeOpt *pOption) {
|
||||||
|
|
||||||
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
||||||
SJson *replica = tjsonGetArrayItem(replicas, i);
|
SJson *replica = tjsonGetArrayItem(replicas, i);
|
||||||
if (replica == NULL) return -1;
|
if (replica == NULL) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
|
||||||
SReplica *pReplica = pOption->replicas + i;
|
SReplica *pReplica = pOption->replicas + i;
|
||||||
tjsonGetInt32ValueFromDouble(replica, "id", pReplica->id, code);
|
tjsonGetInt32ValueFromDouble(replica, "id", pReplica->id, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
code = tjsonGetStringValue(replica, "fqdn", pReplica->fqdn);
|
code = tjsonGetStringValue(replica, "fqdn", pReplica->fqdn);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
tjsonGetUInt16ValueFromDouble(replica, "port", pReplica->port, code);
|
tjsonGetUInt16ValueFromDouble(replica, "port", pReplica->port, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
tjsonGetInt32ValueFromDouble(replica, "role", pOption->nodeRoles[i], code);
|
tjsonGetInt32ValueFromDouble(replica, "role", pOption->nodeRoles[i], code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
if (pOption->nodeRoles[i] == TAOS_SYNC_ROLE_VOTER) {
|
if (pOption->nodeRoles[i] == TAOS_SYNC_ROLE_VOTER) {
|
||||||
pOption->numOfReplicas++;
|
pOption->numOfReplicas++;
|
||||||
}
|
}
|
||||||
|
@ -63,36 +63,41 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
||||||
char *pData = NULL;
|
char *pData = NULL;
|
||||||
SJson *pJson = NULL;
|
SJson *pJson = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
|
||||||
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json", path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("mnode file:%s not exist", file);
|
dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(TAOS_SYSTEM_ERROR(errno)));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open mnode file:%s since %s", file, terrstr());
|
dError("failed to open mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pData = taosMemoryMalloc(size + 1);
|
pData = taosMemoryMalloc(size + 1);
|
||||||
if (pData == NULL) {
|
if (pData == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, pData, size) != size) {
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read mnode file:%s since %s", file, terrstr());
|
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,12 +105,11 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
|
||||||
|
|
||||||
pJson = tjsonParse(pData);
|
pJson = tjsonParse(pData);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmDecodeOption(pJson, pOption) < 0) {
|
if ((code = mmDecodeOption(pJson, pOption)) < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,37 +122,42 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to read mnode file:%s since %s", file, terrstr());
|
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mmEncodeOption(SJson *pJson, const SMnodeOpt *pOption) {
|
static int32_t mmEncodeOption(SJson *pJson, const SMnodeOpt *pOption) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pOption->deploy && pOption->numOfTotalReplicas > 0) {
|
if (pOption->deploy && pOption->numOfTotalReplicas > 0) {
|
||||||
if (tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(pJson, "selfIndex", pOption->selfIndex)) < 0) return code;
|
||||||
|
|
||||||
SJson *replicas = tjsonCreateArray();
|
SJson *replicas = tjsonCreateArray();
|
||||||
if (replicas == NULL) return -1;
|
if (replicas == NULL) {
|
||||||
if (tjsonAddItemToObject(pJson, "replicas", replicas) < 0) return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
if ((code = tjsonAddItemToObject(pJson, "replicas", replicas)) < 0) return code;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
for (int32_t i = 0; i < pOption->numOfTotalReplicas; ++i) {
|
||||||
SJson *replica = tjsonCreateObject();
|
SJson *replica = tjsonCreateObject();
|
||||||
if (replica == NULL) return -1;
|
if (replica == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
const SReplica *pReplica = pOption->replicas + i;
|
const SReplica *pReplica = pOption->replicas + i;
|
||||||
if (tjsonAddDoubleToObject(replica, "id", pReplica->id) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(replica, "id", pReplica->id)) < 0) return code;
|
||||||
if (tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn) < 0) return -1;
|
if ((code = tjsonAddStringToObject(replica, "fqdn", pReplica->fqdn)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(replica, "port", pReplica->port) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(replica, "port", pReplica->port)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(replica, "role", pOption->nodeRoles[i]) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(replica, "role", pOption->nodeRoles[i])) < 0) return code;
|
||||||
if (tjsonAddItemToArray(replicas, replica) < 0) return -1;
|
if ((code = tjsonAddItemToArray(replicas, replica)) < 0) return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tjsonAddDoubleToObject(pJson, "lastIndex", pOption->lastIndex) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(pJson, "lastIndex", pOption->lastIndex)) < 0) return code;
|
||||||
|
|
||||||
if (tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(pJson, "deployed", pOption->deploy)) < 0) return code;
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||||
|
@ -158,28 +167,59 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
|
||||||
snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%smnode.json.bak", path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(realfile, sizeof(realfile), "%s%smnode.json", path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(realfile)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) {
|
||||||
if (mmEncodeOption(pJson, pOption) != 0) goto _OVER;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
TAOS_CHECK_GOTO(mmEncodeOption(pJson, pOption), NULL, _OVER);
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) {
|
||||||
terrno = 0;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
if (taosCloseFile(&pFile) < 0) {
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
code = 0;
|
|
||||||
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
@ -188,8 +228,7 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, tstrerror(code), pOption->deploy);
|
||||||
dError("failed to write mnode file:%s since %s, deloyed:%d", realfile, terrstr(), pOption->deploy);
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,11 +26,12 @@ void mmGetMnodeLoads(SMnodeMgmt *pMgmt, SMonMloadInfo *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
SDCreateMnodeReq createReq = {0};
|
SDCreateMnodeReq createReq = {0};
|
||||||
if (tDeserializeSDCreateMnodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
if (tDeserializeSDCreateMnodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnodeOpt option = {.deploy = true,
|
SMnodeOpt option = {.deploy = true,
|
||||||
|
@ -56,43 +57,45 @@ int32_t mmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option.selfIndex == -1) {
|
if (option.selfIndex == -1) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dGError("failed to create mnode since %s, selfIndex is -1", terrstr());
|
dGError("failed to create mnode since %s, selfIndex is -1", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mmWriteFile(pInput->path, &option) != 0) {
|
if ((code = mmWriteFile(pInput->path, &option)) != 0) {
|
||||||
dGError("failed to write mnode file since %s", terrstr());
|
dGError("failed to write mnode file since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
SDDropMnodeReq dropReq = {0};
|
SDDropMnodeReq dropReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dGError("failed to drop mnode since %s", terrstr());
|
dGError("failed to drop mnode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnodeOpt option = {.deploy = false};
|
SMnodeOpt option = {.deploy = false};
|
||||||
if (mmWriteFile(pInput->path, &option) != 0) {
|
if ((code = mmWriteFile(pInput->path, &option)) != 0) {
|
||||||
dGError("failed to write mnode file since %s", terrstr());
|
dGError("failed to write mnode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SArray *mmGetMsgHandles() {
|
SArray *mmGetMsgHandles() {
|
||||||
|
|
|
@ -25,9 +25,10 @@ static bool mmDeployRequired(const SMgmtInputOpt *pInput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
||||||
|
int32_t code = 0;
|
||||||
SMnodeOpt option = {0};
|
SMnodeOpt option = {0};
|
||||||
if (mmReadFile(pInput->path, &option) != 0) {
|
if ((code = mmReadFile(pInput->path, &option)) != 0) {
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!option.deploy) {
|
if (!option.deploy) {
|
||||||
|
@ -41,7 +42,7 @@ static int32_t mmRequire(const SMgmtInputOpt *pInput, bool *required) {
|
||||||
dInfo("deploy mnode required. option deploy:%d", option.deploy);
|
dInfo("deploy mnode required. option deploy:%d", option.deploy);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) {
|
static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInput, SMnodeOpt *pOption) {
|
||||||
|
@ -73,22 +74,31 @@ static void mmClose(SMnodeMgmt *pMgmt) {
|
||||||
|
|
||||||
taosMemoryFree(pMgmt);
|
taosMemoryFree(pMgmt);
|
||||||
}
|
}
|
||||||
|
static int32_t mndOpenWrapper(const char *path, SMnodeOpt *opt, SMnode **pMnode) {
|
||||||
|
int32_t code = 0;
|
||||||
|
*pMnode = mndOpen(path, opt);
|
||||||
|
if (*pMnode == NULL) {
|
||||||
|
code = terrno;
|
||||||
|
}
|
||||||
|
///*pMnode = pNode;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
if (walInit() != 0) {
|
int32_t code = 0;
|
||||||
dError("failed to init wal since %s", terrstr());
|
if ((code = walInit()) != 0) {
|
||||||
return -1;
|
dError("failed to init wal since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (syncInit() != 0) {
|
if ((code = syncInit()) != 0) {
|
||||||
dError("failed to init sync since %s", terrstr());
|
dError("failed to init sync since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SMnodeMgmt));
|
SMnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SMnodeMgmt));
|
||||||
if (pMgmt == NULL) {
|
if (pMgmt == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
|
@ -100,10 +110,10 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||||
|
|
||||||
SMnodeOpt option = {0};
|
SMnodeOpt option = {0};
|
||||||
if (mmReadFile(pMgmt->path, &option) != 0) {
|
if ((code = mmReadFile(pMgmt->path, &option)) != 0) {
|
||||||
dError("failed to read file since %s", terrstr());
|
dError("failed to read file since %s", tstrerror(code));
|
||||||
mmClose(pMgmt);
|
mmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!option.deploy) {
|
if (!option.deploy) {
|
||||||
|
@ -115,18 +125,18 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
mmBuildOptionForOpen(pMgmt, &option);
|
mmBuildOptionForOpen(pMgmt, &option);
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pMnode = mndOpen(pMgmt->path, &option);
|
code = mndOpenWrapper(pMgmt->path, &option, &pMgmt->pMnode);
|
||||||
if (pMgmt->pMnode == NULL) {
|
if (code != 0) {
|
||||||
dError("failed to open mnode since %s", terrstr());
|
dError("failed to open mnode since %s", tstrerror(code));
|
||||||
mmClose(pMgmt);
|
mmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("mnode-impl", "initialized");
|
tmsgReportStartup("mnode-impl", "initialized");
|
||||||
|
|
||||||
if (mmStartWorker(pMgmt) != 0) {
|
if ((code = mmStartWorker(pMgmt)) != 0) {
|
||||||
dError("failed to start mnode worker since %s", terrstr());
|
dError("failed to start mnode worker since %s", tstrerror(code));
|
||||||
mmClose(pMgmt);
|
mmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("mnode-worker", "initialized");
|
tmsgReportStartup("mnode-worker", "initialized");
|
||||||
|
|
||||||
|
@ -134,9 +144,9 @@ static int32_t mmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
option.deploy = true;
|
option.deploy = true;
|
||||||
option.numOfReplicas = 0;
|
option.numOfReplicas = 0;
|
||||||
option.numOfTotalReplicas = 0;
|
option.numOfTotalReplicas = 0;
|
||||||
if (mmWriteFile(pMgmt->path, &option) != 0) {
|
if ((code = mmWriteFile(pMgmt->path, &option)) != 0) {
|
||||||
dError("failed to write mnode file since %s", terrstr());
|
dError("failed to write mnode file since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,13 +170,9 @@ static void mmStop(SMnodeMgmt *pMgmt) {
|
||||||
mndStop(pMgmt->pMnode);
|
mndStop(pMgmt->pMnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) {
|
static int32_t mmSyncIsCatchUp(SMnodeMgmt *pMgmt) { return mndIsCatchUp(pMgmt->pMnode); }
|
||||||
return mndIsCatchUp(pMgmt->pMnode);
|
|
||||||
}
|
|
||||||
|
|
||||||
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) {
|
static ESyncRole mmSyncGetRole(SMnodeMgmt *pMgmt) { return mndGetRole(pMgmt->pMnode); }
|
||||||
return mndGetRole(pMgmt->pMnode);
|
|
||||||
}
|
|
||||||
|
|
||||||
SMgmtFunc mmGetMgmtFunc() {
|
SMgmtFunc mmGetMgmtFunc() {
|
||||||
SMgmtFunc mgmtFunc = {0};
|
SMgmtFunc mgmtFunc = {0};
|
||||||
|
|
|
@ -179,13 +179,15 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
pWorker = &pMgmt->syncRdWorker;
|
pWorker = &pMgmt->syncRdWorker;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWorker == NULL) return -1;
|
if (pWorker == NULL) return code;
|
||||||
|
|
||||||
SRpcMsg *pMsg;
|
SRpcMsg *pMsg;
|
||||||
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
code = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM, pRpc->contLen, (void **)&pMsg);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
|
|
||||||
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
memcpy(pMsg, pRpc, sizeof(SRpcMsg));
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
|
|
||||||
|
@ -201,6 +203,7 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
SSingleWorkerCfg qCfg = {
|
SSingleWorkerCfg qCfg = {
|
||||||
.min = tsNumOfMnodeQueryThreads,
|
.min = tsNumOfMnodeQueryThreads,
|
||||||
.max = tsNumOfMnodeQueryThreads,
|
.max = tsNumOfMnodeQueryThreads,
|
||||||
|
@ -209,9 +212,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
.poolType = QUERY_AUTO_QWORKER_POOL,
|
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &qCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &qCfg)) != 0) {
|
||||||
dError("failed to start mnode-query worker since %s", terrstr());
|
dError("failed to start mnode-query worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg fCfg = {
|
SSingleWorkerCfg fCfg = {
|
||||||
|
@ -221,9 +224,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->fetchWorker, &fCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fCfg)) != 0) {
|
||||||
dError("failed to start mnode-fetch worker since %s", terrstr());
|
dError("failed to start mnode-fetch worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg rCfg = {
|
SSingleWorkerCfg rCfg = {
|
||||||
|
@ -233,9 +236,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->readWorker, &rCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->readWorker, &rCfg)) != 0) {
|
||||||
dError("failed to start mnode-read worker since %s", terrstr());
|
dError("failed to start mnode-read worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg wCfg = {
|
SSingleWorkerCfg wCfg = {
|
||||||
|
@ -245,9 +248,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->writeWorker, &wCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->writeWorker, &wCfg)) != 0) {
|
||||||
dError("failed to start mnode-write worker since %s", terrstr());
|
dError("failed to start mnode-write worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg sCfg = {
|
SSingleWorkerCfg sCfg = {
|
||||||
|
@ -257,9 +260,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessSyncMsg,
|
.fp = (FItem)mmProcessSyncMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->syncWorker, &sCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->syncWorker, &sCfg)) != 0) {
|
||||||
dError("failed to start mnode mnode-sync worker since %s", terrstr());
|
dError("failed to start mnode mnode-sync worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg scCfg = {
|
SSingleWorkerCfg scCfg = {
|
||||||
|
@ -269,9 +272,9 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessSyncMsg,
|
.fp = (FItem)mmProcessSyncMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->syncRdWorker, &scCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->syncRdWorker, &scCfg)) != 0) {
|
||||||
dError("failed to start mnode mnode-sync-rd worker since %s", terrstr());
|
dError("failed to start mnode mnode-sync-rd worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg arbCfg = {
|
SSingleWorkerCfg arbCfg = {
|
||||||
|
@ -281,13 +284,13 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)mmProcessRpcMsg,
|
.fp = (FItem)mmProcessRpcMsg,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->arbWorker, &arbCfg)) != 0) {
|
||||||
dError("failed to start mnode mnode-arb worker since %s", terrstr());
|
dError("failed to start mnode mnode-arb worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("mnode workers are initialized");
|
dDebug("mnode workers are initialized");
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mmStopWorker(SMnodeMgmt *pMgmt) {
|
void mmStopWorker(SMnodeMgmt *pMgmt) {
|
||||||
|
|
|
@ -30,24 +30,25 @@ void qmGetQnodeLoads(SQnodeMgmt *pMgmt, SQnodeLoad *pInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDCreateQnodeReq createReq = {0};
|
SDCreateQnodeReq createReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dError("failed to create qnode since %s", terrstr());
|
dError("failed to create qnode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deployed = true;
|
bool deployed = true;
|
||||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||||
dError("failed to write qnode file since %s", terrstr());
|
dError("failed to write qnode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
|
@ -55,24 +56,25 @@ int32_t qmProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t qmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDDropQnodeReq dropReq = {0};
|
SDDropQnodeReq dropReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dError("failed to drop qnode since %s", terrstr());
|
dError("failed to drop qnode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deployed = false;
|
bool deployed = false;
|
||||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||||
dError("failed to write qnode file since %s", terrstr());
|
dError("failed to write qnode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
|
|
|
@ -33,11 +33,18 @@ static void qmClose(SQnodeMgmt *pMgmt) {
|
||||||
taosMemoryFree(pMgmt);
|
taosMemoryFree(pMgmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t qndOpenWrapper(SQnodeOpt *pOption, SQnode **pQnode) {
|
||||||
|
*pQnode = qndOpen(pOption);
|
||||||
|
if (*pQnode == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
int32_t code = 0;
|
||||||
SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
|
SQnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SQnodeMgmt));
|
||||||
if (pMgmt == NULL) {
|
if (pMgmt == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
|
@ -50,29 +57,30 @@ static int32_t qmOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
|
||||||
SQnodeOpt option = {0};
|
SQnodeOpt option = {0};
|
||||||
qmInitOption(pMgmt, &option);
|
qmInitOption(pMgmt, &option);
|
||||||
pMgmt->pQnode = qndOpen(&option);
|
|
||||||
if (pMgmt->pQnode == NULL) {
|
code = qndOpenWrapper(&option, &pMgmt->pQnode);
|
||||||
dError("failed to open qnode since %s", terrstr());
|
if (code != 0) {
|
||||||
|
dError("failed to open qnode since %s", tstrerror(code));
|
||||||
qmClose(pMgmt);
|
qmClose(pMgmt);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("qnode-impl", "initialized");
|
tmsgReportStartup("qnode-impl", "initialized");
|
||||||
|
|
||||||
if (udfcOpen() != 0) {
|
if ((code = udfcOpen()) != 0) {
|
||||||
dError("qnode can not open udfc");
|
dError("qnode can not open udfc");
|
||||||
qmClose(pMgmt);
|
qmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qmStartWorker(pMgmt) != 0) {
|
if ((code = qmStartWorker(pMgmt)) != 0) {
|
||||||
dError("failed to start qnode worker since %s", terrstr());
|
dError("failed to start qnode worker since %s", tstrerror(code));
|
||||||
qmClose(pMgmt);
|
qmClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("qnode-worker", "initialized");
|
tmsgReportStartup("qnode-worker", "initialized");
|
||||||
|
|
||||||
pOutput->pMgmt = pMgmt;
|
pOutput->pMgmt = pMgmt;
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMgmtFunc qmGetMgmtFunc() {
|
SMgmtFunc qmGetMgmtFunc() {
|
||||||
|
|
|
@ -102,6 +102,8 @@ int32_t qmGetQueueSize(SQnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
SSingleWorkerCfg queryCfg = {
|
SSingleWorkerCfg queryCfg = {
|
||||||
.min = tsNumOfVnodeQueryThreads,
|
.min = tsNumOfVnodeQueryThreads,
|
||||||
.max = tsNumOfVnodeQueryThreads,
|
.max = tsNumOfVnodeQueryThreads,
|
||||||
|
@ -111,9 +113,9 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
.poolType = QUERY_AUTO_QWORKER_POOL,
|
.poolType = QUERY_AUTO_QWORKER_POOL,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->queryWorker, &queryCfg)) != 0) {
|
||||||
dError("failed to start qnode-query worker since %s", terrstr());
|
dError("failed to start qnode-query worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSingleWorkerCfg fetchCfg = {
|
SSingleWorkerCfg fetchCfg = {
|
||||||
|
@ -124,13 +126,13 @@ int32_t qmStartWorker(SQnodeMgmt *pMgmt) {
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg) != 0) {
|
if ((code = tSingleWorkerInit(&pMgmt->fetchWorker, &fetchCfg)) != 0) {
|
||||||
dError("failed to start qnode-fetch worker since %s", terrstr());
|
dError("failed to start qnode-fetch worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("qnode workers are initialized");
|
dDebug("qnode workers are initialized");
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qmStopWorker(SQnodeMgmt *pMgmt) {
|
void qmStopWorker(SQnodeMgmt *pMgmt) {
|
||||||
|
|
|
@ -19,24 +19,25 @@
|
||||||
void smGetMonitorInfo(SSnodeMgmt *pMgmt, SMonSmInfo *smInfo) {}
|
void smGetMonitorInfo(SSnodeMgmt *pMgmt, SMonSmInfo *smInfo) {}
|
||||||
|
|
||||||
int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDCreateSnodeReq createReq = {0};
|
SDCreateSnodeReq createReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &createReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && createReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dError("failed to create snode since %s", terrstr());
|
dError("failed to create snode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deployed = true;
|
bool deployed = true;
|
||||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||||
dError("failed to write snode file since %s", terrstr());
|
dError("failed to write snode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&createReq);
|
tFreeSMCreateQnodeReq(&createReq);
|
||||||
|
@ -44,24 +45,26 @@ int32_t smProcessCreateReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
int32_t smProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDDropSnodeReq dropReq = {0};
|
SDDropSnodeReq dropReq = {0};
|
||||||
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
if (tDeserializeSCreateDropMQSNodeReq(pMsg->pCont, pMsg->contLen, &dropReq) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
if (pInput->pData->dnodeId != 0 && dropReq.dnodeId != pInput->pData->dnodeId) {
|
||||||
terrno = TSDB_CODE_INVALID_OPTION;
|
code = TSDB_CODE_INVALID_OPTION;
|
||||||
dError("failed to drop snode since %s", terrstr());
|
dError("failed to drop snode since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool deployed = false;
|
bool deployed = false;
|
||||||
if (dmWriteFile(pInput->path, pInput->name, deployed) != 0) {
|
if ((code = dmWriteFile(pInput->path, pInput->name, deployed)) != 0) {
|
||||||
dError("failed to write snode file since %s", terrstr());
|
dError("failed to write snode file since %s", tstrerror(code));
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tFreeSMCreateQnodeReq(&dropReq);
|
tFreeSMCreateQnodeReq(&dropReq);
|
||||||
|
|
|
@ -33,12 +33,19 @@ static void smClose(SSnodeMgmt *pMgmt) {
|
||||||
|
|
||||||
taosMemoryFree(pMgmt);
|
taosMemoryFree(pMgmt);
|
||||||
}
|
}
|
||||||
|
int32_t sndOpenWrapper(const char *path, SSnodeOpt *pOption, SSnode **pNode) {
|
||||||
|
*pNode = sndOpen(path, pOption);
|
||||||
|
if (*pNode == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
int32_t code = 0;
|
||||||
SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt));
|
SSnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SSnodeMgmt));
|
||||||
if (pMgmt == NULL) {
|
if (pMgmt == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
|
@ -50,35 +57,34 @@ int32_t smOpen(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
|
|
||||||
SSnodeOpt option = {0};
|
SSnodeOpt option = {0};
|
||||||
smInitOption(pMgmt, &option);
|
smInitOption(pMgmt, &option);
|
||||||
pMgmt->pSnode = sndOpen(pMgmt->path, &option);
|
|
||||||
if (pMgmt->pSnode == NULL) {
|
code = sndOpenWrapper(pMgmt->path, &option, &pMgmt->pSnode);
|
||||||
dError("failed to open snode since %s", terrstr());
|
if (code != 0) {
|
||||||
|
dError("failed to open snode since %s", tstrerror(code));
|
||||||
smClose(pMgmt);
|
smClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmsgReportStartup("snode-impl", "initialized");
|
tmsgReportStartup("snode-impl", "initialized");
|
||||||
|
|
||||||
if (smStartWorker(pMgmt) != 0) {
|
if ((code = smStartWorker(pMgmt)) != 0) {
|
||||||
dError("failed to start snode worker since %s", terrstr());
|
dError("failed to start snode worker since %s", tstrerror(code));
|
||||||
smClose(pMgmt);
|
smClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("snode-worker", "initialized");
|
tmsgReportStartup("snode-worker", "initialized");
|
||||||
|
|
||||||
if (udfcOpen() != 0) {
|
if ((code = udfcOpen()) != 0) {
|
||||||
dError("failed to open udfc in snode");
|
dError("failed to open udfc in snode since:%s", tstrerror(code));
|
||||||
smClose(pMgmt);
|
smClose(pMgmt);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pOutput->pMgmt = pMgmt;
|
pOutput->pMgmt = pMgmt;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) {
|
static int32_t smStartSnodes(SSnodeMgmt *pMgmt) { return sndInit(pMgmt->pSnode); }
|
||||||
return sndInit(pMgmt->pSnode);
|
|
||||||
}
|
|
||||||
|
|
||||||
SMgmtFunc smGetMgmtFunc() {
|
SMgmtFunc smGetMgmtFunc() {
|
||||||
SMgmtFunc mgmtFunc = {0};
|
SMgmtFunc mgmtFunc = {0};
|
||||||
|
|
|
@ -68,17 +68,18 @@ static void smProcessStreamQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
pMgmt->writeWroker = taosArrayInit(0, sizeof(SMultiWorker *));
|
pMgmt->writeWroker = taosArrayInit(0, sizeof(SMultiWorker *));
|
||||||
if (pMgmt->writeWroker == NULL) {
|
if (pMgmt->writeWroker == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < tsNumOfSnodeWriteThreads; i++) {
|
for (int32_t i = 0; i < tsNumOfSnodeWriteThreads; i++) {
|
||||||
SMultiWorker *pWriteWorker = taosMemoryMalloc(sizeof(SMultiWorker));
|
SMultiWorker *pWriteWorker = taosMemoryMalloc(sizeof(SMultiWorker));
|
||||||
if (pWriteWorker == NULL) {
|
if (pWriteWorker == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMultiWorkerCfg cfg = {
|
SMultiWorkerCfg cfg = {
|
||||||
|
@ -87,13 +88,13 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
||||||
.fp = smProcessWriteQueue,
|
.fp = smProcessWriteQueue,
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
if (tMultiWorkerInit(pWriteWorker, &cfg) != 0) {
|
if ((code = tMultiWorkerInit(pWriteWorker, &cfg)) != 0) {
|
||||||
dError("failed to start snode-unique worker since %s", terrstr());
|
dError("failed to start snode-unique worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
if (taosArrayPush(pMgmt->writeWroker, &pWriteWorker) == NULL) {
|
if (taosArrayPush(pMgmt->writeWroker, &pWriteWorker) == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,13 +106,13 @@ int32_t smStartWorker(SSnodeMgmt *pMgmt) {
|
||||||
.param = pMgmt,
|
.param = pMgmt,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) {
|
if ((code = tSingleWorkerInit(&pMgmt->streamWorker, &cfg)) != 0) {
|
||||||
dError("failed to start snode shared-worker since %s", terrstr());
|
dError("failed to start snode shared-worker since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("snode workers are initialized");
|
dDebug("snode workers are initialized");
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void smStopWorker(SSnodeMgmt *pMgmt) {
|
void smStopWorker(SSnodeMgmt *pMgmt) {
|
||||||
|
@ -133,17 +134,18 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
if (code) {
|
if (code) {
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
return -1;
|
return code = terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSnode *pSnode = pMgmt->pSnode;
|
SSnode *pSnode = pMgmt->pSnode;
|
||||||
if (pSnode == NULL) {
|
if (pSnode == NULL) {
|
||||||
dError("msg:%p failed to put into snode queue since %s, type:%s qtype:%d len:%d", pMsg, terrstr(),
|
code = terrno;
|
||||||
|
dError("msg:%p failed to put into snode queue since %s, type:%s qtype:%d len:%d", pMsg, tstrerror(code),
|
||||||
TMSG_INFO(pMsg->msgType), qtype, pRpc->contLen);
|
TMSG_INFO(pMsg->msgType), qtype, pRpc->contLen);
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMsgHead *pHead = pRpc->pCont;
|
SMsgHead *pHead = pRpc->pCont;
|
||||||
|
@ -154,48 +156,44 @@ int32_t smPutMsgToQueue(SSnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
|
|
||||||
switch (qtype) {
|
switch (qtype) {
|
||||||
case STREAM_QUEUE:
|
case STREAM_QUEUE:
|
||||||
smPutNodeMsgToStreamQueue(pMgmt, pMsg);
|
code = smPutNodeMsgToStreamQueue(pMgmt, pMsg);
|
||||||
break;
|
break;
|
||||||
case WRITE_QUEUE:
|
case WRITE_QUEUE:
|
||||||
smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
code = smPutNodeMsgToWriteQueue(pMgmt, pMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
code = TSDB_CODE_INVALID_PARA;
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t smPutNodeMsgToMgmtQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
||||||
if (pWorker == NULL) {
|
if (pWorker == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||||
taosWriteQitem(pWorker->queue, pMsg);
|
return taosWriteQitem(pWorker->queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t smPutNodeMsgToWriteQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
SMultiWorker *pWorker = taosArrayGetP(pMgmt->writeWroker, 0);
|
||||||
if (pWorker == NULL) {
|
if (pWorker == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||||
taosWriteQitem(pWorker->queue, pMsg);
|
return taosWriteQitem(pWorker->queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t smPutNodeMsgToStreamQueue(SSnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
SSingleWorker *pWorker = &pMgmt->streamWorker;
|
SSingleWorker *pWorker = &pMgmt->streamWorker;
|
||||||
|
|
||||||
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
dTrace("msg:%p, put into worker %s", pMsg, pWorker->name);
|
||||||
taosWriteQitem(pWorker->queue, pMsg);
|
return taosWriteQitem(pWorker->queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ int32_t vmProcessArbHeartBeatReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||||
// vmFile.c
|
// vmFile.c
|
||||||
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes);
|
||||||
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt);
|
int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt);
|
||||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes);
|
int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes);
|
||||||
|
|
||||||
// vmWorker.c
|
// vmWorker.c
|
||||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt);
|
int32_t vmStartWorker(SVnodeMgmt *pMgmt);
|
||||||
|
|
|
@ -19,12 +19,16 @@
|
||||||
|
|
||||||
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
#define MAX_CONTENT_LEN 2 * 1024 * 1024
|
||||||
|
|
||||||
SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
int32_t vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes, SVnodeObj ***ppVnodes) {
|
||||||
taosThreadRwlockRdlock(&pMgmt->lock);
|
taosThreadRwlockRdlock(&pMgmt->lock);
|
||||||
|
|
||||||
int32_t num = 0;
|
int32_t num = 0;
|
||||||
int32_t size = taosHashGetSize(pMgmt->hash);
|
int32_t size = taosHashGetSize(pMgmt->hash);
|
||||||
SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *));
|
SVnodeObj **pVnodes = taosMemoryCalloc(size, sizeof(SVnodeObj *));
|
||||||
|
if (pVnodes == NULL) {
|
||||||
|
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
void *pIter = taosHashIterate(pMgmt->hash, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
|
@ -42,8 +46,9 @@ SVnodeObj **vmGetVnodeListFromHash(SVnodeMgmt *pMgmt, int32_t *numOfVnodes) {
|
||||||
|
|
||||||
taosThreadRwlockUnlock(&pMgmt->lock);
|
taosThreadRwlockUnlock(&pMgmt->lock);
|
||||||
*numOfVnodes = num;
|
*numOfVnodes = num;
|
||||||
|
*ppVnodes = pVnodes;
|
||||||
|
|
||||||
return pVnodes;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes) {
|
static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t *numOfVnodes) {
|
||||||
|
@ -52,29 +57,32 @@ static int32_t vmDecodeVnodeList(SJson *pJson, SVnodeMgmt *pMgmt, SWrapperCfg **
|
||||||
*ppCfgs = NULL;
|
*ppCfgs = NULL;
|
||||||
|
|
||||||
SJson *vnodes = tjsonGetObjectItem(pJson, "vnodes");
|
SJson *vnodes = tjsonGetObjectItem(pJson, "vnodes");
|
||||||
if (vnodes == NULL) return -1;
|
if (vnodes == NULL) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
|
||||||
int32_t vnodesNum = cJSON_GetArraySize(vnodes);
|
int32_t vnodesNum = cJSON_GetArraySize(vnodes);
|
||||||
if (vnodesNum > 0) {
|
if (vnodesNum > 0) {
|
||||||
pCfgs = taosMemoryCalloc(vnodesNum, sizeof(SWrapperCfg));
|
pCfgs = taosMemoryCalloc(vnodesNum, sizeof(SWrapperCfg));
|
||||||
if (pCfgs == NULL) return -1;
|
if (pCfgs == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < vnodesNum; ++i) {
|
for (int32_t i = 0; i < vnodesNum; ++i) {
|
||||||
SJson *vnode = tjsonGetArrayItem(vnodes, i);
|
SJson *vnode = tjsonGetArrayItem(vnodes, i);
|
||||||
if (vnode == NULL) goto _OVER;
|
if (vnode == NULL) {
|
||||||
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
SWrapperCfg *pCfg = &pCfgs[i];
|
SWrapperCfg *pCfg = &pCfgs[i];
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "vgId", pCfg->vgId, code);
|
tjsonGetInt32ValueFromDouble(vnode, "vgId", pCfg->vgId, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "dropped", pCfg->dropped, code);
|
tjsonGetInt32ValueFromDouble(vnode, "dropped", pCfg->dropped, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "vgVersion", pCfg->vgVersion, code);
|
tjsonGetInt32ValueFromDouble(vnode, "vgVersion", pCfg->vgVersion, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "diskPrimary", pCfg->diskPrimary, code);
|
tjsonGetInt32ValueFromDouble(vnode, "diskPrimary", pCfg->diskPrimary, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
tjsonGetInt32ValueFromDouble(vnode, "toVgId", pCfg->toVgId, code);
|
tjsonGetInt32ValueFromDouble(vnode, "toVgId", pCfg->toVgId, code);
|
||||||
if (code < 0) goto _OVER;
|
if (code != 0) goto _OVER;
|
||||||
|
|
||||||
snprintf(pCfg->path, sizeof(pCfg->path), "%s%svnode%d", pMgmt->path, TD_DIRSEP, pCfg->vgId);
|
snprintf(pCfg->path, sizeof(pCfg->path), "%s%svnode%d", pMgmt->path, TD_DIRSEP, pCfg->vgId);
|
||||||
}
|
}
|
||||||
|
@ -98,33 +106,35 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
||||||
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("vnode file:%s not exist", file);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return 0;
|
dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code));
|
||||||
|
code = 0;
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open vnode file:%s since %s", file, terrstr());
|
dError("failed to open vnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat mnode file:%s since %s", file, terrstr());
|
dError("failed to fstat mnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pData = taosMemoryMalloc(size + 1);
|
pData = taosMemoryMalloc(size + 1);
|
||||||
if (pData == NULL) {
|
if (pData == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, pData, size) != size) {
|
if (taosReadFile(pFile, pData, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read vnode file:%s since %s", file, terrstr());
|
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,12 +142,12 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
|
||||||
|
|
||||||
pJson = tjsonParse(pData);
|
pJson = tjsonParse(pData);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vmDecodeVnodeList(pJson, pMgmt, ppCfgs, numOfVnodes) < 0) {
|
if (vmDecodeVnodeList(pJson, pMgmt, ppCfgs, numOfVnodes) < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,28 +160,36 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to read vnode file:%s since %s", file, terrstr());
|
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vmEncodeVnodeList(SJson *pJson, SVnodeObj **ppVnodes, int32_t numOfVnodes) {
|
static int32_t vmEncodeVnodeList(SJson *pJson, SVnodeObj **ppVnodes, int32_t numOfVnodes) {
|
||||||
|
int32_t code = 0;
|
||||||
SJson *vnodes = tjsonCreateArray();
|
SJson *vnodes = tjsonCreateArray();
|
||||||
if (vnodes == NULL) return -1;
|
if (vnodes == NULL) {
|
||||||
if (tjsonAddItemToObject(pJson, "vnodes", vnodes) < 0) return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
if ((code = tjsonAddItemToObject(pJson, "vnodes", vnodes)) < 0) {
|
||||||
|
tjsonDelete(vnodes);
|
||||||
|
return code;
|
||||||
|
};
|
||||||
|
|
||||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||||
SVnodeObj *pVnode = ppVnodes[i];
|
SVnodeObj *pVnode = ppVnodes[i];
|
||||||
if (pVnode == NULL) continue;
|
if (pVnode == NULL) continue;
|
||||||
|
|
||||||
SJson *vnode = tjsonCreateObject();
|
SJson *vnode = tjsonCreateObject();
|
||||||
if (vnode == NULL) return -1;
|
if (vnode == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
if (tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "vgId", pVnode->vgId)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "dropped", pVnode->dropped)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "vgVersion", pVnode->vgVersion)) < 0) return code;
|
||||||
if (tjsonAddDoubleToObject(vnode, "diskPrimary", pVnode->diskPrimary) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "diskPrimary", pVnode->diskPrimary)) < 0) return code;
|
||||||
if (pVnode->toVgId && tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId) < 0) return -1;
|
if (pVnode->toVgId) {
|
||||||
if (tjsonAddItemToArray(vnodes, vnode) < 0) return -1;
|
if ((code = tjsonAddDoubleToObject(vnode, "toVgId", pVnode->toVgId)) < 0) return code;
|
||||||
|
}
|
||||||
|
if ((code = tjsonAddItemToArray(vnodes, vnode)) < 0) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -185,30 +203,60 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
|
||||||
SVnodeObj **ppVnodes = NULL;
|
SVnodeObj **ppVnodes = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
|
||||||
snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%svnodes_tmp.json", pMgmt->path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(file)) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(realfile, sizeof(realfile), "%s%svnodes.json", pMgmt->path, TD_DIRSEP);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(realfile)) {
|
||||||
|
return TSDB_CODE_OUT_OF_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
if (ppVnodes == NULL) goto _OVER;
|
if (code) goto _OVER;
|
||||||
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
// terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) {
|
||||||
if (vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes) != 0) goto _OVER;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if ((code = vmEncodeVnodeList(pJson, ppVnodes, numOfVnodes)) != 0) goto _OVER;
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) {
|
||||||
terrno = 0;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
code = taosCloseFile(&pFile);
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
if (code != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
|
||||||
|
@ -228,8 +276,7 @@ _OVER:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, tstrerror(code), numOfVnodes);
|
||||||
dError("failed to write vnodes file:%s since %s, vnodes:%d", realfile, terrstr(), numOfVnodes);
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -256,8 +256,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
char path[TSDB_FILENAME_LEN] = {0};
|
char path[TSDB_FILENAME_LEN] = {0};
|
||||||
|
|
||||||
if (tDeserializeSCreateVnodeReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
if (tDeserializeSCreateVnodeReq(pMsg->pCont, pMsg->contLen, &req) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.learnerReplica == 0) {
|
if (req.learnerReplica == 0) {
|
||||||
|
@ -298,25 +297,24 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort ||
|
if (pReplica->id != pMgmt->pData->dnodeId || pReplica->port != tsServerPort ||
|
||||||
strcmp(pReplica->fqdn, tsLocalFqdn) != 0) {
|
strcmp(pReplica->fqdn, tsLocalFqdn) != 0) {
|
||||||
terrno = TSDB_CODE_INVALID_MSG;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode", req.vgId, pReplica->id, pReplica->fqdn,
|
dError("vgId:%d, dnodeId:%d ep:%s:%u not matched with local dnode, reason:%s", req.vgId, pReplica->id,
|
||||||
pReplica->port);
|
pReplica->fqdn, pReplica->port, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.encryptAlgorithm == DND_CA_SM4) {
|
if (req.encryptAlgorithm == DND_CA_SM4) {
|
||||||
if (strlen(tsEncryptKey) == 0) {
|
if (strlen(tsEncryptKey) == 0) {
|
||||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||||
dError("vgId:%d, failed to create vnode since encrypt key is empty", req.vgId);
|
dError("vgId:%d, failed to create vnode since encrypt key is empty, reason:%s", req.vgId, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vmGenerateVnodeCfg(&req, &vnodeCfg);
|
vmGenerateVnodeCfg(&req, &vnodeCfg);
|
||||||
|
|
||||||
if (vmTsmaAdjustDays(&vnodeCfg, &req) < 0) {
|
if ((code = vmTsmaAdjustDays(&vnodeCfg, &req)) < 0) {
|
||||||
dError("vgId:%d, failed to adjust tsma days since %s", req.vgId, terrstr());
|
dError("vgId:%d, failed to adjust tsma days since %s", req.vgId, tstrerror(code));
|
||||||
code = terrno != 0 ? terrno : -1;
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,8 +325,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
dError("vgId:%d, already exist", req.vgId);
|
dError("vgId:%d, already exist", req.vgId);
|
||||||
tFreeSCreateVnodeReq(&req);
|
tFreeSCreateVnodeReq(&req);
|
||||||
vmReleaseVnode(pMgmt, pVnode);
|
vmReleaseVnode(pMgmt, pVnode);
|
||||||
terrno = TSDB_CODE_VND_ALREADY_EXIST;
|
code = TSDB_CODE_VND_ALREADY_EXIST;
|
||||||
code = terrno;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ int32_t vmGetPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
|
int32_t code = 0;
|
||||||
STfs *pTfs = pMgmt->pTfs;
|
STfs *pTfs = pMgmt->pTfs;
|
||||||
int32_t diskId = 0;
|
int32_t diskId = 0;
|
||||||
if (!pTfs) {
|
if (!pTfs) {
|
||||||
|
@ -59,7 +60,12 @@ int32_t vmAllocPrimaryDisk(SVnodeMgmt *pMgmt, int32_t vgId) {
|
||||||
// alloc
|
// alloc
|
||||||
int32_t disks[TFS_MAX_DISKS_PER_TIER] = {0};
|
int32_t disks[TFS_MAX_DISKS_PER_TIER] = {0};
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
|
||||||
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
|
if (code != 0) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
for (int32_t v = 0; v < numOfVnodes; v++) {
|
for (int32_t v = 0; v < numOfVnodes; v++) {
|
||||||
SVnodeObj *pVnode = ppVnodes[v];
|
SVnodeObj *pVnode = ppVnodes[v];
|
||||||
disks[pVnode->diskPrimary] += 1;
|
disks[pVnode->diskPrimary] += 1;
|
||||||
|
@ -436,6 +442,7 @@ static void *vmCloseVnodeInThread(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
dInfo("start to close all vnodes");
|
dInfo("start to close all vnodes");
|
||||||
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
||||||
dInfo("vnodes mgmt worker is stopped");
|
dInfo("vnodes mgmt worker is stopped");
|
||||||
|
@ -443,7 +450,12 @@ static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
||||||
dInfo("vnodes multiple mgmt worker is stopped");
|
dInfo("vnodes multiple mgmt worker is stopped");
|
||||||
|
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get vnode list since %s", tstrerror(code));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t threadNum = tsNumOfCores / 2;
|
int32_t threadNum = tsNumOfCores / 2;
|
||||||
if (threadNum < 1) threadNum = 1;
|
if (threadNum < 1) threadNum = 1;
|
||||||
|
@ -513,8 +525,14 @@ static void vmCleanup(SVnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vmCheckSyncTimeout(SVnodeMgmt *pMgmt) {
|
static void vmCheckSyncTimeout(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get vnode list since %s", tstrerror(code));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ppVnodes != NULL) {
|
if (ppVnodes != NULL) {
|
||||||
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
for (int32_t i = 0; i < numOfVnodes; ++i) {
|
||||||
|
@ -549,12 +567,14 @@ static void *vmThreadFp(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vmInitTimer(SVnodeMgmt *pMgmt) {
|
static int32_t vmInitTimer(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
TdThreadAttr thAttr;
|
TdThreadAttr thAttr;
|
||||||
taosThreadAttrInit(&thAttr);
|
taosThreadAttrInit(&thAttr);
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pMgmt->thread, &thAttr, vmThreadFp, pMgmt) != 0) {
|
if (taosThreadCreate(&pMgmt->thread, &thAttr, vmThreadFp, pMgmt) != 0) {
|
||||||
dError("failed to create vnode timer thread since %s", strerror(errno));
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
dError("failed to create vnode timer thread since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
@ -573,7 +593,10 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
|
||||||
SVnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SVnodeMgmt));
|
SVnodeMgmt *pMgmt = taosMemoryCalloc(1, sizeof(SVnodeMgmt));
|
||||||
if (pMgmt == NULL) goto _OVER;
|
if (pMgmt == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pMgmt->pData = pInput->pData;
|
pMgmt->pData = pInput->pData;
|
||||||
pMgmt->path = pInput->path;
|
pMgmt->path = pInput->path;
|
||||||
|
@ -582,8 +605,18 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
pMgmt->msgCb.putToQueueFp = (PutToQueueFp)vmPutRpcMsgToQueue;
|
pMgmt->msgCb.putToQueueFp = (PutToQueueFp)vmPutRpcMsgToQueue;
|
||||||
pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)vmGetQueueSize;
|
pMgmt->msgCb.qsizeFp = (GetQueueSizeFp)vmGetQueueSize;
|
||||||
pMgmt->msgCb.mgmt = pMgmt;
|
pMgmt->msgCb.mgmt = pMgmt;
|
||||||
taosThreadRwlockInit(&pMgmt->lock, NULL);
|
|
||||||
taosThreadMutexInit(&pMgmt->createLock, NULL);
|
code = taosThreadRwlockInit(&pMgmt->lock, NULL);
|
||||||
|
if (code != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = taosThreadMutexInit(&pMgmt->createLock, NULL);
|
||||||
|
if (code != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pMgmt->pTfs = pInput->pTfs;
|
pMgmt->pTfs = pInput->pTfs;
|
||||||
if (pMgmt->pTfs == NULL) {
|
if (pMgmt->pTfs == NULL) {
|
||||||
|
@ -592,38 +625,39 @@ static int32_t vmInit(SMgmtInputOpt *pInput, SMgmtOutputOpt *pOutput) {
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-tfs", "initialized");
|
tmsgReportStartup("vnode-tfs", "initialized");
|
||||||
|
|
||||||
if (walInit() != 0) {
|
if ((code = walInit()) != 0) {
|
||||||
dError("failed to init wal since %s", terrstr());
|
dError("failed to init wal since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmsgReportStartup("vnode-wal", "initialized");
|
tmsgReportStartup("vnode-wal", "initialized");
|
||||||
|
|
||||||
if (syncInit() != 0) {
|
if ((code = syncInit()) != 0) {
|
||||||
dError("failed to open sync since %s", terrstr());
|
dError("failed to open sync since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-sync", "initialized");
|
tmsgReportStartup("vnode-sync", "initialized");
|
||||||
|
|
||||||
if (vnodeInit(tsNumOfCommitThreads) != 0) {
|
if ((code = vnodeInit(tsNumOfCommitThreads)) != 0) {
|
||||||
dError("failed to init vnode since %s", terrstr());
|
dError("failed to init vnode since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-commit", "initialized");
|
tmsgReportStartup("vnode-commit", "initialized");
|
||||||
|
|
||||||
if (vmStartWorker(pMgmt) != 0) {
|
if ((code = vmStartWorker(pMgmt)) != 0) {
|
||||||
dError("failed to init workers since %s", terrstr());
|
dError("failed to init workers since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-worker", "initialized");
|
tmsgReportStartup("vnode-worker", "initialized");
|
||||||
|
|
||||||
if (vmOpenVnodes(pMgmt) != 0) {
|
if ((code = vmOpenVnodes(pMgmt)) != 0) {
|
||||||
dError("failed to open all vnodes since %s", terrstr());
|
dError("failed to open all vnodes since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
tmsgReportStartup("vnode-vnodes", "initialized");
|
tmsgReportStartup("vnode-vnodes", "initialized");
|
||||||
|
|
||||||
if (udfcOpen() != 0) {
|
if ((code = udfcOpen()) != 0) {
|
||||||
dError("failed to open udfc in vnode");
|
dError("failed to open udfc in vnode since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -633,7 +667,7 @@ _OVER:
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
pOutput->pMgmt = pMgmt;
|
pOutput->pMgmt = pMgmt;
|
||||||
} else {
|
} else {
|
||||||
dError("failed to init vnodes-mgmt since %s", terrstr());
|
dError("failed to init vnodes-mgmt since %s", tstrerror(code));
|
||||||
vmCleanup(pMgmt);
|
vmCleanup(pMgmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,18 +717,32 @@ static void *vmRestoreVnodeInThread(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = NULL;
|
||||||
|
code = vmGetVnodeListFromHash(pMgmt, &numOfVnodes, &ppVnodes);
|
||||||
|
if (code != 0) {
|
||||||
|
dError("failed to get vnode list since %s", tstrerror(code));
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t threadNum = tsNumOfCores / 2;
|
int32_t threadNum = tsNumOfCores / 2;
|
||||||
if (threadNum < 1) threadNum = 1;
|
if (threadNum < 1) threadNum = 1;
|
||||||
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
int32_t vnodesPerThread = numOfVnodes / threadNum + 1;
|
||||||
|
|
||||||
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
|
SVnodeThread *threads = taosMemoryCalloc(threadNum, sizeof(SVnodeThread));
|
||||||
|
if (threads == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t t = 0; t < threadNum; ++t) {
|
for (int32_t t = 0; t < threadNum; ++t) {
|
||||||
threads[t].threadIndex = t;
|
threads[t].threadIndex = t;
|
||||||
threads[t].pMgmt = pMgmt;
|
threads[t].pMgmt = pMgmt;
|
||||||
threads[t].ppVnodes = taosMemoryCalloc(vnodesPerThread, sizeof(SVnode *));
|
threads[t].ppVnodes = taosMemoryCalloc(vnodesPerThread, sizeof(SVnode *));
|
||||||
|
if (threads[t].ppVnodes == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
for (int32_t v = 0; v < numOfVnodes; ++v) {
|
||||||
|
@ -717,6 +765,7 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
||||||
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
|
||||||
if (taosThreadCreate(&pThread->thread, &thAttr, vmRestoreVnodeInThread, pThread) != 0) {
|
if (taosThreadCreate(&pThread->thread, &thAttr, vmRestoreVnodeInThread, pThread) != 0) {
|
||||||
dError("thread:%d, failed to create thread to restore vnode since %s", pThread->threadIndex, strerror(errno));
|
dError("thread:%d, failed to create thread to restore vnode since %s", pThread->threadIndex, strerror(errno));
|
||||||
|
ASSERT(errno == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadAttrDestroy(&thAttr);
|
taosThreadAttrDestroy(&thAttr);
|
||||||
|
@ -742,6 +791,14 @@ static int32_t vmStartVnodes(SVnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return vmInitTimer(pMgmt);
|
return vmInitTimer(pMgmt);
|
||||||
|
|
||||||
|
_exit:
|
||||||
|
for (int32_t t = 0; t < threadNum; ++t) {
|
||||||
|
SVnodeThread *pThread = &threads[t];
|
||||||
|
taosMemoryFree(pThread->ppVnodes);
|
||||||
|
}
|
||||||
|
taosMemoryFree(threads);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vmStop(SVnodeMgmt *pMgmt) { vmCleanupTimer(pMgmt); }
|
static void vmStop(SVnodeMgmt *pMgmt) { vmCleanupTimer(pMgmt); }
|
||||||
|
|
|
@ -200,26 +200,33 @@ static bool vmDataSpaceSufficient(SVnodeObj *pVnode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t vmAcquireVnodeWrapper(SVnodeMgmt *pMgt, int32_t vgId, SVnodeObj **pNode) {
|
||||||
|
*pNode = vmAcquireVnode(pMgt, vgId);
|
||||||
|
if (*pNode == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtype) {
|
||||||
|
int32_t code = 0;
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
if (pMsg->contLen < sizeof(SMsgHead)) {
|
if (pMsg->contLen < sizeof(SMsgHead)) {
|
||||||
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
|
dGError("invalid rpc msg with no msg head at pCont. pMsg:%p, type:%s, contLen:%d", pMsg, TMSG_INFO(pMsg->msgType),
|
||||||
pMsg->contLen);
|
pMsg->contLen);
|
||||||
return -1;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMsgHead *pHead = pMsg->pCont;
|
SMsgHead *pHead = pMsg->pCont;
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
pHead->contLen = ntohl(pHead->contLen);
|
pHead->contLen = ntohl(pHead->contLen);
|
||||||
pHead->vgId = ntohl(pHead->vgId);
|
pHead->vgId = ntohl(pHead->vgId);
|
||||||
|
|
||||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId);
|
SVnodeObj *pVnode = NULL;
|
||||||
if (pVnode == NULL) {
|
code = vmAcquireVnodeWrapper(pMgmt, pHead->vgId, &pVnode);
|
||||||
|
if (code != 0) {
|
||||||
dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
dGDebug("vgId:%d, msg:%p failed to put into vnode queue since %s, type:%s qtype:%d contLen:%d", pHead->vgId, pMsg,
|
||||||
terrstr(), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
tstrerror(code), TMSG_INFO(pMsg->msgType), qtype, pHead->contLen);
|
||||||
terrno = (terrno != 0) ? terrno : -1;
|
return code;
|
||||||
return terrno;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (qtype) {
|
switch (qtype) {
|
||||||
|
@ -234,49 +241,45 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
||||||
break;
|
break;
|
||||||
case STREAM_QUEUE:
|
case STREAM_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-stream queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pStreamQ, pMsg);
|
code = taosWriteQitem(pVnode->pStreamQ, pMsg);
|
||||||
break;
|
break;
|
||||||
case FETCH_QUEUE:
|
case FETCH_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-fetch queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pFetchQ, pMsg);
|
code = taosWriteQitem(pVnode->pFetchQ, pMsg);
|
||||||
break;
|
break;
|
||||||
case WRITE_QUEUE:
|
case WRITE_QUEUE:
|
||||||
if (!vmDataSpaceSufficient(pVnode)) {
|
if (!vmDataSpaceSufficient(pVnode)) {
|
||||||
terrno = TSDB_CODE_NO_ENOUGH_DISKSPACE;
|
code = TSDB_CODE_NO_ENOUGH_DISKSPACE;
|
||||||
code = terrno;
|
|
||||||
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
dError("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
if (pMsg->msgType == TDMT_VND_SUBMIT && (grantCheck(TSDB_GRANT_STORAGE) != TSDB_CODE_SUCCESS)) {
|
||||||
terrno = TSDB_CODE_VND_NO_WRITE_AUTH;
|
code = TSDB_CODE_VND_NO_WRITE_AUTH;
|
||||||
code = terrno;
|
|
||||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since %s", pVnode->vgId, pMsg, tstrerror(code));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
|
if (pMsg->msgType != TDMT_VND_ALTER_CONFIRM && pVnode->disable) {
|
||||||
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
|
dDebug("vgId:%d, msg:%p put into vnode-write queue failed since its disable", pVnode->vgId, pMsg);
|
||||||
terrno = TSDB_CODE_VND_STOPPED;
|
code = TSDB_CODE_VND_STOPPED;
|
||||||
code = terrno;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-write queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pWriteW.queue, pMsg);
|
code = taosWriteQitem(pVnode->pWriteW.queue, pMsg);
|
||||||
break;
|
break;
|
||||||
case SYNC_QUEUE:
|
case SYNC_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-sync queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pSyncW.queue, pMsg);
|
code = taosWriteQitem(pVnode->pSyncW.queue, pMsg);
|
||||||
break;
|
break;
|
||||||
case SYNC_RD_QUEUE:
|
case SYNC_RD_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-sync-rd queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
|
code = taosWriteQitem(pVnode->pSyncRdW.queue, pMsg);
|
||||||
break;
|
break;
|
||||||
case APPLY_QUEUE:
|
case APPLY_QUEUE:
|
||||||
dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
|
dGTrace("vgId:%d, msg:%p put into vnode-apply queue", pVnode->vgId, pMsg);
|
||||||
taosWriteQitem(pVnode->pApplyW.queue, pMsg);
|
code = taosWriteQitem(pVnode->pApplyW.queue, pMsg);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
code = -1;
|
code = TSDB_CODE_INVALID_MSG;
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,15 +302,13 @@ int32_t vmPutMsgToStreamQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMs
|
||||||
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t vmPutMsgToMultiMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
|
dGTrace("msg:%p, put into vnode-multi-mgmt queue", pMsg);
|
||||||
taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
|
return taosWriteQitem(pMgmt->mgmtMultiWorker.queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t vmPutMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
|
dGTrace("msg:%p, put into vnode-mgmt queue", pMsg);
|
||||||
taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
|
return taosWriteQitem(pMgmt->mgmtWorker.queue, pMsg);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
|
@ -317,7 +318,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
pRpc->contLen);
|
pRpc->contLen);
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
return -1;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
}
|
}
|
||||||
|
|
||||||
EQItype itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
|
EQItype itype = APPLY_QUEUE == qtype ? DEF_QITEM : RPC_QITEM;
|
||||||
|
@ -326,7 +327,7 @@ int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
if (code) {
|
if (code) {
|
||||||
rpcFreeCont(pRpc->pCont);
|
rpcFreeCont(pRpc->pCont);
|
||||||
pRpc->pCont = NULL;
|
pRpc->pCont = NULL;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMsgHead *pHead = pRpc->pCont;
|
SMsgHead *pHead = pRpc->pCont;
|
||||||
|
@ -383,6 +384,7 @@ int32_t vmGetQueueSize(SVnodeMgmt *pMgmt, int32_t vgId, EQueueType qtype) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||||
|
int32_t code = 0;
|
||||||
SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
|
SMultiWorkerCfg wcfg = {.max = 1, .name = "vnode-write", .fp = (FItems)vnodeProposeWriteMsg, .param = pVnode->pImpl};
|
||||||
SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
SMultiWorkerCfg scfg = {.max = 1, .name = "vnode-sync", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
||||||
SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
SMultiWorkerCfg sccfg = {.max = 1, .name = "vnode-sync-rd", .fp = (FItems)vmProcessSyncQueue, .param = pVnode};
|
||||||
|
@ -398,8 +400,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||||
|
|
||||||
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
|
if (pVnode->pWriteW.queue == NULL || pVnode->pSyncW.queue == NULL || pVnode->pSyncRdW.queue == NULL ||
|
||||||
pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
|
pVnode->pApplyW.queue == NULL || pVnode->pQueryQ == NULL || pVnode->pStreamQ == NULL || pVnode->pFetchQ == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
|
dInfo("vgId:%d, write-queue:%p is alloced, thread:%08" PRId64, pVnode->vgId, pVnode->pWriteW.queue,
|
||||||
|
@ -428,26 +429,27 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
||||||
|
int32_t code = 0;
|
||||||
SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
|
SQueryAutoQWorkerPool *pQPool = &pMgmt->queryPool;
|
||||||
pQPool->name = "vnode-query";
|
pQPool->name = "vnode-query";
|
||||||
pQPool->min = tsNumOfVnodeQueryThreads;
|
pQPool->min = tsNumOfVnodeQueryThreads;
|
||||||
pQPool->max = tsNumOfVnodeQueryThreads;
|
pQPool->max = tsNumOfVnodeQueryThreads;
|
||||||
if (tQueryAutoQWorkerInit(pQPool) != 0) return -1;
|
if ((code = tQueryAutoQWorkerInit(pQPool)) != 0) return code;
|
||||||
|
|
||||||
SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
SAutoQWorkerPool *pStreamPool = &pMgmt->streamPool;
|
||||||
pStreamPool->name = "vnode-stream";
|
pStreamPool->name = "vnode-stream";
|
||||||
pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
|
pStreamPool->ratio = tsRatioOfVnodeStreamThreads;
|
||||||
if (tAutoQWorkerInit(pStreamPool) != 0) return -1;
|
if ((code = tAutoQWorkerInit(pStreamPool)) != 0) return code;
|
||||||
|
|
||||||
SWWorkerPool *pFPool = &pMgmt->fetchPool;
|
SWWorkerPool *pFPool = &pMgmt->fetchPool;
|
||||||
pFPool->name = "vnode-fetch";
|
pFPool->name = "vnode-fetch";
|
||||||
pFPool->max = tsNumOfVnodeFetchThreads;
|
pFPool->max = tsNumOfVnodeFetchThreads;
|
||||||
if (tWWorkerInit(pFPool) != 0) return -1;
|
if ((code = tWWorkerInit(pFPool)) != 0) return code;
|
||||||
|
|
||||||
SSingleWorkerCfg mgmtCfg = {
|
SSingleWorkerCfg mgmtCfg = {
|
||||||
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
.min = 1, .max = 1, .name = "vnode-mgmt", .fp = (FItem)vmProcessMgmtQueue, .param = pMgmt};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg) != 0) return -1;
|
if ((code = tSingleWorkerInit(&pMgmt->mgmtWorker, &mgmtCfg)) != 0) return code;
|
||||||
|
|
||||||
int32_t threadNum = 0;
|
int32_t threadNum = 0;
|
||||||
if (tsNumOfCores == 1) {
|
if (tsNumOfCores == 1) {
|
||||||
|
@ -461,7 +463,7 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
||||||
.fp = (FItem)vmProcessMultiMgmtQueue,
|
.fp = (FItem)vmProcessMultiMgmtQueue,
|
||||||
.param = pMgmt};
|
.param = pMgmt};
|
||||||
|
|
||||||
if (tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg) != 0) return -1;
|
if ((code = tSingleWorkerInit(&pMgmt->mgmtMultiWorker, &multiMgmtCfg)) != 0) return code;
|
||||||
|
|
||||||
dDebug("vnode workers are initialized");
|
dDebug("vnode workers are initialized");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -98,6 +98,7 @@ SMgmtWrapper *dmAcquireWrapper(SDnode *pDnode, EDndNodeType nType);
|
||||||
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
int32_t dmMarkWrapper(SMgmtWrapper *pWrapper);
|
||||||
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
void dmReleaseWrapper(SMgmtWrapper *pWrapper);
|
||||||
int32_t dmInitVars(SDnode *pDnode);
|
int32_t dmInitVars(SDnode *pDnode);
|
||||||
|
int32_t dmInitVarsWrapper(SDnode *pDnode);
|
||||||
void dmClearVars(SDnode *pDnode);
|
void dmClearVars(SDnode *pDnode);
|
||||||
int32_t dmInitModule(SDnode *pDnode);
|
int32_t dmInitModule(SDnode *pDnode);
|
||||||
SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper);
|
SMgmtInputOpt dmBuildMgmtInputOpt(SMgmtWrapper *pWrapper);
|
||||||
|
|
|
@ -14,19 +14,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
|
// clang-format off
|
||||||
#include "dmMgmt.h"
|
#include "dmMgmt.h"
|
||||||
#include "audit.h"
|
#include "audit.h"
|
||||||
#include "libs/function/tudf.h"
|
#include "libs/function/tudf.h"
|
||||||
#include "tgrant.h"
|
#include "tgrant.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
#define DM_INIT_AUDIT() \
|
#define DM_INIT_AUDIT() \
|
||||||
do { \
|
do { \
|
||||||
auditCfg.port = tsMonitorPort; \
|
auditCfg.port = tsMonitorPort; \
|
||||||
auditCfg.server = tsMonitorFqdn; \
|
auditCfg.server = tsMonitorFqdn; \
|
||||||
auditCfg.comp = tsMonitorComp; \
|
auditCfg.comp = tsMonitorComp; \
|
||||||
if (auditInit(&auditCfg) != 0) { \
|
if ((code = auditInit(&auditCfg)) != 0) { \
|
||||||
return -1; \
|
return code; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -35,10 +37,11 @@ static SDnode globalDnode = {0};
|
||||||
SDnode *dmInstance() { return &globalDnode; }
|
SDnode *dmInstance() { return &globalDnode; }
|
||||||
|
|
||||||
static int32_t dmCheckRepeatInit(SDnode *pDnode) {
|
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) {
|
if (atomic_val_compare_exchange_8(&pDnode->once, DND_ENV_INIT, DND_ENV_READY) != DND_ENV_INIT) {
|
||||||
dError("env is already initialized");
|
dError("env is already initialized");
|
||||||
terrno = TSDB_CODE_REPEAT_INIT;
|
code = TSDB_CODE_REPEAT_INIT;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -58,18 +61,15 @@ static int32_t dmInitMonitor() {
|
||||||
monCfg.port = tsMonitorPort;
|
monCfg.port = tsMonitorPort;
|
||||||
monCfg.server = tsMonitorFqdn;
|
monCfg.server = tsMonitorFqdn;
|
||||||
monCfg.comp = tsMonitorComp;
|
monCfg.comp = tsMonitorComp;
|
||||||
if (monInit(&monCfg) != 0) {
|
if ((code = monInit(&monCfg)) != 0) {
|
||||||
if (terrno != 0) code = terrno;
|
dError("failed to init monitor since %s", tstrerror(code));
|
||||||
goto _exit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
|
||||||
if (code) terrno = code;
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmInitAudit() {
|
static int32_t dmInitAudit() {
|
||||||
SAuditCfg auditCfg = {0};
|
SAuditCfg auditCfg = {0};
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
DM_INIT_AUDIT();
|
DM_INIT_AUDIT();
|
||||||
|
|
||||||
|
@ -88,27 +88,34 @@ static bool dmDataSpaceAvailable() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool dmCheckDiskSpace() {
|
static int32_t dmCheckDiskSpace() {
|
||||||
osUpdate();
|
osUpdate();
|
||||||
// availability
|
// availability
|
||||||
bool ret = true;
|
int32_t code = 0;
|
||||||
if (!dmDataSpaceAvailable()) {
|
if (!dmDataSpaceAvailable()) {
|
||||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
code = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
return code;
|
||||||
}
|
}
|
||||||
if (!osLogSpaceAvailable()) {
|
if (!osLogSpaceAvailable()) {
|
||||||
dError("log disk space unavailable, i.e. %s", tsLogDir);
|
dError("log disk space unavailable, i.e. %s", tsLogDir);
|
||||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
code = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
return code;
|
||||||
}
|
}
|
||||||
if (!osTempSpaceAvailable()) {
|
if (!osTempSpaceAvailable()) {
|
||||||
dError("temp disk space unavailable, i.e. %s", tsTempDir);
|
dError("temp disk space unavailable, i.e. %s", tsTempDir);
|
||||||
terrno = TSDB_CODE_NO_DISKSPACE;
|
code = TSDB_CODE_NO_DISKSPACE;
|
||||||
ret = false;
|
return code;
|
||||||
}
|
}
|
||||||
return ret;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t tfsOpenWrapper(SDiskCfg *pCfg, int32_t ndisk, STfs **tfs) {
|
||||||
|
*tfs = tfsOpen(pCfg, ndisk);
|
||||||
|
if (*tfs == NULL) {
|
||||||
|
return terrno;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int32_t dmDiskInit() {
|
int32_t dmDiskInit() {
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
SDiskCfg dCfg = {.level = 0, .primary = 1, .disable = 0};
|
SDiskCfg dCfg = {.level = 0, .primary = 1, .disable = 0};
|
||||||
|
@ -120,10 +127,10 @@ int32_t dmDiskInit() {
|
||||||
numOfDisks = 1;
|
numOfDisks = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pDnode->pTfs = tfsOpen(pDisks, numOfDisks);
|
int32_t code = tfsOpenWrapper(pDisks, numOfDisks, &pDnode->pTfs);
|
||||||
if (pDnode->pTfs == NULL) {
|
if (code != 0) {
|
||||||
dError("failed to init tfs since %s", terrstr());
|
dError("failed to init tfs since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -146,6 +153,12 @@ static bool dmCheckDataDirVersion() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t dmCheckDataDirVersionWrapper() {
|
||||||
|
if (!dmCheckDataDirVersion()) {
|
||||||
|
return TSDB_CODE_INVALID_DATA_FMT;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
#if defined(USE_S3)
|
#if defined(USE_S3)
|
||||||
|
|
||||||
extern int32_t s3Begin();
|
extern int32_t s3Begin();
|
||||||
|
@ -156,17 +169,21 @@ extern int8_t tsS3Enabled;
|
||||||
|
|
||||||
int32_t dmInit() {
|
int32_t dmInit() {
|
||||||
dInfo("start to init dnode env");
|
dInfo("start to init dnode env");
|
||||||
if (dmDiskInit() != 0) return -1;
|
int32_t code = 0;
|
||||||
if (!dmCheckDataDirVersion()) return -1;
|
if ((code = dmDiskInit()) != 0) return code;
|
||||||
if (!dmCheckDiskSpace()) return -1;
|
if (!dmCheckDataDirVersion()) {
|
||||||
if (dmCheckRepeatInit(dmInstance()) != 0) return -1;
|
code = TSDB_CODE_INVALID_DATA_FMT;
|
||||||
if (dmInitSystem() != 0) return -1;
|
return code;
|
||||||
if (dmInitMonitor() != 0) return -1;
|
}
|
||||||
if (dmInitAudit() != 0) return -1;
|
if ((code = dmCheckDiskSpace()) != 0) return code;
|
||||||
if (dmInitDnode(dmInstance()) != 0) return -1;
|
if ((code = dmCheckRepeatInit(dmInstance())) != 0) return code;
|
||||||
if (InitRegexCache() != 0) return -1;
|
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 ((code = InitRegexCache() != 0)) return code;
|
||||||
#if defined(USE_S3)
|
#if defined(USE_S3)
|
||||||
if (s3Begin() != 0) return -1;
|
if ((code = s3Begin()) != 0) return code;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
dInfo("dnode env is initialized");
|
dInfo("dnode env is initialized");
|
||||||
|
@ -217,6 +234,7 @@ int32_t dmRun() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
|
|
||||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||||
|
@ -224,19 +242,19 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
dmReleaseWrapper(pWrapper);
|
dmReleaseWrapper(pWrapper);
|
||||||
switch (ntype) {
|
switch (ntype) {
|
||||||
case MNODE:
|
case MNODE:
|
||||||
terrno = TSDB_CODE_MNODE_ALREADY_DEPLOYED;
|
code = TSDB_CODE_MNODE_ALREADY_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
case QNODE:
|
case QNODE:
|
||||||
terrno = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
code = TSDB_CODE_QNODE_ALREADY_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
case SNODE:
|
case SNODE:
|
||||||
terrno = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
code = TSDB_CODE_SNODE_ALREADY_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
code = TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
dError("failed to create node since %s", terrstr());
|
dError("failed to create node since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dInfo("start to process create-node-request");
|
dInfo("start to process create-node-request");
|
||||||
|
@ -244,18 +262,18 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
pWrapper = &pDnode->wrappers[ntype];
|
pWrapper = &pDnode->wrappers[ntype];
|
||||||
if (taosMkDir(pWrapper->path) != 0) {
|
if (taosMkDir(pWrapper->path) != 0) {
|
||||||
dmReleaseWrapper(pWrapper);
|
dmReleaseWrapper(pWrapper);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexLock(&pDnode->mutex);
|
taosThreadMutexLock(&pDnode->mutex);
|
||||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||||
|
|
||||||
dInfo("node:%s, start to create", pWrapper->name);
|
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) {
|
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 {
|
} else {
|
||||||
dInfo("node:%s, has been created", pWrapper->name);
|
dInfo("node:%s, has been created", pWrapper->name);
|
||||||
code = dmOpenNode(pWrapper);
|
code = dmOpenNode(pWrapper);
|
||||||
|
@ -271,12 +289,13 @@ static int32_t dmProcessCreateNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
|
|
||||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||||
if (pWrapper == NULL) {
|
if (pWrapper == NULL) {
|
||||||
dError("fail to process alter node type since node not exist");
|
dError("fail to process alter node type since node not exist");
|
||||||
return -1;
|
return TSDB_CODE_INVALID_MSG;
|
||||||
}
|
}
|
||||||
dmReleaseWrapper(pWrapper);
|
dmReleaseWrapper(pWrapper);
|
||||||
|
|
||||||
|
@ -289,16 +308,16 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
dInfo("node:%s, checking node role:%d", pWrapper->name, role);
|
dInfo("node:%s, checking node role:%d", pWrapper->name, role);
|
||||||
if (role == TAOS_SYNC_ROLE_VOTER) {
|
if (role == TAOS_SYNC_ROLE_VOTER) {
|
||||||
dError("node:%s, failed to alter node type since node already is role:%d", pWrapper->name, role);
|
dError("node:%s, failed to alter node type since node already is role:%d", pWrapper->name, role);
|
||||||
terrno = TSDB_CODE_MNODE_ALREADY_IS_VOTER;
|
code = TSDB_CODE_MNODE_ALREADY_IS_VOTER;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pWrapper->func.isCatchUpFp != NULL) {
|
if (pWrapper->func.isCatchUpFp != NULL) {
|
||||||
dInfo("node:%s, checking node catch up", pWrapper->name);
|
dInfo("node:%s, checking node catch up", pWrapper->name);
|
||||||
if ((*pWrapper->func.isCatchUpFp)(pWrapper->pMgmt) != 1) {
|
if ((*pWrapper->func.isCatchUpFp)(pWrapper->pMgmt) != 1) {
|
||||||
terrno = TSDB_CODE_MNODE_NOT_CATCH_UP;
|
code = TSDB_CODE_MNODE_NOT_CATCH_UP;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,17 +333,17 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
pWrapper = &pDnode->wrappers[ntype];
|
pWrapper = &pDnode->wrappers[ntype];
|
||||||
if (taosMkDir(pWrapper->path) != 0) {
|
if (taosMkDir(pWrapper->path) != 0) {
|
||||||
taosThreadMutexUnlock(&pDnode->mutex);
|
taosThreadMutexUnlock(&pDnode->mutex);
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to create dir:%s since %s", pWrapper->path, terrstr());
|
dError("failed to create dir:%s since %s", pWrapper->path, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||||
|
|
||||||
dInfo("node:%s, start to create", pWrapper->name);
|
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) {
|
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 {
|
} else {
|
||||||
dInfo("node:%s, has been created", pWrapper->name);
|
dInfo("node:%s, has been created", pWrapper->name);
|
||||||
code = dmOpenNode(pWrapper);
|
code = dmOpenNode(pWrapper);
|
||||||
|
@ -340,35 +359,36 @@ static int32_t dmProcessAlterNodeTypeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmProcessDropNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
static int32_t dmProcessDropNodeReq(EDndNodeType ntype, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
|
|
||||||
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
SMgmtWrapper *pWrapper = dmAcquireWrapper(pDnode, ntype);
|
||||||
if (pWrapper == NULL) {
|
if (pWrapper == NULL) {
|
||||||
switch (ntype) {
|
switch (ntype) {
|
||||||
case MNODE:
|
case MNODE:
|
||||||
terrno = TSDB_CODE_MNODE_NOT_DEPLOYED;
|
code = TSDB_CODE_MNODE_NOT_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
case QNODE:
|
case QNODE:
|
||||||
terrno = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
code = TSDB_CODE_QNODE_NOT_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
case SNODE:
|
case SNODE:
|
||||||
terrno = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
code = TSDB_CODE_SNODE_NOT_DEPLOYED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
code = TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
dError("failed to drop node since %s", terrstr());
|
dError("failed to drop node since %s", tstrerror(code));
|
||||||
return -1;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
taosThreadMutexLock(&pDnode->mutex);
|
taosThreadMutexLock(&pDnode->mutex);
|
||||||
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
SMgmtInputOpt input = dmBuildMgmtInputOpt(pWrapper);
|
||||||
|
|
||||||
dInfo("node:%s, start to drop", pWrapper->name);
|
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) {
|
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 {
|
} else {
|
||||||
dInfo("node:%s, has been dropped", pWrapper->name);
|
dInfo("node:%s, has been dropped", pWrapper->name);
|
||||||
pWrapper->required = false;
|
pWrapper->required = false;
|
||||||
|
@ -416,6 +436,4 @@ void dmReportStartup(const char *pName, const char *pDesc) {
|
||||||
|
|
||||||
int64_t dmGetClusterId() { return globalDnode.data.clusterId; }
|
int64_t dmGetClusterId() { return globalDnode.data.clusterId; }
|
||||||
|
|
||||||
bool dmReadyForTest() {
|
bool dmReadyForTest() { return dmInstance()->data.dnodeVer > 0; }
|
||||||
return dmInstance()->data.dnodeVer > 0;
|
|
||||||
}
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ int32_t dmInitDnode(SDnode *pDnode) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
char path[PATH_MAX + 100] = {0};
|
char path[PATH_MAX + 100] = {0};
|
||||||
|
|
||||||
if (dmInitVars(pDnode) != 0) {
|
if ((code = dmInitVarsWrapper(pDnode)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,26 +65,31 @@ int32_t dmInitDnode(SDnode *pDnode) {
|
||||||
snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name);
|
snprintf(path, sizeof(path), "%s%s%s", tsDataDir, TD_DIRSEP, pWrapper->name);
|
||||||
pWrapper->path = taosStrdup(path);
|
pWrapper->path = taosStrdup(path);
|
||||||
if (pWrapper->path == NULL) {
|
if (pWrapper->path == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pWrapper->required = dmRequireNode(pDnode, pWrapper);
|
pWrapper->required = dmRequireNode(pDnode, pWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
pDnode->lockfile = dmCheckRunning(tsDataDir);
|
code = dmCheckRunning(tsDataDir, &pDnode->lockfile);
|
||||||
if (pDnode->lockfile == NULL) {
|
if (code != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
if (dmInitModule(pDnode) != 0) {
|
|
||||||
|
if ((code = dmInitModule(pDnode)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
indexInit(tsNumOfCommitThreads);
|
indexInit(tsNumOfCommitThreads);
|
||||||
streamMetaInit();
|
streamMetaInit();
|
||||||
|
|
||||||
dmInitStatusClient(pDnode);
|
if ((code = dmInitStatusClient(pDnode)) != 0) {
|
||||||
dmInitSyncClient(pDnode);
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if ((code = dmInitSyncClient(pDnode)) != 0) {
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
dmReportStartup("dnode-transport", "initialized");
|
dmReportStartup("dnode-transport", "initialized");
|
||||||
dDebug("dnode is created, ptr:%p", pDnode);
|
dDebug("dnode is created, ptr:%p", pDnode);
|
||||||
|
@ -94,7 +99,7 @@ _OVER:
|
||||||
if (code != 0 && pDnode != NULL) {
|
if (code != 0 && pDnode != NULL) {
|
||||||
dmClearVars(pDnode);
|
dmClearVars(pDnode);
|
||||||
pDnode = NULL;
|
pDnode = NULL;
|
||||||
dError("failed to create dnode since %s", terrstr());
|
dError("failed to create dnode since %s", tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -122,7 +127,15 @@ void dmCleanupDnode(SDnode *pDnode) {
|
||||||
dDebug("dnode is closed, ptr:%p", 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 dmInitVars(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnodeData *pData = &pDnode->data;
|
SDnodeData *pData = &pDnode->data;
|
||||||
pData->dnodeId = 0;
|
pData->dnodeId = 0;
|
||||||
pData->clusterId = 0;
|
pData->clusterId = 0;
|
||||||
|
@ -138,21 +151,21 @@ int32_t dmInitVars(SDnode *pDnode) {
|
||||||
taosMemoryFreeClear(machineId);
|
taosMemoryFreeClear(machineId);
|
||||||
} else {
|
} else {
|
||||||
#if defined(TD_ENTERPRISE) && !defined(GRANTS_CFG)
|
#if defined(TD_ENTERPRISE) && !defined(GRANTS_CFG)
|
||||||
terrno = TSDB_CODE_DNODE_NO_MACHINE_CODE;
|
code = TSDB_CODE_DNODE_NO_MACHINE_CODE;
|
||||||
return -1;
|
return terrno = code;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
pData->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK);
|
||||||
if (pData->dnodeHash == NULL) {
|
if (pData->dnodeHash == NULL) {
|
||||||
dError("failed to init dnode hash");
|
dError("failed to init dnode hash");
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return -1;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmReadEps(pData) != 0) {
|
if ((code = dmReadEps(pData)) != 0) {
|
||||||
dError("failed to read file since %s", terrstr());
|
dError("failed to read file since %s", tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(TD_ENTERPRISE)
|
#if defined(TD_ENTERPRISE)
|
||||||
|
@ -274,22 +287,21 @@ int32_t dmMarkWrapper(SMgmtWrapper *pWrapper) {
|
||||||
} else {
|
} else {
|
||||||
switch (pWrapper->ntype) {
|
switch (pWrapper->ntype) {
|
||||||
case MNODE:
|
case MNODE:
|
||||||
terrno = TSDB_CODE_MNODE_NOT_FOUND;
|
code = TSDB_CODE_MNODE_NOT_FOUND;
|
||||||
break;
|
break;
|
||||||
case QNODE:
|
case QNODE:
|
||||||
terrno = TSDB_CODE_QNODE_NOT_FOUND;
|
code = TSDB_CODE_QNODE_NOT_FOUND;
|
||||||
break;
|
break;
|
||||||
case SNODE:
|
case SNODE:
|
||||||
terrno = TSDB_CODE_SNODE_NOT_FOUND;
|
code = TSDB_CODE_SNODE_NOT_FOUND;
|
||||||
break;
|
break;
|
||||||
case VNODE:
|
case VNODE:
|
||||||
terrno = TSDB_CODE_VND_STOPPED;
|
code = TSDB_CODE_VND_STOPPED;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
code = -1;
|
|
||||||
}
|
}
|
||||||
taosThreadRwlockUnlock(&pWrapper->lock);
|
taosThreadRwlockUnlock(&pWrapper->lock);
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,13 @@
|
||||||
#include "dmMgmt.h"
|
#include "dmMgmt.h"
|
||||||
|
|
||||||
int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = pWrapper->pDnode;
|
SDnode *pDnode = pWrapper->pDnode;
|
||||||
|
|
||||||
if (taosMkDir(pWrapper->path) != 0) {
|
if (taosMkDir(pWrapper->path) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, terrstr());
|
dError("node:%s, failed to create dir:%s since %s", pWrapper->name, pWrapper->path, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMgmtOutputOpt output = {0};
|
SMgmtOutputOpt output = {0};
|
||||||
|
@ -30,9 +31,9 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
||||||
|
|
||||||
dInfo("node:%s, start to open", pWrapper->name);
|
dInfo("node:%s, start to open", pWrapper->name);
|
||||||
tmsgSetDefault(&input.msgCb);
|
tmsgSetDefault(&input.msgCb);
|
||||||
if ((*pWrapper->func.openFp)(&input, &output) != 0) {
|
if ((code = (*pWrapper->func.openFp)(&input, &output)) != 0) {
|
||||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to open since %s", pWrapper->name, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
dInfo("node:%s, has been opened", pWrapper->name);
|
dInfo("node:%s, has been opened", pWrapper->name);
|
||||||
pWrapper->deployed = true;
|
pWrapper->deployed = true;
|
||||||
|
@ -46,11 +47,12 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmStartNode(SMgmtWrapper *pWrapper) {
|
int32_t dmStartNode(SMgmtWrapper *pWrapper) {
|
||||||
|
int32_t code = 0;
|
||||||
if (pWrapper->func.startFp != NULL) {
|
if (pWrapper->func.startFp != NULL) {
|
||||||
dDebug("node:%s, start to start", pWrapper->name);
|
dDebug("node:%s, start to start", pWrapper->name);
|
||||||
if ((*pWrapper->func.startFp)(pWrapper->pMgmt) != 0) {
|
if ((code = (*pWrapper->func.startFp)(pWrapper->pMgmt)) != 0) {
|
||||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to start since %s", pWrapper->name, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
dDebug("node:%s, has been started", pWrapper->name);
|
dDebug("node:%s, has been started", pWrapper->name);
|
||||||
}
|
}
|
||||||
|
@ -86,12 +88,13 @@ void dmCloseNode(SMgmtWrapper *pWrapper) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmOpenNodes(SDnode *pDnode) {
|
static int32_t dmOpenNodes(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||||
if (!pWrapper->required) continue;
|
if (!pWrapper->required) continue;
|
||||||
if (dmOpenNode(pWrapper) != 0) {
|
if ((code = dmOpenNode(pWrapper)) != 0) {
|
||||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to open since %s", pWrapper->name, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,12 +103,13 @@ static int32_t dmOpenNodes(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmStartNodes(SDnode *pDnode) {
|
static int32_t dmStartNodes(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
for (EDndNodeType ntype = DNODE; ntype < NODE_END; ++ntype) {
|
||||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
SMgmtWrapper *pWrapper = &pDnode->wrappers[ntype];
|
||||||
if (!pWrapper->required) continue;
|
if (!pWrapper->required) continue;
|
||||||
if (dmStartNode(pWrapper) != 0) {
|
if ((code = dmStartNode(pWrapper)) != 0) {
|
||||||
dError("node:%s, failed to start since %s", pWrapper->name, terrstr());
|
dError("node:%s, failed to start since %s", pWrapper->name, tstrerror(code));
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,19 +133,20 @@ static void dmCloseNodes(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmRunDnode(SDnode *pDnode) {
|
int32_t dmRunDnode(SDnode *pDnode) {
|
||||||
|
int32_t code = 0;
|
||||||
int32_t count = 0;
|
int32_t count = 0;
|
||||||
if (dmOpenNodes(pDnode) != 0) {
|
if ((code = dmOpenNodes(pDnode)) != 0) {
|
||||||
dError("failed to open nodes since %s", terrstr());
|
dError("failed to open nodes since %s", tstrerror(code));
|
||||||
dmCloseNodes(pDnode);
|
dmCloseNodes(pDnode);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmStartNodes(pDnode) != 0) {
|
if ((code = dmStartNodes(pDnode)) != 0) {
|
||||||
dError("failed to start nodes since %s", terrstr());
|
dError("failed to start nodes since %s", tstrerror(code));
|
||||||
dmSetStatus(pDnode, DND_STAT_STOPPED);
|
dmSetStatus(pDnode, DND_STAT_STOPPED);
|
||||||
dmStopNodes(pDnode);
|
dmStopNodes(pDnode);
|
||||||
dmCloseNodes(pDnode);
|
dmCloseNodes(pDnode);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
|
@ -39,9 +39,9 @@ int32_t dmProcessNodeMsg(SMgmtWrapper *pWrapper, SRpcMsg *pMsg) {
|
||||||
|
|
||||||
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pMsg->msgType)];
|
NodeMsgFp msgFp = pWrapper->msgFps[TMSG_INDEX(pMsg->msgType)];
|
||||||
if (msgFp == NULL) {
|
if (msgFp == NULL) {
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
// terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
dGError("msg:%p, not processed since no handler, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
dGError("msg:%p, not processed since no handler, type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
return -1;
|
return TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
}
|
}
|
||||||
|
|
||||||
dGTrace("msg:%p, will be processed by %s", pMsg, pWrapper->name);
|
dGTrace("msg:%p, will be processed by %s", pMsg, pWrapper->name);
|
||||||
|
@ -54,14 +54,15 @@ static bool dmFailFastFp(tmsg_t msgType) {
|
||||||
return msgType == TDMT_SYNC_HEARTBEAT || msgType == TDMT_SYNC_APPEND_ENTRIES;
|
return msgType == TDMT_SYNC_HEARTBEAT || msgType == TDMT_SYNC_APPEND_ENTRIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dmConvertErrCode(tmsg_t msgType) {
|
static int32_t dmConvertErrCode(tmsg_t msgType, int32_t code) {
|
||||||
if (terrno != TSDB_CODE_APP_IS_STOPPING) {
|
if (code != TSDB_CODE_APP_IS_STOPPING) {
|
||||||
return;
|
return code;
|
||||||
}
|
}
|
||||||
if ((msgType > TDMT_VND_MSG_MIN && msgType < TDMT_VND_MSG_MAX) ||
|
if ((msgType > TDMT_VND_MSG_MIN && msgType < TDMT_VND_MSG_MAX) ||
|
||||||
(msgType > TDMT_SCH_MSG_MIN && msgType < TDMT_SCH_MSG_MAX)) {
|
(msgType > TDMT_SCH_MSG_MIN && msgType < TDMT_SCH_MSG_MAX)) {
|
||||||
terrno = TSDB_CODE_VND_STOPPED;
|
code = TSDB_CODE_VND_STOPPED;
|
||||||
}
|
}
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
static void dmUpdateRpcIpWhite(SDnodeData *pData, void *pTrans, SRpcMsg *pRpc) {
|
static void dmUpdateRpcIpWhite(SDnodeData *pData, void *pTrans, SRpcMsg *pRpc) {
|
||||||
SUpdateIpWhite ipWhite = {0}; // aosMemoryCalloc(1, sizeof(SUpdateIpWhite));
|
SUpdateIpWhite ipWhite = {0}; // aosMemoryCalloc(1, sizeof(SUpdateIpWhite));
|
||||||
|
@ -99,14 +100,14 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
|
|
||||||
int32_t svrVer = 0;
|
int32_t svrVer = 0;
|
||||||
taosVersionStrToInt(version, &svrVer);
|
taosVersionStrToInt(version, &svrVer);
|
||||||
if (0 != taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) {
|
if ((code = taosCheckVersionCompatible(pRpc->info.cliVer, svrVer, 3)) != 0) {
|
||||||
dError("Version not compatible, cli ver: %d, svr ver: %d", pRpc->info.cliVer, svrVer);
|
dError("Version not compatible, cli ver: %d, svr ver: %d", pRpc->info.cliVer, svrVer);
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isForbidden = dmIsForbiddenIp(pRpc->info.forbiddenIp, pRpc->info.conn.user, pRpc->info.conn.clientIp);
|
bool isForbidden = dmIsForbiddenIp(pRpc->info.forbiddenIp, pRpc->info.conn.user, pRpc->info.conn.clientIp);
|
||||||
if (isForbidden) {
|
if (isForbidden) {
|
||||||
terrno = TSDB_CODE_IP_NOT_IN_WHITE_LIST;
|
code = TSDB_CODE_IP_NOT_IN_WHITE_LIST;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +120,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
case TDMT_SCH_FETCH_RSP:
|
case TDMT_SCH_FETCH_RSP:
|
||||||
case TDMT_SCH_MERGE_FETCH_RSP:
|
case TDMT_SCH_MERGE_FETCH_RSP:
|
||||||
case TDMT_VND_SUBMIT_RSP:
|
case TDMT_VND_SUBMIT_RSP:
|
||||||
qWorkerProcessRspMsg(NULL, NULL, pRpc, 0);
|
code = qWorkerProcessRspMsg(NULL, NULL, pRpc, 0);
|
||||||
return;
|
return;
|
||||||
case TDMT_MND_STATUS_RSP:
|
case TDMT_MND_STATUS_RSP:
|
||||||
if (pEpSet != NULL) {
|
if (pEpSet != NULL) {
|
||||||
|
@ -148,32 +149,32 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
if (pDnode->status == DND_STAT_INIT) {
|
if (pDnode->status == DND_STAT_INIT) {
|
||||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
code = TSDB_CODE_APP_IS_STARTING;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
}
|
}
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
code = TSDB_CODE_APP_IS_STARTING;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pRpc->pCont == NULL && (IsReq(pRpc) || pRpc->contLen != 0)) {
|
if (pRpc->pCont == NULL && (IsReq(pRpc) || pRpc->contLen != 0)) {
|
||||||
dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType));
|
dGError("msg:%p, type:%s pCont is NULL", pRpc, TMSG_INFO(pRpc->msgType));
|
||||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
code = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
} else if ((pRpc->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRpc->code == TSDB_CODE_RPC_BROKEN_LINK) &&
|
} else if ((pRpc->code == TSDB_CODE_RPC_NETWORK_UNAVAIL || pRpc->code == TSDB_CODE_RPC_BROKEN_LINK) &&
|
||||||
(!IsReq(pRpc)) && (pRpc->pCont == NULL)) {
|
(!IsReq(pRpc)) && (pRpc->pCont == NULL)) {
|
||||||
dGError("msg:%p, type:%s pCont is NULL, err: %s", pRpc, TMSG_INFO(pRpc->msgType), tstrerror(pRpc->code));
|
dGError("msg:%p, type:%s pCont is NULL, err: %s", pRpc, TMSG_INFO(pRpc->msgType), tstrerror(pRpc->code));
|
||||||
terrno = pRpc->code;
|
code = pRpc->code;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pHandle->defaultNtype == NODE_END) {
|
if (pHandle->defaultNtype == NODE_END) {
|
||||||
dGError("msg:%p, type:%s not processed since no handle", pRpc, TMSG_INFO(pRpc->msgType));
|
dGError("msg:%p, type:%s not processed since no handle", pRpc, TMSG_INFO(pRpc->msgType));
|
||||||
terrno = TSDB_CODE_MSG_NOT_PROCESSED;
|
code = TSDB_CODE_MSG_NOT_PROCESSED;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,12 +198,12 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dGError("msg:%p, type:%s contLen is 0", pRpc, TMSG_INFO(pRpc->msgType));
|
dGError("msg:%p, type:%s contLen is 0", pRpc, TMSG_INFO(pRpc->msgType));
|
||||||
terrno = TSDB_CODE_INVALID_MSG_LEN;
|
code = TSDB_CODE_INVALID_MSG_LEN;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmMarkWrapper(pWrapper) != 0) {
|
if ((code = dmMarkWrapper(pWrapper)) != 0) {
|
||||||
pWrapper = NULL;
|
pWrapper = NULL;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -221,12 +222,11 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dmConvertErrCode(pRpc->msgType);
|
code = dmConvertErrCode(pRpc->msgType, code);
|
||||||
if (terrno != 0) code = terrno;
|
|
||||||
if (pMsg) {
|
if (pMsg) {
|
||||||
dGTrace("msg:%p, failed to process %s since %s", pMsg, TMSG_INFO(pMsg->msgType), terrstr());
|
dGTrace("msg:%p, failed to process %s since %s", pMsg, TMSG_INFO(pMsg->msgType), tstrerror(code));
|
||||||
} else {
|
} else {
|
||||||
dGTrace("msg:%p, failed to process empty msg since %s", pMsg, terrstr());
|
dGTrace("msg:%p, failed to process empty msg since %s", pMsg, tstrerror(code));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsReq(pRpc)) {
|
if (IsReq(pRpc)) {
|
||||||
|
@ -280,17 +280,19 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
pMsg->pCont = NULL;
|
pMsg->pCont = NULL;
|
||||||
if (pDnode->status == DND_STAT_INIT) {
|
if (pDnode->status == DND_STAT_INIT) {
|
||||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
code = TSDB_CODE_APP_IS_STARTING;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
}
|
}
|
||||||
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), terrstr(), pMsg->info.handle);
|
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), tstrerror(code),
|
||||||
return -1;
|
pMsg->info.handle);
|
||||||
|
return code;
|
||||||
} else {
|
} else {
|
||||||
pMsg->info.handle = 0;
|
pMsg->info.handle = 0;
|
||||||
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pMsg, NULL);
|
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pMsg, NULL);
|
||||||
|
@ -298,17 +300,19 @@ static inline int32_t dmSendReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static inline int32_t dmSendSyncReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
static inline int32_t dmSendSyncReq(const SEpSet *pEpSet, SRpcMsg *pMsg) {
|
||||||
|
int32_t code = 0;
|
||||||
SDnode *pDnode = dmInstance();
|
SDnode *pDnode = dmInstance();
|
||||||
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
if (pDnode->status != DND_STAT_RUNNING && pMsg->msgType < TDMT_SYNC_MSG_MIN) {
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
pMsg->pCont = NULL;
|
pMsg->pCont = NULL;
|
||||||
if (pDnode->status == DND_STAT_INIT) {
|
if (pDnode->status == DND_STAT_INIT) {
|
||||||
terrno = TSDB_CODE_APP_IS_STARTING;
|
code = TSDB_CODE_APP_IS_STARTING;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_IS_STOPPING;
|
code = TSDB_CODE_APP_IS_STOPPING;
|
||||||
}
|
}
|
||||||
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), terrstr(), pMsg->info.handle);
|
dError("failed to send rpc msg:%s since %s, handle:%p", TMSG_INFO(pMsg->msgType), tstrerror(code),
|
||||||
return -1;
|
pMsg->info.handle);
|
||||||
|
return code;
|
||||||
} else {
|
} else {
|
||||||
rpcSendRequest(pDnode->trans.syncRpc, pEpSet, pMsg, NULL);
|
rpcSendRequest(pDnode->trans.syncRpc, pEpSet, pMsg, NULL);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -426,7 +430,7 @@ int32_t dmInitStatusClient(SDnode *pDnode) {
|
||||||
pTrans->statusRpc = rpcOpen(&rpcInit);
|
pTrans->statusRpc = rpcOpen(&rpcInit);
|
||||||
if (pTrans->statusRpc == NULL) {
|
if (pTrans->statusRpc == NULL) {
|
||||||
dError("failed to init dnode rpc status client");
|
dError("failed to init dnode rpc status client");
|
||||||
return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode rpc status client is initialized");
|
dDebug("dnode rpc status client is initialized");
|
||||||
|
@ -471,7 +475,7 @@ int32_t dmInitSyncClient(SDnode *pDnode) {
|
||||||
pTrans->syncRpc = rpcOpen(&rpcInit);
|
pTrans->syncRpc = rpcOpen(&rpcInit);
|
||||||
if (pTrans->syncRpc == NULL) {
|
if (pTrans->syncRpc == NULL) {
|
||||||
dError("failed to init dnode rpc sync client");
|
dError("failed to init dnode rpc sync client");
|
||||||
return -1;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode rpc sync client is initialized");
|
dDebug("dnode rpc sync client is initialized");
|
||||||
|
@ -521,7 +525,7 @@ int32_t dmInitServer(SDnode *pDnode) {
|
||||||
pTrans->serverRpc = rpcOpen(&rpcInit);
|
pTrans->serverRpc = rpcOpen(&rpcInit);
|
||||||
if (pTrans->serverRpc == NULL) {
|
if (pTrans->serverRpc == NULL) {
|
||||||
dError("failed to init dnode rpc server");
|
dError("failed to init dnode rpc server");
|
||||||
return -1;
|
return terrno;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("dnode rpc server is initialized");
|
dDebug("dnode rpc server is initialized");
|
||||||
|
|
|
@ -205,7 +205,8 @@ void dmGetMonitorSystemInfo(SMonSysInfo *pInfo);
|
||||||
// dmFile.c
|
// dmFile.c
|
||||||
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
|
int32_t dmReadFile(const char *path, const char *name, bool *pDeployed);
|
||||||
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
|
int32_t dmWriteFile(const char *path, const char *name, bool deployed);
|
||||||
TdFilePtr dmCheckRunning(const char *dataDir);
|
int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile);
|
||||||
|
//int32_t dmCheckRunningWrapper(const char *dataDir, TdFilePtr *pFile);
|
||||||
|
|
||||||
// dmodule.c
|
// dmodule.c
|
||||||
int32_t dmInitDndInfo(SDnodeData *pData);
|
int32_t dmInitDndInfo(SDnodeData *pData);
|
||||||
|
|
|
@ -135,8 +135,7 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
if (strlen(tsEncryptAlgorithm) > 0) {
|
if (strlen(tsEncryptAlgorithm) > 0) {
|
||||||
if (strcmp(tsEncryptAlgorithm, "sm4") == 0) {
|
if (strcmp(tsEncryptAlgorithm, "sm4") == 0) {
|
||||||
pData->encryptAlgorigthm = DND_CA_SM4;
|
pData->encryptAlgorigthm = DND_CA_SM4;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
||||||
dError("invalid tsEncryptAlgorithm:%s", tsEncryptAlgorithm);
|
dError("invalid tsEncryptAlgorithm:%s", tsEncryptAlgorithm);
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
|
@ -204,26 +203,26 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 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());
|
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size + 1);
|
content = taosMemoryMalloc(size + 1);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
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());
|
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -232,12 +231,11 @@ int32_t dmReadEps(SDnodeData *pData) {
|
||||||
|
|
||||||
pJson = tjsonParse(content);
|
pJson = tjsonParse(content);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmDecodeEps(pJson, pData) < 0) {
|
if ((code = dmDecodeEps(pJson, pData)) < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -251,7 +249,7 @@ _OVER:
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
dError("failed to read dnode file:%s since %s", file, terrstr());
|
dError("failed to read dnode file:%s since %s", file, terrstr());
|
||||||
return code;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosArrayGetSize(pData->dnodeEps) == 0) {
|
if (taosArrayGetSize(pData->dnodeEps) == 0) {
|
||||||
|
@ -261,8 +259,8 @@ _OVER:
|
||||||
taosArrayPush(pData->dnodeEps, &dnodeEp);
|
taosArrayPush(pData->dnodeEps, &dnodeEp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmReadDnodePairs(pData) != 0) {
|
if ((code = dmReadDnodePairs(pData)) != 0) {
|
||||||
return -1;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
dDebug("reset dnode list on startup");
|
dDebug("reset dnode list on startup");
|
||||||
|
@ -270,8 +268,8 @@ _OVER:
|
||||||
|
|
||||||
if (pData->oldDnodeEps == NULL && dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) {
|
if (pData->oldDnodeEps == NULL && dmIsEpChanged(pData, pData->dnodeId, tsLocalEp)) {
|
||||||
dError("localEp %s different with %s and need to be reconfigured", tsLocalEp, file);
|
dError("localEp %s different with %s and need to be reconfigured", tsLocalEp, file);
|
||||||
terrno = TSDB_CODE_INVALID_CFG;
|
code = TSDB_CODE_INVALID_CFG;
|
||||||
return -1;
|
return terrno = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
@ -308,7 +306,7 @@ static int32_t dmEncodeEps(SJson *pJson, SDnodeData *pData) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t dmWriteEps(SDnodeData *pData) {
|
int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
int32_t code = -1;
|
int32_t code = 0;
|
||||||
char *buffer = NULL;
|
char *buffer = NULL;
|
||||||
SJson *pJson = NULL;
|
SJson *pJson = NULL;
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
|
@ -317,26 +315,30 @@ int32_t dmWriteEps(SDnodeData *pData) {
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sdnode.json.bak", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
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);
|
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;
|
||||||
|
TAOS_CHECK_GOTO(dmInitDndInfo(pData), NULL, _OVER);
|
||||||
|
|
||||||
if ((code == dmInitDndInfo(pData)) != 0) goto _OVER;
|
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||||
|
|
||||||
pData->engineVer = tsVersion;
|
pData->engineVer = tsVersion;
|
||||||
if (dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
|
||||||
|
TAOS_CHECK_GOTO(dmEncodeEps(pJson, pData), NULL, _OVER); // dmEncodeEps(pJson, pData) != 0) goto _OVER;
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) {
|
||||||
terrno = 0;
|
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(&pFile);
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
pData->updateTime = taosGetTimestampMs();
|
pData->updateTime = taosGetTimestampMs();
|
||||||
|
@ -349,8 +351,7 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, tstrerror(code), pData->dnodeVer);
|
||||||
dError("failed to write dnode file:%s since %s, dnodeVer:%" PRId64, realfile, terrstr(), pData->dnodeVer);
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -592,28 +593,29 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP);
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
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;
|
code = 0;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
dError("failed to open dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 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());
|
dError("failed to fstat dnode file:%s since %s", file, terrstr());
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size + 1);
|
content = taosMemoryMalloc(size + 1);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,12 +629,13 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
|
|
||||||
pJson = tjsonParse(content);
|
pJson = tjsonParse(content);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
pData->oldDnodeEps = taosArrayInit(1, sizeof(SDnodeEpPair));
|
pData->oldDnodeEps = taosArrayInit(1, sizeof(SDnodeEpPair));
|
||||||
if (pData->oldDnodeEps == NULL) {
|
if (pData->oldDnodeEps == NULL) {
|
||||||
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
dError("failed to calloc dnodeEp array since %s", strerror(errno));
|
dError("failed to calloc dnodeEp array since %s", strerror(errno));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -640,7 +643,8 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
|
||||||
if (dmDecodeEpPairs(pJson, pData) < 0) {
|
if (dmDecodeEpPairs(pJson, pData) < 0) {
|
||||||
taosArrayDestroy(pData->oldDnodeEps);
|
taosArrayDestroy(pData->oldDnodeEps);
|
||||||
pData->oldDnodeEps = NULL;
|
pData->oldDnodeEps = NULL;
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
|
||||||
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,7 +657,7 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
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;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,8 +684,8 @@ _OVER:
|
||||||
pair->oldPort, pair->newFqdn, pair->newPort, pDnodeEp->id);
|
pair->oldPort, pair->newFqdn, pair->newPort, pDnodeEp->id);
|
||||||
taosArrayDestroy(pData->oldDnodeEps);
|
taosArrayDestroy(pData->oldDnodeEps);
|
||||||
pData->oldDnodeEps = NULL;
|
pData->oldDnodeEps = NULL;
|
||||||
terrno = TSDB_CODE_INVALID_CFG;
|
code = TSDB_CODE_INVALID_CFG;
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,11 +14,11 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "dmUtil.h"
|
|
||||||
#include "tjson.h"
|
|
||||||
#include "tgrant.h"
|
|
||||||
#include "crypt.h"
|
#include "crypt.h"
|
||||||
|
#include "dmUtil.h"
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
|
#include "tgrant.h"
|
||||||
|
#include "tjson.h"
|
||||||
|
|
||||||
#define MAXLEN 1024
|
#define MAXLEN 1024
|
||||||
#define DM_KEY_INDICATOR "this indicator!"
|
#define DM_KEY_INDICATOR "this indicator!"
|
||||||
|
@ -30,7 +30,7 @@ static int32_t dmDecodeFile(SJson *pJson, bool *deployed) {
|
||||||
int32_t value = 0;
|
int32_t value = 0;
|
||||||
|
|
||||||
tjsonGetInt32ValueFromDouble(pJson, "deployed", value, code);
|
tjsonGetInt32ValueFromDouble(pJson, "deployed", value, code);
|
||||||
if (code < 0) return -1;
|
if (code < 0) return code;
|
||||||
|
|
||||||
*deployed = (value != 0);
|
*deployed = (value != 0);
|
||||||
return code;
|
return code;
|
||||||
|
@ -42,7 +42,11 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
char *content = NULL;
|
char *content = NULL;
|
||||||
SJson *pJson = NULL;
|
SJson *pJson = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
if (taosStatFile(file, NULL, NULL, NULL) < 0) {
|
||||||
dInfo("file:%s not exist", file);
|
dInfo("file:%s not exist", file);
|
||||||
|
@ -52,27 +56,27 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open file:%s since %s", file, terrstr());
|
dError("failed to open file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to fstat file:%s since %s", file, terrstr());
|
dError("failed to fstat file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size + 1);
|
content = taosMemoryMalloc(size + 1);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to read file:%s since %s", file, terrstr());
|
dError("failed to read file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,12 +84,12 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
|
||||||
|
|
||||||
pJson = tjsonParse(content);
|
pJson = tjsonParse(content);
|
||||||
if (pJson == NULL) {
|
if (pJson == NULL) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dmDecodeFile(pJson, pDeployed) < 0) {
|
if (dmDecodeFile(pJson, pDeployed) < 0) {
|
||||||
terrno = TSDB_CODE_INVALID_JSON_FORMAT;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,13 +102,13 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
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;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t dmEncodeFile(SJson *pJson, bool deployed) {
|
static int32_t dmEncodeFile(SJson *pJson, bool deployed) {
|
||||||
if (tjsonAddDoubleToObject(pJson, "deployed", deployed) < 0) return -1;
|
if (tjsonAddDoubleToObject(pJson, "deployed", deployed) < 0) return TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,26 +119,57 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
char file[PATH_MAX] = {0};
|
char file[PATH_MAX] = {0};
|
||||||
char realfile[PATH_MAX] = {0};
|
char realfile[PATH_MAX] = {0};
|
||||||
snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
|
||||||
snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
|
|
||||||
|
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
int32_t nBytes = snprintf(file, sizeof(file), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(realfile, sizeof(realfile), "%s%s%s.json", path, TD_DIRSEP, name);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pJson = tjsonCreateObject();
|
pJson = tjsonCreateObject();
|
||||||
if (pJson == NULL) goto _OVER;
|
if (pJson == NULL) {
|
||||||
if (dmEncodeFile(pJson, deployed) != 0) goto _OVER;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((code = dmEncodeFile(pJson, deployed)) != 0) goto _OVER;
|
||||||
|
|
||||||
buffer = tjsonToString(pJson);
|
buffer = tjsonToString(pJson);
|
||||||
if (buffer == NULL) goto _OVER;
|
if (buffer == NULL) {
|
||||||
terrno = 0;
|
code = TSDB_CODE_INVALID_JSON_FORMAT;
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t len = strlen(buffer);
|
int32_t len = strlen(buffer);
|
||||||
if (taosWriteFile(pFile, buffer, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, buffer, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
if (taosCloseFile(&pFile) != 0) {
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
|
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
|
||||||
|
@ -145,43 +180,44 @@ _OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to write file:%s since %s, deloyed:%d", realfile, tstrerror(code), deployed);
|
||||||
dError("failed to write file:%s since %s, deloyed:%d", realfile, terrstr(), deployed);
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
TdFilePtr dmCheckRunning(const char *dataDir) {
|
int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) {
|
||||||
|
int32_t code = 0;
|
||||||
char filepath[PATH_MAX] = {0};
|
char filepath[PATH_MAX] = {0};
|
||||||
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
snprintf(filepath, sizeof(filepath), "%s%s.running", dataDir, TD_DIRSEP);
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
|
*pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC);
|
||||||
if (pFile == NULL) {
|
if (*pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open file:%s since %s", filepath, terrstr());
|
dError("failed to open file:%s since %s", filepath, tstrerror(code));
|
||||||
return NULL;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t retryTimes = 0;
|
int32_t retryTimes = 0;
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
do {
|
do {
|
||||||
ret = taosLockFile(pFile);
|
ret = taosLockFile(*pFile);
|
||||||
if (ret == 0) break;
|
if (ret == 0) break;
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosMsleep(1000);
|
taosMsleep(1000);
|
||||||
retryTimes++;
|
retryTimes++;
|
||||||
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, terrstr(), retryTimes);
|
dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes);
|
||||||
} while (retryTimes < 12);
|
} while (retryTimes < 12);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
taosCloseFile(&pFile);
|
taosCloseFile(pFile);
|
||||||
return NULL;
|
*pFile = NULL;
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
terrno = 0;
|
|
||||||
dDebug("lock file:%s to prevent repeated starts", filepath);
|
dDebug("lock file:%s to prevent repeated starts", filepath);
|
||||||
return pFile;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
|
extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
|
||||||
|
@ -193,6 +229,9 @@ static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key, bool
|
||||||
|
|
||||||
int32_t len = ENCRYPTED_LEN(sizeof(DM_KEY_INDICATOR));
|
int32_t len = ENCRYPTED_LEN(sizeof(DM_KEY_INDICATOR));
|
||||||
result = taosMemoryMalloc(len);
|
result = taosMemoryMalloc(len);
|
||||||
|
if (result == NULL) {
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
SCryptOpts opts;
|
SCryptOpts opts;
|
||||||
strncpy(opts.key, key, ENCRYPT_KEY_LEN);
|
strncpy(opts.key, key, ENCRYPT_KEY_LEN);
|
||||||
|
@ -203,13 +242,30 @@ static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key, bool
|
||||||
CBC_Encrypt(&opts);
|
CBC_Encrypt(&opts);
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosWriteFile(pFile, opts.result, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, opts.result, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosCloseFile(&pFile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
encryptDebug("succeed to write checkCode file:%s", realfile);
|
encryptDebug("succeed to write checkCode file:%s", realfile);
|
||||||
|
|
||||||
|
@ -226,14 +282,30 @@ static int32_t dmWriteEncryptCodeFile(char* file, char* realfile, char* encryptC
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH);
|
||||||
if (pFile == NULL) goto _OVER;
|
if (pFile == NULL) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t len = strlen(encryptCode);
|
int32_t len = strlen(encryptCode);
|
||||||
if (taosWriteFile(pFile, encryptCode, len) <= 0) goto _OVER;
|
if (taosWriteFile(pFile, encryptCode, len) <= 0) {
|
||||||
if (taosFsyncFile(pFile) < 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
if (taosFsyncFile(pFile) < 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
taosCloseFile(&pFile);
|
if (taosCloseFile(&pFile) != 0) {
|
||||||
if (taosRenameFile(file, realfile) != 0) goto _OVER;
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taosRenameFile(file, realfile) != 0) {
|
||||||
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
|
goto _OVER;
|
||||||
|
}
|
||||||
|
|
||||||
encryptDebug("succeed to write encryptCode file:%s", realfile);
|
encryptDebug("succeed to write encryptCode file:%s", realfile);
|
||||||
|
|
||||||
|
@ -253,26 +325,26 @@ static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
encryptError("failed to open dnode file:%s since %s", file, terrstr());
|
encryptError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
if (taosFStatFile(pFile, &size, NULL) < 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
encryptError("failed to fstat dnode file:%s since %s", file, terrstr());
|
encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size);
|
content = taosMemoryMalloc(size);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
if (taosReadFile(pFile, content, size) != size) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
encryptError("failed to read dnode file:%s since %s", file, terrstr());
|
encryptError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +362,7 @@ static int32_t dmCompareEncryptKey(char* file, char* key, bool toLogFile){
|
||||||
CBC_Decrypt(&opts);
|
CBC_Decrypt(&opts);
|
||||||
|
|
||||||
if (strcmp(opts.result, DM_KEY_INDICATOR) != 0) {
|
if (strcmp(opts.result, DM_KEY_INDICATOR) != 0) {
|
||||||
terrno = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED;
|
code = TSDB_CODE_DNODE_ENCRYPTKEY_CHANGED;
|
||||||
encryptError("failed to compare decrypted result");
|
encryptError("failed to compare decrypted result");
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
@ -319,40 +391,57 @@ int32_t dmUpdateEncryptKey(char *key, bool toLogFile) {
|
||||||
char checkFile[PATH_MAX] = {0};
|
char checkFile[PATH_MAX] = {0};
|
||||||
char realCheckFile[PATH_MAX] = {0};
|
char realCheckFile[PATH_MAX] = {0};
|
||||||
|
|
||||||
snprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP);
|
int32_t nBytes = snprintf(folder, sizeof(folder), "%s%sdnode", tsDataDir, TD_DIRSEP);
|
||||||
snprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
snprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
snprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
}
|
||||||
snprintf(realCheckFile, sizeof(realCheckFile), "%s%s%s", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
|
||||||
|
|
||||||
terrno = 0;
|
nBytes = snprintf(encryptFile, sizeof(realEncryptFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(realEncryptFile, sizeof(realEncryptFile), "%s%s%s", folder, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(checkFile, sizeof(checkFile), "%s%s%s.bak", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(realCheckFile, sizeof(realCheckFile), "%s%s%s", folder, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= PATH_MAX) {
|
||||||
|
return TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
if (taosMkDir(folder) != 0) {
|
if (taosMkDir(folder) != 0) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
encryptError("failed to create dir:%s since %s", folder, terrstr());
|
encryptError("failed to create dir:%s since %s", folder, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosCheckExistFile(realCheckFile)) {
|
if (taosCheckExistFile(realCheckFile)) {
|
||||||
if(dmCompareEncryptKey(realCheckFile, key, toLogFile) != 0){
|
if ((code = dmCompareEncryptKey(realCheckFile, key, toLogFile)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(machineId = tGetMachineId())) {
|
if (!(machineId = tGetMachineId())) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (generateEncryptCode(key, machineId, &encryptCode) != 0) {
|
if ((code = generateEncryptCode(key, machineId, &encryptCode)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile) != 0){
|
if ((code = dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode, toLogFile)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dmWriteCheckCodeFile(checkFile, realCheckFile, key, toLogFile) != 0){
|
if ((code = dmWriteCheckCodeFile(checkFile, realCheckFile, key, toLogFile)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,8 +452,7 @@ _OVER:
|
||||||
taosMemoryFree(encryptCode);
|
taosMemoryFree(encryptCode);
|
||||||
taosMemoryFree(machineId);
|
taosMemoryFree(machineId);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
encryptError("failed to update encrypt key since %s", tstrerror(code));
|
||||||
encryptError("failed to update encrypt key since %s", terrstr());
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#else
|
#else
|
||||||
|
@ -381,38 +469,40 @@ static int32_t dmReadEncryptCodeFile(char* file, char** output){
|
||||||
|
|
||||||
pFile = taosOpenFile(file, TD_FILE_READ);
|
pFile = taosOpenFile(file, TD_FILE_READ);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
code = TAOS_SYSTEM_ERROR(errno);
|
||||||
dError("failed to open dnode file:%s since %s", file, terrstr());
|
dError("failed to open dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
if (taosFStatFile(pFile, &size, NULL) < 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());
|
dError("failed to fstat dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content = taosMemoryMalloc(size + 1);
|
content = taosMemoryMalloc(size + 1);
|
||||||
if (content == NULL) {
|
if (content == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (taosReadFile(pFile, content, size) != size) {
|
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());
|
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
content[size] = '\0';
|
content[size] = '\0';
|
||||||
|
|
||||||
*output = content;
|
*output = content;
|
||||||
|
content = NULL;
|
||||||
|
|
||||||
dInfo("succeed to read encryptCode file:%s", file);
|
dInfo("succeed to read encryptCode file:%s", file);
|
||||||
code = 0;
|
code = 0;
|
||||||
_OVER:
|
_OVER:
|
||||||
if (pFile != NULL) taosCloseFile(&pFile);
|
if (pFile != NULL) taosCloseFile(&pFile);
|
||||||
|
taosMemoryFree(content);
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -426,24 +516,35 @@ int32_t dmGetEncryptKey(){
|
||||||
char *encryptKey = NULL;
|
char *encryptKey = NULL;
|
||||||
char *content = NULL;
|
char *content = NULL;
|
||||||
|
|
||||||
snprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_ENCRYPT_CODE_FILE);
|
int32_t nBytes = snprintf(encryptFile, sizeof(encryptFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP,
|
||||||
snprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
DM_ENCRYPT_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(encryptFile)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
nBytes = snprintf(checkFile, sizeof(checkFile), "%s%sdnode%s%s", tsDataDir, TD_DIRSEP, TD_DIRSEP, DM_CHECK_CODE_FILE);
|
||||||
|
if (nBytes <= 0 || nBytes >= sizeof(checkFile)) {
|
||||||
|
code = TSDB_CODE_OUT_OF_BUFFER;
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
if (!taosCheckExistFile(encryptFile)) {
|
if (!taosCheckExistFile(encryptFile)) {
|
||||||
|
code = TSDB_CODE_DNODE_INVALID_ENCRYPT_CONFIG;
|
||||||
dInfo("no exist, checkCode file:%s", encryptFile);
|
dInfo("no exist, checkCode file:%s", encryptFile);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dmReadEncryptCodeFile(encryptFile, &content) != 0){
|
if ((code = dmReadEncryptCodeFile(encryptFile, &content)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(machineId = tGetMachineId())) {
|
if (!(machineId = tGetMachineId())) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(checkAndGetCryptKey(content, machineId, &encryptKey) != 0){
|
if ((code = checkAndGetCryptKey(content, machineId, &encryptKey)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -451,12 +552,12 @@ int32_t dmGetEncryptKey(){
|
||||||
taosMemoryFreeClear(content);
|
taosMemoryFreeClear(content);
|
||||||
|
|
||||||
if (encryptKey[0] == '\0') {
|
if (encryptKey[0] == '\0') {
|
||||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
code = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||||
dError("failed to read key since %s", terrstr());
|
dError("failed to read key since %s", tstrerror(code));
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(dmCompareEncryptKey(checkFile, encryptKey, true) != 0){
|
if ((code = dmCompareEncryptKey(checkFile, encryptKey, true)) != 0) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,8 +572,7 @@ _OVER:
|
||||||
if (encryptKey != NULL) taosMemoryFree(encryptKey);
|
if (encryptKey != NULL) taosMemoryFree(encryptKey);
|
||||||
if (machineId != NULL) taosMemoryFree(machineId);
|
if (machineId != NULL) taosMemoryFree(machineId);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
dError("failed to get encrypt key since %s", tstrerror(code));
|
||||||
dError("failed to get encrypt key since %s", terrstr());
|
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -464,8 +464,7 @@ static int32_t mndCreateDir(SMnode *pMnode, const char *path) {
|
||||||
static int32_t mndInitWal(SMnode *pMnode) {
|
static int32_t mndInitWal(SMnode *pMnode) {
|
||||||
char path[PATH_MAX + 20] = {0};
|
char path[PATH_MAX + 20] = {0};
|
||||||
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
snprintf(path, sizeof(path), "%s%swal", pMnode->path, TD_DIRSEP);
|
||||||
SWalCfg cfg = {
|
SWalCfg cfg = {.vgId = 1,
|
||||||
.vgId = 1,
|
|
||||||
.fsyncPeriod = 0,
|
.fsyncPeriod = 0,
|
||||||
.rollPeriod = -1,
|
.rollPeriod = -1,
|
||||||
.segSize = -1,
|
.segSize = -1,
|
||||||
|
@ -473,8 +472,7 @@ static int32_t mndInitWal(SMnode *pMnode) {
|
||||||
.retentionSize = 0,
|
.retentionSize = 0,
|
||||||
.level = TAOS_WAL_FSYNC,
|
.level = TAOS_WAL_FSYNC,
|
||||||
.encryptAlgorithm = 0,
|
.encryptAlgorithm = 0,
|
||||||
.encryptKey = {0}
|
.encryptKey = {0}};
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(TD_ENTERPRISE)
|
#if defined(TD_ENTERPRISE)
|
||||||
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_MNODE_WAL) == DND_CS_MNODE_WAL) {
|
if (tsiEncryptAlgorithm == DND_CA_SM4 && (tsiEncryptScope & DND_CS_MNODE_WAL) == DND_CS_MNODE_WAL) {
|
||||||
|
@ -482,8 +480,7 @@ static int32_t mndInitWal(SMnode *pMnode) {
|
||||||
if (tsEncryptKey[0] == '\0') {
|
if (tsEncryptKey[0] == '\0') {
|
||||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
strncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
strncpy(cfg.encryptKey, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -142,17 +142,22 @@ int32_t taosConvInit(void) {
|
||||||
|
|
||||||
gConv[M2C] = taosMemoryCalloc(gConvMaxNum[M2C], sizeof(SConv));
|
gConv[M2C] = taosMemoryCalloc(gConvMaxNum[M2C], sizeof(SConv));
|
||||||
gConv[1 - M2C] = taosMemoryCalloc(gConvMaxNum[1 - M2C], sizeof(SConv));
|
gConv[1 - M2C] = taosMemoryCalloc(gConvMaxNum[1 - M2C], sizeof(SConv));
|
||||||
|
if (gConv[M2C] == NULL || gConv[1 - M2C] == NULL) {
|
||||||
|
taosMemoryFree(gConv[M2C]);
|
||||||
|
taosMemoryFree(gConv[1 - M2C]);
|
||||||
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < gConvMaxNum[M2C]; ++i) {
|
for (int32_t i = 0; i < gConvMaxNum[M2C]; ++i) {
|
||||||
gConv[M2C][i].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
gConv[M2C][i].conv = iconv_open(DEFAULT_UNICODE_ENCODEC, tsCharset);
|
||||||
if ((iconv_t)-1 == gConv[M2C][i].conv || (iconv_t)0 == gConv[M2C][i].conv) {
|
if ((iconv_t)-1 == gConv[M2C][i].conv || (iconv_t)0 == gConv[M2C][i].conv) {
|
||||||
return -1;
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int32_t i = 0; i < gConvMaxNum[1 - M2C]; ++i) {
|
for (int32_t i = 0; i < gConvMaxNum[1 - M2C]; ++i) {
|
||||||
gConv[1 - M2C][i].conv = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
gConv[1 - M2C][i].conv = iconv_open(tsCharset, DEFAULT_UNICODE_ENCODEC);
|
||||||
if ((iconv_t)-1 == gConv[1 - M2C][i].conv || (iconv_t)0 == gConv[1 - M2C][i].conv) {
|
if ((iconv_t)-1 == gConv[1 - M2C][i].conv || (iconv_t)0 == gConv[1 - M2C][i].conv) {
|
||||||
return -1;
|
return TAOS_SYSTEM_ERROR(errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,28 +571,41 @@ int32_t taosHex2Ascii(const char *z, uint32_t n, void **data, uint32_t *size) {
|
||||||
// return 0;
|
// return 0;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
static char valueOf(uint8_t symbol)
|
static char valueOf(uint8_t symbol) {
|
||||||
{
|
switch (symbol) {
|
||||||
switch(symbol)
|
case 0:
|
||||||
{
|
return '0';
|
||||||
case 0: return '0';
|
case 1:
|
||||||
case 1: return '1';
|
return '1';
|
||||||
case 2: return '2';
|
case 2:
|
||||||
case 3: return '3';
|
return '2';
|
||||||
case 4: return '4';
|
case 3:
|
||||||
case 5: return '5';
|
return '3';
|
||||||
case 6: return '6';
|
case 4:
|
||||||
case 7: return '7';
|
return '4';
|
||||||
case 8: return '8';
|
case 5:
|
||||||
case 9: return '9';
|
return '5';
|
||||||
case 10: return 'A';
|
case 6:
|
||||||
case 11: return 'B';
|
return '6';
|
||||||
case 12: return 'C';
|
case 7:
|
||||||
case 13: return 'D';
|
return '7';
|
||||||
case 14: return 'E';
|
case 8:
|
||||||
case 15: return 'F';
|
return '8';
|
||||||
default:
|
case 9:
|
||||||
{
|
return '9';
|
||||||
|
case 10:
|
||||||
|
return 'A';
|
||||||
|
case 11:
|
||||||
|
return 'B';
|
||||||
|
case 12:
|
||||||
|
return 'C';
|
||||||
|
case 13:
|
||||||
|
return 'D';
|
||||||
|
case 14:
|
||||||
|
return 'E';
|
||||||
|
case 15:
|
||||||
|
return 'F';
|
||||||
|
default: {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,15 +83,13 @@ int32_t taosCheckVersionCompatible(int32_t clientVer, int32_t serverVer, int32_t
|
||||||
serverVer /= 1000000;
|
serverVer /= 1000000;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_INVALID_VERSION_NUMBER;
|
return TSDB_CODE_INVALID_VERSION_NUMBER;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clientVer == serverVer) {
|
if (clientVer == serverVer) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
return TSDB_CODE_VERSION_NOT_COMPATIBLE;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue