mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 15:31:55 +00:00
Remove reminents of stuff copied in from pt-table-checksum. Handle errors properly in exec_nibble().
This commit is contained in:
@@ -5080,7 +5080,7 @@ sub main {
|
|||||||
}
|
}
|
||||||
$msg .= "Please read the --check-replication-filters documentation "
|
$msg .= "Please read the --check-replication-filters documentation "
|
||||||
. "to learn how to solve this problem.";
|
. "to learn how to solve this problem.";
|
||||||
die ts($msg);
|
die $msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5538,6 +5538,7 @@ sub main {
|
|||||||
|
|
||||||
# Adjust chunk size. This affects the next chunk.
|
# Adjust chunk size. This affects the next chunk.
|
||||||
if ( $chunk_time ) {
|
if ( $chunk_time ) {
|
||||||
|
# Calcuate a new chunk-size based on the rate of rows/s.
|
||||||
$tbl->{chunk_size} = $tbl->{rate}->update(
|
$tbl->{chunk_size} = $tbl->{rate}->update(
|
||||||
$cnt, # processed this many rows
|
$cnt, # processed this many rows
|
||||||
$tbl->{nibble_time}, # is this amount of time
|
$tbl->{nibble_time}, # is this amount of time
|
||||||
@@ -5549,20 +5550,19 @@ sub main {
|
|||||||
$tbl->{chunk_size} = 1;
|
$tbl->{chunk_size} = 1;
|
||||||
|
|
||||||
# This warning is printed once per table.
|
# This warning is printed once per table.
|
||||||
if ( !$tbl->{warned_slow} && $o->get('quiet') < 2 ) {
|
if ( !$tbl->{warned_slow} ) {
|
||||||
warn ts("Checksum queries for table "
|
warn "Rows are copying very slowly. "
|
||||||
. "$tbl->{name} are executing very slowly. "
|
|
||||||
. "--chunk-size has been automatically reduced to 1. "
|
. "--chunk-size has been automatically reduced to 1. "
|
||||||
. "Check that the server is not being overloaded, "
|
. "Check that the server is not being overloaded, "
|
||||||
. "or increase --chunk-time. The last chunk "
|
. "or increase --chunk-time. The last chunk "
|
||||||
. "selected $cnt rows and took "
|
. "selected $cnt rows and took "
|
||||||
. sprintf('%.3f', $tbl->{nibble_time})
|
. sprintf('%.3f', $tbl->{nibble_time})
|
||||||
. " seconds to execute.\n");
|
. " seconds to execute.\n";
|
||||||
$tbl->{warned_slow} = 1;
|
$tbl->{warned_slow} = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update chunk-size based on rows/s checksum rate.
|
# Update chunk-size based on the rate of rows/s.
|
||||||
$nibble_iter->set_chunk_size($tbl->{chunk_size});
|
$nibble_iter->set_chunk_size($tbl->{chunk_size});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6349,11 +6349,6 @@ sub drop_triggers {
|
|||||||
return $exit_status;
|
return $exit_status;
|
||||||
}
|
}
|
||||||
|
|
||||||
# BARON: in this subroutine we still have a lot of references to checksums, so
|
|
||||||
# we can get error messages like this:
|
|
||||||
# Error copying rows from `sbtest`.`sbtest` to `sbtest`.`_sbtest_new`: Error
|
|
||||||
# executing checksum query: Checksum query for table sbtest.sbtest caused MySQL
|
|
||||||
# error 1364:
|
|
||||||
sub exec_nibble {
|
sub exec_nibble {
|
||||||
my (%args) = @_;
|
my (%args) = @_;
|
||||||
my @required_args = qw(Cxn tbl NibbleIterator Retry Quoter OptionParser);
|
my @required_args = qw(Cxn tbl NibbleIterator Retry Quoter OptionParser);
|
||||||
@@ -6395,7 +6390,7 @@ sub exec_nibble {
|
|||||||
wait => sub { return; },
|
wait => sub { return; },
|
||||||
try => sub {
|
try => sub {
|
||||||
# ###################################################################
|
# ###################################################################
|
||||||
# Start timing the checksum query.
|
# Start timing the query.
|
||||||
# ###################################################################
|
# ###################################################################
|
||||||
my $t_start = time;
|
my $t_start = time;
|
||||||
|
|
||||||
@@ -6411,13 +6406,13 @@ sub exec_nibble {
|
|||||||
|
|
||||||
my $t_end = time;
|
my $t_end = time;
|
||||||
# ###################################################################
|
# ###################################################################
|
||||||
# End timing the checksum query.
|
# End timing the query.
|
||||||
# ###################################################################
|
# ###################################################################
|
||||||
|
|
||||||
# How many rows were inserted this time. Used for auto chunk sizing.
|
# How many rows were inserted this time. Used for auto chunk sizing.
|
||||||
$tbl->{row_cnt} = $sth->{nibble}->rows();
|
$tbl->{row_cnt} = $sth->{nibble}->rows();
|
||||||
|
|
||||||
# Check if checksum query caused any warnings.
|
# Check if query caused any warnings.
|
||||||
my $sql_warn = 'SHOW WARNINGS';
|
my $sql_warn = 'SHOW WARNINGS';
|
||||||
PTDEBUG && _d($sql_warn);
|
PTDEBUG && _d($sql_warn);
|
||||||
my $warnings = $dbh->selectall_arrayref($sql_warn, { Slice => {} } );
|
my $warnings = $dbh->selectall_arrayref($sql_warn, { Slice => {} } );
|
||||||
@@ -6433,24 +6428,20 @@ sub exec_nibble {
|
|||||||
|| $message =~ m/$warn_code{$code}->{pattern}/) )
|
|| $message =~ m/$warn_code{$code}->{pattern}/) )
|
||||||
{
|
{
|
||||||
if ( !$tbl->{"warned_code_$code"} ) { # warn once per table
|
if ( !$tbl->{"warned_code_$code"} ) { # warn once per table
|
||||||
if ( $o->get('quiet') < 2 ) {
|
warn "Copying rows caused a MySQL error $code: "
|
||||||
warn "Checksum query for table $tbl->{db}.$tbl->{tbl} "
|
. ($warn_code{$code}->{message}
|
||||||
. "caused MySQL error $code: "
|
? $warn_code{$code}->{message}
|
||||||
. ($warn_code{$code}->{message}
|
: $message)
|
||||||
? $warn_code{$code}->{message}
|
. "\nThis MySQL error is being ignored and further "
|
||||||
: $message)
|
. "occurrences of it will not be reported.\n";
|
||||||
. "\n";
|
|
||||||
}
|
|
||||||
$tbl->{"warned_code_$code"} = 1;
|
$tbl->{"warned_code_$code"} = 1;
|
||||||
$tbl->{checksum_results}->{errors}++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
# This die will propagate to fail which will return 0
|
# This die will propagate to fail which will return 0
|
||||||
# and propagate it to final_fail which will die with
|
# and propagate it to final_fail which will die with
|
||||||
# this error message. (So don't wrap it in ts().)
|
# this error message.
|
||||||
die "Checksum query for table $tbl->{db}.$tbl->{tbl} "
|
die "Copying rows caused a MySQL error $code:\n"
|
||||||
. "caused MySQL error $code:\n"
|
|
||||||
. " Level: " . ($warning->{level} || '') . "\n"
|
. " Level: " . ($warning->{level} || '') . "\n"
|
||||||
. " Code: " . ($warning->{code} || '') . "\n"
|
. " Code: " . ($warning->{code} || '') . "\n"
|
||||||
. " Message: " . ($warning->{message} || '') . "\n"
|
. " Message: " . ($warning->{message} || '') . "\n"
|
||||||
@@ -6465,49 +6456,34 @@ sub exec_nibble {
|
|||||||
my (%args) = @_;
|
my (%args) = @_;
|
||||||
my $error = $args{error};
|
my $error = $args{error};
|
||||||
|
|
||||||
|
# The query failed/caused an error. If the error is one of these,
|
||||||
|
# then we can possibly retry.
|
||||||
if ( $error =~ m/Lock wait timeout exceeded/
|
if ( $error =~ m/Lock wait timeout exceeded/
|
||||||
|| $error =~ m/Query execution was interrupted/
|
|| $error =~ m/Query execution was interrupted/
|
||||||
) {
|
) {
|
||||||
# These errors/warnings can be retried, so don't print
|
# These errors/warnings can be retried, so don't print
|
||||||
# a warning yet; do that in final_fail.
|
# a warning yet; do that in final_fail.
|
||||||
return 1;
|
return 1; # try again
|
||||||
}
|
}
|
||||||
elsif ( $error =~ m/MySQL server has gone away/
|
elsif ( $error =~ m/MySQL server has gone away/
|
||||||
|| $error =~ m/Lost connection to MySQL server/
|
|| $error =~ m/Lost connection to MySQL server/
|
||||||
) {
|
) {
|
||||||
# The 2nd pattern means that MySQL itself died or was stopped.
|
# The 2nd pattern means that MySQL itself died or was stopped.
|
||||||
# The 3rd pattern means that our cxn was killed (KILL <id>).
|
# The 3rd pattern means that our cxn was killed (KILL <id>).
|
||||||
eval { $dbh = $cxn->connect(); };
|
$dbh = $cxn->connect(); # connect or die trying
|
||||||
return 1 unless $EVAL_ERROR; # reconnected, retry checksum query
|
return 1; # reconnected, try again
|
||||||
$oktorun = 0; # failed to reconnect, exit tool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# At this point, either the error/warning cannot be retried,
|
# At this point, either the error/warning cannot be retried,
|
||||||
# or we failed to reconnect. So stop trying and call final_fail.
|
# or we failed to reconnect. Don't retry; call final_fail.
|
||||||
return 0;
|
return 0;
|
||||||
},
|
},
|
||||||
final_fail => sub {
|
final_fail => sub {
|
||||||
my (%args) = @_;
|
my (%args) = @_;
|
||||||
my $error = $args{error};
|
# This die should be caught by the caller. Copying rows and
|
||||||
|
# the tool will stop, which is probably good because by this
|
||||||
if ( $error =~ /Lock wait timeout exceeded/
|
# point the error or warning indicates that something is wrong.
|
||||||
|| $error =~ /Query execution was interrupted/
|
die $args{error};
|
||||||
) {
|
|
||||||
# These errors/warnings are not fatal but only cause this
|
|
||||||
# nibble to be skipped.
|
|
||||||
if ( $o->get('quiet') < 2 ) {
|
|
||||||
warn "$error\n";
|
|
||||||
}
|
|
||||||
return; # skip this nibble
|
|
||||||
}
|
|
||||||
|
|
||||||
# This die will be caught by the eval inside the TABLE loop.
|
|
||||||
# Checksumming for this table will stop, which is probably
|
|
||||||
# good because by this point the error or warning indicates
|
|
||||||
# that something fundamental is broken or wrong. Checksumming
|
|
||||||
# will continue with the next table, unless the fail code set
|
|
||||||
# oktorun=0, in which case the error/warning is fatal.
|
|
||||||
die "Error executing checksum query: $args{error}\n";
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -28,6 +28,9 @@ my $slave_dbh = $sb->get_dbh_for('slave1');
|
|||||||
if ( !$master_dbh ) {
|
if ( !$master_dbh ) {
|
||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
|
elsif ( !$slave_dbh ) {
|
||||||
|
plan skip_all => 'Cannot connect to sandbox slave';
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 55;
|
plan tests => 55;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user