Merge lp:~akopytov/percona-xtrabackup/bug766305 into lp:percona-xtrabackup/2.2

Proposed by Alexey Kopytov
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 5022
Proposed branch: lp:~akopytov/percona-xtrabackup/bug766305
Merge into: lp:percona-xtrabackup/2.2
Diff against target: 250 lines (+65/-94)
6 files modified
configure.cmake (+2/-1)
sql/signal_handler.cc (+5/-84)
storage/innobase/include/univ.i (+3/-9)
storage/innobase/xtrabackup/src/CMakeLists.txt (+2/-0)
storage/innobase/xtrabackup/src/xtrabackup.cc (+17/-0)
storage/innobase/xtrabackup/test/t/bug766305.sh (+36/-0)
To merge this branch: bzr merge lp:~akopytov/percona-xtrabackup/bug766305
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+235387@code.launchpad.net

Description of the change

    Bug #766305: Use MySQL Code to get stack trace

    Implemented the following to reuse MySQL stacktrace dump code:

    - set up handle_fatal_signal() as a signal handler for certain signals
    in xtrabackup.cc::main().

    - handle_fatal_signal() has been modified to avoid
    dumping some server-specific information.

    - the hidden visibility attribute in UNIV_INTERN symbols does not make
    any sense for XtraBackup, but prevents fully resolved stacktraces on
    Linux, so it has been removed.

    - backtrace_symbols() requires passing -export-dynamic to the linker on
    Linux, so the corresponding property has been added for the xtrabackup
    CMake target.

    - fixed cxxabi.h detection in configure.cmake to make symbol demangling
    possible.

http://jenkins.percona.com/view/PXB%202.2/job/percona-xtrabackup-2.2-param/212/

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.cmake'
2--- configure.cmake 2014-09-15 08:52:36 +0000
3+++ configure.cmake 2014-09-20 19:02:31 +0000
4@@ -264,6 +264,7 @@
5 # Tests for header files
6 #
7 INCLUDE (CheckIncludeFiles)
8+INCLUDE (CheckIncludeFileCXX)
9
10 CHECK_INCLUDE_FILES ("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
11 CHECK_INCLUDE_FILES (sys/types.h HAVE_SYS_TYPES_H)
12@@ -271,7 +272,7 @@
13 CHECK_INCLUDE_FILES (aio.h HAVE_AIO_H)
14 CHECK_INCLUDE_FILES (arpa/inet.h HAVE_ARPA_INET_H)
15 CHECK_INCLUDE_FILES (crypt.h HAVE_CRYPT_H)
16-CHECK_INCLUDE_FILES (cxxabi.h HAVE_CXXABI_H)
17+CHECK_INCLUDE_FILE_CXX (cxxabi.h HAVE_CXXABI_H)
18 CHECK_INCLUDE_FILES (dirent.h HAVE_DIRENT_H)
19 CHECK_INCLUDE_FILES (dlfcn.h HAVE_DLFCN_H)
20 CHECK_INCLUDE_FILES (execinfo.h HAVE_EXECINFO_H)
21
22=== modified file 'sql/signal_handler.cc'
23--- sql/signal_handler.cc 2014-09-15 08:52:36 +0000
24+++ sql/signal_handler.cc 2014-09-20 19:02:31 +0000
25@@ -86,65 +86,18 @@
26 my_safe_itoa(10, mins, &mins_buf[2]);
27 my_safe_itoa(10, secs, &secs_buf[2]);
28
29- my_safe_printf_stderr("%s:%s:%s UTC - mysqld got " SIGNAL_FMT " ;\n",
30+ my_safe_printf_stderr("%s:%s:%s UTC - xtrabackup got " SIGNAL_FMT " ;\n",
31 hrs_buf, mins_buf, secs_buf, sig);
32
33 my_safe_printf_stderr("%s",
34- "This could be because you hit a bug. It is also possible that this binary\n"
35- "or one of the libraries it was linked against is corrupt, improperly built,\n"
36- "or misconfigured. This error can also be caused by malfunctioning hardware.\n");
37+ "This could be because you hit a bug or data is corrupted.\n"
38+ "This error can also be caused by malfunctioning hardware.\n");
39
40 my_safe_printf_stderr("%s",
41 "We will try our best to scrape up some info that will hopefully help\n"
42 "diagnose the problem, but since we have already crashed, \n"
43 "something is definitely wrong and this may fail.\n\n");
44
45- my_safe_printf_stderr("key_buffer_size=%lu\n",
46- (ulong) dflt_key_cache->key_cache_mem_size);
47-
48- my_safe_printf_stderr("read_buffer_size=%ld\n",
49- (long) global_system_variables.read_buff_size);
50-
51- my_safe_printf_stderr("max_used_connections=%lu\n",
52- (ulong) max_used_connections);
53-
54- my_safe_printf_stderr("max_threads=%u\n",
55- (uint) thread_scheduler->max_threads);
56-
57- my_safe_printf_stderr("thread_count=%u\n", get_thread_count());
58-
59- my_safe_printf_stderr("connection_count=%u\n", (uint) connection_count);
60-
61- my_safe_printf_stderr("It is possible that mysqld could use up to \n"
62- "key_buffer_size + "
63- "(read_buffer_size + sort_buffer_size)*max_threads = "
64- "%lu K bytes of memory\n",
65- ((ulong) dflt_key_cache->key_cache_mem_size +
66- (global_system_variables.read_buff_size +
67- global_system_variables.sortbuff_size) *
68- thread_scheduler->max_threads +
69- max_connections * sizeof(THD)) / 1024);
70-
71- my_safe_printf_stderr("%s",
72- "Hope that's ok; if not, decrease some variables in the equation.\n\n");
73-
74-#if defined(HAVE_LINUXTHREADS)
75-#define UNSAFE_DEFAULT_LINUX_THREADS 200
76- if (sizeof(char*) == 4 && thread_count > UNSAFE_DEFAULT_LINUX_THREADS)
77- {
78- my_safe_printf_stderr(
79- "You seem to be running 32-bit Linux and have "
80- "%d concurrent connections.\n"
81- "If you have not changed STACK_SIZE in LinuxThreads "
82- "and built the binary \n"
83- "yourself, LinuxThreads is quite likely to steal "
84- "a part of the global heap for\n"
85- "the thread stack. Please read "
86- "http://dev.mysql.com/doc/mysql/en/linux-installation.html\n\n"
87- thread_count);
88- }
89-#endif /* HAVE_LINUXTHREADS */
90-
91 #ifdef HAVE_STACKTRACE
92 THD *thd=current_thd;
93
94@@ -159,40 +112,8 @@
95 my_print_stacktrace(thd ? (uchar*) thd->thread_stack : NULL,
96 my_thread_stack_size);
97 }
98- if (thd)
99- {
100- const char *kreason= "UNKNOWN";
101- switch (thd->killed) {
102- case THD::NOT_KILLED:
103- kreason= "NOT_KILLED";
104- break;
105- case THD::KILL_BAD_DATA:
106- kreason= "KILL_BAD_DATA";
107- break;
108- case THD::KILL_CONNECTION:
109- kreason= "KILL_CONNECTION";
110- break;
111- case THD::KILL_QUERY:
112- kreason= "KILL_QUERY";
113- break;
114- case THD::KILLED_NO_VALUE:
115- kreason= "KILLED_NO_VALUE";
116- break;
117- }
118- my_safe_printf_stderr("%s", "\n"
119- "Trying to get some variables.\n"
120- "Some pointers may be invalid and cause the dump to abort.\n");
121-
122- my_safe_printf_stderr("Query (%p): ", thd->query());
123- my_safe_print_str(thd->query(), MY_MIN(1024U, thd->query_length()));
124- my_safe_printf_stderr("Connection ID (thread ID): %lu\n",
125- (ulong) thd->thread_id);
126- my_safe_printf_stderr("Status: %s\n\n", kreason);
127- }
128- my_safe_printf_stderr("%s",
129- "The manual page at "
130- "http://dev.mysql.com/doc/mysql/en/crashing.html contains\n"
131- "information that should help you find out what is causing the crash.\n");
132+ my_safe_printf_stderr("%s", "\n"
133+ "Please report a bug at https://bugs.launchpad.net/percona-xtrabackup\n");
134
135 #endif /* HAVE_STACKTRACE */
136
137
138=== modified file 'storage/innobase/include/univ.i'
139--- storage/innobase/include/univ.i 2014-09-15 08:52:36 +0000
140+++ storage/innobase/include/univ.i 2014-09-20 19:02:31 +0000
141@@ -247,15 +247,9 @@
142 at a buffer page write: it should be tested with this
143 option off; also some ibuf tests are suppressed */
144
145-/* Linkage specifier for non-static InnoDB symbols (variables and functions)
146-that are only referenced from within InnoDB, not from MySQL. We disable the
147-GCC visibility directive on all Sun operating systems because there is no
148-easy way to get it to work. See http://bugs.mysql.com/bug.php?id=52263. */
149-#if defined(__GNUC__) && (__GNUC__ >= 4) && !defined(sun) || defined(__INTEL_COMPILER)
150-# define UNIV_INTERN __attribute__((visibility ("hidden")))
151-#else
152-# define UNIV_INTERN
153-#endif
154+/* For XtraBackup, we disable the GCC visibility directive for InnoDB internal
155+symbols as that allows XtraBackup print fully resolved stacktraces on Linux. */
156+#define UNIV_INTERN
157 #if defined(INNODB_COMPILER_HINTS) \
158 && defined __GNUC__ \
159 && (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 3)
160
161=== modified file 'storage/innobase/xtrabackup/src/CMakeLists.txt'
162--- storage/innobase/xtrabackup/src/CMakeLists.txt 2014-09-04 16:53:33 +0000
163+++ storage/innobase/xtrabackup/src/CMakeLists.txt 2014-09-20 19:02:31 +0000
164@@ -58,6 +58,8 @@
165 xbstream_write.c
166 )
167
168+SET_TARGET_PROPERTIES(xtrabackup PROPERTIES ENABLE_EXPORTS TRUE)
169+
170 TARGET_LINK_LIBRARIES(xtrabackup
171 mysqlserver
172 ${GCRYPT_LIBS}
173
174=== modified file 'storage/innobase/xtrabackup/src/xtrabackup.cc'
175--- storage/innobase/xtrabackup/src/xtrabackup.cc 2014-09-12 10:09:33 +0000
176+++ storage/innobase/xtrabackup/src/xtrabackup.cc 2014-09-20 19:02:31 +0000
177@@ -309,6 +309,8 @@
178 ds_ctxt_t *ds_data = NULL;
179 ds_ctxt_t *ds_meta = NULL;
180
181+extern "C" sig_handler handle_fatal_signal(int sig);
182+
183 /* Simple datasink creation tracking...add datasinks in the reverse order you
184 want them destroyed. */
185 #define XTRABACKUP_MAX_DATASINKS 10
186@@ -5979,8 +5981,23 @@
187
188 int main(int argc, char **argv)
189 {
190+ struct sigaction sa;
191 int ho_error;
192
193+ /* Print a stacktrace on some signals */
194+ sa.sa_flags = SA_RESETHAND | SA_NODEFER;
195+ sigemptyset(&sa.sa_mask);
196+ sigprocmask(SIG_SETMASK,&sa.sa_mask,NULL);
197+#ifdef HAVE_STACKTRACE
198+ my_init_stacktrace();
199+#endif
200+ sa.sa_handler = handle_fatal_signal;
201+ sigaction(SIGSEGV, &sa, NULL);
202+ sigaction(SIGABRT, &sa, NULL);
203+ sigaction(SIGBUS, &sa, NULL);
204+ sigaction(SIGILL, &sa, NULL);
205+ sigaction(SIGFPE, &sa, NULL);
206+
207 #ifdef __linux__
208 /* Ensure xtrabackup process is killed when the parent one
209 (innobackupex) is terminated with an unhandled signal */
210
211=== added file 'storage/innobase/xtrabackup/test/t/bug766305.sh'
212--- storage/innobase/xtrabackup/test/t/bug766305.sh 1970-01-01 00:00:00 +0000
213+++ storage/innobase/xtrabackup/test/t/bug766305.sh 2014-09-20 19:02:31 +0000
214@@ -0,0 +1,36 @@
215+########################################################################
216+# Bug #766305: Use MySQL Code to get stack trace
217+########################################################################
218+
219+start_server --innodb_file_per_table
220+
221+if [ ${ASAN_OPTIONS:-undefined} = "undefined" ]
222+then
223+ skip_test "Incompatible with AddressSanitizer"
224+fi
225+
226+mkdir $topdir/backup
227+
228+xtrabackup --backup --target-dir=$topdir/backup --debug-sync="data_copy_thread_func" &
229+
230+job_pid=$!
231+pid_file=$topdir/backup/xtrabackup_debug_sync
232+
233+# Wait for xtrabackup to suspend
234+i=0
235+while [ ! -r "$pid_file" ]
236+do
237+ sleep 1
238+ i=$((i+1))
239+ echo "Waited $i seconds for $pid_file to be created"
240+done
241+
242+xb_pid=`cat $pid_file`
243+
244+kill -SIGSEGV $xb_pid
245+kill -SIGCONT $xb_pid
246+
247+run_cmd_expect_failure wait $job_pid
248+
249+grep -q "handle_fatal_signal" $OUTFILE || \
250+ die "Could not find a resolved stacktrace in the log"

Subscribers

People subscribed via source and target branches

to all changes: