OmniSciDB  a5dc49c757
 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 126 of file HeavyDB.cpp.

References g_running, g_saw_signal, and register_signal_handler().

Referenced by register_signal_handlers().

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

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

Referenced by heavydb_signal_handler(), and register_signal_handlers().

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

+ Here is the caller graph for this function:

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

Definition at line 175 of file HeavyDB.cpp.

References heavydb_signal_handler(), and register_signal_handler().

Referenced by startHeavyDBServer().

175  {
177 #ifndef _WIN32
180 #endif
184 #ifndef _WIN32
185  // Thrift secure socket can cause problems with SIGPIPE
186  register_signal_handler(SIGPIPE, SIG_IGN);
187 #endif
188 }
void register_signal_handler(int signum, void(*handler)(int))
Definition: HeavyDB.cpp:105
void heavydb_signal_handler(int signum)
Definition: HeavyDB.cpp:126

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

Referenced by startHeavyDBServer().

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

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

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

Definition at line 95 of file HeavyDB.cpp.

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

Definition at line 97 of file HeavyDB.cpp.

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

Definition at line 99 of file HeavyDB.cpp.