Merge lp:~percona-toolkit-dev/percona-toolkit/fix-pt-osc-drop-bug-1188002 into lp:percona-toolkit/2.2

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 582
Merged at revision: 582
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-pt-osc-drop-bug-1188002
Merge into: lp:percona-toolkit/2.2
Diff against target: 202 lines (+136/-9)
3 files modified
bin/pt-online-schema-change (+20/-9)
t/pt-online-schema-change/cleanup.t (+80/-0)
t/pt-online-schema-change/samples/plugins/make_drop_trigger_fail.pm (+36/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-pt-osc-drop-bug-1188002
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+168183@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
=== modified file 'bin/pt-online-schema-change'
--- bin/pt-online-schema-change 2013-04-19 23:26:48 +0000
+++ bin/pt-online-schema-change 2013-06-07 20:57:30 +0000
@@ -7710,16 +7710,18 @@
7710my $exit_status = 0;7710my $exit_status = 0;
7711my $oktorun = 1;7711my $oktorun = 1;
7712my @drop_trigger_sqls;7712my @drop_trigger_sqls;
7713my @triggers_not_dropped;
77137714
7714$OUTPUT_AUTOFLUSH = 1;7715$OUTPUT_AUTOFLUSH = 1;
77157716
7716sub main {7717sub main {
7717 local @ARGV = @_;7718 local @ARGV = @_;
77187719
7719 # Reset global vars else tests will fail.7720 # Reset global vars else tests will fail.
7720 $exit_status = 0;7721 $exit_status = 0;
7721 $oktorun = 1;7722 $oktorun = 1;
7722 @drop_trigger_sqls = ();7723 @drop_trigger_sqls = ();
7724 @triggers_not_dropped = ();
77237725
7724 my %stats = (7726 my %stats = (
7725 INSERT => 0,7727 INSERT => 0,
@@ -8419,6 +8421,16 @@
8419 . "--no-drop-new-table was specified. To drop the new table, "8421 . "--no-drop-new-table was specified. To drop the new table, "
8420 . "execute:\n$sql\n";8422 . "execute:\n$sql\n";
8421 }8423 }
8424 elsif ( @triggers_not_dropped ) {
8425 # https://bugs.launchpad.net/percona-toolkit/+bug/1188002
8426 print "Not dropping the new table $new_tbl->{name} because "
8427 . "dropping these triggers failed:\n"
8428 . join("\n", map { " $_" } @triggers_not_dropped)
8429 . "\nThese triggers must be dropped before dropping "
8430 . "$new_tbl->{name}, else writing to $orig_tbl->{name} will "
8431 . "cause MySQL error 1146 (42S02): \"Table $new_tbl->{name} "
8432 . " doesn't exist\".\n";
8433 }
8422 else {8434 else {
8423 print "Dropping new table...\n";8435 print "Dropping new table...\n";
8424 print $sql, "\n" if $o->get('print');8436 print $sql, "\n" if $o->get('print');
@@ -10025,8 +10037,7 @@
10025 else {10037 else {
10026 print "Dropping triggers...\n";10038 print "Dropping triggers...\n";
10027 }10039 }
1002810040
10029 my @not_dropped;
10030 foreach my $sql ( @drop_trigger_sqls ) {10041 foreach my $sql ( @drop_trigger_sqls ) {
10031 print $sql, "\n" if $o->get('print');10042 print $sql, "\n" if $o->get('print');
10032 if ( $o->get('execute') ) {10043 if ( $o->get('execute') ) {
@@ -10044,19 +10055,19 @@
10044 };10055 };
10045 if ( $EVAL_ERROR ) {10056 if ( $EVAL_ERROR ) {
10046 warn "Error dropping trigger: $EVAL_ERROR\n";10057 warn "Error dropping trigger: $EVAL_ERROR\n";
10047 push @not_dropped, $sql;10058 push @triggers_not_dropped, $sql;
10048 $exit_status = 1;10059 $exit_status = 1;
10049 }10060 }
10050 }10061 }
10051 }10062 }
1005210063
10053 if ( $o->get('execute') ) {10064 if ( $o->get('execute') ) {
10054 if ( !@not_dropped ) {10065 if ( !@triggers_not_dropped ) {
10055 print "Dropped triggers OK.\n";10066 print "Dropped triggers OK.\n";
10056 }10067 }
10057 else {10068 else {
10058 warn "To try dropping the triggers again, execute:\n"10069 warn "To try dropping the triggers again, execute:\n"
10059 . join("\n", @not_dropped) . "\n";10070 . join("\n", @triggers_not_dropped) . "\n";
10060 }10071 }
10061 }10072 }
1006210073
1006310074
=== added file 't/pt-online-schema-change/cleanup.t'
--- t/pt-online-schema-change/cleanup.t 1970-01-01 00:00:00 +0000
+++ t/pt-online-schema-change/cleanup.t 2013-06-07 20:57:30 +0000
@@ -0,0 +1,80 @@
1#!/usr/bin/env perl
2
3BEGIN {
4 die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5 unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6 unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
7};
8
9use strict;
10use warnings FATAL => 'all';
11use English qw(-no_match_vars);
12use Test::More;
13
14use PerconaTest;
15use Sandbox;
16require "$trunk/bin/pt-online-schema-change";
17require VersionParser;
18
19use Time::HiRes qw(sleep);
20use Data::Dumper;
21$Data::Dumper::Indent = 1;
22$Data::Dumper::Sortkeys = 1;
23$Data::Dumper::Quotekeys = 0;
24
25my $dp = new DSNParser(opts=>$dsn_opts);
26my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
27my $dbh1 = $sb->get_dbh_for('master');
28my $dbh2 = $sb->get_dbh_for('master');
29
30if ( !$dbh1 || !$dbh2 ) {
31 plan skip_all => 'Cannot connect to sandbox master';
32}
33elsif ( $sandbox_version lt '5.5' ) {
34 plan skip_all => "Metadata locks require MySQL 5.5 and newer";
35}
36
37my $output;
38my $master_dsn = $sb->dsn_for('master');
39my $sample = "t/pt-online-schema-change/samples";
40my $plugin = "$trunk/$sample/plugins";
41my $exit;
42my $rows;
43
44# Loads pt_osc.t with cols id (pk), c (unique index),, d.
45$sb->load_file('master', "$sample/basic_no_fks_innodb.sql");
46
47# #############################################################################
48# Meta-block on create_triggers.
49# #############################################################################
50
51($output) = full_output(
52 sub { pt_online_schema_change::main(
53 "$master_dsn,D=pt_osc,t=t",
54 qw(--statistics --execute --tries drop_triggers:1:0.01),
55 qw(--set-vars lock_wait_timeout=1 --print --no-swap-tables),
56 '--plugin', "$plugin/make_drop_trigger_fail.pm",
57 )},
58 stderr => 1,
59);
60
61my $triggers = $dbh1->selectall_arrayref("SHOW TRIGGERS FROM pt_osc");
62is(
63 @$triggers,
64 3,
65 "Bug 1188002: triggers not dropped"
66) or diag(Dumper($triggers));
67
68my $tables = $dbh1->selectall_arrayref("SHOW TABLES FROM pt_osc");
69is_deeply(
70 $tables,
71 [ ['_t_new'], ['t'] ],
72 "Bug 1188002: new table not dropped"
73) or diag(Dumper($tables));
74
75# #############################################################################
76# Done.
77# #############################################################################
78$sb->wipe_clean($dbh1);
79ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
80done_testing;
081
=== added file 't/pt-online-schema-change/samples/plugins/make_drop_trigger_fail.pm'
--- t/pt-online-schema-change/samples/plugins/make_drop_trigger_fail.pm 1970-01-01 00:00:00 +0000
+++ t/pt-online-schema-change/samples/plugins/make_drop_trigger_fail.pm 2013-06-07 20:57:30 +0000
@@ -0,0 +1,36 @@
1package pt_online_schema_change_plugin;
2
3use strict;
4use warnings FATAL => 'all';
5use English qw(-no_match_vars);
6use constant PTDEBUG => $ENV{PTDEBUG} || 0;
7
8sub new {
9 my ($class, %args) = @_;
10 my $self = { %args };
11 return bless $self, $class;
12}
13
14sub init {
15 my ($self, %args) = @_;
16 print "PLUGIN: init()\n";
17 $self->{orig_tbl} = $args{orig_tbl};
18}
19
20sub before_drop_triggers {
21 my ($self, %args) = @_;
22 print "PLUGIN: before_drop_triggers()\n";
23
24 my $dbh = $self->{aux_cxn}->dbh;
25 my $orig_tbl = $self->{orig_tbl};
26
27 # Start a trx and get a metadata lock on the table being altered.
28 $dbh->do('SET autocommit=0');
29 $dbh->{AutoCommit} = 0;
30 $dbh->do("START TRANSACTION");
31 $dbh->do("SELECT * FROM " . $orig_tbl->{name});
32
33 return;
34}
35
361;

Subscribers

People subscribed via source and target branches