diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 780b8f447..350ab10fe 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -10096,7 +10096,9 @@ sub main { # --plugin hook if ( $plugin && $plugin->can('on_copy_rows_after_nibble') ) { - $plugin->on_copy_rows_after_nibble(); + $plugin->on_copy_rows_after_nibble( + tbl => $tbl, + ); } return; diff --git a/t/pt-online-schema-change/pt-2258.t b/t/pt-online-schema-change/pt-2258.t new file mode 100644 index 000000000..13d022a86 --- /dev/null +++ b/t/pt-online-schema-change/pt-2258.t @@ -0,0 +1,92 @@ +#!/usr/bin/env perl + +BEGIN { + die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" + unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; + unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; +}; + +use strict; +use warnings FATAL => 'all'; +use English qw(-no_match_vars); +use Test::More; + +use Data::Dumper; +use PerconaTest; +use Sandbox; + +require "$trunk/bin/pt-online-schema-change"; + +my $dp = new DSNParser(opts=>$dsn_opts); +my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); +my $master_dbh = $sb->get_dbh_for('master'); + +if ( !$master_dbh ) { + plan skip_all => 'Cannot connect to sandbox master'; +} + +# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic +# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the +# tool will die. +my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox'; +my @args = (qw(--set-vars innodb_lock_wait_timeout=3)); +my $sample = "t/pt-online-schema-change/samples/"; +my $plugin = "$trunk/$sample/plugins"; +my $output; +my $exit_status; + +# ############################################################################ +# https://bugs.launchpad.net/percona-toolkit/+bug/1171653 +# +# ############################################################################ +$sb->load_file('master', "$sample/basic_no_fks.sql"); + +# Should be greater than chunk-size and big enough, so plugin will trigger few times +my $num_rows = 5000; +diag("Loading $num_rows into the table. This might take some time."); +diag(`util/mysql_random_data_load --host=127.0.0.1 --port=12345 --user=msandbox --password=msandbox pt_osc t $num_rows`); + +($output, $exit_status) = full_output( + sub { pt_online_schema_change::main(@args, + "$master_dsn,D=pt_osc,t=t", + "--alter", "CHARACTER SET utf8, MODIFY c CHAR(128) CHARACTER SET utf8", + '--plugin', "$plugin/on_copy_rows_after_nibble.pm", + '--execute') }, +); + +like( + $output, + qr/PLUGIN on_copy_rows_after_nibble/s, + 'Plugin on_copy_rows_after_nibble called' +); + +like( + $output, + qr/Rows count: 1000/s, + 'First chunk of rows is reported' +); + +like( + $output, + qr/Rows count: 4020/s, + 'Second chunk of rows is reported' +); + +like( + $output, + qr/Current average rate: \d+\.\d+/s, + 'Current average rate is reported' +); + +like( + $output, + qr/Nibble time: \d+\.\d+/s, + 'Nibble time is reported' +); + +# ############################################################################# +# Done. +# ############################################################################# +$sb->wipe_clean($master_dbh); +ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); +done_testing; diff --git a/t/pt-online-schema-change/samples/plugins/on_copy_rows_after_nibble.pm b/t/pt-online-schema-change/samples/plugins/on_copy_rows_after_nibble.pm new file mode 100644 index 000000000..c58d85489 --- /dev/null +++ b/t/pt-online-schema-change/samples/plugins/on_copy_rows_after_nibble.pm @@ -0,0 +1,24 @@ +package pt_online_schema_change_plugin; + +use strict; +use warnings FATAL => 'all'; +use English qw(-no_match_vars); +use constant PTDEBUG => $ENV{PTDEBUG} || 0; + +sub new { + my ($class, %args) = @_; + my $self = { %args }; + return bless $self, $class; +} + +sub on_copy_rows_after_nibble { + my ($self, %args) = @_; + my $tbl = $args{tbl}; + print "PLUGIN on_copy_rows_after_nibble\n"; + print "Chunk size: $tbl->{chunk_size}\n"; + print "Nibble time: $tbl->{nibble_time}\n"; + print "Rows count: $tbl->{row_cnt}\n"; + print "Current average rate: $tbl->{rate}->{avg_rate}\n"; +} + +1;