#At file:///Users/cbell/source/bzr/50697/ based on revid:ritheesh.vedire@stripped
3111 Chuck Bell 2010-03-19
BUG#52076 : Backup of partition and non-partition tables fail with native storage engine
When a backup contains a partitioned table and a non-partitioned table for a
storage engine that supports a native backup driver, it is possible if the
non-partitioned table is included first in the backup stream that it will
fail to switch the partitioned table to either the default or consistent
snapshot driver.
This patch corrects a logic error in the code and permits the selection of the
default or consistent snapshot driver in the event a table contains partitions
and the native driver has already been identified.
@ mysql-test/suite/backup/r/backup_native_partition.result
New result file.
@ mysql-test/suite/backup/t/backup_native_partition.test
New test file containing test case to ensure default driver is
selected even though a partition and non-partition MyISAM table
has been included in the backup.
@ sql/backup/backup_info.cc
Added check for table has partitions for the default driver selection
code to allow for the case when a native driver has been chosen and
the backup contains a partitioned table of the same storage engine.
In this case, we select the default or consistent snapshot driver
for the partitioned table and skip the native driver.
added:
mysql-test/suite/backup/r/backup_native_partition.result
mysql-test/suite/backup/t/backup_native_partition.test
modified:
sql/backup/backup_info.cc
=== added file 'mysql-test/suite/backup/r/backup_native_partition.result'
--- a/mysql-test/suite/backup/r/backup_native_partition.result 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/r/backup_native_partition.result 2010-03-19 18:31:46 +0000
@@ -0,0 +1,74 @@
+#
+# Creating databases
+#
+CREATE DATABASE backup_part;
+CREATE TABLE backup_part.t_non (i int) ENGINE=MYISAM;
+INSERT INTO backup_part.t_non VALUES (1), (2), (3);
+CREATE TABLE backup_part.t1 (
+t1_autoinc INTEGER NOT NULL AUTO_INCREMENT,
+t1_uuid CHAR(36),
+PRIMARY KEY (t1_autoinc)) ENGINE=MYISAM
+PARTITION BY HASH (t1_autoinc);
+INSERT INTO backup_part.t1(t1_uuid) VALUES ('aaa'),('bbb'),('ccc'),('ddd');
+# Show content
+SELECT * FROM backup_part.t1 ORDER BY t1_autoinc;
+t1_autoinc t1_uuid
+1 aaa
+2 bbb
+3 ccc
+4 ddd
+#
+# Now let's test partition tables with subpartitions.
+#
+CREATE TABLE backup_part.my_tbl (f1 int) ENGINE=MYISAM
+PARTITION BY LIST(f1) SUBPARTITION BY HASH (f1) (
+PARTITION part1 VALUES IN (1,2,3,4) (
+SUBPARTITION subpart11,
+SUBPARTITION subpart12
+),
+PARTITION part2 VALUES IN (5,6,7,8) (
+SUBPARTITION subpart21,
+SUBPARTITION subpart22
+)
+);
+CREATE TABLE backup_part.ts (id INT, purchased DATE) ENGINE=MYISAM
+PARTITION BY RANGE( YEAR(purchased) )
+SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
+PARTITION p0 VALUES LESS THAN (1990) (
+SUBPARTITION s0,
+SUBPARTITION s1
+),
+PARTITION p1 VALUES LESS THAN (2000) (
+SUBPARTITION s2,
+SUBPARTITION s3
+),
+PARTITION p2 VALUES LESS THAN MAXVALUE (
+SUBPARTITION s4,
+SUBPARTITION s5
+)
+);
+#
+# Perform backup
+#
+# Show drivers.
+#
+SELECT drivers FROM mysql.backup_history WHERE backup_id=276;
+drivers
+Default, MyISAM
+
+#
+# Restore and show content
+#
+SHOW FULL TABLES FROM backup_part;
+Tables_in_backup_part Table_type
+my_tbl BASE TABLE
+t1 BASE TABLE
+t_non BASE TABLE
+ts BASE TABLE
+RESTORE FROM 'partition.bak' OVERWRITE;
+backup_id
+#
+#
+# Cleanup
+#
+DROP DATABASE backup_part;
=== added file 'mysql-test/suite/backup/t/backup_native_partition.test'
--- a/mysql-test/suite/backup/t/backup_native_partition.test 1970-01-01 00:00:00 +0000
+++ b/mysql-test/suite/backup/t/backup_native_partition.test 2010-03-19 18:31:46 +0000
@@ -0,0 +1,91 @@
+#
+# This test is designed to test that BACKUP selects the best available
+# driver for partitioned tables and non-partitioned tables when there
+# is a native backup driver present. In this case, the default driver
+# should be chosen for the partitioned table and the native driver for
+# the non-partitioned table.
+#
+
+--source include/have_partition.inc
+--source include/not_embedded.inc
+
+let $bdir=`select @@backupdir`;
+
+--echo #
+--echo # Creating databases
+--echo #
+CREATE DATABASE backup_part;
+
+CREATE TABLE backup_part.t_non (i int) ENGINE=MYISAM;
+
+INSERT INTO backup_part.t_non VALUES (1), (2), (3);
+
+CREATE TABLE backup_part.t1 (
+ t1_autoinc INTEGER NOT NULL AUTO_INCREMENT,
+ t1_uuid CHAR(36),
+ PRIMARY KEY (t1_autoinc)) ENGINE=MYISAM
+PARTITION BY HASH (t1_autoinc);
+
+INSERT INTO backup_part.t1(t1_uuid) VALUES ('aaa'),('bbb'),('ccc'),('ddd');
+
+--echo # Show content
+SELECT * FROM backup_part.t1 ORDER BY t1_autoinc;
+
+--echo #
+--echo # Now let's test partition tables with subpartitions.
+--echo #
+CREATE TABLE backup_part.my_tbl (f1 int) ENGINE=MYISAM
+ PARTITION BY LIST(f1) SUBPARTITION BY HASH (f1) (
+ PARTITION part1 VALUES IN (1,2,3,4) (
+ SUBPARTITION subpart11,
+ SUBPARTITION subpart12
+ ),
+ PARTITION part2 VALUES IN (5,6,7,8) (
+ SUBPARTITION subpart21,
+ SUBPARTITION subpart22
+ )
+ );
+
+CREATE TABLE backup_part.ts (id INT, purchased DATE) ENGINE=MYISAM
+ PARTITION BY RANGE( YEAR(purchased) )
+ SUBPARTITION BY HASH( TO_DAYS(purchased) ) (
+ PARTITION p0 VALUES LESS THAN (1990) (
+ SUBPARTITION s0,
+ SUBPARTITION s1
+ ),
+ PARTITION p1 VALUES LESS THAN (2000) (
+ SUBPARTITION s2,
+ SUBPARTITION s3
+ ),
+ PARTITION p2 VALUES LESS THAN MAXVALUE (
+ SUBPARTITION s4,
+ SUBPARTITION s5
+ )
+ );
+
+--echo #
+--echo # Perform backup
+--replace_column 1 #
+let $bup_id= `BACKUP DATABASE backup_part TO 'partition.bak'`;
+
+--echo #
+--echo # Show drivers.
+--echo #
+--eval SELECT drivers FROM mysql.backup_history WHERE backup_id=$bup_id
+--echo
+
+--echo #
+--echo # Restore and show content
+--echo #
+SHOW FULL TABLES FROM backup_part;
+
+--replace_column 1 #
+RESTORE FROM 'partition.bak' OVERWRITE;
+
+--echo #
+--echo # Cleanup
+--echo #
+
+DROP DATABASE backup_part;
+
+--remove_file $bdir/partition.bak
=== modified file 'sql/backup/backup_info.cc'
--- a/sql/backup/backup_info.cc 2010-02-11 14:04:43 +0000
+++ b/sql/backup/backup_info.cc 2010-03-19 18:31:46 +0000
@@ -302,8 +302,9 @@ Backup_info::find_backup_engine(const ba
});
/*
- If we couldn't locate native snapshot for that table - iterate over
- all existing snapshots and see if one of them can accept the table.
+ If we couldn't locate native snapshot for that table or the table has
+ partitions - iterate over all existing snapshots and see if one of them
+ can accept the table.
The order on the snapshots list determines the preferred backup method
for a table. The snapshots for the built-in backup engines are always
@@ -311,11 +312,12 @@ Backup_info::find_backup_engine(const ba
resort.
*/
- if (!snap)
+ if (tbl_has_partitions || !snap)
{
List_iterator<Snapshot_info> it(snapshots);
- while ((snap= it++))
+ bool accepted= FALSE;
+ while ((snap= it++) && !accepted)
{
if (my_strcasecmp(system_charset_info, se->name.str, "NDBCLUSTER") == 0)
{
@@ -323,8 +325,13 @@ Backup_info::find_backup_engine(const ba
snap= NULL;
break;
}
- if (snap->accept(tbl, se))
- break;
+ /*
+ Skip native driver if table has partitions.
+ */
+ if (tbl_has_partitions &&
+ (snap->type() == Snapshot_info::NATIVE_SNAPSHOT))
+ continue;
+ accepted= snap->accept(tbl, se);
}
}
Attachment: [text/bzr-bundle] bzr/charles.bell@sun.com-20100319183146-5n5swvpeow4kw5e9.bundle
| Thread |
|---|
| • bzr commit into mysql-next-mr-backup branch (charles.bell:3111)Bug#52076 | Chuck Bell | 19 Mar |