added fix for pt-deadlock-logger-introduces-a-noise-to-mysql-1258135

This commit is contained in:
Frank Cizmich
2014-07-04 11:45:14 -03:00

View File

@@ -4616,43 +4616,44 @@ sub main {
}
}
else {
if ( $ins_sth ) {
eval {
PTDEBUG && _d('Saving deadlock to --dest');
foreach my $txn (
sort { $a->{thread} <=> $b->{thread} } values %txns
) {
$ins_sth->execute(@{$txn}{@cols});
}
$dst->dbh->commit();
};
if ( my $e = $EVAL_ERROR ) {
PTDEBUG && _d('Error saving to --dest:', $e);
if ( $dst->lost_connection($e) ) {
eval {
$ins_sth->finish() if $ins_sth;
$dst->dbh->disconnect() if $dst->dbh;
$dst->connect(AutoCommit => 0);
$ins_sth = $dst->dbh->prepare($ins_sql);
};
if ( $EVAL_ERROR ) {
warn "Lost connection to " . $dst->name . ". Will try "
. "to reconnect in the next iteration.\n";
}
else {
PTDEBUG && _d('Reconnected to MySQL (--dest)');
redo ITERATION;
}
}
else {
warn "Error saving to --dest: $EVAL_ERROR";
$exit_status |= 1;
}
}
}
if ( $fingerprint ne $last_fingerprint ) {
PTDEBUG && _d('New deadlock');
if ( $ins_sth ) {
eval {
PTDEBUG && _d('Saving deadlock to --dest');
foreach my $txn (
sort { $a->{thread} <=> $b->{thread} } values %txns
) {
$ins_sth->execute(@{$txn}{@cols});
}
$dst->dbh->commit();
};
if ( my $e = $EVAL_ERROR ) {
PTDEBUG && _d('Error saving to --dest:', $e);
if ( $dst->lost_connection($e) ) {
eval {
$ins_sth->finish() if $ins_sth;
$dst->dbh->disconnect() if $dst->dbh;
$dst->connect(AutoCommit => 0);
$ins_sth = $dst->dbh->prepare($ins_sql);
};
if ( $EVAL_ERROR ) {
warn "Lost connection to " . $dst->name . ". Will try "
. "to reconnect in the next iteration.\n";
}
else {
PTDEBUG && _d('Reconnected to MySQL (--dest)');
redo ITERATION;
}
}
else {
warn "Error saving to --dest: $EVAL_ERROR";
$exit_status |= 1;
}
}
}
if ( !$o->get('quiet') ) {
print join($sep, @cols), "\n";
foreach my $txn (