diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 5d974edf..12bf8097 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -13181,6 +13181,13 @@ sub main { if ( $fh ) { PTDEBUG && _d('Reading', $filename); PTDEBUG && _d('File size:', $filesize); + # catch if user is trying to use an uncoverted (raw) binlog # issue 1377888 + if ( $filename && $o->get('type')->[0] eq 'binlog') { + if (is_raw_binlog($filename)) { + warn "Binlog file $filename must first be converted to text format using mysqlbinlog"; + return 1; + } + } push @read_files, { name => ($filename || "STDIN"), size => $filesize }; # Read the file offset for --resume. @@ -14722,6 +14729,14 @@ sub sanitize_event { return; } +# make an effort to check if file is a raw binlog +# (i.e. was not converted to text using mysqlbinlog) +sub is_raw_binlog { + my $filename = shift; + + return -B $filename; +} + sub _d { my ($package, undef, $line) = caller 0; @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } @@ -14798,7 +14813,8 @@ server. Before using this tool, please: pt-query-digest is a sophisticated but easy to use tool for analyzing MySQL queries. It can analyze queries from MySQL slow, general, and binary -logs, as well as C and MySQL protocol data from tcpdump. +logs. (Binary logs must first be converted to text, see L<"--type">). +It can also use C and MySQL protocol data from tcpdump. By default, the tool reports which queries are the slowest, and therefore the most important to optimize. More complex and custom-tailored reports can be created by using options like L<"--group-by">, L<"--filter">, and @@ -16134,7 +16150,13 @@ The type of input to parse. The permitted types are =item binlog -Parse a binary log file. +Parse a binary log file that has first been converted to text using mysqlbinlog. + +For example: + + mysqlbinlog mysql-bin.000441 > mysql-bin.000441.txt + + pt-query-digest --type binlog mysql-bin.000441.txt =item genlog diff --git a/t/lib/samples/binlogs/raw_binlog.log b/t/lib/samples/binlogs/raw_binlog.log new file mode 100644 index 00000000..58bd214d Binary files /dev/null and b/t/lib/samples/binlogs/raw_binlog.log differ diff --git a/t/pt-query-digest/binlog_analyses.t b/t/pt-query-digest/binlog_analyses.t index 26de9308..f8f76016 100644 --- a/t/pt-query-digest/binlog_analyses.t +++ b/t/pt-query-digest/binlog_analyses.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 3; +use Test::More tests => 4; use PerconaTest; require "$trunk/bin/pt-query-digest"; @@ -46,6 +46,26 @@ ok( 'Analysis for binlog011 - Handles 5.6 binlog with checksum CRC32', ) or diag($test_diff); + + +# ############################################################################# +# Issue 1377888: refuse to parse raw binary log +# ############################################################################# + +my $output = output( + sub { pt_query_digest::main(@args, "$trunk/t/lib/samples/binlogs/raw_binlog.log") }, + stderr => 1 +); + +like( + $output, + qr/mysqlbinlog/i, + 'Refuses to parse raw binlog file' +); + + + + # ############################################################################# # Done. # #############################################################################