OmniSciDB  a987f07e93
 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 117 of file HeavyDB.cpp.

References g_running, g_saw_signal, and register_signal_handler().

Referenced by register_signal_handlers().

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

+ 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 96 of file HeavyDB.cpp.

Referenced by heavydb_signal_handler(), and register_signal_handlers().

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

+ Here is the caller graph for this function:

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

Definition at line 166 of file HeavyDB.cpp.

References heavydb_signal_handler(), and register_signal_handler().

Referenced by startHeavyDBServer().

166  {
168 #ifndef _WIN32
171 #endif
175 #ifndef _WIN32
176  // Thrift secure socket can cause problems with SIGPIPE
177  register_signal_handler(SIGPIPE, SIG_IGN);
178 #endif
179 }
void register_signal_handler(int signum, void(*handler)(int))
Definition: HeavyDB.cpp:96
void heavydb_signal_handler(int signum)
Definition: HeavyDB.cpp:117

+ 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 94 of file HeavyDB.cpp.

Referenced by startHeavyDBServer().

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

Definition at line 84 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 87 of file HeavyDB.cpp.

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

Definition at line 86 of file HeavyDB.cpp.

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

Definition at line 88 of file HeavyDB.cpp.

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

Definition at line 90 of file HeavyDB.cpp.