Merge lp:~akopytov/percona-xtrabackup/bug766607 into lp:percona-xtrabackup/2.0

Proposed by Alexey Kopytov
Status: Merged
Approved by: Stewart Smith
Approved revision: no longer in the source branch.
Merged at revision: 279
Proposed branch: lp:~akopytov/percona-xtrabackup/bug766607
Merge into: lp:percona-xtrabackup/2.0
Prerequisite: lp:~akopytov/percona-xtrabackup/bug798488
Diff against target: 466 lines (+211/-69)
7 files modified
test/inc/common.sh (+23/-3)
test/inc/incremental_sample-db/incremental_sample-schema.sql (+0/-35)
test/run.sh (+43/-9)
test/t/bug766607.sh (+51/-0)
test/t/xb_defaults_file.sh (+25/-0)
test/t/xb_stats.sh (+2/-5)
xtrabackup.c (+67/-17)
To merge this branch: bzr merge lp:~akopytov/percona-xtrabackup/bug766607
Reviewer Review Type Date Requested Status
Stewart Smith (community) Approve
Review via email: mp+65246@code.launchpad.net

This proposal supersedes a proposal from 2011-06-20.

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) wrote : Posted in a previous version of this proposal
Revision history for this message
Stewart Smith (stewart) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'test/inc/common.sh'
2--- test/inc/common.sh 2011-06-15 07:04:42 +0000
3+++ test/inc/common.sh 2011-06-20 18:06:00 +0000
4@@ -4,12 +4,12 @@
5
6 function innobackupex()
7 {
8- run_cmd `which innobackupex` $IB_ARGS $*
9+ run_cmd $IB_BIN $IB_ARGS $*
10 }
11
12 function xtrabackup()
13 {
14- run_cmd `which $XB_BIN` $XB_ARGS $*
15+ run_cmd $XB_BIN $XB_ARGS $*
16 }
17
18 function vlog
19@@ -129,7 +129,27 @@
20 function run_cmd()
21 {
22 vlog "===> $@"
23- "$@" || die "===> `basename $1` failed with exit code $?"
24+ set +e
25+ "$@"
26+ local rc=$?
27+ set -e
28+ if [ $rc -ne 0 ]
29+ then
30+ die "===> `basename $1` failed with exit code $rc"
31+ fi
32+}
33+
34+function run_cmd_expect_failure()
35+{
36+ vlog "===> $@"
37+ set +e
38+ "$@"
39+ local rc=$?
40+ set -e
41+ if [ $rc -eq 0 ]
42+ then
43+ die "===> `basename $1` succeeded when it was expected to fail"
44+ fi
45 }
46
47 function stop_mysqld()
48
49=== modified file 'test/inc/incremental_sample-db/incremental_sample-schema.sql'
50--- test/inc/incremental_sample-db/incremental_sample-schema.sql 2010-12-09 09:37:20 +0000
51+++ test/inc/incremental_sample-db/incremental_sample-schema.sql 2011-06-20 18:06:00 +0000
52@@ -1,40 +1,5 @@
53--- MySQL dump 10.13 Distrib 5.1.51, for unknown-linux-gnu (x86_64)
54---
55--- Host: localhost Database: test
56--- ------------------------------------------------------
57--- Server version 5.1.51-rel11.5-log
58-
59-/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
60-/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
61-/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
62-/*!40101 SET NAMES utf8 */;
63-/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
64-/*!40103 SET TIME_ZONE='+00:00' */;
65-/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
66-/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
67-/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
68-/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
69-
70---
71--- Table structure for table `test`
72---
73-
74 DROP TABLE IF EXISTS `test`;
75-/*!40101 SET @saved_cs_client = @@character_set_client */;
76-/*!40101 SET character_set_client = utf8 */;
77 CREATE TABLE `test` (
78 `a` int(11) DEFAULT NULL,
79 `number` int(11) DEFAULT NULL
80 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
81-/*!40101 SET character_set_client = @saved_cs_client */;
82-/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
83-
84-/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
85-/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
86-/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
87-/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
88-/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
89-/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
90-/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
91-
92--- Dump completed on 2010-11-15 15:02:47
93
94=== modified file 'test/run.sh'
95--- test/run.sh 2011-06-15 07:04:42 +0000
96+++ test/run.sh 2011-06-20 18:06:00 +0000
97@@ -94,10 +94,10 @@
98
99 function get_version_info()
100 {
101- init
102+ init >>$OUTFILE 2>&1
103 MYSQL_VERSION=""
104 INNODB_VERSION=""
105- run_mysqld
106+ run_mysqld >>$OUTFILE 2>&1
107 # Get MySQL and InnoDB versions
108 MYSQL_VERSION=`$MYSQL ${MYSQL_ARGS} -Nsf -e "SHOW VARIABLES LIKE 'version'"`
109 MYSQL_VERSION=${MYSQL_VERSION#"version "}
110@@ -105,7 +105,7 @@
111 MYSQL_VERSION_COMMENT=${MYSQL_VERSION_COMMENT#"version_comment "}
112 INNODB_VERSION=`$MYSQL ${MYSQL_ARGS} -Nsf -e "SHOW VARIABLES LIKE 'innodb_version'"`
113 INNODB_VERSION=${INNODB_VERSION#"innodb_version "}
114- XTRADB_VERSION=`echo $INNODB_VERSION | sed 's/[0-9]\.[0-9]\.[0-9][0-9]*\(-[0-9][0-9]*\.[0-9][0-9]*\)*$/\1/'`
115+ XTRADB_VERSION="`echo $INNODB_VERSION | sed 's/[0-9]\.[0-9]\.[0-9][0-9]*\(-[0-9][0-9]*\.[0-9][0-9]*\)*$/\1/'`"
116 if [ "${MYSQL_VERSION:0:3}" = "5.1" ]
117 then
118 if [ -z "$INNODB_VERSION" ]
119@@ -126,11 +126,25 @@
120 vlog "Uknown MySQL/InnoDB version: $MYSQL_VERSION/$INNODB_VERSION"
121 exit -1
122 fi
123- vlog "Using '$XB_BIN' as xtrabackup binary"
124- # Set the correct binary for innobackupex
125+
126+ XB_PATH="`which $XB_BIN`"
127+ if [ -z "$XB_PATH" ]
128+ then
129+ vlog "Cannot find '$XB_BIN' in PATH"
130+ return 1
131+ fi
132+ XB_BIN="$XB_PATH"
133+
134+ IB_BIN="`which innobackupex`"
135+ if [ -z "$IB_BIN" ]
136+ then
137+ vlog "Cannot find 'innobackupex' in PATH"
138+ return 1
139+ fi
140 IB_ARGS="$IB_ARGS --ibbackup=$XB_BIN"
141
142- export MYSQL_VERSION/ MYSQL_VERSION_COMMENT INNODB_VERSION XTRADB_VERSION XB_BIN
143+ export MYSQL_VERSION MYSQL_VERSION_COMMENT INNODB_VERSION XTRADB_VERSION \
144+ XB_BIN IB_BIN
145 }
146
147 tname=""
148@@ -163,15 +177,32 @@
149 total_count=0
150
151 export OUTFILE="$PWD/results/setup"
152-get_version_info >$OUTFILE 2>&1
153-kill_leftovers >$OUTFILE 2>&1
154-clean >$OUTFILE 2>&1
155+
156+if ! get_version_info
157+then
158+ echo "get_version_info failed. See $OUTFILE for details."
159+ exit -1
160+fi
161+
162+if [ -n "$XTRADB_VERSION" ]
163+then
164+ echo "Running against Percona Server $MYSQL_VERSION (XtraDB $INNODB_VERSION)" | tee -a $OUTFILE
165+else
166+ echo "Running against MySQL $MYSQL_VERSION (InnoDB $INNODB_VERSION)" | tee -a $OUTFILE
167+fi
168+echo "Using '`basename $XB_BIN`' as xtrabackup binary" | tee -a $OUTFILE
169+echo | tee -a $OUTFILE
170+
171+kill_leftovers >>$OUTFILE 2>&1
172+clean >>$OUTFILE 2>&1
173
174 source subunit.sh
175
176 SUBUNIT_OUT=test_results.subunit
177 rm -f $SUBUNIT_OUT
178
179+echo "========================================================================"
180+
181 for t in $tests
182 do
183 printf "%-40s" $t
184@@ -212,6 +243,9 @@
185 total_count=$((total_count+1))
186 done
187
188+echo "========================================================================"
189+echo
190+
191 kill_leftovers
192
193 if [ $result -eq 1 ]
194
195=== added file 'test/t/bug766607.sh'
196--- test/t/bug766607.sh 1970-01-01 00:00:00 +0000
197+++ test/t/bug766607.sh 2011-06-20 18:06:00 +0000
198@@ -0,0 +1,51 @@
199+. inc/common.sh
200+
201+init
202+run_mysqld --innodb_file_per_table
203+load_dbase_schema incremental_sample
204+
205+# Full backup dir
206+mkdir -p $topdir/data/full
207+# Incremental backup dir
208+mkdir -p $topdir/data/delta
209+
210+xtrabackup --datadir=$mysql_datadir --backup --target-dir=$topdir/data/full
211+
212+vlog "Creating and filling a new table"
213+run_cmd $MYSQL $MYSQL_ARGS test <<EOF
214+CREATE TABLE t(a int) ENGINE=InnoDB;
215+INSERT INTO t VALUES (1), (2), (3);
216+FLUSH LOGS;
217+EOF
218+
219+stop_mysqld
220+run_mysqld --innodb_file_per_table
221+
222+vlog "Making incremental backup"
223+xtrabackup --datadir=$mysql_datadir --backup --target-dir=$topdir/data/delta --incremental-basedir=$topdir/data/full
224+
225+vlog "Preparing full backup"
226+xtrabackup --datadir=$mysql_datadir --prepare --apply-log-only \
227+ --target-dir=$topdir/data/full
228+
229+# The following would fail before the bugfix
230+vlog "Applying incremental delta"
231+xtrabackup --datadir=$mysql_datadir --prepare --apply-log-only \
232+ --target-dir=$topdir/data/full --incremental-dir=$topdir/data/delta
233+
234+vlog "Preparing full backup"
235+xtrabackup --datadir=$mysql_datadir --prepare --target-dir=$topdir/data/full
236+vlog "Data prepared for restore"
237+
238+stop_mysqld
239+
240+vlog "Copying files"
241+
242+cd $topdir/data/full/
243+cp -r * $mysql_datadir
244+cd $topdir
245+
246+vlog "Data restored"
247+run_mysqld --innodb_file_per_table
248+
249+run_cmd $MYSQL $MYSQL_ARGS -e "SELECT * FROM t" test
250
251=== added file 'test/t/xb_defaults_file.sh'
252--- test/t/xb_defaults_file.sh 1970-01-01 00:00:00 +0000
253+++ test/t/xb_defaults_file.sh 2011-06-20 18:06:00 +0000
254@@ -0,0 +1,25 @@
255+#
256+# Bug #798488: xtrabackup ignores defaults-file in apply-log-only prepare mode
257+#
258+# Test xtrabackup fails with an error when --defaults-file is not the first argument
259+# on the command line (and thus would be ignored).
260+
261+. inc/common.sh
262+
263+init
264+run_mysqld
265+
266+# The following should succeed (can't use xtrabackup directly as it uses
267+# --no-defaults)
268+run_cmd $XB_BIN --defaults-file=$topdir/my.cnf --backup \
269+ --datadir=$mysql_datadir --target-dir=$topdir/backup
270+
271+rm -rf $topdir/backup
272+
273+# The following should fail (can't use xtrabackup directly as that would make
274+# the test fail)
275+
276+run_cmd_expect_failure $XB_BIN --backup --defaults-file=$topdir/my.cnf \
277+ --datadir=$mysql_datadir --target-dir=$topdir/backup
278+
279+exit 0
280
281=== modified file 'test/t/xb_stats.sh'
282--- test/t/xb_stats.sh 2011-06-10 07:55:26 +0000
283+++ test/t/xb_stats.sh 2011-06-20 18:06:00 +0000
284@@ -15,11 +15,8 @@
285 # when trying to get stats before creating the log files
286
287 vlog "===> xtrabackup --stats --datadir=$topdir/backup"
288-# Cannot use run_cmd here
289-if $XB_BIN $XB_ARGS --stats --datadir=$topdir/backup >$OUTFILE 2>&1
290-then
291- die "xtrabackup --stats was expected to fail, but it did not."
292-fi
293+run_cmd_expect_failure $XB_BIN $XB_ARGS --stats --datadir=$topdir/backup
294+
295 if ! grep "Cannot find log file ib_logfile0" $OUTFILE
296 then
297 die "Cannot find the expected error message from xtrabackup --stats"
298
299=== modified file 'xtrabackup.c'
300--- xtrabackup.c 2011-06-15 07:04:42 +0000
301+++ xtrabackup.c 2011-06-20 18:06:00 +0000
302@@ -5058,7 +5058,11 @@
303 return TRUE;
304 }
305
306-static void
307+/************************************************************************
308+Applies a given .delta file to the corresponding data file.
309+@return TRUE on success */
310+static
311+ibool
312 xtrabackup_apply_delta(
313 const char* dirname, /* in: dir name of incremental */
314 const char* dbname, /* in: database name (ibdata: NULL) */
315@@ -5141,8 +5145,33 @@
316 dst_file = xb_file_create_no_error_handling(dst_path, OS_FILE_OPEN,
317 OS_FILE_READ_WRITE,
318 &success);
319+again:
320 if (!success) {
321- os_file_get_last_error(TRUE);
322+ ulint errcode = os_file_get_last_error(TRUE);
323+
324+ if (errcode == OS_FILE_NOT_FOUND) {
325+ fprintf(stderr, "xtrabackup: target data file %s "
326+ "is not found, creating a new one\n", dst_path);
327+ /* Create the database directory if it doesn't exist yet
328+ */
329+ if (dbname) {
330+ char dst_dir[FN_REFLEN];
331+
332+ snprintf(dst_dir, sizeof(dst_dir), "%s/%s",
333+ xtrabackup_real_target_dir, dbname);
334+ srv_normalize_path_for_win(dst_dir);
335+
336+ if (!os_file_create_directory(dst_dir, FALSE))
337+ goto error;
338+ }
339+ dst_file =
340+ xb_file_create_no_error_handling(dst_path,
341+ OS_FILE_CREATE,
342+ OS_FILE_READ_WRITE,
343+ &success);
344+ goto again;
345+ }
346+
347 fprintf(stderr,
348 "xtrabackup: error: cannot open %s\n",
349 dst_path);
350@@ -5155,7 +5184,7 @@
351
352 xb_file_set_nocache(dst_file, dst_path, "OPEN");
353
354- printf("Applying %s ...\n", src_path);
355+ fprintf(stderr, "Applying %s ...\n", src_path);
356
357 while (!last_buffer) {
358 ulint cluster_header;
359@@ -5241,18 +5270,23 @@
360 os_file_close(src_file);
361 if (dst_file != XB_FILE_UNDEFINED)
362 os_file_close(dst_file);
363- return;
364+ return TRUE;
365
366 error:
367 if (src_file != XB_FILE_UNDEFINED)
368 os_file_close(src_file);
369 if (dst_file != XB_FILE_UNDEFINED)
370 os_file_close(dst_file);
371- fprintf(stderr, "xtrabackup: Error: xtrabackup_apply_delta() failed.\n");
372- return;
373+ fprintf(stderr, "xtrabackup: Error: xtrabackup_apply_delta(): "
374+ "failed to apply %s to %s.\n", src_path, dst_path);
375+ return FALSE;
376 }
377
378-static void
379+/************************************************************************
380+Applies all .delta files from incremental_dir to the full backup.
381+@return TRUE on success. */
382+static
383+ibool
384 xtrabackup_apply_deltas(my_bool check_newer)
385 {
386 int ret;
387@@ -5283,9 +5317,12 @@
388 && 0 == strcmp(fileinfo.name +
389 strlen(fileinfo.name) - 6,
390 ".delta")) {
391- xtrabackup_apply_delta(
392- xtrabackup_incremental_dir, NULL,
393- fileinfo.name, check_newer);
394+ if (!xtrabackup_apply_delta(
395+ xtrabackup_incremental_dir, NULL,
396+ fileinfo.name, check_newer))
397+ {
398+ return FALSE;
399+ }
400 }
401 next_file_item_1:
402 ret = fil_file_readdir_next_file(&err,
403@@ -5337,9 +5374,13 @@
404 ".delta")) {
405 /* The name ends in .delta; try opening
406 the file */
407- xtrabackup_apply_delta(
408- xtrabackup_incremental_dir, dbinfo.name,
409- fileinfo.name, check_newer);
410+ if (!xtrabackup_apply_delta(
411+ xtrabackup_incremental_dir,
412+ dbinfo.name,
413+ fileinfo.name, check_newer))
414+ {
415+ return FALSE;
416+ }
417 }
418 next_file_item_2:
419 ret = fil_file_readdir_next_file(&err,
420@@ -5357,6 +5398,7 @@
421
422 os_file_closedir(dir);
423
424+ return TRUE;
425 }
426
427 static my_bool
428@@ -5508,8 +5550,8 @@
429 if(xtrabackup_init_temp_log())
430 goto error;
431
432- if(xtrabackup_incremental)
433- xtrabackup_apply_deltas(TRUE);
434+ if(xtrabackup_incremental && !xtrabackup_apply_deltas(TRUE))
435+ goto error;
436
437 sync_close();
438 sync_initialized = FALSE;
439@@ -5935,6 +5977,12 @@
440 uint count;
441 struct my_option *opt= (struct my_option *) my_long_options;
442 optend= strcend((argv)[i], '=');
443+ if (!strncmp(argv[i], "--defaults-file", optend - argv[i]))
444+ {
445+ fprintf(stderr, "xtrabackup: Error: --defaults-file "
446+ "be specified first on the command line\n");
447+ exit(EXIT_FAILURE);
448+ }
449 for (count= 0; opt->name; opt++) {
450 if (!getopt_compare_strings(opt->name, (argv)[i] + 2,
451 (uint)(optend - (argv)[i] - 2))) /* match found */
452@@ -6201,10 +6249,12 @@
453 print_version();
454 if (xtrabackup_incremental) {
455 #ifndef INNODB_VERSION_SHORT
456- printf("incremental backup from %lu:%lu is enabled.\n",
457+ fprintf(stderr,
458+ "incremental backup from %lu:%lu is enabled.\n",
459 incremental_lsn.high, incremental_lsn.low);
460 #else
461- printf("incremental backup from %llu is enabled.\n",
462+ fprintf(stderr,
463+ "incremental backup from %llu is enabled.\n",
464 incremental_lsn);
465 #endif
466 }

Subscribers

People subscribed via source and target branches