mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-07 04:49:48 +00:00
Changes as requested by daniel in merge feedback:
- change to get_slave_lag - if then else - chop comments 80 char wide
This commit is contained in:
@@ -8105,25 +8105,27 @@ sub main {
|
||||
return;
|
||||
};
|
||||
|
||||
my $get_lag = sub {
|
||||
my ($cxn) = @_;
|
||||
my $dbh = $cxn->dbh();
|
||||
if ( !$dbh || !$dbh->ping() ) {
|
||||
eval { $dbh = $cxn->connect() }; # connect or die trying
|
||||
if ( $EVAL_ERROR ) {
|
||||
$oktorun = 0; # flag for cleanup tasks
|
||||
chomp $EVAL_ERROR;
|
||||
die "Lost connection to replica " . $cxn->name()
|
||||
. " while attempting to get its lag ($EVAL_ERROR)\n";
|
||||
my $get_lag;
|
||||
# The plugin is able to override the slavelag check so tools like
|
||||
# pt-heartbeat or other replicators (Tungsten...) can be used to
|
||||
# measure replication lag
|
||||
if ( $plugin && $plugin->can('get_slave_lag') ) {
|
||||
$get_lag = $plugin->get_slave_lag(oktorun => \$oktorun);
|
||||
} else {
|
||||
$get_lag = sub {
|
||||
my ($cxn) = @_;
|
||||
my $dbh = $cxn->dbh();
|
||||
if ( !$dbh || !$dbh->ping() ) {
|
||||
eval { $dbh = $cxn->connect() }; # connect or die trying
|
||||
if ( $EVAL_ERROR ) {
|
||||
$oktorun = 0; # flag for cleanup tasks
|
||||
chomp $EVAL_ERROR;
|
||||
die "Lost connection to replica " . $cxn->name()
|
||||
. " while attempting to get its lag ($EVAL_ERROR)\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ms->get_slave_lag($dbh);
|
||||
};
|
||||
|
||||
# The plugin is able to override the slavelag check so tools like pt-heartbeat
|
||||
# or other replicators (Tungsten...) can be used to measure replication lag
|
||||
if ( $plugin && $plugin->can('override_slavelag_check') ) {
|
||||
$get_lag = $plugin->override_slavelag_check(oktorun => \$oktorun);
|
||||
return $ms->get_slave_lag($dbh);
|
||||
};
|
||||
}
|
||||
|
||||
$replica_lag = new ReplicaLagWaiter(
|
||||
@@ -11351,7 +11353,7 @@ These hooks, in this order, are called if defined:
|
||||
after_drop_old_table
|
||||
before_drop_triggers
|
||||
before_exit
|
||||
override_slavelag_check
|
||||
get_slave_lag
|
||||
|
||||
Each hook is passed different arguments. To see which arguments are passed
|
||||
to a hook, search for the hook's name in the tool's source code, like:
|
||||
|
@@ -9579,27 +9579,29 @@ sub main {
|
||||
return;
|
||||
};
|
||||
|
||||
my $get_lag = sub {
|
||||
my ($cxn) = @_;
|
||||
my $dbh = $cxn->dbh();
|
||||
if ( !$dbh || !$dbh->ping() ) {
|
||||
PTDEBUG && _d('Lost connection to slave', $cxn->name(),
|
||||
'while waiting for slave lag');
|
||||
eval { $dbh = $cxn->connect() }; # connect or die trying
|
||||
if ( $EVAL_ERROR ) {
|
||||
$oktorun = 0; # Fatal error
|
||||
chomp $EVAL_ERROR;
|
||||
die "Lost connection to replica " . $cxn->name()
|
||||
. " while attempting to get its lag ($EVAL_ERROR)";
|
||||
my $get_lag;
|
||||
# The plugin is able to override the slavelag check so tools like
|
||||
# pt-heartbeat or other replicators (Tungsten...) can be used to
|
||||
# measure replication lag
|
||||
if ( $plugin && $plugin->can('get_slave_lag') ) {
|
||||
$get_lag = $plugin->get_slave_lag(oktorun => \$oktorun);
|
||||
} else {
|
||||
$get_lag = sub {
|
||||
my ($cxn) = @_;
|
||||
my $dbh = $cxn->dbh();
|
||||
if ( !$dbh || !$dbh->ping() ) {
|
||||
PTDEBUG && _d('Lost connection to slave', $cxn->name(),
|
||||
'while waiting for slave lag');
|
||||
eval { $dbh = $cxn->connect() }; # connect or die trying
|
||||
if ( $EVAL_ERROR ) {
|
||||
$oktorun = 0; # Fatal error
|
||||
chomp $EVAL_ERROR;
|
||||
die "Lost connection to replica " . $cxn->name()
|
||||
. " while attempting to get its lag ($EVAL_ERROR)";
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ms->get_slave_lag($dbh);
|
||||
};
|
||||
|
||||
# The plugin is able to override the slavelag check so tools like pt-heartbeat
|
||||
# or other replicators (Tungsten...) can be used to measure replication lag
|
||||
if ( $plugin && $plugin->can('override_slavelag_check') ) {
|
||||
$get_lag = $plugin->override_slavelag_check(oktorun => \$oktorun);
|
||||
return $ms->get_slave_lag($dbh);
|
||||
};
|
||||
}
|
||||
|
||||
$replica_lag = new ReplicaLagWaiter(
|
||||
@@ -12492,7 +12494,7 @@ These hooks, in this order, are called if defined:
|
||||
init
|
||||
before_replicate_check
|
||||
after_replicate_check
|
||||
override_slavelag_check
|
||||
get_slave_lag
|
||||
before_checksum_table
|
||||
after_checksum_table
|
||||
|
||||
|
@@ -56,7 +56,7 @@ my @called = $output =~ m/^PLUGIN \S+$/gm;
|
||||
is_deeply(
|
||||
\@called,
|
||||
[
|
||||
'PLUGIN override_slavelag_check',
|
||||
'PLUGIN get_slave_lag',
|
||||
'PLUGIN init',
|
||||
'PLUGIN before_create_new_table',
|
||||
'PLUGIN after_create_new_table',
|
||||
|
@@ -96,9 +96,9 @@ sub before_exit {
|
||||
print "PLUGIN before_exit\n";
|
||||
}
|
||||
|
||||
sub override_slavelag_check {
|
||||
sub get_slave_lag {
|
||||
my ($self, %args) = @_;
|
||||
print "PLUGIN override_slavelag_check\n";
|
||||
print "PLUGIN get_slave_lag\n";
|
||||
|
||||
return sub { return 0; };
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ my @called = $output =~ m/^PLUGIN \S+$/gm;
|
||||
is_deeply(
|
||||
\@called,
|
||||
[
|
||||
'PLUGIN override_slavelag_check',
|
||||
'PLUGIN get_slave_lag',
|
||||
'PLUGIN init',
|
||||
'PLUGIN before_checksum_table',
|
||||
'PLUGIN after_checksum_table',
|
||||
|
@@ -26,9 +26,9 @@ sub after_replicate_check {
|
||||
print "PLUGIN after_replicate_check\n";
|
||||
}
|
||||
|
||||
sub override_slavelag_check {
|
||||
sub get_slave_lag {
|
||||
my ($self, %args) = @_;
|
||||
print "PLUGIN override_slavelag_check\n";
|
||||
print "PLUGIN get_slave_lag\n";
|
||||
return sub { return 0; };
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user