pt-deadlock-logger should store query checksums

Bug #1043924 reported by Baron Schwartz
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
Invalid
Undecided
Unassigned

Bug Description

To help analyze information on which deadlocks are most frequent, pt-deadlock-logger should store a checksum of the query's fingerprint with the record it inserts. A quick and dirty hack in my local copy: add a couple of modules, then:

+# ###########################################################################
 # This is a combination of modules and programs in one -- a runnable module.
 # http://www.perl.com/pub/a/2006/07/13/lightning-articles.html?page=last
 # Or, look it up in the Camel book on pages 642 and 643 in the 3rd edition.
@@ -2371,6 +3515,7 @@
 use English qw(-no_match_vars);
 use List::Util qw(max);
 use Socket qw(inet_aton);
+Transformers->import(qw(make_checksum));
 use sigtrap qw(handler finish untrapped normal-signals);

 use constant PTDEBUG => $ENV{PTDEBUG} || 0;
@@ -2392,6 +3537,8 @@
 my $n = qr/([^`\s]+)/; # MySQL object name
 my $w = qr/(\w+)/; # Words
 my $s = qr/(\d{6} .\d:\d\d:\d\d)/; # InnoDB timestamp
+my $qp = new QueryParser();
+my $qr = new QueryRewriter(QueryParser=>$qp);

 # A thread's proc_info can be at least 98 different things I've found in the
 # source. Fortunately, most of them begin with a gerunded verb. These are
@@ -2489,7 +3636,7 @@
    }

    my @cols = qw( server ts thread txn_id txn_time user hostname ip db tbl idx
- lock_type lock_mode wait_hold victim query );
+ lock_type lock_mode wait_hold victim query checksum );
    if ( $o->got('columns') ) {
       @cols = grep { $o->get('columns')->{$_} } @cols;
    }
@@ -2551,6 +3698,7 @@
       if ( $ins_sth ) {
          foreach my $txn (sort { $a->{thread} <=> $b->{thread} } values %txns) {
             die $text unless $txn->{db};
+ $txn->{checksum} = make_checksum($qr->fingerprint($txn->{query} || ''));
             $ins_sth->execute(@{$txn}{@cols});
          }
          $dest_dbh->commit();
@@ -3108,6 +4256,7 @@
    wait_hold char(1) NOT NULL,
    victim tinyint unsigned NOT NULL,
    query text NOT NULL,
+ checksum char(32) NOT NULL,
    PRIMARY KEY (server,ts,thread)
  ) ENGINE=InnoDB

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Is this a bug or feature? :-)

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :
Changed in percona-toolkit:
status: New → Invalid
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PT-1017

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers