Update issue_388.t, issue_47.t, issue_602.t. Rename issue_81.t to error_handling.t. Move issue_69.t tests into basics.t and remove issue_69.t.

This commit is contained in:
Daniel Nichter
2011-10-13 12:46:44 -06:00
parent dfcb7dc157
commit 60d8b1a710
9 changed files with 119 additions and 121 deletions

View File

@@ -6179,8 +6179,8 @@ my %warn_code = (
# Error: 1265 SQLSTATE: 01000 (WARN_DATA_TRUNCATED)
# Message: Data truncated for column '%s' at row %ld
1265 => {
pattern => qr/for column '(?:lower|upper)_boundary'/,
warning => "WHERE clause too large for boundaries.",
# any pattern
# use MySQL's message for this warning
},
);
@@ -6241,19 +6241,24 @@ sub exec_nibble {
MKDEBUG && _d($sql_warn);
my $warnings = $dbh->selectall_arrayref($sql_warn, { Slice => {} } );
foreach my $warning ( @$warnings ) {
my $code = ($warning->{code} || 0);
my $code = ($warning->{code} || 0);
my $message = $warning->{message};
if ( $ignore_code{$code} ) {
MKDEBUG && _d('Ignoring warning:', $code, $warning->{message});
MKDEBUG && _d('Ignoring warning:', $code, $message);
next;
}
elsif ( $warn_code{$code}
&& $warning->{message} =~ m/$warn_code{$code}->{pattern}/ )
&& (!$warn_code{$code}->{pattern}
|| $message =~ m/$warn_code{$code}->{pattern}/) )
{
if ( !$tbl->{"warned_code_$code"} ) { # warn once per table
if ( $o->get('quiet') < 2 ) {
warn ts("Checksum query for table $tbl->{db}.$tbl->{tbl} "
. "caused MySQL error $code: "
. $warn_code{$code}->{warning} . "\n");
. ($warn_code{$code}->{message}
? $warn_code{$code}->{message}
: $message)
. "\n");
}
$tbl->{"warned_code_$code"} = 1;
$tbl->{checksum_results}->{errors}++;

View File

@@ -31,7 +31,7 @@ elsif ( !@{$master_dbh->selectall_arrayref('show databases like "sakila"')} ) {
plan skip_all => 'sakila database is not loaded';
}
else {
plan tests => 8;
plan tests => 9;
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
@@ -174,8 +174,26 @@ is_deeply(
"--emptry-replicate-table on by default"
) or print STDERR Dumper($row);
# ############################################################################
# --[no]recheck
# ############################################################################
$exit_status = pt_table_checksum::main(@args,
qw(--quiet --quiet --chunk-time 0 --chunk-size 100 -t sakila.city));
$slave_dbh->do("update percona.checksums set this_crc='' where db='sakila' and tbl='city' and (chunk=1 or chunk=6)");
ok(
no_diff(
sub { pt_table_checksum::main(@args, qw(--no-recheck)) },
"$sample/no-recheck.txt",
),
"--no-recheck (just --replicate-check)"
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
#$sb->wipe_clean($master_dbh);
exit;

View File

@@ -23,12 +23,14 @@ if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
else {
plan tests => 1;
plan tests => 2;
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
# so we need to specify --lock-wait-timeout=3 else the tool will die.
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
my @args = ($master_dsn, qw(--lock-wait-timeout 3));
my $output;
my $cnf='/tmp/12345/my.sandbox.cnf';
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
$sb->create_dbs($master_dbh, [qw(test)]);
@@ -36,8 +38,26 @@ $sb->create_dbs($master_dbh, [qw(test)]);
# Issue 81: put some data that's too big into the boundaries table
# #############################################################################
$sb->load_file('master', 't/pt-table-checksum/samples/checksum_tbl_truncated.sql');
$output = `$cmd --ignore-databases sakila,mysql --empty-replicate-table --replicate test.checksum 2>&1`;
like($output, qr/boundaries/, 'Truncation causes an error');
$output = output(
sub { pt_table_checksum::main(@args,
qw(--replicate test.truncated_checksums -t sakila.film_category),
qw(--chunk-time 0 --chunk-size 100) ) },
stderr => 1,
);
like(
$output,
qr/MySQL error 1265: Data truncated/,
"MySQL error 1265: Data truncated for column"
);
my (@errors) = $output =~ m/error/;
is(
scalar @errors,
1,
"Only one warning for MySQL error 1265"
);
# #############################################################################
# Done.

View File

@@ -26,8 +26,11 @@ else {
plan tests => 2;
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
# so we need to specify --lock-wait-timeout=3 else the tool will die.
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
my @args = ($master_dsn, qw(--lock-wait-timeout 3));
my $output;
my $cnf = '/tmp/12345/my.sandbox.cnf';
# #############################################################################
# Issue 388: mk-table-checksum crashes when column with comma in the name
@@ -39,7 +42,9 @@ $sb->load_file('master', 't/lib/samples/tables/issue-388.sql', 'test');
$dbh->do('insert into test.foo values (null, "john, smith")');
$output = `$trunk/bin/pt-table-checksum -F $cnf h=127.1 -d test 2>&1`;
$output = output(
sub { pt_table_checksum::main(@args, qw(-d test)) },
);
unlike(
$output,
@@ -49,7 +54,7 @@ unlike(
like(
$output,
qr/test\s+foo\s+0\s+127.1\s+MyISAM\s+NULL\s+1906802343/,
qr/^\S+\s+0\s+0\s+1\s+1\s+/m,
'Checksums the table (issue 388)'
);

View File

@@ -18,21 +18,20 @@ require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $master_dbh = $sb->get_dbh_for('master');
my $slave_dbh = $sb->get_dbh_for('slave1');
if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
elsif ( !$slave_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave';
}
else {
plan tests => 2;
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
# so we need to specify --lock-wait-timeout=3 else the tool will die.
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
my @args = ($master_dsn, qw(--lock-wait-timeout 3));
my $output;
my $cnf='/tmp/12345/my.sandbox.cnf';
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
my $row;
$sb->create_dbs($master_dbh, [qw(test)]);
$sb->load_file('master', 't/pt-table-checksum/samples/issue_47.sql');
@@ -41,15 +40,31 @@ $sb->load_file('master', 't/pt-table-checksum/samples/issue_47.sql');
# Issue 47: TableChunker::range_num broken for very large bigint
# #############################################################################
$output = `/tmp/12345/use -e 'SELECT * FROM test.issue_47'`;
like($output, qr/18446744073709551615/, 'Loaded max unsigned bigint for testing issue 47');
# pt-table-checksum 2.0 doesn't use TableChunker; it uses NibbleIterator.
# But we'll test this anyway to make sure that NibbleIterator can't handle
# very larger integers.
$output = `$cmd P=12346 -d test -t issue_47 --chunk-size 4 2>&1`;
unlike($output, qr/Chunk size is too small/, 'Unsigned bigint chunks (issue 47)');
$output = pt_table_checksum::main(@args, qw(-t test.issue_47),
qw(--chunk-time 0 --chunk-size 3 --quiet));
is(
$output,
"0",
"No error nibbling very large int"
);
$row = $master_dbh->selectall_arrayref("select lower_boundary, upper_boundary from percona.checksums where db='test' and tbl='issue_47' order by chunk");
is_deeply(
$row,
[
[ '1', '300' ],
[ '1000', '2220293' ],
[ '65553510', '18446744073709551615' ],
],
"Uses very large int as chunk boundary"
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
$sb->wipe_clean($slave_dbh);
#$sb->wipe_clean($master_dbh);
exit;

View File

@@ -26,8 +26,12 @@ else {
plan tests => 1;
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
# so we need to specify --lock-wait-timeout=3 else the tool will die.
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
my @args = ($master_dsn, qw(--lock-wait-timeout 3));
my $output;
my $cnf = '/tmp/12345/my.sandbox.cnf';
$sb->load_file('master', 't/pt-table-checksum/samples/issue_602.sql');
# #############################################################################
@@ -35,14 +39,13 @@ $sb->load_file('master', 't/pt-table-checksum/samples/issue_602.sql');
# #############################################################################
$output = output(
sub {
pt_table_checksum::main("F=$cnf", qw(-t issue_602.t --chunk-size 5)) },
sub { pt_table_checksum::main(@args, qw(-t issue_602.t --chunk-size 5)) },
stderr => 1,
);
like(
$output,
qr/^issue_602\s+t\s+2/m,
qr/^\S+\s+0\s+0\s+11\s+2\s+/m,
"Checksums table despite invalid datetime"
);

View File

@@ -1,75 +0,0 @@
#!/usr/bin/env perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More;
use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $master_dbh = $sb->get_dbh_for('master');
my $slave_dbh = $sb->get_dbh_for('slave1');
if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
elsif ( !$slave_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave';
}
else {
plan tests => 2;
}
`$trunk/sandbox/test-env reset >/dev/null`;
my $output;
my $cnf='/tmp/12345/my.sandbox.cnf';
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
$sb->create_dbs($master_dbh, [qw(test)]);
$sb->load_file('master', 't/pt-table-checksum/samples/checksum_tbl.sql');
$sb->load_file('master', 't/pt-table-checksum/samples/issue_21.sql');
# #############################################################################
# Issue 69: mk-table-checksum should be able to re-checksum things that differ
# #############################################################################
`$cmd -d test --replicate test.checksum`;
$slave_dbh->do("update test.checksum set this_crc='' where test.checksum.tbl = 'issue_21'");
# Can't use $cmd; see http://code.google.com/p/maatkit/issues/detail?id=802
`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --replicate test.checksum --replicate-check 1 2>&1`;
$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --replicate test.checksum --replicate-check 1 --recheck`;
like(
$output,
qr/^test\s+issue_21\s+0\s+127.1\s+InnoDB\s+5\s+b88b4eff\s+\d\s+NULL\s+NULL\s+NULL$/m,
'--recheck reports inconsistent table like --replicate'
);
# Now check that --recheck actually caused the inconsistent table to be
# re-checksummed on the master.
$output = 'foo';
$output = `$cmd --replicate test.checksum --replicate-check 1`;
is(
$output,
'',
'--recheck re-checksummed inconsistent table; it is now consistent'
);
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
$sb->wipe_clean($slave_dbh);
exit;

View File

@@ -1,15 +1,17 @@
CREATE DATABASE IF NOT EXISTS test;
USE test;
DROP TABLE IF EXISTS checksum;
CREATE TABLE checksum (
db char(64) NOT NULL,
tbl char(64) NOT NULL,
chunk int NOT NULL,
boundaries char(1) NOT NULL, -- should cause a truncation
this_crc char(40) NOT NULL,
this_cnt int NOT NULL,
master_crc char(40) NULL,
master_cnt int NULL,
ts timestamp NOT NULL,
PRIMARY KEY (db, tbl, chunk)
);
DROP TABLE IF EXISTS truncated_checksums;
CREATE TABLE truncated_checksums (
db char(64) NOT NULL,
tbl char(64) NOT NULL,
chunk int NOT NULL,
chunk_time float NULL,
chunk_index varchar(200) NULL,
lower_boundary char(1) NOT NULL, -- will cause truncation error
upper_boundary char(1) NOT NULL, -- will cause truncation error
this_crc char(40) NOT NULL,
this_cnt int NOT NULL,
master_crc char(40) NULL,
master_cnt int NULL,
ts timestamp NOT NULL,
PRIMARY KEY (db, tbl, chunk)
) ENGINE=InnoDB;

View File

@@ -0,0 +1,5 @@
Differences on h=127.0.0.1,P=12346
TABLE CHUNK CNT_DIFF CRC_DIFF CHUNK_INDEX LOWER_BOUNDARY UPPER_BOUNDARY
sakila.city 1 0 1 PRIMARY 1 100
sakila.city 6 0 1 PRIMARY 501 600