Merge lp:~percona-toolkit-dev/percona-toolkit/manual-for-pt-query-digest--type-binlog-is-ambiguous-1377888 into lp:~percona-toolkit-dev/percona-toolkit/release-2.2.12

Proposed by Frank Cizmich
Status: Merged
Merged at revision: 631
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/manual-for-pt-query-digest--type-binlog-is-ambiguous-1377888
Merge into: lp:~percona-toolkit-dev/percona-toolkit/release-2.2.12
Diff against target: 99 lines (+45/-3)
2 files modified
bin/pt-query-digest (+24/-2)
t/pt-query-digest/binlog_analyses.t (+21/-1)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/manual-for-pt-query-digest--type-binlog-is-ambiguous-1377888
Reviewer Review Type Date Requested Status
Daniel Nichter Needs Fixing
Review via email: mp+237332@code.launchpad.net

Description of the change

Changed DOC to make clear the fact that pt-query-digest reads binlog files that have been previously converted to text format through mysqlbinlog
Changed code to make an effort to catch attempts at processing raw binlog files.
Added test for this.

To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Needs Fixing
630. By Frank Cizmich

Improved test. Changed test file location. Added doc example.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-query-digest'
2--- bin/pt-query-digest 2014-09-25 13:48:22 +0000
3+++ bin/pt-query-digest 2014-11-05 14:42:15 +0000
4@@ -13181,6 +13181,13 @@
5 if ( $fh ) {
6 PTDEBUG && _d('Reading', $filename);
7 PTDEBUG && _d('File size:', $filesize);
8+ # catch if user is trying to use an uncoverted (raw) binlog # issue 1377888
9+ if ( $filename && $o->get('type')->[0] eq 'binlog') {
10+ if (is_raw_binlog($filename)) {
11+ warn "Binlog file $filename must first be converted to text format using mysqlbinlog";
12+ return 1;
13+ }
14+ }
15 push @read_files, { name => ($filename || "STDIN"), size => $filesize };
16
17 # Read the file offset for --resume.
18@@ -14722,6 +14729,14 @@
19 return;
20 }
21
22+# make an effort to check if file is a raw binlog
23+# (i.e. was not converted to text using mysqlbinlog)
24+sub is_raw_binlog {
25+ my $filename = shift;
26+
27+ return -B $filename;
28+}
29+
30 sub _d {
31 my ($package, undef, $line) = caller 0;
32 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
33@@ -14798,7 +14813,8 @@
34
35 pt-query-digest is a sophisticated but easy to use tool for analyzing
36 MySQL queries. It can analyze queries from MySQL slow, general, and binary
37-logs, as well as C<SHOW PROCESSLIST> and MySQL protocol data from tcpdump.
38+logs. (Binary logs must first be converted to text, see L<"--type">).
39+It can also use C<SHOW PROCESSLIST> and MySQL protocol data from tcpdump.
40 By default, the tool reports which queries are the slowest, and therefore
41 the most important to optimize. More complex and custom-tailored reports
42 can be created by using options like L<"--group-by">, L<"--filter">, and
43@@ -16134,7 +16150,13 @@
44
45 =item binlog
46
47-Parse a binary log file.
48+Parse a binary log file that has first been converted to text using mysqlbinlog.
49+
50+For example:
51+
52+ mysqlbinlog mysql-bin.000441 > mysql-bin.000441.txt
53+
54+ pt-query-digest --type binlog mysql-bin.000441.txt
55
56 =item genlog
57
58
59=== added file 't/lib/samples/binlogs/raw_binlog.log'
60Binary files t/lib/samples/binlogs/raw_binlog.log 1970-01-01 00:00:00 +0000 and t/lib/samples/binlogs/raw_binlog.log 2014-11-05 14:42:15 +0000 differ
61=== modified file 't/pt-query-digest/binlog_analyses.t'
62--- t/pt-query-digest/binlog_analyses.t 2014-07-02 20:55:31 +0000
63+++ t/pt-query-digest/binlog_analyses.t 2014-11-05 14:42:15 +0000
64@@ -9,7 +9,7 @@
65 use strict;
66 use warnings FATAL => 'all';
67 use English qw(-no_match_vars);
68-use Test::More tests => 3;
69+use Test::More tests => 4;
70
71 use PerconaTest;
72 require "$trunk/bin/pt-query-digest";
73@@ -46,6 +46,26 @@
74 'Analysis for binlog011 - Handles 5.6 binlog with checksum CRC32',
75 ) or diag($test_diff);
76
77+
78+
79+# #############################################################################
80+# Issue 1377888: refuse to parse raw binary log
81+# #############################################################################
82+
83+my $output = output(
84+ sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/binlogs/raw_binlog.log") },
85+ stderr => 1
86+);
87+
88+like(
89+ $output,
90+ qr/mysqlbinlog/i,
91+ 'Refuses to parse raw binlog file'
92+);
93+
94+
95+
96+
97 # #############################################################################
98 # Done.
99 # #############################################################################

Subscribers

People subscribed via source and target branches

to all changes: