Merge lp:~akopytov/percona-xtrabackup/bug1130627-2.1 into lp:percona-xtrabackup/2.1

Proposed by Alexey Kopytov
Status: Merged
Approved by: Sergei Glushchenko
Approved revision: no longer in the source branch.
Merged at revision: 509
Proposed branch: lp:~akopytov/percona-xtrabackup/bug1130627-2.1
Merge into: lp:percona-xtrabackup/2.1
Diff against target: 320 lines (+174/-47)
3 files modified
innobackupex (+30/-11)
src/xtrabackup.cc (+70/-36)
test/t/bug1130627.sh (+74/-0)
To merge this branch: bzr merge lp:~akopytov/percona-xtrabackup/bug1130627-2.1
Reviewer Review Type Date Requested Status
Sergei Glushchenko (community) g2 Approve
Review via email: mp+152244@code.launchpad.net

This proposal supersedes a proposal from 2013-03-06.

Description of the change

    Bug #1130627: Can't backup individual partitions

    The bug is a regression introduced in 2.0.5 by the fix for bug
    #711166. The fix introduced partition suffix ('#P#...') trimming in
    tables names before checking them against regular expressions specified
    by the --include option in innobackupex or the --tables option in
    xtrabackup. Which made impossible partial backups of partitioned tables.

    Fixed in both innobackupex and xtrabackup by first checking the table
    name without the suffix trimmed, and then repeating the check with the
    suffix trimmed if the former check fails.

    This patch also fixes bug #1131084 "Unneccessary/debug print in
    xtrabackup output" and a few other minor issues introduced by the fix
    for bug #711166.

http://jenkins.percona.com/view/XtraBackup/job/percona-xtrabackup-2.1-param/199/

To post a comment you must log in.
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote : Posted in a previous version of this proposal

Same comments as for 2.0 version.

review: Needs Fixing (g2)
Revision history for this message
Alexey Kopytov (akopytov) wrote : Posted in a previous version of this proposal
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote : Posted in a previous version of this proposal

See comments re: testcase on 2.0 version of MP.

review: Needs Fixing (g2)
Revision history for this message
Alexey Kopytov (akopytov) wrote : Posted in a previous version of this proposal

No idea why LP thinks this has been merged. It hasn't. Let's see if resubmitting will fix it.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'innobackupex'
2--- innobackupex 2013-02-04 07:33:56 +0000
3+++ innobackupex 2013-03-07 17:52:22 +0000
4@@ -2037,13 +2037,18 @@
5 next unless check_if_required($database, $file);
6
7 if($option_include) {
8- my $table_name = get_table_name($file);
9- if (!("$database.$table_name" =~ /$option_include/)) {
10- print STDERR "$database.$file is skipped because it does not match $option_include.\n";
11- next;
12- }
13+ my $table = get_table_name($file);
14+ my $table_part = get_table_name_with_part_suffix($file);
15+
16+ if (!("$database.$table_part" =~ /$option_include/ ||
17+ "$database.$table" =~ /$option_include/)) {
18+
19+ if ($print_each_file) {
20+ print STDERR "$database.$file is skipped because it does not match '$option_include'.\n";
21+ }
22+ next;
23+ }
24 }
25-
26
27 if ($print_each_file) {
28 print STDERR "$prefix Backing up file '$source_dir/$database/$file'\n";
29@@ -2371,6 +2376,17 @@
30 # 1 table name
31 #
32 sub get_table_name {
33+ my $table;
34+
35+ $table = get_table_name_with_part_suffix($_[0]);
36+ # trim partition suffix
37+ $table = (split('#P#', $table))[0];
38+
39+ return $table;
40+}
41+
42+# Like get_table_name(), but keeps the partition suffix if present
43+sub get_table_name_with_part_suffix {
44 my $table_path = shift;
45 my $filename;
46 my $table;
47@@ -2379,8 +2395,6 @@
48 $filename = (reverse(split(/\//, $table_path)))[0];
49 # get name of the table by removing file suffix
50 $table = (split(/\./, $filename))[0];
51- # and partition suffix
52- $table = (split('#P#', $table))[0];
53
54 return $table;
55 }
56@@ -2398,14 +2412,16 @@
57 my $db_count = scalar keys %databases_list;
58 my $tbl_count = scalar keys %table_list;
59 my $table;
60+ my $table_part;
61
62 if ( $db_count == 0 && $tbl_count == 0 ) {
63 # No databases defined with --databases option, include all databases,
64 # and no tables defined with --tables-file option, include all tables.
65- return 1;
66+ return 1;
67 }
68 else {
69 if ( $table_path ) {
70+ $table_part = get_table_name_with_part_suffix($table_path);
71 $table = get_table_name($table_path);
72 }
73 }
74@@ -2416,7 +2432,9 @@
75 if (defined $table_path) {
76 my $db_hash = $databases_list{$db};
77 $db_count = keys %$db_hash;
78- if ($db_count > 0 && ! defined $databases_list{$db}->{$table}) {
79+ if ($db_count > 0 &&
80+ !defined $databases_list{$db}->{$table_part} &&
81+ !defined $databases_list{$db}->{$table}) {
82 # --databases option specified, but table is not included
83 return 0;
84 }
85@@ -2433,7 +2451,8 @@
86 # Filter for --tables-file.
87 if ( $tbl_count ) {
88 return 0 unless exists $table_list{$db};
89- return 0 if $table && !$table_list{$db}->{$table};
90+ return 0 if $table && !$table_list{$db}->{$table_part} &&
91+ !$table_list{$db}->{$table};
92 }
93
94 return 1; # backup the table
95
96=== modified file 'src/xtrabackup.cc'
97--- src/xtrabackup.cc 2013-03-01 07:01:10 +0000
98+++ src/xtrabackup.cc 2013-03-07 17:52:22 +0000
99@@ -1506,6 +1506,46 @@
100 }
101
102 /************************************************************************
103+Checks if a given table name matches any of specifications in the --tables or
104+--tables-file options.
105+
106+@return TRUE on match. */
107+static my_bool
108+check_if_table_matches_filters(const char *name)
109+{
110+ int regres;
111+ int i;
112+ xtrabackup_tables_t* table;
113+
114+ if (xtrabackup_tables) {
115+
116+ regres = REG_NOMATCH;
117+
118+ for (i = 0; i < tables_regex_num; i++) {
119+ regres = xb_regexec(&tables_regex[i], name, 1,
120+ tables_regmatch, 0);
121+ if (regres != REG_NOMATCH) {
122+
123+ return(TRUE);
124+ }
125+ }
126+ }
127+
128+ if (xtrabackup_tables_file) {
129+
130+ XB_HASH_SEARCH(name_hash, tables_hash, ut_fold_string(name),
131+ table, (void) 0,
132+ !strcmp(table->name, name));
133+ if (table) {
134+
135+ return(TRUE);
136+ }
137+ }
138+
139+ return(FALSE);
140+}
141+
142+/************************************************************************
143 Checks if a table specified as a path should be skipped from backup
144 based on the --tables or --tables-file options.
145
146@@ -1548,37 +1588,24 @@
147 }
148 buf[dbname_len - 1] = 0;
149
150+ /* For partitioned tables first try to match against the regexp
151+ without truncating the #P#... suffix so we can backup individual
152+ partitions with regexps like '^test[.]t#P#p5' */
153+ if (check_if_table_matches_filters(buf)) {
154+
155+ return(FALSE);
156+ }
157 if ((eptr = strstr(buf, "#P#")) != NULL) {
158+
159 *eptr = 0;
160- }
161-
162- if (xtrabackup_tables) {
163- int regres = REG_NOMATCH;
164- int i;
165- for (i = 0; i < tables_regex_num; i++) {
166- regres = xb_regexec(&tables_regex[i], buf, 1,
167- tables_regmatch, 0);
168- if (regres != REG_NOMATCH) {
169- break;
170- }
171- }
172- if (regres == REG_NOMATCH) {
173- return(TRUE);
174- }
175- }
176-
177- if (xtrabackup_tables_file) {
178- xtrabackup_tables_t* table;
179-
180- XB_HASH_SEARCH(name_hash, tables_hash, ut_fold_string(buf),
181- table, (void) 0,
182- !strcmp(table->name, buf));
183- if (!table) {
184- return(TRUE);
185- }
186- }
187-
188- return(FALSE);
189+
190+ if (check_if_table_matches_filters(buf)) {
191+
192+ return(FALSE);
193+ }
194+ }
195+
196+ return(TRUE);
197 }
198
199 /***********************************************************************
200@@ -2383,6 +2410,8 @@
201
202 p = xtrabackup_tables;
203 for (i=0; i < tables_regex_num; i++) {
204+ int rc;
205+
206 next = strchr(p, ',');
207 ut_a(next || i == tables_regex_num - 1);
208
209@@ -2390,10 +2419,18 @@
210 if (i != tables_regex_num - 1)
211 *(next - 1) = '\0';
212
213- xb_regerror(xb_regcomp(&tables_regex[i], p,
214- REG_EXTENDED),
215- &tables_regex[i], errbuf, sizeof(errbuf));
216- msg("xtrabackup: tables regcomp(%s): %s\n", p, errbuf);
217+ rc = xb_regcomp(&tables_regex[i], p,
218+ REG_EXTENDED);
219+
220+ if (rc) {
221+
222+ xb_regerror(rc, &tables_regex[i], errbuf,
223+ sizeof(errbuf));
224+ msg("xtrabackup: regcomp(%s) failed: %s\n",
225+ p, errbuf);
226+
227+ exit(EXIT_FAILURE);
228+ }
229
230 if (i != tables_regex_num - 1)
231 *(next - 1) = ',';
232@@ -2440,9 +2477,6 @@
233
234 HASH_INSERT(xtrabackup_tables_t, name_hash, tables_hash,
235 ut_fold_string(table->name), table);
236-
237- msg("xtrabackup: table '%s' is registered to the "
238- "list.\n", table->name);
239 }
240 }
241 }
242
243=== added file 'test/t/bug1130627.sh'
244--- test/t/bug1130627.sh 1970-01-01 00:00:00 +0000
245+++ test/t/bug1130627.sh 2013-03-07 17:52:22 +0000
246@@ -0,0 +1,74 @@
247+########################################################################
248+# Bug #1130627: Can't backup individual partitions
249+########################################################################
250+
251+. inc/common.sh
252+. inc/ib_part.sh
253+
254+start_server --innodb_file_per_table
255+
256+require_partitioning
257+
258+run_cmd $MYSQL $MYSQL_ARGS test <<EOF
259+CREATE TABLE t_innodb (
260+ i INT NOT NULL AUTO_INCREMENT,
261+ c CHAR(10) DEFAULT NULL,
262+ PRIMARY KEY (i)
263+) ENGINE=InnoDB
264+/*!50100 PARTITION BY HASH (i)
265+PARTITIONS 10 */;
266+
267+CREATE TABLE t_myisam (
268+ i INT NOT NULL AUTO_INCREMENT,
269+ c CHAR(10) DEFAULT NULL,
270+ PRIMARY KEY (i)
271+) ENGINE=MyISAM
272+/*!50100 PARTITION BY HASH (i)
273+PARTITIONS 10 */;
274+EOF
275+
276+# Force a checkpoint
277+stop_server
278+start_server --innodb_file_per_table
279+
280+# Test that specifying partitions with --include works
281+innobackupex --no-timestamp --include='^test.*#P#p5' $topdir/backup
282+innobackupex --apply-log $topdir/backup
283+
284+file_cnt=`ls $topdir/backup/test | wc -l`
285+
286+test "$file_cnt" -eq 3
287+
288+test -f $topdir/backup/test/t_innodb#P#p5.ibd
289+test -f $topdir/backup/test/t_myisam#P#p5.MYD
290+test -f $topdir/backup/test/t_myisam#P#p5.MYI
291+
292+rm -rf $topdir/backup
293+
294+# Test that specifying partitions with --databases works
295+# TODO: uncomment when bug #569387 is fixed
296+
297+# innobackupex --no-timestamp \
298+# --databases='test.t_myisam#P#p5 test.t_innodb#P#p5' $topdir/backup
299+# innobackupex --apply-log $topdir/backup
300+
301+# test "$file_cnt" -eq 3
302+# test -f $topdir/backup/test/t_innodb#P#p5.ibd
303+# test -f $topdir/backup/test/t_myisam#P#p5.MYD
304+# test -f $topdir/backup/test/t_myisam#P#p5.MYI
305+
306+# rm -rf $topdir/backup
307+
308+# Test that specifying partitions with --tables-file works
309+cat >$topdir/tables_file <<EOF
310+test.t_myisam#P#p5
311+test.t_innodb#P#p5
312+EOF
313+innobackupex --no-timestamp --tables-file=$topdir/tables_file $topdir/backup
314+innobackupex --apply-log $topdir/backup
315+
316+test "$file_cnt" -eq 3
317+test -f $topdir/backup/test/t_myisam#P#p5.MYD
318+test -f $topdir/backup/test/t_myisam#P#p5.MYI
319+
320+rm -rf $topdir/backup

Subscribers

People subscribed via source and target branches

to all changes: