diff --git a/t/pt-table-checksum/basics.t b/t/pt-table-checksum/basics.t index 99b7ab74..ce6ce599 100644 --- a/t/pt-table-checksum/basics.t +++ b/t/pt-table-checksum/basics.t @@ -37,7 +37,7 @@ elsif ( !@{$master_dbh->selectall_arrayref('show databases like "sakila"')} ) { plan skip_all => 'sakila database is not loaded'; } else { - plan tests => 9; + plan tests => 13; } # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic @@ -198,6 +198,52 @@ ok( "--no-recheck (just --replicate-check)" ); +# ############################################################################ +# Detect infinite loop. +# ############################################################################ +$sb->load_file('master', "t/pt-table-checksum/samples/oversize-chunks.sql"); + +$output = output( + sub { pt_table_checksum::main(@args, qw(-t osc.t --chunk-size 10)) }, + stderr => 1, +); + +like( + $output, + qr/infinite loop detected/, + "Detects infinite loop" +); + +# ############################################################################ +# Oversize chunk. +# ############################################################################ +ok( + no_diff( + sub { pt_table_checksum::main(@args, + qw(-t osc.t2 --chunk-size 8 --explain --explain)) }, + "$sample/oversize-chunks.txt", + ), + "Upper boundary same as next lower boundary" +); + +$output = output( + sub { pt_table_checksum::main(@args, + qw(-t osc.t2 --chunk-time 0 --chunk-size 8 --chunk-size-limit 1)) }, + stderr => 1, +); + +is( + PerconaTest::count_checksum_results($output, 'skipped'), + 2, + "Skipped oversize chunks" +); + +is( + PerconaTest::count_checksum_results($output, 'errors'), + 0, + "Oversize chunks are not errors" +); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-table-checksum/oversize_chunks.t b/t/pt-table-checksum/oversize_chunks.t deleted file mode 100644 index ad36de99..00000000 --- a/t/pt-table-checksum/oversize_chunks.t +++ /dev/null @@ -1,70 +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 skip_all => 'Finish updating oversize_chunks.t'; - -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'); - -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; -} -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. -# And --max-load "" prevents waiting for status variables. -my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox'; -my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', ''); -my $row; -my $output; - -$sb->load_file('master', "t/pt-table-checksum/samples/oversize-chunks.sql"); - -# pt-table-checksum 2.0 isn't fooled as easily as 1.0 was. This -# test results in: -# Error checksumming table osc.t: Possible infinite loop detected! -# The lower boundary for chunk 2 is <13, 13> and the lower boundary -# for chunk 3 is also <13, 13>. This usually happens when using a -# non-unique single column index. The current chunk index for table -# osc.t is i which is not unique and covers 1 column. - -ok( - no_diff( - sub { pt_table_checksum::main(@args, - qw(-t osc.t --chunk-size 10)) }, - "t/pt-table-checksum/samples/oversize-chunks.txt", - ), - "Skip oversize chunk" -); - -ok( - no_diff( - sub { pt_table_checksum::main(@args, - qw(-t osc.t --chunk-size 10 --chunk-size-limit 0)) }, - "t/pt-table-checksum/samples/oversize-chunks-allowed.txt" - ), - "Allow oversize chunk" -); - -# ############################################################################# -# Done. -# ############################################################################# -$sb->wipe_clean($master_dbh); -exit; diff --git a/t/pt-table-checksum/samples/checksum_tbl.sql b/t/pt-table-checksum/samples/checksum_tbl.sql deleted file mode 100644 index 57eecabc..00000000 --- a/t/pt-table-checksum/samples/checksum_tbl.sql +++ /dev/null @@ -1,14 +0,0 @@ -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(100) NOT NULL, - 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; diff --git a/t/pt-table-checksum/samples/oversize-chunks-allowed.txt b/t/pt-table-checksum/samples/oversize-chunks-allowed.txt deleted file mode 100644 index 7cb0412e..00000000 --- a/t/pt-table-checksum/samples/oversize-chunks-allowed.txt +++ /dev/null @@ -1,6 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -osc t 0 127.1 MyISAM 0 NULL 0 0 NULL NULL -osc t 1 127.1 MyISAM 23 54a0c224 0 0 NULL NULL -osc t 2 127.1 MyISAM 0 NULL 0 0 NULL NULL -osc t 3 127.1 MyISAM 3 16533cd7 0 0 NULL NULL -osc t 4 127.1 MyISAM 0 NULL 0 0 NULL NULL diff --git a/t/pt-table-checksum/samples/oversize-chunks.sql b/t/pt-table-checksum/samples/oversize-chunks.sql index 40389ebc..5b27f780 100644 --- a/t/pt-table-checksum/samples/oversize-chunks.sql +++ b/t/pt-table-checksum/samples/oversize-chunks.sql @@ -7,6 +7,27 @@ create table t ( ); insert into t values - (1),(2),(3), - (10),(11),(12),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(24), - (101),(102),(103); + (1), + (2), + (3), + (10), + (11), + (12), + + -- 15 dupes + (13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13),(13), + + (24), + (101), + (102), + (103); + +create table t2 ( + c char, + index (c) +); + +insert into t2 values + ('a'), ('a'), ('a'), ('a'), ('a'), ('a'), ('a'), ('b'), ('b'), ('b'), ('c'), + ('c'), ('d'), ('d'), ('d'), ('d'), + ('e'), ('f'), ('g'); diff --git a/t/pt-table-checksum/samples/oversize-chunks.txt b/t/pt-table-checksum/samples/oversize-chunks.txt index bf197065..6e881153 100644 --- a/t/pt-table-checksum/samples/oversize-chunks.txt +++ b/t/pt-table-checksum/samples/oversize-chunks.txt @@ -1,6 +1,12 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -osc t 0 127.1 MyISAM 0 NULL 0 0 NULL NULL -osc t 1 127.1 MyISAM OVERSIZE NULL NULL NULL NULL NULL -osc t 2 127.1 MyISAM 0 NULL 0 0 NULL NULL -osc t 3 127.1 MyISAM 3 16533cd7 0 0 NULL NULL -osc t 4 127.1 MyISAM 0 NULL 0 0 NULL NULL +-- +-- osc.t2 +-- + +REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*) AS cnt, COALESCE(LOWER(CONV(BIT_XOR(CAST(CRC32(CONCAT_WS('#', `c`, CONCAT(ISNULL(`c`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `osc`.`t2` FORCE INDEX(`c`) WHERE (((? IS NULL OR `c` >= ?))) AND (((? IS NULL OR `c` <= ?))) ORDER BY `c` /*checksum chunk*/ + +SELECT /*!40001 SQL_NO_CACHE */ `c`, `c` FROM `osc`.`t2` FORCE INDEX(`c`) WHERE (((? IS NULL OR `c` >= ?))) ORDER BY `c` LIMIT ?, 2 /*next chunk boundary*/ + +1 a,a b,b +2 b,b d,d +3 d,d g,g + diff --git a/t/pt-table-checksum/samples/resume-chunked-complete.txt b/t/pt-table-checksum/samples/resume-chunked-complete.txt deleted file mode 100644 index b1e773e2..00000000 --- a/t/pt-table-checksum/samples/resume-chunked-complete.txt +++ /dev/null @@ -1,9 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -test resume 0 127.0.0.1 InnoDB 3 f4dbdf21 0 0 NULL NULL -test resume 0 127.1 InnoDB 3 f4dbdf21 0 0 NULL NULL -test resume 1 127.0.0.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 1 127.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 2 127.0.0.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 2 127.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 3 127.0.0.1 InnoDB 4 bce55ff5 0 0 NULL NULL -test resume 3 127.1 InnoDB 4 bce55ff5 0 0 NULL NULL diff --git a/t/pt-table-checksum/samples/resume-chunked-partial.txt b/t/pt-table-checksum/samples/resume-chunked-partial.txt deleted file mode 100644 index 6574c766..00000000 --- a/t/pt-table-checksum/samples/resume-chunked-partial.txt +++ /dev/null @@ -1,5 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -test resume 0 127.0.0.1 InnoDB 3 f4dbdf21 0 0 NULL NULL -test resume 0 127.1 InnoDB 3 f4dbdf21 0 0 NULL NULL -test resume 1 127.0.0.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 1 127.1 InnoDB 3 6abf4a82 0 0 NULL NULL diff --git a/t/pt-table-checksum/samples/resume-complete.txt b/t/pt-table-checksum/samples/resume-complete.txt deleted file mode 100644 index b357ed72..00000000 --- a/t/pt-table-checksum/samples/resume-complete.txt +++ /dev/null @@ -1,3 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -test resume 0 127.0.0.1 InnoDB NULL 2465609721 0 0 NULL NULL -test resume 0 127.1 InnoDB NULL 2465609721 0 0 NULL NULL diff --git a/t/pt-table-checksum/samples/resume-partial.txt b/t/pt-table-checksum/samples/resume-partial.txt deleted file mode 100644 index 583b91bc..00000000 --- a/t/pt-table-checksum/samples/resume-partial.txt +++ /dev/null @@ -1,2 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -test resume 0 127.0.0.1 InnoDB NULL 2465609721 0 0 NULL NULL diff --git a/t/pt-table-checksum/samples/resume.sql b/t/pt-table-checksum/samples/resume.sql deleted file mode 100644 index bbe67c47..00000000 --- a/t/pt-table-checksum/samples/resume.sql +++ /dev/null @@ -1,5 +0,0 @@ -use test; -create table resume ( - i int not null unique key -) engine=innodb; -insert into test.resume values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10); diff --git a/t/pt-table-checksum/samples/resume2-chunked-complete.txt b/t/pt-table-checksum/samples/resume2-chunked-complete.txt deleted file mode 100644 index dc32f5a3..00000000 --- a/t/pt-table-checksum/samples/resume2-chunked-complete.txt +++ /dev/null @@ -1,17 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -test2 resume2 0 127.0.0.1 MyISAM 0 NULL 0 0 NULL NULL -test2 resume2 0 127.1 MyISAM 0 NULL 0 0 NULL NULL -test2 resume2 1 127.0.0.1 MyISAM 3 f4dbdf21 0 0 NULL NULL -test2 resume2 1 127.1 MyISAM 3 f4dbdf21 0 0 NULL NULL -test2 resume2 2 127.0.0.1 MyISAM 3 6abf4a82 0 0 NULL NULL -test2 resume2 2 127.1 MyISAM 3 6abf4a82 0 0 NULL NULL -test2 resume2 3 127.0.0.1 MyISAM 4 bce55ff5 0 0 NULL NULL -test2 resume2 3 127.1 MyISAM 4 bce55ff5 0 0 NULL NULL -test resume 0 127.0.0.1 InnoDB 3 f4dbdf21 0 0 NULL NULL -test resume 0 127.1 InnoDB 3 f4dbdf21 0 0 NULL NULL -test resume 1 127.0.0.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 1 127.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 2 127.0.0.1 InnoDB 4 bce55ff5 0 0 NULL NULL -test resume 2 127.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 3 127.0.0.1 InnoDB 4 bce55ff5 0 0 NULL NULL -test resume 3 127.1 InnoDB 4 bce55ff5 0 0 NULL NULL diff --git a/t/pt-table-checksum/samples/resume2-chunked-partial.txt b/t/pt-table-checksum/samples/resume2-chunked-partial.txt deleted file mode 100644 index ca2ffd9d..00000000 --- a/t/pt-table-checksum/samples/resume2-chunked-partial.txt +++ /dev/null @@ -1,6 +0,0 @@ -DATABASE TABLE CHUNK HOST ENGINE COUNT CHECKSUM TIME WAIT STAT LAG -test resume 0 127.0.0.1 InnoDB 3 f4dbdf21 0 0 NULL NULL -test resume 0 127.1 InnoDB 3 f4dbdf21 0 0 NULL NULL -test resume 1 127.0.0.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 1 127.1 InnoDB 3 6abf4a82 0 0 NULL NULL -test resume 2 127.0.0.1 InnoDB 4 bce55ff5 0 0 NULL NULL diff --git a/t/pt-table-checksum/samples/resume2.sql b/t/pt-table-checksum/samples/resume2.sql deleted file mode 100644 index b5319b39..00000000 --- a/t/pt-table-checksum/samples/resume2.sql +++ /dev/null @@ -1,7 +0,0 @@ -drop database if exists test2; -create database test2; -use test2; -create table resume2 ( - i int not null unique key -); -insert into test2.resume2 values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10);