From 4d2560c24c87d31e6449fdc368e4d2a14625465c Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Wed, 6 Jun 2012 12:21:26 -0300 Subject: [PATCH 1/3] pt-osc: Wait for the slaves to replicate the table before working on them. --- bin/pt-online-schema-change | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index a0a8a99b..d38cb3e6 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -5680,6 +5680,18 @@ sub main { PTDEBUG && _d('Getting table row estimate on replicas'); my @too_large; foreach my $slave ( @$slaves ) { + PTDEBUG && _d('Waiting until', $slave->name(), + 'replicates the table'); + my $slave_has_repl_table; + do { + sleep 0.5; + $slave_has_repl_table = $tp->check_table( + dbh => $slave->dbh(), + db => $tbl->{db}, + tbl => $tbl->{tbl} + ); + } while ( !$slave_has_repl_table ); + my ($n_rows) = NibbleIterator::get_row_estimate( Cxn => $slave, tbl => $tbl, From 02eb9b7a0a8937a408de42d0a07eb67e4744b7f9 Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Wed, 6 Jun 2012 13:28:59 -0300 Subject: [PATCH 2/3] Moved the slave replication wait to execute earlier --- bin/pt-online-schema-change | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index d38cb3e6..697f25d8 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -5546,6 +5546,20 @@ sub main { } }; + for my $slave (@$slaves) { + PTDEBUG && _d('Waiting until', $slave->name(), + 'replicates the table'); + my $slave_has_repl_table; + do { + $slave_has_repl_table = $tp->check_table( + dbh => $slave->dbh(), + db => $new_tbl->{db}, + tbl => $new_tbl->{tbl}, + ); + sleep 0.5 unless $slave_has_repl_table; + } while ( !$slave_has_repl_table ); + } + # ##################################################################### # Step 2: Alter the new, empty table. This should be very quick, # or die if the user specified a bad alter statement. @@ -5680,18 +5694,6 @@ sub main { PTDEBUG && _d('Getting table row estimate on replicas'); my @too_large; foreach my $slave ( @$slaves ) { - PTDEBUG && _d('Waiting until', $slave->name(), - 'replicates the table'); - my $slave_has_repl_table; - do { - sleep 0.5; - $slave_has_repl_table = $tp->check_table( - dbh => $slave->dbh(), - db => $tbl->{db}, - tbl => $tbl->{tbl} - ); - } while ( !$slave_has_repl_table ); - my ($n_rows) = NibbleIterator::get_row_estimate( Cxn => $slave, tbl => $tbl, From 000fdd86b84f41a838a5e6a869170582117051ea Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Wed, 6 Jun 2012 13:36:53 -0300 Subject: [PATCH 3/3] pt-osc: Nicer waiting code --- bin/pt-online-schema-change | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 697f25d8..37ffca7f 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -5549,15 +5549,11 @@ sub main { for my $slave (@$slaves) { PTDEBUG && _d('Waiting until', $slave->name(), 'replicates the table'); - my $slave_has_repl_table; - do { - $slave_has_repl_table = $tp->check_table( - dbh => $slave->dbh(), - db => $new_tbl->{db}, - tbl => $new_tbl->{tbl}, - ); - sleep 0.5 unless $slave_has_repl_table; - } while ( !$slave_has_repl_table ); + sleep 0.5 while ! $tp->check_table( + dbh => $slave->dbh(), + db => $new_tbl->{db}, + tbl => $new_tbl->{tbl} + ); } # #####################################################################