OmniSciDB  471d68cefb
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{MapDServer.cpp} Namespace Reference

Functions

void register_signal_handler (int signum, void(*handler)(int))
 
void omnisci_signal_handler (int signum)
 
void register_signal_handlers ()
 

Variables

std::atomic< int > g_saw_signal {-1}
 
std::shared_ptr< TThreadedServer > g_thrift_http_server
 
std::shared_ptr< TThreadedServer > g_thrift_tcp_server
 
std::shared_ptr< DBHandlerg_warmup_handler
 
std::shared_ptr< DBHandlerg_mapd_handler
 

Function Documentation

void anonymous_namespace{MapDServer.cpp}::omnisci_signal_handler ( int  signum)

Definition at line 110 of file MapDServer.cpp.

References g_running, g_saw_signal, and register_signal_handler().

Referenced by register_signal_handlers().

110  {
111  // Record the signal number for logging during shutdown.
112  // Only records the first signal if called more than once.
113  int expected_signal{-1};
114  if (!g_saw_signal.compare_exchange_strong(expected_signal, signum)) {
115  return; // this wasn't the first signal
116  }
117 
118  // This point should never be reached more than once.
119 
120  // Tell heartbeat() to shutdown by unsetting the 'g_running' flag.
121  // If 'g_running' is already false, this has no effect and the
122  // shutdown is already in progress.
123  g_running = false;
124 
125  // Handle core dumps specially by pausing inside this signal handler
126  // because on some systems, some signals will execute their default
127  // action immediately when and if the signal handler returns.
128  // We would like to do some emergency cleanup before core dump.
129  if (signum == SIGABRT || signum == SIGSEGV || signum == SIGFPE
130 #ifndef _WIN32
131  || signum == SIGQUIT
132 #endif
133  ) {
134  // Wait briefly to give heartbeat() a chance to flush the logs and
135  // do any other emergency shutdown tasks.
136  std::this_thread::sleep_for(std::chrono::seconds(2));
137 
138  // Explicitly trigger whatever default action this signal would
139  // have done, such as terminate the process or dump core.
140  // Signals are currently blocked so this new signal will be queued
141  // until this signal handler returns.
142  register_signal_handler(signum, SIG_DFL);
143 #ifdef _WIN32
144  raise(signum);
145 #else
146  kill(getpid(), signum);
147 #endif
148  std::this_thread::sleep_for(std::chrono::seconds(5));
149 
150 #ifndef __APPLE__
151  // as a last resort, abort
152  // primary used in Docker environments, where we can end up with PID 1 and fail to
153  // catch unix signals
154  quick_exit(signum);
155 #endif
156  }
157 }
void register_signal_handler(int signum, void(*handler)(int))
Definition: MapDServer.cpp:89
std::atomic< bool > g_running
Definition: MapDServer.cpp:74

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void anonymous_namespace{MapDServer.cpp}::register_signal_handler ( int  signum,
void(*)(int)  handler 
)

Definition at line 89 of file MapDServer.cpp.

Referenced by omnisci_signal_handler(), and register_signal_handlers().

89  {
90 #ifdef _WIN32
91  signal(signum, handler);
92 #else
93  struct sigaction act;
94  memset(&act, 0, sizeof(act));
95  if (handler != SIG_DFL && handler != SIG_IGN) {
96  // block all signal deliveries while inside the signal handler
97  sigfillset(&act.sa_mask);
98  }
99  act.sa_handler = handler;
100  sigaction(signum, &act, NULL);
101 #endif
102 }

+ Here is the caller graph for this function:

void anonymous_namespace{MapDServer.cpp}::register_signal_handlers ( )

Definition at line 159 of file MapDServer.cpp.

References omnisci_signal_handler(), and register_signal_handler().

Referenced by startMapdServer().

159  {
161 #ifndef _WIN32
164 #endif
168 #ifndef _WIN32
169  // Thrift secure socket can cause problems with SIGPIPE
170  register_signal_handler(SIGPIPE, SIG_IGN);
171 #endif
172 }
void register_signal_handler(int signum, void(*handler)(int))
Definition: MapDServer.cpp:89

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

std::shared_ptr<DBHandler> anonymous_namespace{MapDServer.cpp}::g_mapd_handler

Definition at line 87 of file MapDServer.cpp.

Referenced by startMapdServer().

std::atomic<int> anonymous_namespace{MapDServer.cpp}::g_saw_signal {-1}

Definition at line 78 of file MapDServer.cpp.

Referenced by heartbeat(), omnisci_signal_handler(), and startMapdServer().

std::shared_ptr<TThreadedServer> anonymous_namespace{MapDServer.cpp}::g_thrift_http_server

Definition at line 80 of file MapDServer.cpp.

std::shared_ptr<TThreadedServer> anonymous_namespace{MapDServer.cpp}::g_thrift_tcp_server

Definition at line 81 of file MapDServer.cpp.

std::shared_ptr<DBHandler> anonymous_namespace{MapDServer.cpp}::g_warmup_handler

Definition at line 83 of file MapDServer.cpp.