diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 90aac6edcdec34c4efee9abacb995c7d3827f9f3..089cb5bb94935a4a5b40cb19db4c86ec47c5c29b 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -51,7 +51,7 @@ extern int32_t tsCompatibleModel; extern bool tsEnableSlaveQuery; extern bool tsPrintAuth; extern int64_t tsTickPerDay[3]; -extern int32_t tsMultiProcess; +extern bool tsMultiProcess; // monitor extern bool tsEnableMonitor; diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index 8d19ce23dfdfce22a3e0e9b0961f58aa9319bc74..f4516e9e1904fad6f4dffe3464325644e93ef7f3 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -48,9 +48,10 @@ typedef struct { char secondEp[TSDB_EP_LEN]; SDiskCfg *pDisks; int32_t numOfDisks; + int8_t ntype; } SDnodeOpt; -typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_RELOAD } EDndEvent; +typedef enum { DND_EVENT_START, DND_EVENT_STOP = 1, DND_EVENT_CHILD } EDndEvent; /** * @brief Initialize and start the dnode. diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index efd790ade8c143dd40b5cb9b0bfe749e0f57b06f..c79e1531229330ab4611319b77f5305d81d80b95 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -45,7 +45,7 @@ float tsRatioOfQueryCores = 1.0f; int32_t tsMaxBinaryDisplayWidth = 30; bool tsEnableSlaveQuery = 1; bool tsPrintAuth = 0; -int32_t tsMultiProcess = 0; +bool tsMultiProcess = 0; // monitor bool tsEnableMonitor = 1; @@ -347,7 +347,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) { if (cfgAddBool(pCfg, "printAuth", tsPrintAuth, 0) != 0) return -1; if (cfgAddBool(pCfg, "slaveQuery", tsEnableSlaveQuery, 0) != 0) return -1; if (cfgAddBool(pCfg, "deadLockKillQuery", tsDeadLockKillQuery, 0) != 0) return -1; - if (cfgAddInt32(pCfg, "multiProcess", tsMultiProcess, 0, 2, 0) != 0) return -1; + if (cfgAddBool(pCfg, "multiProcess", tsMultiProcess, 0) != 0) return -1; if (cfgAddBool(pCfg, "monitor", tsEnableMonitor, 0) != 0) return -1; if (cfgAddInt32(pCfg, "monitorInterval", tsMonitorInterval, 1, 360000, 0) != 0) return -1; @@ -466,7 +466,7 @@ static int32_t taosSetServerCfg(SConfig *pCfg) { tsPrintAuth = cfgGetItem(pCfg, "printAuth")->bval; tsEnableSlaveQuery = cfgGetItem(pCfg, "slaveQuery")->bval; tsDeadLockKillQuery = cfgGetItem(pCfg, "deadLockKillQuery")->bval; - tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->i32; + tsMultiProcess = cfgGetItem(pCfg, "multiProcess")->bval; tsEnableMonitor = cfgGetItem(pCfg, "monitor")->bval; tsMonitorInterval = cfgGetItem(pCfg, "monitorInterval")->i32; diff --git a/source/dnode/mgmt/main/exe/dndMain.c b/source/dnode/mgmt/main/exe/dndMain.c index 634e2caa28462049fc092492bf6ed778469ef846..5b506ae4eebeee90fddd708d732601a3f878dda6 100644 --- a/source/dnode/mgmt/main/exe/dndMain.c +++ b/source/dnode/mgmt/main/exe/dndMain.c @@ -29,7 +29,7 @@ static struct { ENodeType ntype; } global = {0}; -static void dndSigintHandle(int signum, void *info, void *ctx) { +static void dndStopDnode(int signum, void *info, void *ctx) { dInfo("signal:%d is received", signum); SDnode *pDnode = atomic_val_compare_exchange_ptr(&global.pDnode, 0, global.pDnode); if (pDnode != NULL) { @@ -37,12 +37,29 @@ static void dndSigintHandle(int signum, void *info, void *ctx) { } } +static void dndHandleChild(int signum, void *info, void *ctx) { + dInfo("signal:%d is received", signum); + dndHandleEvent(global.pDnode, DND_EVENT_CHILD); +} + static void dndSetSignalHandle() { - taosSetSignal(SIGTERM, dndSigintHandle); - taosSetSignal(SIGHUP, dndSigintHandle); - taosSetSignal(SIGINT, dndSigintHandle); - taosSetSignal(SIGABRT, dndSigintHandle); - taosSetSignal(SIGBREAK, dndSigintHandle); + taosSetSignal(SIGTERM, dndStopDnode); + taosSetSignal(SIGHUP, dndStopDnode); + taosSetSignal(SIGINT, dndStopDnode); + taosSetSignal(SIGABRT, dndStopDnode); + taosSetSignal(SIGBREAK, dndStopDnode); + + if (!tsMultiProcess) { + // Set the single process signal + } else if (global.ntype == DNODE) { + // Set the parent process signal + // When the child process exits, the parent process receives a signal + taosSetSignal(SIGCHLD, dndHandleChild); + } else { + // Set child process signal + // When the parent process exits, the child process will receive the SIGKILL signal + prctl(PR_SET_PDEATHSIG, SIGKILL); + } } static int32_t dndParseArgs(int32_t argc, char const *argv[]) { @@ -111,6 +128,7 @@ static SDnodeOpt dndGetOpt() { snprintf(option.localEp, sizeof(option.localEp), "%s:%u", option.localFqdn, option.serverPort); option.pDisks = tsDiskCfg; option.numOfDisks = tsDiskCfgNum; + option.ntype = global.ntype; return option; } @@ -121,7 +139,7 @@ static int32_t dndInitLog() { } static void dndSetProcName(char **argv) { - if (global.ntype != 0) { + if (global.ntype != DNODE) { const char *name = dndNodeProcStr(global.ntype); prctl(PR_SET_NAME, name); strcpy(argv[0], name); diff --git a/source/dnode/mgmt/main/inc/dnd.h b/source/dnode/mgmt/main/inc/dnd.h index 046200510dd408d5abaacf1634b051fddae2cd83..8e0f545ca37a6fa216cb00b1201c3fdd88f6020f 100644 --- a/source/dnode/mgmt/main/inc/dnd.h +++ b/source/dnode/mgmt/main/inc/dnd.h @@ -123,6 +123,7 @@ typedef struct SDnode { int32_t numOfDisks; uint16_t serverPort; bool dropped; + ENodeType ntype; EDndStatus status; EDndEvent event; SStartupReq startup; diff --git a/source/dnode/mgmt/main/src/dndExec.c b/source/dnode/mgmt/main/src/dndExec.c index 5a9077a93794c36fe356b75c96469b4cc17bd4d4..c41d4f28e40dce726ef43015254c54c2720f9bf6 100644 --- a/source/dnode/mgmt/main/src/dndExec.c +++ b/source/dnode/mgmt/main/src/dndExec.c @@ -259,7 +259,7 @@ static int32_t dndRunInMultiProcess(SDnode *pDnode) { } int32_t dndRun(SDnode *pDnode) { - if (tsMultiProcess == 0) { + if (!tsMultiProcess) { if (dndRunInSingleProcess(pDnode) != 0) { dError("failed to run dnode in single process mode since %s", terrstr()); return -1; diff --git a/source/dnode/mgmt/main/src/dndObj.c b/source/dnode/mgmt/main/src/dndObj.c index b9ea8df8080f6cd63ec738f1a65a9b9398d3dd0e..33b1dfc9858a679c012556a2a2965c64481e3d94 100644 --- a/source/dnode/mgmt/main/src/dndObj.c +++ b/source/dnode/mgmt/main/src/dndObj.c @@ -26,6 +26,7 @@ static int32_t dndInitMemory(SDnode *pDnode, const SDnodeOpt *pOption) { pDnode->secondEp = strdup(pOption->secondEp); pDnode->pDisks = pOption->pDisks; pDnode->numOfDisks = pOption->numOfDisks; + pDnode->ntype = pOption->ntype; pDnode->rebootTime = taosGetTimestampMs(); if (pDnode->dataDir == NULL || pDnode->localEp == NULL || pDnode->localFqdn == NULL || pDnode->firstEp == NULL ||