From 8eb99ef6d1a0297b3ca5f98cd6ce82c6c6486627 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 1 Apr 2022 11:57:35 +0800 Subject: [PATCH] shm --- include/os/osProc.h | 4 ++- source/dnode/mgmt/main/src/dndExec.c | 40 +++++++++++++++++++++------- source/os/src/osProc.c | 17 ++++++++---- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/include/os/osProc.h b/include/os/osProc.h index 0b22105e5e..f09b695ef4 100644 --- a/include/os/osProc.h +++ b/include/os/osProc.h @@ -21,9 +21,11 @@ extern "C" { #endif 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 taosSetProcPath(int32_t argc, char **argv); -bool taosProcExists(int32_t pid); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/main/src/dndExec.c b/source/dnode/mgmt/main/src/dndExec.c index 82f54d4fc9..b37893aa6f 100644 --- a/source/dnode/mgmt/main/src/dndExec.c +++ b/source/dnode/mgmt/main/src/dndExec.c @@ -255,17 +255,39 @@ static int32_t dndRunInParentProcess(SDnode *pDnode) { while (1) { if (pDnode->event == DND_EVENT_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) { - SMgmtWrapper *pWrapper = &pDnode->wrappers[n]; - if (!pWrapper->required) continue; - if (pDnode->ntype == NODE_MAX) continue; + 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 || !taosProcExists(pWrapper->procId)) { - dInfo("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId); - dndNewProc(pWrapper, n); + 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); + dndNewProc(pWrapper, n); + } } } diff --git a/source/os/src/osProc.c b/source/os/src/osProc.c index 2d2174a4c8..6b52fa30be 100644 --- a/source/os/src/osProc.c +++ b/source/os/src/osProc.c @@ -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 void taosSetProcName(int32_t argc, char **argv, const char *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]; } - -bool taosProcExists(int32_t pid) { - int32_t p = getpgid(pid); - return p >= 0; -} -- GitLab