diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 895df775..cb891a2c 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -11930,6 +11930,147 @@ to a hook, search for the hook's name in the tool's source code, like: The comment C<# --plugin hook> precedes every hook call. +Here's a plugin file template for all hooks: + + package pt_online_schema_change_plugin; + + use strict; + + sub new { + my ($class, %args) = @_; + my $self = { %args }; + return bless $self, $class; + } + + sub init { + my ($self, %args) = @_; + print "PLUGIN init\n"; + } + + sub before_create_new_table { + my ($self, %args) = @_; + print "PLUGIN before_create_new_table\n"; + } + + sub after_create_new_table { + my ($self, %args) = @_; + print "PLUGIN after_create_new_table\n"; + } + + sub before_alter_new_table { + my ($self, %args) = @_; + print "PLUGIN before_alter_new_table\n"; + } + + sub after_alter_new_table { + my ($self, %args) = @_; + print "PLUGIN after_alter_new_table\n"; + } + + sub before_create_triggers { + my ($self, %args) = @_; + print "PLUGIN before_create_triggers\n"; + } + + sub after_create_triggers { + my ($self, %args) = @_; + print "PLUGIN after_create_triggers\n"; + } + + sub before_copy_rows { + my ($self, %args) = @_; + print "PLUGIN before_copy_rows\n"; + } + + sub after_copy_rows { + my ($self, %args) = @_; + print "PLUGIN after_copy_rows\n"; + } + + sub before_swap_tables { + my ($self, %args) = @_; + print "PLUGIN before_swap_tables\n"; + } + + sub after_swap_tables { + my ($self, %args) = @_; + print "PLUGIN after_swap_tables\n"; + } + + sub before_update_foreign_keys { + my ($self, %args) = @_; + print "PLUGIN before_update_foreign_keys\n"; + } + + sub after_update_foreign_keys { + my ($self, %args) = @_; + print "PLUGIN after_update_foreign_keys\n"; + } + + sub before_drop_old_table { + my ($self, %args) = @_; + print "PLUGIN before_drop_old_table\n"; + } + + sub after_drop_old_table { + my ($self, %args) = @_; + print "PLUGIN after_drop_old_table\n"; + } + + sub before_drop_triggers { + my ($self, %args) = @_; + print "PLUGIN before_drop_triggers\n"; + } + + sub before_exit { + my ($self, %args) = @_; + print "PLUGIN before_exit\n"; + } + + sub get_slave_lag { + my ($self, %args) = @_; + print "PLUGIN get_slave_lag\n"; + + return sub { return 0; }; + } + + 1; + +Notice that C must return a function reference; +ideally one that returns actual slave lag, not simply zero like in the example. + +Here's an example that actually does something: + + package pt_online_schema_change_plugin; + + use strict; + + sub new { + my ($class, %args) = @_; + my $self = { %args }; + return bless $self, $class; + } + + sub after_create_new_table { + my ($self, %args) = @_; + my $new_tbl = $args{new_tbl}; + my $dbh = $self->{cxn}->dbh; + my $row = $dbh->selectrow_arrayref("SHOW CREATE TABLE $new_tbl->{name}"); + warn "after_create_new_table: $row->[1]\n\n"; + } + + sub after_alter_new_table { + my ($self, %args) = @_; + my $new_tbl = $args{new_tbl}; + my $dbh = $self->{cxn}->dbh; + my $row = $dbh->selectrow_arrayref("SHOW CREATE TABLE $new_tbl->{name}"); + warn "after_alter_new_table: $row->[1]\n\n"; + } + + 1; + +You could use this with L<"--dry-run"> to check how the table will look before and after. + Please contact Percona if you have questions or need help. =head1 DSN OPTIONS