TD-1207
This commit is contained in:
parent
a47e778b5c
commit
65a28796cd
|
@ -19,8 +19,10 @@
|
||||||
#include "tconfig.h"
|
#include "tconfig.h"
|
||||||
#include "dnodeMain.h"
|
#include "dnodeMain.h"
|
||||||
|
|
||||||
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
|
|
||||||
static tsem_t exitSem;
|
static tsem_t exitSem;
|
||||||
|
static void siguser1Handler(int32_t signum);
|
||||||
|
static void siguser2Handler(int32_t signum);
|
||||||
|
static void sigintHandler(int32_t signum);
|
||||||
|
|
||||||
int32_t main(int32_t argc, char *argv[]) {
|
int32_t main(int32_t argc, char *argv[]) {
|
||||||
int dump_config = 0;
|
int dump_config = 0;
|
||||||
|
@ -28,7 +30,7 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
// Set global configuration file
|
// Set global configuration file
|
||||||
for (int32_t i = 1; i < argc; ++i) {
|
for (int32_t i = 1; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "-c") == 0) {
|
if (strcmp(argv[i], "-c") == 0) {
|
||||||
if (i < argc - 1) {
|
if (i < argc - 1) {
|
||||||
if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) {
|
if (strlen(argv[++i]) >= TSDB_FILENAME_LEN) {
|
||||||
printf("config file path overflow");
|
printf("config file path overflow");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -80,8 +82,8 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
taosSetRandomFileFailOutput(NULL);
|
taosSetRandomFileFailOutput(NULL);
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "--random-file-fail-factor") == 0) {
|
} else if (strcmp(argv[i], "--random-file-fail-factor") == 0) {
|
||||||
if ( (i+1) < argc ) {
|
if ((i + 1) < argc) {
|
||||||
int factor = atoi(argv[i+1]);
|
int factor = atoi(argv[i + 1]);
|
||||||
printf("The factor of random failure is %d\n", factor);
|
printf("The factor of random failure is %d\n", factor);
|
||||||
taosSetRandomFileFailFactor(factor);
|
taosSetRandomFileFailFactor(factor);
|
||||||
} else {
|
} else {
|
||||||
|
@ -93,7 +95,7 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 != dump_config) {
|
if (0 != dump_config) {
|
||||||
tscEmbedded = 1;
|
tscEmbedded = 1;
|
||||||
taosInitGlobalCfg();
|
taosInitGlobalCfg();
|
||||||
taosReadGlobalLogCfg();
|
taosReadGlobalLogCfg();
|
||||||
|
|
||||||
|
@ -112,14 +114,12 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set termination handler. */
|
/* Set termination handler. */
|
||||||
struct sigaction act = {{0}};
|
taosSetSignal(SIGUSR1, siguser1Handler);
|
||||||
act.sa_flags = SA_SIGINFO;
|
taosSetSignal(SIGUSR2, siguser2Handler);
|
||||||
act.sa_sigaction = signal_handler;
|
taosSetSignal(SIGTERM, sigintHandler);
|
||||||
sigaction(SIGTERM, &act, NULL);
|
taosSetSignal(SIGHUP, sigintHandler);
|
||||||
sigaction(SIGHUP, &act, NULL);
|
taosSetSignal(SIGINT, sigintHandler);
|
||||||
sigaction(SIGINT, &act, NULL);
|
taosSetSignal(SIGABRT, sigintHandler);
|
||||||
sigaction(SIGUSR1, &act, NULL);
|
|
||||||
sigaction(SIGUSR2, &act, NULL);
|
|
||||||
|
|
||||||
// Open /var/log/syslog file to record information.
|
// Open /var/log/syslog file to record information.
|
||||||
openlog("TDengine:", LOG_PID | LOG_CONS | LOG_NDELAY, LOG_LOCAL1);
|
openlog("TDengine:", LOG_PID | LOG_CONS | LOG_NDELAY, LOG_LOCAL1);
|
||||||
|
@ -147,32 +147,25 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
|
static void siguser1Handler(int32_t signum) { taosCfgDynamicOptions("debugFlag 143"); }
|
||||||
if (signum == SIGUSR1) {
|
|
||||||
taosCfgDynamicOptions("debugFlag 143");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (signum == SIGUSR2) {
|
|
||||||
taosCfgDynamicOptions("resetlog");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
syslog(LOG_INFO, "Shut down signal is %d", signum);
|
static void siguser2Handler(int32_t signum) { taosCfgDynamicOptions("resetlog"); }
|
||||||
syslog(LOG_INFO, "Shutting down TDengine service...");
|
|
||||||
// clean the system.
|
|
||||||
dInfo("shut down signal is %d, sender PID:%d cmdline:%s", signum, sigInfo->si_pid, taosGetCmdlineByPID(sigInfo->si_pid));
|
|
||||||
|
|
||||||
// protect the application from receive another signal
|
static void sigintHandler(int32_t signum) {
|
||||||
struct sigaction act = {{0}};
|
// clean the system.
|
||||||
#ifndef WINDOWS
|
dInfo("shut down signal is %d", signum);
|
||||||
act.sa_handler = SIG_IGN;
|
|
||||||
#endif
|
|
||||||
sigaction(SIGTERM, &act, NULL);
|
|
||||||
sigaction(SIGHUP, &act, NULL);
|
|
||||||
sigaction(SIGINT, &act, NULL);
|
|
||||||
sigaction(SIGUSR1, &act, NULL);
|
|
||||||
sigaction(SIGUSR2, &act, NULL);
|
|
||||||
|
|
||||||
// inform main thread to exit
|
syslog(LOG_INFO, "Shut down signal is %d", signum);
|
||||||
tsem_post(&exitSem);
|
syslog(LOG_INFO, "Shutting down TDengine service...");
|
||||||
|
|
||||||
|
// protect the application from receive another signal
|
||||||
|
taosIgnSignal(SIGUSR1);
|
||||||
|
taosIgnSignal(SIGUSR2);
|
||||||
|
taosIgnSignal(SIGTERM);
|
||||||
|
taosIgnSignal(SIGHUP);
|
||||||
|
taosIgnSignal(SIGINT);
|
||||||
|
taosIgnSignal(SIGABRT);
|
||||||
|
|
||||||
|
// inform main thread to exit
|
||||||
|
tsem_post(&exitSem);
|
||||||
}
|
}
|
|
@ -21,7 +21,7 @@
|
||||||
pthread_t pid;
|
pthread_t pid;
|
||||||
static tsem_t cancelSem;
|
static tsem_t cancelSem;
|
||||||
|
|
||||||
void shellQueryInterruptHandler(int32_t signum, siginfo_t *sigInfo, void *context) {
|
void shellQueryInterruptHandler(int32_t signum) {
|
||||||
tsem_post(&cancelSem);
|
tsem_post(&cancelSem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,12 +130,10 @@ int main(int argc, char* argv[]) {
|
||||||
pthread_create(&spid, NULL, cancelHandler, NULL);
|
pthread_create(&spid, NULL, cancelHandler, NULL);
|
||||||
|
|
||||||
/* Interrupt handler. */
|
/* Interrupt handler. */
|
||||||
struct sigaction act;
|
taosSetSignal(SIGTERM, shellQueryInterruptHandler);
|
||||||
memset(&act, 0, sizeof(struct sigaction));
|
taosSetSignal(SIGINT, shellQueryInterruptHandler);
|
||||||
|
taosSetSignal(SIGHUP, shellQueryInterruptHandler);
|
||||||
act.sa_handler = shellQueryInterruptHandler;
|
taosSetSignal(SIGABRT, shellQueryInterruptHandler);
|
||||||
sigaction(SIGTERM, &act, NULL);
|
|
||||||
sigaction(SIGINT, &act, NULL);
|
|
||||||
|
|
||||||
/* Get grant information */
|
/* Get grant information */
|
||||||
shellGetGrantInfo(con);
|
shellGetGrantInfo(con);
|
||||||
|
|
|
@ -62,6 +62,7 @@ extern "C" {
|
||||||
#include "osMemory.h"
|
#include "osMemory.h"
|
||||||
#include "osRand.h"
|
#include "osRand.h"
|
||||||
#include "osSemphone.h"
|
#include "osSemphone.h"
|
||||||
|
#include "osSignal.h"
|
||||||
#include "osSocket.h"
|
#include "osSocket.h"
|
||||||
#include "osString.h"
|
#include "osString.h"
|
||||||
#include "osSysinfo.h"
|
#include "osSysinfo.h"
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TDENGINE_OS_SIGNAL_H
|
||||||
|
#define TDENGINE_OS_SIGNAL_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "os.h"
|
||||||
|
#include "taosdef.h"
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
#ifndef SIGALRM
|
||||||
|
#define SIGALRM 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGHUP
|
||||||
|
#define SIGHUP 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGCHLD
|
||||||
|
#define SIGCHLD 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGUSR1
|
||||||
|
#define SIGUSR1 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGUSR2
|
||||||
|
#define SIGUSR2 1234
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef void (*FSignalHandler)(int32_t signum);
|
||||||
|
void taosSetSignal(int32_t signum, FSignalHandler sigfp);
|
||||||
|
void taosIgnSignal(int32_t signum);
|
||||||
|
void taosDflSignal(int32_t signum);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // TDENGINE_TTIME_H
|
|
@ -191,24 +191,6 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone);
|
||||||
#define PATH_MAX 256
|
#define PATH_MAX 256
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//for signal, not dispose
|
|
||||||
#define SIGALRM 1234
|
|
||||||
#define SIGHUP 1234
|
|
||||||
#define SIGUSR1 1234
|
|
||||||
#define SIGUSR2 1234
|
|
||||||
#define SA_SIGINFO 1234
|
|
||||||
|
|
||||||
typedef int sigset_t;
|
|
||||||
typedef struct siginfo_t {
|
|
||||||
int si_pid;
|
|
||||||
} siginfo_t;
|
|
||||||
struct sigaction {
|
|
||||||
int sa_flags;
|
|
||||||
void (*sa_handler)(int32_t signum, siginfo_t *sigInfo, void *context);
|
|
||||||
void (*sa_sigaction)(int32_t signum, siginfo_t *sigInfo, void *context);
|
|
||||||
};
|
|
||||||
int sigaction(int, struct sigaction *, void *);
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int we_wordc;
|
int we_wordc;
|
||||||
char **we_wordv;
|
char **we_wordv;
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "os.h"
|
||||||
|
#include "tconfig.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
#include "tulog.h"
|
||||||
|
|
||||||
|
#ifndef TAOS_OS_FUNC_SIGNAL
|
||||||
|
|
||||||
|
void taosSetSignal(int32_t signum, FSignalHandler sigfp) {
|
||||||
|
struct sigaction act = {{0}};
|
||||||
|
act.sa_handler = sigfp;
|
||||||
|
sigaction(signum, &act, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosIgnSignal(int32_t signum) {
|
||||||
|
signal(signum, SIG_IGN);
|
||||||
|
}
|
||||||
|
|
||||||
|
void taosDflSignal(int32_t signum) {
|
||||||
|
signal(signum, SIG_DFL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
|
@ -43,6 +43,7 @@ void osInit() {
|
||||||
char cmdline[1024];
|
char cmdline[1024];
|
||||||
|
|
||||||
char* taosGetCmdlineByPID(int pid) {
|
char* taosGetCmdlineByPID(int pid) {
|
||||||
|
#if 0
|
||||||
sprintf(cmdline, "/proc/%d/cmdline", pid);
|
sprintf(cmdline, "/proc/%d/cmdline", pid);
|
||||||
FILE* f = fopen(cmdline, "r");
|
FILE* f = fopen(cmdline, "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
|
@ -54,4 +55,7 @@ char* taosGetCmdlineByPID(int pid) {
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
return cmdline;
|
return cmdline;
|
||||||
|
#else
|
||||||
|
return "";
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -235,8 +235,6 @@ int taosSystem(const char *cmd) {
|
||||||
|
|
||||||
int flock(int fd, int option) { return 0; }
|
int flock(int fd, int option) { return 0; }
|
||||||
|
|
||||||
int sigaction(int sig, struct sigaction *d, void *p) { return 0; }
|
|
||||||
|
|
||||||
LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
|
LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
|
||||||
typedef BOOL(WINAPI * FxMiniDumpWriteDump)(IN HANDLE hProcess, IN DWORD ProcessId, IN HANDLE hFile,
|
typedef BOOL(WINAPI * FxMiniDumpWriteDump)(IN HANDLE hProcess, IN DWORD ProcessId, IN HANDLE hFile,
|
||||||
IN MINIDUMP_TYPE DumpType,
|
IN MINIDUMP_TYPE DumpType,
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncTcp.h"
|
#include "syncTcp.h"
|
||||||
|
|
||||||
static void arbSignalHandler(int32_t signum, siginfo_t *sigInfo, void *context);
|
static void arbSignalHandler(int32_t signum);
|
||||||
static void arbProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp);
|
static void arbProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp);
|
||||||
static void arbProcessBrokenLink(int64_t rid);
|
static void arbProcessBrokenLink(int64_t rid);
|
||||||
static int32_t arbProcessPeerMsg(int64_t rid, void *buffer);
|
static int32_t arbProcessPeerMsg(int64_t rid, void *buffer);
|
||||||
|
@ -69,14 +69,10 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set termination handler. */
|
/* Set termination handler. */
|
||||||
struct sigaction act = {{0}};
|
taosSetSignal(SIGTERM, arbSignalHandler);
|
||||||
act.sa_flags = SA_SIGINFO;
|
taosSetSignal(SIGINT, arbSignalHandler);
|
||||||
act.sa_sigaction = arbSignalHandler;
|
taosSetSignal(SIGHUP, arbSignalHandler);
|
||||||
|
taosSetSignal(SIGABRT, arbSignalHandler);
|
||||||
act.sa_handler = arbSignalHandler;
|
|
||||||
sigaction(SIGTERM, &act, NULL);
|
|
||||||
sigaction(SIGHUP, &act, NULL);
|
|
||||||
sigaction(SIGINT, &act, NULL);
|
|
||||||
|
|
||||||
tsAsyncLog = 0;
|
tsAsyncLog = 0;
|
||||||
strcat(arbLogPath, "/arbitrator.log");
|
strcat(arbLogPath, "/arbitrator.log");
|
||||||
|
@ -174,16 +170,13 @@ static int32_t arbProcessPeerMsg(int64_t rid, void *buffer) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arbSignalHandler(int32_t signum, siginfo_t *sigInfo, void *context) {
|
static void arbSignalHandler(int32_t signum) {
|
||||||
struct sigaction act = {{0}};
|
taosIgnSignal(SIGTERM);
|
||||||
#ifndef WINDOWS
|
taosIgnSignal(SIGINT);
|
||||||
act.sa_handler = SIG_IGN;
|
taosIgnSignal(SIGABRT);
|
||||||
#endif
|
taosIgnSignal(SIGHUP);
|
||||||
sigaction(SIGTERM, &act, NULL);
|
|
||||||
sigaction(SIGHUP, &act, NULL);
|
|
||||||
sigaction(SIGINT, &act, NULL);
|
|
||||||
|
|
||||||
sInfo("shut down signal is %d, sender PID:%d", signum, sigInfo->si_pid);
|
sInfo("shut down signal is %d", signum);
|
||||||
|
|
||||||
// inform main thread to exit
|
// inform main thread to exit
|
||||||
tsem_post(&tsArbSem);
|
tsem_post(&tsArbSem);
|
||||||
|
|
|
@ -314,9 +314,7 @@ bool simExecuteSystemCmd(SScript *script, char *option) {
|
||||||
simError("script:%s, failed to execute %s , code %d, errno:%d %s, repeatTimes:%d", script->fileName, buf, code,
|
simError("script:%s, failed to execute %s , code %d, errno:%d %s, repeatTimes:%d", script->fileName, buf, code,
|
||||||
errno, strerror(errno), repeatTimes);
|
errno, strerror(errno), repeatTimes);
|
||||||
taosMsleep(1000);
|
taosMsleep(1000);
|
||||||
#ifdef LINUX
|
taosDflSignal(SIGCHLD);
|
||||||
signal(SIGCHLD, SIG_DFL);
|
|
||||||
#endif
|
|
||||||
if (repeatTimes++ >= 10) {
|
if (repeatTimes++ >= 10) {
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ int32_t main(int32_t argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
simInfo("simulator is running ...");
|
simInfo("simulator is running ...");
|
||||||
signal(SIGINT, simHandleSignal);
|
taosSetSignal(SIGINT, simHandleSignal);
|
||||||
|
|
||||||
SScript *script = simParseScript(scriptFile);
|
SScript *script = simParseScript(scriptFile);
|
||||||
if (script == NULL) {
|
if (script == NULL) {
|
||||||
|
|
Loading…
Reference in New Issue