Merge lp:~percona-toolkit-dev/percona-toolkit/pt-deadlock-logger-introduces-a-noise-to-mysql-1258135 into lp:percona-toolkit/2.2

Proposed by Frank Cizmich
Status: Merged
Merged at revision: 607
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-deadlock-logger-introduces-a-noise-to-mysql-1258135
Merge into: lp:percona-toolkit/2.2
Diff against target: 83 lines (+36/-35)
1 file modified
bin/pt-deadlock-logger (+36/-35)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-deadlock-logger-introduces-a-noise-to-mysql-1258135
Reviewer Review Type Date Requested Status
Percona Toolkit developers Pending
Review via email: mp+220719@code.launchpad.net

Description of the change

Background:

By default the tool prints deadlocks to stdout and, if the --dest option is provided, also inserts a log of the deadlock into a table.

To avoid duplicates in the stdout output the tool compares the last deadlocks fingerprint to the current one, discarding if they matched. (the timestamp of the deadlock is mixed in the fingerprint to avoid false negatives)

It did no such check for the output directed to the table, simply relying on the "insert ignore" directive to avoid duplicate key errors.

Fix:

Extended the fingerprint check to the table mode of logging.

Manually verified correct operation by generating deadlocks and checking binlogs.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-deadlock-logger'
--- bin/pt-deadlock-logger 2014-02-20 08:10:16 +0000
+++ bin/pt-deadlock-logger 2014-05-22 20:53:38 +0000
@@ -4601,43 +4601,44 @@
4601 }4601 }
4602 }4602 }
4603 else {4603 else {
4604 if ( $ins_sth ) {
4605 eval {
4606 PTDEBUG && _d('Saving deadlock to --dest');
4607 foreach my $txn (
4608 sort { $a->{thread} <=> $b->{thread} } values %txns
4609 ) {
4610 $ins_sth->execute(@{$txn}{@cols});
4611 }
4612 $dst->dbh->commit();
4613 };
4614 if ( my $e = $EVAL_ERROR ) {
4615 PTDEBUG && _d('Error saving to --dest:', $e);
4616 if ( $dst->lost_connection($e) ) {
4617 eval {
4618 $ins_sth->finish() if $ins_sth;
4619 $dst->dbh->disconnect() if $dst->dbh;
4620 $dst->connect(AutoCommit => 0);
4621 $ins_sth = $dst->dbh->prepare($ins_sql);
4622 };
4623 if ( $EVAL_ERROR ) {
4624 warn "Lost connection to " . $dst->name . ". Will try "
4625 . "to reconnect in the next iteration.\n";
4626 }
4627 else {
4628 PTDEBUG && _d('Reconnected to MySQL (--dest)');
4629 redo ITERATION;
4630 }
4631 }
4632 else {
4633 warn "Error saving to --dest: $EVAL_ERROR";
4634 $exit_status |= 1;
4635 }
4636 }
4637 }
4638
4639 if ( $fingerprint ne $last_fingerprint ) {4604 if ( $fingerprint ne $last_fingerprint ) {
4640 PTDEBUG && _d('New deadlock');4605 PTDEBUG && _d('New deadlock');
4606
4607 if ( $ins_sth ) {
4608 eval {
4609 PTDEBUG && _d('Saving deadlock to --dest');
4610 foreach my $txn (
4611 sort { $a->{thread} <=> $b->{thread} } values %txns
4612 ) {
4613 $ins_sth->execute(@{$txn}{@cols});
4614 }
4615 $dst->dbh->commit();
4616 };
4617 if ( my $e = $EVAL_ERROR ) {
4618 PTDEBUG && _d('Error saving to --dest:', $e);
4619 if ( $dst->lost_connection($e) ) {
4620 eval {
4621 $ins_sth->finish() if $ins_sth;
4622 $dst->dbh->disconnect() if $dst->dbh;
4623 $dst->connect(AutoCommit => 0);
4624 $ins_sth = $dst->dbh->prepare($ins_sql);
4625 };
4626 if ( $EVAL_ERROR ) {
4627 warn "Lost connection to " . $dst->name . ". Will try "
4628 . "to reconnect in the next iteration.\n";
4629 }
4630 else {
4631 PTDEBUG && _d('Reconnected to MySQL (--dest)');
4632 redo ITERATION;
4633 }
4634 }
4635 else {
4636 warn "Error saving to --dest: $EVAL_ERROR";
4637 $exit_status |= 1;
4638 }
4639 }
4640 }
4641
4641 if ( !$o->get('quiet') ) {4642 if ( !$o->get('quiet') ) {
4642 print join($sep, @cols), "\n";4643 print join($sep, @cols), "\n";
4643 foreach my $txn (4644 foreach my $txn (

Subscribers

People subscribed via source and target branches