提交 4dc47f7b 编写于 作者: S Shengliang Guan

set signal

上级 dd94e2da
......@@ -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;
......
......@@ -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.
......
......@@ -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;
......
......@@ -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);
......
......@@ -123,6 +123,7 @@ typedef struct SDnode {
int32_t numOfDisks;
uint16_t serverPort;
bool dropped;
ENodeType ntype;
EDndStatus status;
EDndEvent event;
SStartupReq startup;
......
......@@ -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;
......
......@@ -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 ||
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册