pt-deadlock-logger should store query checksums

Registered by Daniel Nichter on 2012-10-11

From bug 1043924:

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

Blueprint information

Status:
Not started
Approver:
None
Priority:
Undefined
Drafter:
None
Direction:
Needs approval
Assignee:
None
Definition:
New
Series goal:
None
Implementation:
Unknown
Milestone target:
None

Related branches

Sprints

Whiteboard

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.