Merge lp:~percona-toolkit-dev/percona-toolkit/pt-kill-should-print-query-fingerprint-hash-after-killing-a-query-1391240 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.13

Proposed by Frank Cizmich
Status: Merged
Approved by: Daniel Nichter
Approved revision: 613
Merged at revision: 614
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pt-kill-should-print-query-fingerprint-hash-after-killing-a-query-1391240
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.13
Diff against target: 91 lines (+33/-2)
2 files modified
bin/pt-kill (+22/-1)
t/pt-kill/match.t (+11/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pt-kill-should-print-query-fingerprint-hash-after-killing-a-query-1391240
Reviewer Review Type Date Requested Status
Daniel Nichter Needs Fixing
Review via email: mp+245160@code.launchpad.net

Description of the change

Adds a --fingerprint option to pt-kill
This prints the hash fingerprint after every query kill (or print), equivalent to the one in pt-query-digest.
This is useful for cross-referencing.

Note:
A tiny modification was made in the MasterSlave module fatpacked in pt-kill.
Since most tools are out of sync with that module, I left the delicate task of synching them for later, since the risks outweigh the benefits at this point.

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

This mixes terms: fingerprint is "select c from t where id=?", checksum is 0xA4F90EC8, so --fingerprint is misleading: users will expect the former. Look in pqd docs and see if we call it "query ID" or "query checksum" and then either --query-id or --query-checksum.

Also the line

   my $chksm = uc substr(md5_hex($fp), -16);

duplicates Transformers::make_checksum(). Granted it's just one line though.

review: Needs Fixing
613. By Frank Cizmich

used Transformers::make_checksum. Changed option to --query-id

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-kill'
2--- bin/pt-kill 2014-11-11 13:28:27 +0000
3+++ bin/pt-kill 2015-01-12 17:24:08 +0000
4@@ -4007,7 +4007,7 @@
5 die "You do not have the PROCESS privilege";
6 }
7
8- $sql = 'SHOW PROCESSLIST';
9+ $sql = 'SHOW FULL PROCESSLIST';
10 PTDEBUG && _d($dbh, $sql);
11 grep { $_->{command} =~ m/Binlog Dump/i }
12 map { # Lowercase the column names
13@@ -6567,6 +6567,7 @@
14 use English qw(-no_match_vars);
15 use POSIX qw(setsid);
16 use List::Util qw(max);
17+use Digest::MD5 qw(md5_hex);
18
19 use Data::Dumper;
20 $Data::Dumper::Indent = 1;
21@@ -7101,6 +7102,11 @@
22 $query->{Id}, ($query->{Command} || 'NULL'), $query->{Time},
23 ($query->{Info} || 'NULL');
24 }
25+ if ( $o->get('query-id') ) {
26+ my $fp = $qr->fingerprint($query->{'Info'});
27+ my $chksm = Transformers::make_checksum($fp);
28+ print "Query ID: 0x$chksm\n";
29+ }
30 if ( $o->get('execute-command') ) {
31 exec_cmd($o->get('execute-command'));
32 msg('Executed ' . $o->get('execute-command'));
33@@ -7487,6 +7493,7 @@
34
35 It is permissible for the code to have side effects (to alter C<$event>).
36
37+
38 =item --group-by
39
40 type: string
41@@ -7590,6 +7597,20 @@
42
43 Port number to use for connection.
44
45+=item --query-id
46+
47+Prints an ID of the query that was just killed. This is
48+equivalent to the "ID" output of pt-query-digest. This allows
49+cross-referencing the output of both tools.
50+
51+Example:
52+
53+ Query ID 0xE9800998ECF8427E
54+
55+Note that this is a digest (or hash) of the query's "fingerprint",
56+so queries of the same form but with different values will have the same ID.
57+See pt-query-digest for more information.
58+
59 =item --run-time
60
61 type: time
62
63=== modified file 't/pt-kill/match.t'
64--- t/pt-kill/match.t 2012-06-03 19:14:30 +0000
65+++ t/pt-kill/match.t 2015-01-12 17:24:08 +0000
66@@ -9,7 +9,7 @@
67 use strict;
68 use warnings FATAL => 'all';
69 use English qw(-no_match_vars);
70-use Test::More tests => 15;
71+use Test::More tests => 16;
72
73 use PerconaTest;
74 use Sandbox;
75@@ -137,6 +137,16 @@
76 "--match-all"
77 );
78
79+# --query-id option
80+$output = output(
81+ sub { pt_kill::main(@args, "$trunk/t/lib/samples/pl/recset011.txt", qw(--match-all --print --query-id)); }
82+);
83+like(
84+ $output,
85+ qr/0x69962191E64980E6/,
86+ '--query-id'
87+);
88+
89 # #############################################################################
90 # Live tests.
91 # #############################################################################

Subscribers

People subscribed via source and target branches

to all changes: