Merge lp:~sergei.glushchenko/percona-xtrabackup/2.2-xb-bug1395143 into lp:percona-xtrabackup/2.2

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 5056
Proposed branch: lp:~sergei.glushchenko/percona-xtrabackup/2.2-xb-bug1395143
Merge into: lp:percona-xtrabackup/2.2
Diff against target: 185 lines (+45/-1)
5 files modified
storage/innobase/xtrabackup/src/compact.cc (+2/-0)
storage/innobase/xtrabackup/src/ds_archive.c (+9/-0)
storage/innobase/xtrabackup/src/ds_xbstream.c (+11/-0)
storage/innobase/xtrabackup/src/xbcrypt_read.c (+2/-0)
storage/innobase/xtrabackup/src/xtrabackup.cc (+21/-1)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-xtrabackup/2.2-xb-bug1395143
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Sergei Glushchenko (community) Needs Fixing
Review via email: mp+243951@code.launchpad.net

Description of the change

    Following leaks fixed:

    - Memory allocated for pmap_cur in page_map_file_open was never
      released.
    - Memory allocated for ivbuffer in xb_crypt_read_open was never
      released.
    - Doublewrite buffer allocated in open_or_create_data_files was
      not released after xtrabackup applied incremental deltas.
    - dst_log_file was never released.
    - fil_system was never released.
    - Memory allocated in innodb_init_param was not allocated after
      apply-log stage.

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

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

Sergei,

I wonder if we really need to set buf_dblwr to NULL after calling buf_dblwr_free() and fil_system to NULL after calling fil_close(). That seems to be redundant?

review: Needs Information
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

fil_init expect fil_system to be NULL, we will get assertion failure if we will try to init innodb once again.
As for buf_dblwr, I did it just for the case. If some part of code still trying to use it after I released it, I will get clear SEGFAULT crash instead of undefined behavior of trying to access memory which has been released.

Revision history for this message
Alexey Kopytov (akopytov) wrote :

My point was that buf_dblwr_free() sets buf_dblwr to NULL, and fil_close() sets fil_system to NULL, so there's no need to set them to NULL explicitly after calling the corresponding functions, i.e. that code is redundant.

review: Needs Fixing
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :
Revision history for this message
Alexey Kopytov (akopytov) wrote :

Sergei,

Any idea what happens with galera-specific tests with ASAN enabled?

review: Needs Information
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

I am not an expert in Galera and SST, but PXC fails with following message:

2014-12-17 07:22:47 17194 [Warning] Buffered warning: Changed limits: table_cache: 431 (requested 2000)

2014-12-17 07:22:47 17194 [Note] WSREP: Read nil XID from storage engines, skipping position init
2014-12-17 07:22:47 17194 [Note] WSREP: wsrep_load(): loading provider library '/mnt/workspace/percona-xtrabackup-2.2-param/BUILD_TYPE/release/Host/asan/xtrabackuptarget/galera56/storage/innobase/xtrabackup/test/server/lib/libgalera_smm.so'
2014-12-17 07:22:47 17194 [ERROR] WSREP: wsrep_load(): dlopen(): libssl.so.10: cannot open shared object file: No such file or directory
2014-12-17 07:22:47 17194 [ERROR] WSREP: wsrep_load(/mnt/workspace/percona-xtrabackup-2.2-param/BUILD_TYPE/release/Host/asan/xtrabackuptarget/galera56/storage/innobase/xtrabackup/test/server/lib/libgalera_smm.so) failed: Invalid argument (22). Reverting to no provider.
2014-12-17 07:22:47 17194 [Note] WSREP: Read nil XID from storage engines, skipping position init
2014-12-17 07:22:47 17194 [Note] WSREP: wsrep_load(): loading provider library 'none'
2014-12-17 07:22:47 17194 [ERROR] Aborting

2014-12-17 07:22:47 17194 [Note] WSREP: Service disconnected.
2014-12-17 07:22:48 17194 [Note] WSREP: Some threads may fail to exit.
2014-12-17 07:22:48 17194 [Note] Binlog end
2014-12-17 07:22:48 17194 [Note] /mnt/workspace/percona-xtrabackup-2.2-param/BUILD_TYPE/release/Host/asan/xtrabackuptarget/galera56/storage/innobase/xtrabackup/test/server/bin//mysqld: Shutdown complete

2014-12-17 07:22:49: run.sh: ----------------

Looks like it did not try to run SST script.

Revision history for this message
Alexey Kopytov (akopytov) wrote :

Here's the reason:

2014-12-17 07:22:47 17194 [ERROR] WSREP: wsrep_load(): dlopen(): libssl.so.10: cannot open shared object file: No such file or directory
2014-12-17 07:22:47 17194 [ERROR] WSREP: wsrep_load(/mnt/workspace/percona-xtrabackup-2.2-param/BUILD_TYPE/release/Host/asan/xtrabackuptarget/galera56/storage/innobase/xtrabackup/test/server/lib/libgalera_smm.so) failed: Invalid argument (22). Reverting to no provider.

Which looks like another SSL-related build/packaging issue. Which is weird, but most likely has nothing to do with this fix.

review: Approve
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

Indeed, ubuntu 14.10 doesn't have libssl.so.10. It doesn't have libssl.so.6 also, which is required by PS tarball. How was it worked around?

I found race condition in xbstream_open which is not triggered in this Jenkins build, but is triggered in 2.3 build.

In code below
 if (stream_ctxt->dest_file == NULL) {
  stream_ctxt->dest_file = ds_open(dest_ctxt, path, mystat);
  if (stream_ctxt->dest_file == NULL) {
   return NULL;
  }
 }

stream_ctxt->dest_file could be opened twice in case of --parallel option.

review: Needs Fixing
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

I fixed the race condition

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

There is a crash on compact.sh with following message (debug):

This could be because you hit a bug or data is corrupted.
This error can also be caused by malfunctioning hardware.
We will try our best to scrape up some info that will hopefully help
diagnose the problem, but since we have already crashed,
something is definitely wrong and this may fail.

Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x10000
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup(my_print_stacktrace+0x32) [0x874ec5b]
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup(handle_fatal_signal+0x282) [0x86107a2]
[0xb76e8500]
/lib/libc.so.6(abort+0x17a) [0xb734c14a]
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup() [0x847102e]
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup() [0x8475296]
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup() [0x84760ec]
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup() [0x847a5db]
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup(row_merge_build_indexes(trx_t*, dict_table_t*, dict_table_t*, bool, dict_index_t**, unsigned long const*, unsigned long, TABLE*, dtuple_t const*, unsigned long const*, unsigned long, ib_sequence_t&)+0x38b) [0x847f015]
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup() [0x8223610]
/home/jenkins/workspace/percona-xtrabackup-2.3-param/BUILD_TYPE/debug/Host/centos6-32/xtrabackuptarget/galera55/storage/innobase/xtrabackup/src/xtrabackup() [0x8223988]
/lib/libpthread.so.0(+0x6b39) [0xb76c5b39]
/lib/libc.so.6(clone+0x5e) [0xb7402c1e]

I cannot reproduce it locally, but it doesn't look related to the fixes.
My best guess is that this is somewhere in row_merge_read_clustered_index or in row_merge_insert_index_tuples, rec pointer is NULL. To me it needs further investigation, but doesn't look related to the dix.

Revision history for this message
Alexey Kopytov (akopytov) wrote :

Sergei,

Doesn't ds_archive have the same problem as ds_xbstream?

review: Needs Fixing
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

Agree, ds_archive is similar in this respect. I made same fix for it.

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

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 'storage/innobase/xtrabackup/src/compact.cc'
2--- storage/innobase/xtrabackup/src/compact.cc 2014-09-21 18:38:17 +0000
3+++ storage/innobase/xtrabackup/src/compact.cc 2014-12-22 11:29:31 +0000
4@@ -419,6 +419,8 @@
5
6 rc = my_close(pmap_cur->fd, MY_WME);
7 xb_a(rc == 0);
8+
9+ my_free(pmap_cur);
10 }
11
12 /****************************************************************************
13
14=== modified file 'storage/innobase/xtrabackup/src/ds_archive.c'
15--- storage/innobase/xtrabackup/src/ds_archive.c 2013-11-26 10:44:44 +0000
16+++ storage/innobase/xtrabackup/src/ds_archive.c 2014-12-22 11:29:31 +0000
17@@ -27,6 +27,7 @@
18 typedef struct {
19 struct archive *archive;
20 ds_file_t *dest_file;
21+ pthread_mutex_t mutex;
22 } ds_archive_ctxt_t;
23
24 typedef struct {
25@@ -99,6 +100,10 @@
26 MYF(MY_FAE));
27 archive_ctxt = (ds_archive_ctxt_t *)(ctxt + 1);
28
29+ if (pthread_mutex_init(&archive_ctxt->mutex, NULL)) {
30+ msg("archive_init: pthread_mutex_init() failed.\n");
31+ goto err;
32+ }
33
34 a = archive_write_new();
35 if (a == NULL) {
36@@ -153,12 +158,14 @@
37
38 archive_ctxt = (ds_archive_ctxt_t *) ctxt->ptr;
39
40+ pthread_mutex_lock(&archive_ctxt->mutex);
41 if (archive_ctxt->dest_file == NULL) {
42 archive_ctxt->dest_file = ds_open(dest_ctxt, path, mystat);
43 if (archive_ctxt->dest_file == NULL) {
44 return NULL;
45 }
46 }
47+ pthread_mutex_unlock(&archive_ctxt->mutex);
48
49 file = (ds_file_t *) my_malloc(sizeof(ds_file_t) +
50 sizeof(ds_archive_file_t),
51@@ -262,5 +269,7 @@
52 archive_ctxt->dest_file = NULL;
53 }
54
55+ pthread_mutex_destroy(&archive_ctxt->mutex);
56+
57 my_free(ctxt);
58 }
59
60=== modified file 'storage/innobase/xtrabackup/src/ds_xbstream.c'
61--- storage/innobase/xtrabackup/src/ds_xbstream.c 2013-11-26 10:44:44 +0000
62+++ storage/innobase/xtrabackup/src/ds_xbstream.c 2014-12-22 11:29:31 +0000
63@@ -27,6 +27,7 @@
64 typedef struct {
65 xb_wstream_t *xbstream;
66 ds_file_t *dest_file;
67+ pthread_mutex_t mutex;
68 } ds_stream_ctxt_t;
69
70 typedef struct {
71@@ -82,6 +83,11 @@
72 MYF(MY_FAE));
73 stream_ctxt = (ds_stream_ctxt_t *)(ctxt + 1);
74
75+ if (pthread_mutex_init(&stream_ctxt->mutex, NULL)) {
76+ msg("xbstream_init: pthread_mutex_init() failed.\n");
77+ goto err;
78+ }
79+
80 xbstream = xb_stream_write_new();
81 if (xbstream == NULL) {
82 msg("xb_stream_write_new() failed.\n");
83@@ -116,12 +122,14 @@
84
85 stream_ctxt = (ds_stream_ctxt_t *) ctxt->ptr;
86
87+ pthread_mutex_lock(&stream_ctxt->mutex);
88 if (stream_ctxt->dest_file == NULL) {
89 stream_ctxt->dest_file = ds_open(dest_ctxt, path, mystat);
90 if (stream_ctxt->dest_file == NULL) {
91 return NULL;
92 }
93 }
94+ pthread_mutex_unlock(&stream_ctxt->mutex);
95
96 file = (ds_file_t *) my_malloc(sizeof(ds_file_t) +
97 sizeof(ds_stream_file_t),
98@@ -208,5 +216,8 @@
99 ds_close(stream_ctxt->dest_file);
100 stream_ctxt->dest_file = NULL;
101 }
102+
103+ pthread_mutex_destroy(&stream_ctxt->mutex);
104+
105 my_free(ctxt);
106 }
107
108=== modified file 'storage/innobase/xtrabackup/src/xbcrypt_read.c'
109--- storage/innobase/xtrabackup/src/xbcrypt_read.c 2014-02-28 14:37:59 +0000
110+++ storage/innobase/xtrabackup/src/xbcrypt_read.c 2014-12-22 11:29:31 +0000
111@@ -249,6 +249,8 @@
112 {
113 if (crypt->buffer)
114 my_free(crypt->buffer);
115+ if (crypt->ivbuffer)
116+ my_free(crypt->ivbuffer);
117 my_free(crypt);
118
119 return 0;
120
121=== modified file 'storage/innobase/xtrabackup/src/xtrabackup.cc'
122--- storage/innobase/xtrabackup/src/xtrabackup.cc 2014-10-17 13:02:28 +0000
123+++ storage/innobase/xtrabackup/src/xtrabackup.cc 2014-12-22 11:29:31 +0000
124@@ -65,6 +65,7 @@
125 #include <row0mysql.h>
126 #include <row0quiesce.h>
127 #include <srv0start.h>
128+#include <buf0dblwr.h>
129
130 #include <sstream>
131
132@@ -2707,7 +2708,11 @@
133 os_aio_free();
134
135 fil_close_all_files();
136- fil_system = NULL;
137+
138+ /* Free the double write data structures. */
139+ if (buf_dblwr) {
140+ buf_dblwr_free();
141+ }
142
143 /* Reset srv_file_io_threads to its default value to avoid confusing
144 warning on --prepare in innobase_start_or_create_for_mysql()*/
145@@ -3675,6 +3680,7 @@
146 msg("\n");
147
148 os_event_free(log_copying_stop);
149+ ds_close(dst_log_file);
150
151 /* Signal innobackupex that log copying has stopped and it may now
152 unlock tables, so we can possibly stream xtrabackup_logfile later
153@@ -5578,6 +5584,15 @@
154 return xtrabackup_arch_first_file_lsn != 0;
155 }
156
157+static
158+void
159+innodb_free_param()
160+{
161+ srv_free_paths_and_sizes();
162+ free(internal_innobase_data_file_path);
163+ free_tmpdir(&mysql_tmpdir_list);
164+}
165+
166 static void
167 xtrabackup_prepare_func(void)
168 {
169@@ -5712,11 +5727,16 @@
170 }
171 sync_close();
172 sync_initialized = FALSE;
173+ if (fil_system) {
174+ fil_close();
175+ }
176 os_sync_free();
177 mem_close();
178 os_sync_mutex = NULL;
179 ut_free_all_mem();
180
181+ innodb_free_param();
182+
183 /* Reset the configuration as it might have been changed by
184 xb_data_files_init(). */
185 if(innodb_init_param()) {

Subscribers

People subscribed via source and target branches