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 on 2014-05-22
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 2014-05-22 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
1=== modified file 'bin/pt-deadlock-logger'
2--- bin/pt-deadlock-logger 2014-02-20 08:10:16 +0000
3+++ bin/pt-deadlock-logger 2014-05-22 20:53:38 +0000
4@@ -4601,43 +4601,44 @@
5 }
6 }
7 else {
8- if ( $ins_sth ) {
9- eval {
10- PTDEBUG && _d('Saving deadlock to --dest');
11- foreach my $txn (
12- sort { $a->{thread} <=> $b->{thread} } values %txns
13- ) {
14- $ins_sth->execute(@{$txn}{@cols});
15- }
16- $dst->dbh->commit();
17- };
18- if ( my $e = $EVAL_ERROR ) {
19- PTDEBUG && _d('Error saving to --dest:', $e);
20- if ( $dst->lost_connection($e) ) {
21- eval {
22- $ins_sth->finish() if $ins_sth;
23- $dst->dbh->disconnect() if $dst->dbh;
24- $dst->connect(AutoCommit => 0);
25- $ins_sth = $dst->dbh->prepare($ins_sql);
26- };
27- if ( $EVAL_ERROR ) {
28- warn "Lost connection to " . $dst->name . ". Will try "
29- . "to reconnect in the next iteration.\n";
30- }
31- else {
32- PTDEBUG && _d('Reconnected to MySQL (--dest)');
33- redo ITERATION;
34- }
35- }
36- else {
37- warn "Error saving to --dest: $EVAL_ERROR";
38- $exit_status |= 1;
39- }
40- }
41- }
42-
43 if ( $fingerprint ne $last_fingerprint ) {
44 PTDEBUG && _d('New deadlock');
45+
46+ if ( $ins_sth ) {
47+ eval {
48+ PTDEBUG && _d('Saving deadlock to --dest');
49+ foreach my $txn (
50+ sort { $a->{thread} <=> $b->{thread} } values %txns
51+ ) {
52+ $ins_sth->execute(@{$txn}{@cols});
53+ }
54+ $dst->dbh->commit();
55+ };
56+ if ( my $e = $EVAL_ERROR ) {
57+ PTDEBUG && _d('Error saving to --dest:', $e);
58+ if ( $dst->lost_connection($e) ) {
59+ eval {
60+ $ins_sth->finish() if $ins_sth;
61+ $dst->dbh->disconnect() if $dst->dbh;
62+ $dst->connect(AutoCommit => 0);
63+ $ins_sth = $dst->dbh->prepare($ins_sql);
64+ };
65+ if ( $EVAL_ERROR ) {
66+ warn "Lost connection to " . $dst->name . ". Will try "
67+ . "to reconnect in the next iteration.\n";
68+ }
69+ else {
70+ PTDEBUG && _d('Reconnected to MySQL (--dest)');
71+ redo ITERATION;
72+ }
73+ }
74+ else {
75+ warn "Error saving to --dest: $EVAL_ERROR";
76+ $exit_status |= 1;
77+ }
78+ }
79+ }
80+
81 if ( !$o->get('quiet') ) {
82 print join($sep, @cols), "\n";
83 foreach my $txn (

Subscribers

People subscribed via source and target branches