Merge lp:~percona-toolkit-dev/percona-toolkit/pt-osc-5.0-fix into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 502
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-osc-5.0-fix
Merge into: lp:percona-toolkit/2.1
Diff against target: 99 lines (+59/-2)
2 files modified
bin/pt-online-schema-change (+30/-2)
t/pt-online-schema-change/bugs.t (+29/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-osc-5.0-fix
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+139338@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-online-schema-change'
2--- bin/pt-online-schema-change 2012-12-11 14:48:44 +0000
3+++ bin/pt-online-schema-change 2012-12-11 22:54:22 +0000
4@@ -7860,10 +7860,15 @@
5 # Although triggers were introduced in 5.0.2, "Prior to MySQL 5.0.10,
6 # triggers cannot contain direct references to tables by name."
7 # ########################################################################
8- if ( VersionParser->new($cxn->dbh()) < '5.0.10' ) {
9+ my $server_version = VersionParser->new($cxn->dbh());
10+ if ( $server_version < '5.0.10' ) {
11 die "This tool requires MySQL 5.0.10 or newer.\n";
12 }
13
14+ # Use LOCK IN SHARE mode unless MySQL 5.0 because there's a bug like
15+ # http://bugs.mysql.com/bug.php?id=45694
16+ my $lock_in_share_mode = $server_version < '5.1' ? 0 : 1;
17+
18 # ########################################################################
19 # Setup lag and load monitors.
20 # ########################################################################
21@@ -8698,7 +8703,7 @@
22 dml => $dml,
23 select => $select,
24 callbacks => $callbacks,
25- lock_in_share_mode => 1,
26+ lock_in_share_mode => $lock_in_share_mode,
27 OptionParser => $o,
28 Quoter => $q,
29 TableParser => $tp,
30@@ -10082,6 +10087,29 @@
31
32 You must specify C<--alter "DROP FOREIGN KEY _fk_foo">.
33
34+=item *
35+
36+The tool does not use C<LOCK IN SHARE MODE> with MySQL 5.0 because it can
37+cause a slave error which breaks replication:
38+
39+ Query caused different errors on master and slave. Error on master:
40+ 'Deadlock found when trying to get lock; try restarting transaction' (1213),
41+ Error on slave: 'no error' (0). Default database: 'pt_osc'.
42+ Query: 'INSERT INTO pt_osc.t (id, c) VALUES ('730', 'new row')'
43+
44+The error happens when converting a MyISAM table to InnoDB because MyISAM
45+is non-transactional but InnoDB is transactional. MySQL 5.1 and newer
46+handle this case correctly, but testing reproduces the error 5% of the time
47+with MySQL 5.0.
48+
49+This is a MySQL bug, similar to L<http://bugs.mysql.com/bug.php?id=45694>,
50+but there is no fix or workaround in MySQL 5.0. Without C<LOCK IN SHARE MODE>,
51+tests pass 100% of the time, so the risk of data loss or breaking replication
52+should be negligible.
53+
54+B<Be sure to verify the new table if using MySQL 5.0 and converting
55+from MyISAM to InnoDB!>
56+
57 =back
58
59 =item --alter-foreign-keys-method
60
61=== modified file 't/pt-online-schema-change/bugs.t'
62--- t/pt-online-schema-change/bugs.t 2012-11-08 23:38:07 +0000
63+++ t/pt-online-schema-change/bugs.t 2012-12-11 22:54:22 +0000
64@@ -236,6 +236,35 @@
65 }
66
67 # #############################################################################
68+# Something like http://bugs.mysql.com/bug.php?id=45694 means we should not
69+# use LOCK IN SHARE MODE with MySQL 5.0.
70+# #############################################################################
71+$sb->load_file('master', "$sample/basic_no_fks_innodb.sql");
72+
73+($output, $exit_status) = full_output(
74+ sub { pt_online_schema_change::main(@args,
75+ "$master_dsn,D=pt_osc,t=t",
76+ "--alter", "add column (foo int)",
77+ qw(--execute --print))
78+ },
79+);
80+
81+if ( $sandbox_version eq '5.0' ) {
82+ unlike(
83+ $output,
84+ qr/LOCK IN SHARE MODE/,
85+ "No LOCK IN SHARE MODE for MySQL $sandbox_version"
86+ );
87+}
88+else {
89+ like(
90+ $output,
91+ qr/LOCK IN SHARE MODE/,
92+ "LOCK IN SHARE MODE for MySQL $sandbox_version",
93+ );
94+}
95+
96+# #############################################################################
97 # Done.
98 # #############################################################################
99 $sb->wipe_clean($master_dbh);

Subscribers

People subscribed via source and target branches