OmniSciDB  4201147b46
 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 116 of file HeavyDB.cpp.

References g_running, g_saw_signal, and register_signal_handler().

Referenced by register_signal_handlers().

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

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

Referenced by heavydb_signal_handler(), and register_signal_handlers().

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

+ Here is the caller graph for this function:

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

Definition at line 165 of file HeavyDB.cpp.

References heavydb_signal_handler(), and register_signal_handler().

Referenced by startHeavyDBServer().

165  {
167 #ifndef _WIN32
170 #endif
174 #ifndef _WIN32
175  // Thrift secure socket can cause problems with SIGPIPE
176  register_signal_handler(SIGPIPE, SIG_IGN);
177 #endif
178 }
void register_signal_handler(int signum, void(*handler)(int))
Definition: HeavyDB.cpp:95
void heavydb_signal_handler(int signum)
Definition: HeavyDB.cpp:116

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

Referenced by startHeavyDBServer().

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

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

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

Definition at line 85 of file HeavyDB.cpp.

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

Definition at line 87 of file HeavyDB.cpp.

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

Definition at line 89 of file HeavyDB.cpp.