pt-qry-dgst: clearer doc about type binlog. Also try to detect binlog file type-1377888

This commit is contained in:
Frank Cizmich
2014-10-06 17:25:52 -02:00
parent 4ba15b4887
commit 1887ae5770
2 changed files with 42 additions and 3 deletions

View File

@@ -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";
exit 1;
}
}
push @read_files, { name => ($filename || "STDIN"), size => $filesize };
# Read the file offset for --resume.
@@ -14722,6 +14729,24 @@ 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;
my $output;
eval {
$output = `file $filename`;
};
# if we can't determine file type, let's assume it's ok
if ($EVAL_ERROR || !$output) {
return 0;
}
return $output =~ /MySQL\s*replication/i;
}
sub _d {
my ($package, undef, $line) = caller 0;
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
@@ -14798,7 +14823,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<SHOW PROCESSLIST> and MySQL protocol data from tcpdump.
logs. ( Binary logs must first be converted to text, see L<"--type"> ).
It can also use C<SHOW PROCESSLIST> 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 +16160,7 @@ The type of input to parse. The permitted types are
=item binlog
Parse a binary log file.
Parse a binary log file that has been converted to text using mysqlbinlog.
=item genlog

View File

@@ -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,19 @@ 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 = `$trunk/bin/pt-query-digest --type binlog '$trunk/t/pt-query-digest/samples/raw_binlog.log' 2>&1`;
ok(
$output =~ /mysqlbinlog/i ,
'Refuses to parse raw binlog file.'
);
# #############################################################################
# Done.
# #############################################################################