diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 8aca9b39..1da2e579 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -6989,7 +6989,7 @@ sub nibble_is_safe { if ( !$nibble_iter->one_nibble() && lc($expl->{key} || '') ne lc($nibble_iter->nibble_index() || '') ) { if ( !$tbl->{warned}->{not_using_chunk_index}++ - && $o->get('quiet') < 2 ) { + && !$o->get('quiet') ) { die "Error copying rows at chunk " . $nibble_iter->nibble_number() . " of $tbl->{db}.$tbl->{tbl} because MySQL chose " . ($expl->{key} ? "the $expl->{key}" : "no") . " index " @@ -7009,7 +7009,7 @@ sub nibble_is_safe { && $nibble_iter->identical_boundaries($boundary->{upper}, $boundary->{next_lower}) ) { if ( !$tbl->{warned}->{oversize_chunk}++ - && $o->get('quiet') < 2 ) { + && !$o->get('quiet') ) { die "Error copying rows at chunk " . $nibble_iter->nibble_number() . " of $tbl->{db}.$tbl->{tbl} because it is oversized. " . "The current chunk size limit is " @@ -7028,7 +7028,7 @@ sub nibble_is_safe { && $tbl->{key_len} && ($expl->{key_len} || 0) < $tbl->{key_len} ) { if ( !$tbl->{warned}->{key_len}++ - && $o->get('quiet') < 2 ) { + && !$o->get('quiet') ) { die "Error copying rows at chunk " . $nibble_iter->nibble_number() . " of $tbl->{db}.$tbl->{tbl} because MySQL used " . "only " . ($expl->{key_len} || 0) . " bytes " @@ -8360,7 +8360,7 @@ percentage, seconds, or number of iterations. =item --quiet -short form: -q; cumulative: yes; default: 0 +short form: -q Do not print messages to STDOUT. Errors and warnings are still printed to STDERR. diff --git a/t/pt-online-schema-change/bugs.t b/t/pt-online-schema-change/bugs.t index a364fee2..fd6d5f34 100644 --- a/t/pt-online-schema-change/bugs.t +++ b/t/pt-online-schema-change/bugs.t @@ -28,9 +28,6 @@ if ( !$master_dbh ) { elsif ( !$slave_dbh ) { plan skip_all => 'Cannot connect to sandbox slave1'; } -else { - plan tests => 7; -} # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic # so we need to specify --lock-wait-timeout=3 else the tool will die. @@ -111,9 +108,61 @@ like $output, qr/\QNot updating foreign key constraints because this is a dry run./, "Bug 1003315: But now we do get an explanation from --dry-run"; +# ############################################################################ +# This fakes the conditions to trigger +# ############################################################################ +{ + my $o = new OptionParser(file => "$trunk/bin/pt-table-checksum"); + $o->get_specs(); + no warnings; + local *pt_online_schema_change::explain_statement = sub { + return { key => 'some_key' } + }; + { + package PerconaTest::Fake::NibbleIterator; + sub AUTOLOAD { + our $AUTOLOAD = $AUTOLOAD; + return if $AUTOLOAD =~ /one_nibble/; + return { lower => [], upper => [] } + } + } + + eval { + pt_online_schema_change::nibble_is_safe( + Cxn => 1, + tbl => {qw( db some_db tbl some_table )}, + NibbleIterator => bless({}, "PerconaTest::Fake::NibbleIterator"), + OptionParser => $o, + ); + }; + + like( + $EVAL_ERROR, + qr/Error copying rows at chunk.*because MySQL chose/, + "Dies if MySQL isn't using the chunk index" + ); + + $o->set('quiet', 1); + eval { + pt_online_schema_change::nibble_is_safe( + Cxn => 1, + tbl => {qw( db some_db tbl some_table )}, + NibbleIterator => bless({}, "PerconaTest::Fake::NibbleIterator"), + OptionParser => $o, + ); + }; + + is( + $EVAL_ERROR, + '', + "..unless --quiet was specified", + ); +} + # ############################################################################# # Done. # ############################################################################# $sb->wipe_clean($master_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); -exit; + +done_testing; diff --git a/t/pt-online-schema-change/option_sanity.t b/t/pt-online-schema-change/option_sanity.t index 4a4e7fc7..f44a002f 100644 --- a/t/pt-online-schema-change/option_sanity.t +++ b/t/pt-online-schema-change/option_sanity.t @@ -51,19 +51,6 @@ like( "--execute FALSE by default" ); -like( - $output, - qr/--quiet\s+0/, - "--quiet is 0 by default", -); - -$output = `$cmd --quiet --quiet --help`; -like( - $output, - qr/--quiet\s+2/, - "--quiet is cummulative", -); - $output = `$cmd h=127.1,P=12345,u=msandbox,p=msandbox --alter-foreign-keys-method drop_swap --no-drop-new-table`; like( $output,