mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-26 01:02:25 +08:00
Add Cxn::lost_connection(). Rename runtime to run_time in Runtime.pm.
This commit is contained in:
@@ -173,6 +173,15 @@ sub set_dbh {
|
|||||||
return $dbh;
|
return $dbh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub lost_connection {
|
||||||
|
my ($self, $e) = @_;
|
||||||
|
return 0 unless $e;
|
||||||
|
return $e =~ m/MySQL server has gone away/
|
||||||
|
|| $e =~ m/Lost connection to MySQL server/;
|
||||||
|
# The 1st pattern means that MySQL itself died or was stopped.
|
||||||
|
# The 2nd pattern means that our cxn was killed (KILL <id>).
|
||||||
|
}
|
||||||
|
|
||||||
# Sub: dbh
|
# Sub: dbh
|
||||||
# Return the cxn's dbh.
|
# Return the cxn's dbh.
|
||||||
sub dbh {
|
sub dbh {
|
||||||
|
|||||||
+14
-27
@@ -18,13 +18,6 @@
|
|||||||
# Runtime package
|
# Runtime package
|
||||||
# ###########################################################################
|
# ###########################################################################
|
||||||
{
|
{
|
||||||
# Package: Runtime
|
|
||||||
# Runtime keeps track of time to control how long a tool's main loop runs.
|
|
||||||
# This package was created to handle mk-query-digest --run-time-mode event.
|
|
||||||
# In essence, we abstract time so that the tool doesn't know/care whether
|
|
||||||
# now() comes from a clock, a log timestamp, or wherever. The creator of
|
|
||||||
# Runtime object determines how, or from where, time is gotten so that the
|
|
||||||
# caller of the object can simply ask, "What time is it?".
|
|
||||||
package Runtime;
|
package Runtime;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
@@ -32,30 +25,24 @@ use warnings FATAL => 'all';
|
|||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||||
|
|
||||||
# Sub: new
|
|
||||||
#
|
|
||||||
# Parameters:
|
|
||||||
# %args - Arguments
|
|
||||||
#
|
|
||||||
# Required Arguments:
|
|
||||||
# now - Callback that sets current time.
|
|
||||||
# runtime - Amount of time to run in seconds, or undef for forever.
|
|
||||||
#
|
|
||||||
# Returns:
|
|
||||||
# Runtime object
|
|
||||||
sub new {
|
sub new {
|
||||||
my ( $class, %args ) = @_;
|
my ( $class, %args ) = @_;
|
||||||
my @required_args = qw(now);
|
my @required_args = qw(run_time now);
|
||||||
foreach my $arg ( @required_args ) {
|
foreach my $arg ( @required_args ) {
|
||||||
die "I need a $arg argument" unless $args{$arg};
|
die "I need a $arg argument" unless exists $args{$arg};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ($args{runtime} || 0) < 0 ) {
|
my $run_time = $args{run_time};
|
||||||
die "runtime argument must be greater than zero"
|
if ( defined $run_time ) {
|
||||||
|
die "run_time must be > 0" if $run_time <= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $now = $args{now};
|
||||||
|
die "now must be a callback" unless ref $now eq 'CODE';
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
%args,
|
run_time => $run_time,
|
||||||
|
now => $now,
|
||||||
start_time => undef,
|
start_time => undef,
|
||||||
end_time => undef,
|
end_time => undef,
|
||||||
time_left => undef,
|
time_left => undef,
|
||||||
@@ -99,14 +86,14 @@ sub time_left {
|
|||||||
# we know the current time.
|
# we know the current time.
|
||||||
return unless defined $now;
|
return unless defined $now;
|
||||||
|
|
||||||
# If runtime is also defined, then we can determine time left.
|
# If run_time is also defined, then we can determine time left.
|
||||||
# If it's not defined, then we're running forever.
|
# If it's not defined, then we're running forever.
|
||||||
my $runtime = $self->{runtime};
|
my $run_time = $self->{run_time};
|
||||||
return unless defined $runtime;
|
return unless defined $run_time;
|
||||||
|
|
||||||
# Set the end time once.
|
# Set the end time once.
|
||||||
if ( !$self->{end_time} ) {
|
if ( !$self->{end_time} ) {
|
||||||
$self->{end_time} = $now + $runtime;
|
$self->{end_time} = $now + $run_time;
|
||||||
PTDEBUG && _d("End time:", $self->{end_time});
|
PTDEBUG && _d("End time:", $self->{end_time});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user