OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
anonymous_namespace{HeavyDB.cpp} Namespace Reference

Functions

void register_signal_handler (int signum, void(*handler)(int))
 
void heavydb_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_http_binary_server
 
std::shared_ptr< TThreadedServer > g_thrift_tcp_server
 
std::shared_ptr< DBHandlerg_warmup_handler
 
std::shared_ptr< DBHandlerg_db_handler
 

Function Documentation

void anonymous_namespace{HeavyDB.cpp}::heavydb_signal_handler ( int  signum)

Definition at line 121 of file HeavyDB.cpp.

References g_running, g_saw_signal, and register_signal_handler().

Referenced by register_signal_handlers().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 100 of file HeavyDB.cpp.

Referenced by heavydb_signal_handler(), and register_signal_handlers().

100  {
101 #ifdef _WIN32
102  signal(signum, handler);
103 #else
104  struct sigaction act;
105  memset(&act, 0, sizeof(act));
106  if (handler != SIG_DFL && handler != SIG_IGN) {
107  // block all signal deliveries while inside the signal handler
108  sigfillset(&act.sa_mask);
109  }
110  act.sa_handler = handler;
111  sigaction(signum, &act, NULL);
112 #endif
113 }

+ Here is the caller graph for this function:

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

Definition at line 170 of file HeavyDB.cpp.

References heavydb_signal_handler(), and register_signal_handler().

Referenced by startHeavyDBServer().

170  {
172 #ifndef _WIN32
175 #endif
179 #ifndef _WIN32
180  // Thrift secure socket can cause problems with SIGPIPE
181  register_signal_handler(SIGPIPE, SIG_IGN);
182 #endif
183 }
void register_signal_handler(int signum, void(*handler)(int))
Definition: HeavyDB.cpp:100
void heavydb_signal_handler(int signum)
Definition: HeavyDB.cpp:121

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

std::shared_ptr<DBHandler> anonymous_namespace{HeavyDB.cpp}::g_db_handler

Definition at line 98 of file HeavyDB.cpp.

Referenced by startHeavyDBServer().

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

Definition at line 88 of file HeavyDB.cpp.

Referenced by heartbeat(), heavydb_signal_handler(), and startHeavyDBServer().

std::shared_ptr<TThreadedServer> anonymous_namespace{HeavyDB.cpp}::g_thrift_http_binary_server

Definition at line 91 of file HeavyDB.cpp.

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

Definition at line 90 of file HeavyDB.cpp.

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

Definition at line 92 of file HeavyDB.cpp.

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

Definition at line 94 of file HeavyDB.cpp.