提交 de09879d 编写于 作者: S Shengliang Guan

TD-1207

上级 8a9ed8e2
......@@ -19,43 +19,9 @@
#include "tconfig.h"
#include "dnodeMain.h"
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context);
static tsem_t exitSem;
#ifdef WINDOWS
static void signal_handler(int32_t signum) {
dInfo("shut down signal is %d", signum);
#else
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
if (signum == SIGUSR1) {
taosCfgDynamicOptions("debugFlag 143");
return;
}
if (signum == SIGUSR2) {
taosCfgDynamicOptions("resetlog");
return;
}
dInfo("shut down signal is %d, sender PID:%d cmdline:%s", signum, sigInfo->si_pid, taosGetCmdlineByPID(sigInfo->si_pid));
#endif
syslog(LOG_INFO, "Shut down signal is %d", signum);
syslog(LOG_INFO, "Shutting down TDengine service...");
// protect the application from receive another signal
struct sigaction act = {{0}};
act.sa_handler = SIG_IGN;
sigaction(SIGTERM, &act, NULL);
sigaction(SIGINT, &act, NULL);
#ifndef WINDOWS
sigaction(SIGHUP, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
#endif
// inform main thread to exit
tsem_post(&exitSem);
}
int32_t main(int32_t argc, char *argv[]) {
int dump_config = 0;
......@@ -147,8 +113,6 @@ int32_t main(int32_t argc, char *argv[]) {
/* Set termination handler. */
struct sigaction act = {{0}};
#ifndef WINDOWS
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = signal_handler;
sigaction(SIGTERM, &act, NULL);
......@@ -156,11 +120,6 @@ int32_t main(int32_t argc, char *argv[]) {
sigaction(SIGINT, &act, NULL);
sigaction(SIGUSR1, &act, NULL);
sigaction(SIGUSR2, &act, NULL);
#else
act.sa_handler = signal_handler;
sigaction(SIGTERM, &act, NULL);
sigaction(SIGINT, &act, NULL);
#endif
// Open /var/log/syslog file to record information.
openlog("TDengine:", LOG_PID | LOG_CONS | LOG_NDELAY, LOG_LOCAL1);
......@@ -187,3 +146,33 @@ int32_t main(int32_t argc, char *argv[]) {
closelog();
return EXIT_SUCCESS;
}
static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) {
if (signum == SIGUSR1) {
taosCfgDynamicOptions("debugFlag 143");
return;
}
if (signum == SIGUSR2) {
taosCfgDynamicOptions("resetlog");
return;
}
syslog(LOG_INFO, "Shut down signal is %d", signum);
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
struct sigaction act = {{0}};
#ifndef WINDOWS
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
tsem_post(&exitSem);
}
\ No newline at end of file
......@@ -21,7 +21,7 @@
pthread_t pid;
static tsem_t cancelSem;
void shellQueryInterruptHandler(int32_t signum) {
void shellQueryInterruptHandler(int32_t signum, siginfo_t *sigInfo, void *context) {
tsem_post(&cancelSem);
}
......
......@@ -193,9 +193,19 @@ int gettimeofday(struct timeval *ptv, void *pTimeZone);
//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 {
void (*sa_handler)(int);
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 *);
......
......@@ -18,7 +18,6 @@
#include "tglobal.h"
void osInit() {
#ifdef _TD_POWER_
if (configDir[0] == 0) {
strcpy(configDir, "/etc/power");
......@@ -43,16 +42,14 @@ void osInit() {
char cmdline[1024];
char *taosGetCmdlineByPID(int pid)
{
sprintf(cmdline, "/proc/%d/cmdline",pid);
FILE* f = fopen(cmdline,"r");
if(f){
char* taosGetCmdlineByPID(int pid) {
sprintf(cmdline, "/proc/%d/cmdline", pid);
FILE* f = fopen(cmdline, "r");
if (f) {
size_t size;
size = fread(cmdline, sizeof(char), 1024, f);
if(size>0){
if('\n'==cmdline[size-1])
cmdline[size-1]='\0';
if (size > 0) {
if ('\n' == cmdline[size - 1]) cmdline[size - 1] = '\0';
}
fclose(f);
}
......
......@@ -32,10 +32,51 @@
#endif
#pragma warning(push)
#pragma warning(disable:4091)
#pragma warning(disable : 4091)
#include <DbgHelp.h>
#pragma warning(pop)
static int32_t taosGetTotalMemory() {
MEMORYSTATUSEX memsStat;
memsStat.dwLength = sizeof(memsStat);
if (!GlobalMemoryStatusEx(&memsStat)) {
return 0;
}
float nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f);
return (int32_t)nMemTotal;
}
bool taosGetSysMemory(float *memoryUsedMB) {
MEMORYSTATUSEX memsStat;
memsStat.dwLength = sizeof(memsStat);
if (!GlobalMemoryStatusEx(&memsStat)) {
return false;
}
float nMemFree = memsStat.ullAvailPhys / (1024.0f * 1024.0f);
float nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f);
*memoryUsedMB = nMemTotal - nMemFree;
return true;
}
bool taosGetProcMemory(float *memoryUsedMB) {
unsigned bytes_used = 0;
#if defined(_WIN32) && defined(_MSC_VER)
PROCESS_MEMORY_COUNTERS pmc;
HANDLE cur_proc = GetCurrentProcess();
if (GetProcessMemoryInfo(cur_proc, &pmc, sizeof(pmc))) {
bytes_used = (unsigned)(pmc.WorkingSetSize + pmc.PagefileUsage);
}
#endif
*memoryUsedMB = (float)bytes_used / 1024 / 1024;
return true;
}
static void taosGetSystemTimezone() {
// get and set default timezone
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
......@@ -71,16 +112,16 @@ static void taosGetSystemLocale() {
}
}
void taosPrintOsInfo() {}
void taosKillSystem() {
uError("function taosKillSystem, exit!");
exit(0);
static int32_t taosGetCpuCores() {
SYSTEM_INFO info;
GetSystemInfo(&info);
return (int32_t)info.dwNumberOfProcessors;
}
void taosGetSystemInfo() {
taosGetSystemTimezone();
taosGetSystemLocale();
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
*sysCpuUsage = 0;
*procCpuUsage = 0;
return true;
}
bool taosGetDisk() {
......@@ -89,20 +130,35 @@ bool taosGetDisk() {
unsigned _int64 i64FreeBytesToCaller;
unsigned _int64 i64TotalBytes;
unsigned _int64 i64FreeBytes;
char dir[4] = {'C', ':', '\\', '\0'};
int drive_type;
if (tscEmbedded) {
drive_type = GetDriveTypeA(dir);
if (drive_type == DRIVE_FIXED) {
fResult = GetDiskFreeSpaceExA(dir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult) {
tsTotalDataDirGB = tsTotalLogDirGB = tsTotalTmpDirGB = (float)(i64TotalBytes / unit);
tsAvailDataDirGB = tsAvailLogDirGB = tsAvailTmpDirectorySpace = (float)(i64FreeBytes / unit);
}
fResult = GetDiskFreeSpaceExA(tsDataDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult) {
tsTotalDataDirGB = (float)(i64TotalBytes / unit);
tsAvailDataDirGB = (float)(i64FreeBytes / unit);
}
}
fResult = GetDiskFreeSpaceExA(tsLogDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult) {
tsTotalLogDirGB = (float)(i64TotalBytes / unit);
tsAvailLogDirGB = (float)(i64FreeBytes / unit);
}
fResult = GetDiskFreeSpaceExA(tsTempDir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes);
if (fResult) {
tsTotalTmpDirGB = (float)(i64TotalBytes / unit);
tsAvailTmpDirectorySpace = (float)(i64FreeBytes / unit);
}
return true;
}
bool taosGetBandSpeed(float *bandSpeedKb) {
*bandSpeedKb = 0;
return true;
}
......@@ -144,48 +200,30 @@ bool taosGetProcIO(float *readKB, float *writeKB) {
return true;
}
bool taosGetBandSpeed(float *bandSpeedKb) {
*bandSpeedKb = 0;
return true;
}
bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) {
*sysCpuUsage = 0;
*procCpuUsage = 0;
return true;
}
bool taosGetProcMemory(float *memoryUsedMB) {
unsigned bytes_used = 0;
#if 0
#if defined(_WIN32) && defined(_MSC_VER)
PROCESS_MEMORY_COUNTERS pmc;
HANDLE cur_proc = GetCurrentProcess();
if (GetProcessMemoryInfo(cur_proc, &pmc, sizeof(pmc))) {
bytes_used = (unsigned)(pmc.WorkingSetSize + pmc.PagefileUsage);
}
#endif
#endif
void taosGetSystemInfo() {
tsNumOfCores = taosGetCpuCores();
tsTotalMemoryMB = taosGetTotalMemory();
*memoryUsedMB = (float)bytes_used / 1024 / 1024;
float tmp1, tmp2;
taosGetDisk();
taosGetBandSpeed(&tmp1);
taosGetCpuUsage(&tmp1, &tmp2);
taosGetProcIO(&tmp1, &tmp2);
return true;
taosGetSystemTimezone();
taosGetSystemLocale();
}
bool taosGetSysMemory(float *memoryUsedMB) {
MEMORYSTATUSEX memsStat;
float nMemFree;
float nMemTotal;
void taosPrintOsInfo() {
uInfo(" os numOfCores: %d", tsNumOfCores);
uInfo(" os totalDisk: %f(GB)", tsTotalDataDirGB);
uInfo(" os totalMemory: %d(MB)", tsTotalMemoryMB);
uInfo("==================================");
}
memsStat.dwLength = sizeof(memsStat);
if (!GlobalMemoryStatusEx(&memsStat)) {
return false;
}
nMemFree = memsStat.ullAvailPhys / (1024.0f * 1024.0f);
nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f);
*memoryUsedMB = nMemTotal - nMemFree;
return true;
void taosKillSystem() {
uError("function taosKillSystem, exit!");
exit(0);
}
int taosSystem(const char *cmd) {
......@@ -240,4 +278,6 @@ void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); }
bool taosGetSystemUid(char *uid) {
sprintf(uid, "uid_not_implemented_yet");
return true;
}
\ No newline at end of file
}
char *taosGetCmdlineByPID(int pid) { return ""; }
......@@ -27,7 +27,7 @@
#include "syncInt.h"
#include "syncTcp.h"
static void arbSignalHandler(int32_t signum);
static void arbSignalHandler(int32_t signum, siginfo_t *sigInfo, void *context);
static void arbProcessIncommingConnection(SOCKET connFd, uint32_t sourceIp);
static void arbProcessBrokenLink(int64_t rid);
static int32_t arbProcessPeerMsg(int64_t rid, void *buffer);
......@@ -35,9 +35,9 @@ static tsem_t tsArbSem;
static void * tsArbTcpPool;
typedef struct {
char id[TSDB_EP_LEN + 24];
SOCKET nodeFd;
void * pConn;
char id[TSDB_EP_LEN + 24];
SOCKET nodeFd;
void * pConn;
} SNodeConn;
int32_t main(int32_t argc, char *argv[]) {
......@@ -70,14 +70,13 @@ int32_t main(int32_t argc, char *argv[]) {
/* Set termination handler. */
struct sigaction act = {{0}};
memset(&act, 0, sizeof(struct sigaction));
act.sa_flags = SA_SIGINFO;
act.sa_sigaction = arbSignalHandler;
act.sa_handler = arbSignalHandler;
sigaction(SIGTERM, &act, NULL);
sigaction(SIGINT, &act, NULL);
#ifndef WINDOWS
sigaction(SIGHUP, &act, NULL);
#endif
sigaction(SIGINT, &act, NULL);
tsAsyncLog = 0;
strcat(arbLogPath, "/arbitrator.log");
......@@ -107,6 +106,7 @@ int32_t main(int32_t argc, char *argv[]) {
syncCloseTcpThreadPool(tsArbTcpPool);
sInfo("TAOS arbitrator is shut down");
closelog();
return 0;
}
......@@ -174,16 +174,16 @@ static int32_t arbProcessPeerMsg(int64_t rid, void *buffer) {
return 0;
}
static void arbSignalHandler(int32_t signum) {
static void arbSignalHandler(int32_t signum, siginfo_t *sigInfo, void *context) {
struct sigaction act = {{0}};
#ifndef WINDOWS
act.sa_handler = SIG_IGN;
#endif
sigaction(SIGTERM, &act, NULL);
sigaction(SIGINT, &act, NULL);
#ifndef WINDOWS
sigaction(SIGHUP, &act, NULL);
#endif
sigaction(SIGINT, &act, NULL);
sInfo("shut down signal is %d", signum);
sInfo("shut down signal is %d, sender PID:%d", signum, sigInfo->si_pid);
// inform main thread to exit
tsem_post(&tsArbSem);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册