Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added new hook before_die #509

Merged
merged 3 commits into from Nov 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions bin/pt-online-schema-change
Expand Up @@ -8412,7 +8412,7 @@ my $term_readkey = eval {

use sigtrap 'handler', \&sig_int, 'normal-signals';


my $plugin;
svetasmirnova marked this conversation as resolved.
Show resolved Hide resolved
my $exit_status = 0;
my $oktorun = 1;
my $dont_interrupt_now = 0;
Expand Down Expand Up @@ -8466,6 +8466,9 @@ sub _die {
$exit_status ||= 255;
chomp ($msg);
print "$msg\n";
if ( $plugin && $plugin->can('before_die') ) {
$plugin->before_die(exit_status => $exit_status);
}
exit $exit_status;
}

Expand Down Expand Up @@ -8773,7 +8776,7 @@ sub main {
# ########################################################################
# Create --plugin.
# ########################################################################
my $plugin;

if ( my $file = $o->get('plugin') ) {
_die("--plugin file $file does not exist", INVALID_PLUGIN_FILE) unless -f $file;
eval {
Expand Down Expand Up @@ -9513,6 +9516,9 @@ sub main {
$cxn->dbh()->do($sql);
};
if ( $EVAL_ERROR ) {
if ( $plugin && $plugin->can('before_die') ) {
$plugin->before_die(exit_status => $EVAL_ERROR);
}
# this is trapped by a signal handler. Don't replace it with _die
die "Error altering new table $new_tbl->{name}: $EVAL_ERROR\n";
}
Expand Down Expand Up @@ -10076,6 +10082,10 @@ sub main {
1 while $nibble_iter->next();
};
if ( $EVAL_ERROR ) {
if ( $plugin && $plugin->can('before_die') ) {
$plugin->before_die(exit_status => $EVAL_ERROR);
}

die ts("Error copying rows from $orig_tbl->{name} to "
. "$new_tbl->{name}: $EVAL_ERROR");
}
Expand Down Expand Up @@ -13106,6 +13116,7 @@ These hooks, in this order, are called if defined:
before_drop_old_table
after_drop_old_table
before_drop_triggers
before_die
before_exit
get_slave_lag

Expand Down Expand Up @@ -13217,6 +13228,11 @@ Here's a plugin file template for all hooks:
print "PLUGIN before_drop_triggers\n";
}

sub before_die {
my ($self, %args) = @_;
print "PLUGIN before_die\n";
}

sub before_exit {
my ($self, %args) = @_;
print "PLUGIN before_exit\n";
Expand Down