This commit is contained in:
Shengliang Guan 2022-04-01 11:57:35 +08:00
parent ea8a336269
commit 8eb99ef6d1
3 changed files with 46 additions and 15 deletions

View File

@ -21,9 +21,11 @@ extern "C" {
#endif #endif
int32_t taosNewProc(char **args); int32_t taosNewProc(char **args);
void taosWaitProc(int32_t pid);
void taosKillProc(int32_t pid);
bool taosProcExist(int32_t pid);
void taosSetProcName(int32_t argc, char **argv, const char *name); void taosSetProcName(int32_t argc, char **argv, const char *name);
void taosSetProcPath(int32_t argc, char **argv); void taosSetProcPath(int32_t argc, char **argv);
bool taosProcExists(int32_t pid);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -255,7 +255,15 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
while (1) { while (1) {
if (pDnode->event == DND_EVENT_STOP) { if (pDnode->event == DND_EVENT_STOP) {
dInfo("dnode is about to stop"); dInfo("dnode is about to stop");
break; for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
if (!pWrapper->required) continue;
if (pDnode->ntype == NODE_MAX) continue;
if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) {
dInfo("node:%s, send kill signal to the child process:%d", pWrapper->name, pWrapper->procId);
taosKillProc(pWrapper->procId);
}
} }
for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) { for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
@ -263,11 +271,25 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) {
if (!pWrapper->required) continue; if (!pWrapper->required) continue;
if (pDnode->ntype == NODE_MAX) continue; if (pDnode->ntype == NODE_MAX) continue;
if (pWrapper->procId <= 0 || !taosProcExists(pWrapper->procId)) { if (pWrapper->procId > 0 && taosProcExist(pWrapper->procId)) {
dInfo("node:%s, wait for child process:%d to stop", pWrapper->name, pWrapper->procId);
taosWaitProc(pWrapper->procId);
dInfo("node:%s, child process:%d is stopped", pWrapper->name, pWrapper->procId);
}
}
break;
} else {
for (ENodeType n = DNODE + 1; n < NODE_MAX; ++n) {
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
if (!pWrapper->required) continue;
if (pDnode->ntype == NODE_MAX) continue;
if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) {
dInfo("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); dInfo("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
dndNewProc(pWrapper, n); dndNewProc(pWrapper, n);
} }
} }
}
taosMsleep(100); taosMsleep(100);
} }

View File

@ -32,6 +32,18 @@ int32_t taosNewProc(char **args) {
} }
} }
void taosWaitProc(int32_t pid) {
int32_t status = 0;
waitpid(pid, &status, 0);
}
void taosKillProc(int32_t pid) { kill(pid, SIGINT); }
bool taosProcExist(int32_t pid) {
int32_t p = getpgid(pid);
return p >= 0;
}
// the length of the new name must be less than the original name to take effect // the length of the new name must be less than the original name to take effect
void taosSetProcName(int32_t argc, char **argv, const char *name) { void taosSetProcName(int32_t argc, char **argv, const char *name) {
prctl(PR_SET_NAME, name); prctl(PR_SET_NAME, name);
@ -48,8 +60,3 @@ void taosSetProcName(int32_t argc, char **argv, const char *name) {
} }
void taosSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; } void taosSetProcPath(int32_t argc, char **argv) { tsProcPath = argv[0]; }
bool taosProcExists(int32_t pid) {
int32_t p = getpgid(pid);
return p >= 0;
}