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