Update all tests except resume.t for new OobNibbleIterator. Let NibbleIterator handle resume in pt-table-checksum.

This commit is contained in:
Daniel Nichter
2011-11-15 12:35:44 -07:00
parent 619cda713f
commit 27456d00b7
29 changed files with 241 additions and 166 deletions

View File

@@ -3490,6 +3490,14 @@ sub new {
: 0; : 0;
MKDEBUG && _d('One nibble:', $one_nibble ? 'yes' : 'no'); MKDEBUG && _d('One nibble:', $one_nibble ? 'yes' : 'no');
if ( my $nibble = $args{resume} ) {
if ( !defined $nibble->{lower_boundary}
&& !defined $nibble->{upper_boundary} ) {
MKDEBUG && _d('Resuming from one nibble table');
$one_nibble = 1;
}
}
my $index = _find_best_index(%args, mysql_index => $mysql_index); my $index = _find_best_index(%args, mysql_index => $mysql_index);
if ( !$index && !$one_nibble ) { if ( !$index && !$one_nibble ) {
die "There is no good index and the table is oversized."; die "There is no good index and the table is oversized.";
@@ -3526,6 +3534,7 @@ sub new {
limit => 0, limit => 0,
nibble_sql => $nibble_sql, nibble_sql => $nibble_sql,
explain_nibble_sql => $explain_nibble_sql, explain_nibble_sql => $explain_nibble_sql,
no_more_boundaries => $args{resume} ? 1 : 0,
}; };
} }
else { else {
@@ -3543,11 +3552,15 @@ sub new {
my $from = $q->quote(@{$tbl}{qw(db tbl)}) . " FORCE INDEX(`$index`)"; my $from = $q->quote(@{$tbl}{qw(db tbl)}) . " FORCE INDEX(`$index`)";
my $order_by = join(', ', map {$q->quote($_)} @{$index_cols}); my $order_by = join(', ', map {$q->quote($_)} @{$index_cols});
my $first_lb_where = $where ? "($where)" : '';
if ( $args{resume} ) {
$first_lb_where .= ($where ? " AND " : '') . $asc->{boundaries}->{'>'};
}
my $first_lb_sql my $first_lb_sql
= "SELECT /*!40001 SQL_NO_CACHE */ " = "SELECT /*!40001 SQL_NO_CACHE */ "
. join(', ', map { $q->quote($_) } @{$asc->{scols}}) . join(', ', map { $q->quote($_) } @{$asc->{scols}})
. " FROM $from" . " FROM $from"
. ($where ? " WHERE $where" : '') . ($first_lb_where ? " WHERE $first_lb_where" : '')
. " ORDER BY $order_by" . " ORDER BY $order_by"
. " LIMIT 1" . " LIMIT 1"
. " /*first lower boundary*/"; . " /*first lower boundary*/";
@@ -3612,6 +3625,7 @@ sub new {
nibble_sql => $nibble_sql, nibble_sql => $nibble_sql,
explain_ub_sql => "EXPLAIN $ub_sql", explain_ub_sql => "EXPLAIN $ub_sql",
explain_nibble_sql => $explain_nibble_sql, explain_nibble_sql => $explain_nibble_sql,
resume => $args{resume},
sql => { sql => {
columns => $asc->{scols}, columns => $asc->{scols},
from => $from, from => $from,
@@ -3916,7 +3930,17 @@ sub _get_bounds {
my $dbh = $self->{Cxn}->dbh(); my $dbh = $self->{Cxn}->dbh();
$self->{first_lower} = $dbh->selectrow_arrayref($self->{first_lb_sql}); if ( my $nibble = $self->{resume} ) {
my $sth = $dbh->prepare($self->{first_lb_sql});
my @ub = split ',', $nibble->{upper_boundary};
MKDEBUG && _d($sth->{Statement}, 'params:', @ub);
$sth->execute(@ub);
$self->{first_lower} = $sth->fetchrow_arrayref();
$sth->finish();
}
else {
$self->{first_lower} = $dbh->selectrow_arrayref($self->{first_lb_sql});
}
$self->{next_lower} = $self->{first_lower}; $self->{next_lower} = $self->{first_lower};
MKDEBUG && _d('First lower boundary:', Dumper($self->{next_lower})); MKDEBUG && _d('First lower boundary:', Dumper($self->{next_lower}));
@@ -3940,6 +3964,12 @@ sub _next_boundaries {
return 1; # continue nibbling return 1; # continue nibbling
} }
if ( !$self->{next_lower} ) {
MKDEBUG && _d('At end of table');
$self->{no_more_boundaries} = 1; # for next call
return; # stop nibbling
}
if ( $self->identical_boundaries($self->{lower}, $self->{next_lower}) ) { if ( $self->identical_boundaries($self->{lower}, $self->{next_lower}) ) {
MKDEBUG && _d('Infinite loop detected'); MKDEBUG && _d('Infinite loop detected');
my $tbl = $self->{tbl}; my $tbl = $self->{tbl};
@@ -6166,28 +6196,19 @@ sub main {
} }
} }
elsif ( $last_chunk ) { # resuming elsif ( $last_chunk ) { # resuming
my $next_lb = next_lower_boundary( if ( have_more_chunks(%args, last_chunk => $last_chunk) ) {
%args,
last_chunk => $last_chunk,
Quoter => $q,
);
if ( !$next_lb ) {
# This can happen if the tool stops after the last checksum
# of a table. So we just start with the next table.
MKDEBUG && _d('Resuming from last chunk in table;',
'getting next table');
$oktonibble = 0; # don't nibbling table; next table
}
else {
$nibble_iter->set_nibble_number($last_chunk->{chunk}); $nibble_iter->set_nibble_number($last_chunk->{chunk});
$nibble_iter->set_boundary('next_lower', $next_lb); MKDEBUG && _d('Have more chunks; resuming from',
MKDEBUG && _d('Resuming from', $last_chunk->{chunk}, $last_chunk->{chunk}, 'at', $last_chunk->{ts});
'at', $last_chunk->{ts});
if ( !$o->get('quiet') ) { if ( !$o->get('quiet') ) {
print "Resuming from $tbl->{db}.$tbl->{tbl} chunk " print "Resuming from $tbl->{db}.$tbl->{tbl} chunk "
. "$last_chunk->{chunk}, timestamp $last_chunk->{ts}\n"; . "$last_chunk->{chunk}, timestamp $last_chunk->{ts}\n";
} }
} }
else {
# Problem resuming or no next lower boundary.
$oktonibble = 0; # don't nibble table; next table
}
# Just need to call us once to kick-start the resume process. # Just need to call us once to kick-start the resume process.
$last_chunk = undef; $last_chunk = undef;
@@ -6555,6 +6576,7 @@ sub main {
past_dms => $checksum_dml, past_dms => $checksum_dml,
past_select => $past_cols, past_select => $past_cols,
callbacks => $callbacks, callbacks => $callbacks,
resume => $last_chunk,
OptionParser => $o, OptionParser => $o,
Quoter => $q, Quoter => $q,
TableNibbler => $tn, TableNibbler => $tn,
@@ -7105,22 +7127,23 @@ sub last_chunk {
return $last_chunk; return $last_chunk;
} }
sub next_lower_boundary { sub have_more_chunks {
my (%args) = @_; my (%args) = @_;
my @required_args = qw(Cxn tbl last_chunk NibbleIterator Quoter); my @required_args = qw(tbl last_chunk NibbleIterator);
foreach my $arg ( @required_args ) { foreach my $arg ( @required_args ) {
die "I need a $arg argument" unless $args{$arg}; die "I need a $arg argument" unless $args{$arg};
} }
my ($cxn, $tbl, $last_chunk, $nibble_iter, $q) = @args{@required_args}; my ($tbl, $last_chunk, $nibble_iter) = @args{@required_args};
# If the last chunk (which should be the max chunk) is 1 and there # If there's no next lower boundary, then this is the last
# was no chunk index, then the table was checksummed in a single chunk. # chunk of the table.
if ( $last_chunk->{chunk} == 1 if ( !$nibble_iter->boundaries()->{next_lower} ) {
&& !$last_chunk->{chunk_index} MKDEBUG && _d('No more rows in table; resuming from next table');
&& !$nibble_iter->nibble_index() ) { return 0;
return;
} }
# The previous chunk index must match the current chunk index,
# else we don't know what to do.
my $chunk_index = $nibble_iter->nibble_index() || ''; my $chunk_index = $nibble_iter->nibble_index() || '';
if ( ($last_chunk->{chunk_index} || '') if ( ($last_chunk->{chunk_index} || '')
ne ($nibble_iter->nibble_index() || '') ) { ne ($nibble_iter->nibble_index() || '') ) {
@@ -7136,28 +7159,10 @@ sub next_lower_boundary {
. "line options. This table will be skipped and checksumming " . "line options. This table will be skipped and checksumming "
. "will resume with the next table.\n"); . "will resume with the next table.\n");
$tbl->{checksum_results}->{errors}++; $tbl->{checksum_results}->{errors}++;
return; return 0;
} }
my $sql = $nibble_iter->sql(); return 1; # more chunks
my $next_lb_sql
= "SELECT /*!40001 SQL_NO_CACHE */ "
. join(', ', map { $q->quote($_) } @{$sql->{columns}})
. " FROM $sql->{from}"
. " WHERE " . $sql->{boundaries}->{'>'}
. ($sql->{where} ? " AND ($sql->{where})" : '')
. " ORDER BY $sql->{order_by}"
. " LIMIT 1"
. " /*resume next chunk boundary*/";
MKDEBUG && _d($next_lb_sql);
my $sth = $cxn->dbh()->prepare($next_lb_sql);
my @ub = split ',', $last_chunk->{upper_boundary};
MKDEBUG && _d($sth->{Statement}, 'params:', @ub);
$sth->execute(@ub);
my $next_lb = $sth->fetchrow_arrayref();
$sth->finish();
return $next_lb;
} }
# Catches signals so we can exit gracefully. # Catches signals so we can exit gracefully.

View File

@@ -108,15 +108,15 @@ ok(
$row = $master_dbh->selectrow_arrayref("select count(*) from percona.checksums"); $row = $master_dbh->selectrow_arrayref("select count(*) from percona.checksums");
is( is(
$row->[0], $row->[0],
78, 86,
'78 checksums on master' '86 checksums on master'
); );
$row = $slave_dbh->selectrow_arrayref("select count(*) from percona.checksums"); $row = $slave_dbh->selectrow_arrayref("select count(*) from percona.checksums");
is( is(
$row->[0], $row->[0],
78, 86,
'78 checksums on slave' '86 checksums on slave'
); );
# ############################################################################ # ############################################################################
@@ -177,13 +177,14 @@ is_deeply(
[qw(issue_21 1)], [qw(issue_21 1)],
[qw(issue_21 2)], [qw(issue_21 2)],
[qw(issue_21 3)], [qw(issue_21 3)],
[qw(issue_21 4)], # lower oob
[qw(issue_21 5)], # upper oob
# fake row for chunk 999 is gone # fake row for chunk 999 is gone
[qw(other_tbl 1)], # this row is still here [qw(other_tbl 1)], # this row is still here
], ],
"--emptry-replicate-table on by default" "--emptry-replicate-table on by default"
) or print STDERR Dumper($row); ) or print STDERR Dumper($row);
# ############################################################################ # ############################################################################
# --[no]recheck # --[no]recheck
# ############################################################################ # ############################################################################

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);
@@ -32,89 +34,41 @@ else {
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox'; my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
my @args = ($master_dsn, qw(--lock-wait-timeout 3 -d issue_519 --explain --explain --chunk-size 3), '--max-load', ''); my @args = ($master_dsn, qw(--lock-wait-timeout 3 -d issue_519 --explain --explain --chunk-size 3), '--max-load', '');
my $output; my $output;
my $out = "t/pt-table-checksum/samples/";
$sb->load_file('master', "t/pt-table-checksum/samples/issue_519.sql"); $sb->load_file('master', "t/pt-table-checksum/samples/issue_519.sql");
my $default_output = "-- ok(
-- issue_519.t no_diff(
-- sub { pt_table_checksum::main(@args) },
"$out/chunkidx001.txt",
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` >= ?)) AND ((`i` <= ?)) ORDER BY `i` /*checksum chunk*/ ),
SELECT /*!40001 SQL_NO_CACHE */ `i` FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` >= ?)) ORDER BY `i` LIMIT ?, 2 /*next chunk boundary*/
1 1 3
2 4 6
3 7 9
4 10 11
";
$output = output(
sub { pt_table_checksum::main(@args) },
);
is(
$output,
$default_output,
"Chooses chunk index by default" "Chooses chunk index by default"
); );
$output = output( ok(
sub { pt_table_checksum::main(@args, qw(--chunk-index dog)) }, no_diff(
); sub { pt_table_checksum::main(@args, qw(--chunk-index dog)) },
"$out/chunkidx001.txt",
is( ),
$output,
$default_output,
"Chooses chunk index if --chunk-index doesn't exist" "Chooses chunk index if --chunk-index doesn't exist"
); );
$output = output( ok(
sub { pt_table_checksum::main(@args, qw(--chunk-index myidx)) }, no_diff(
); sub { pt_table_checksum::main(@args, qw(--chunk-index myidx)) },
"$out/chunkidx002.txt",
is( ),
$output,
"--
-- issue_519.t
--
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`myidx`) WHERE ((`i` > ?) OR (`i` = ? AND `y` >= ?)) AND ((`i` < ?) OR (`i` = ? AND `y` <= ?)) ORDER BY `i`, `y` /*checksum chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `i`, `i`, `y` FROM `issue_519`.`t` FORCE INDEX(`myidx`) WHERE ((`i` > ?) OR (`i` = ? AND `y` >= ?)) ORDER BY `i`, `y` LIMIT ?, 2 /*next chunk boundary*/
1 1,1,2000 3,3,2002
2 4,4,2003 6,6,2005
3 7,7,2006 9,9,2008
4 10,10,2009 11,11,2010
",
"Use --chunk-index" "Use --chunk-index"
); );
$output = output(
sub { pt_table_checksum::main(@args, qw(--chunk-index y)) },
);
# XXX I'm not sure what this tests thinks it's testing because index y # XXX I'm not sure what this tests thinks it's testing because index y
# is a single column index, so there's really not "left-most". # is a single column index, so there's really not "left-most".
is( ok(
$output, no_diff(
"-- sub { pt_table_checksum::main(@args, qw(--chunk-index y)) },
-- issue_519.t "$out/chunkidx003.txt",
-- ),
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` >= ?)) AND ((`y` <= ?)) ORDER BY `y` /*checksum chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `y` FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` >= ?)) ORDER BY `y` LIMIT ?, 2 /*next chunk boundary*/
1 2000 2002
2 2003 2005
3 2006 2008
4 2009 2010
",
"Chunks on left-most --chunk-index column" "Chunks on left-most --chunk-index column"
); );
@@ -127,46 +81,22 @@ SELECT /*!40001 SQL_NO_CACHE */ `y` FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE
# when --where is given but no explicit --chunk-index|column is given. # when --where is given but no explicit --chunk-index|column is given.
# Given the --where clause, MySQL will prefer the y index. # Given the --where clause, MySQL will prefer the y index.
$output = output( ok(
sub { pt_table_checksum::main(@args, "--where", "y > 2009") }, no_diff(
); sub { pt_table_checksum::main(@args, "--where", "y > 2009") },
"$out/chunkidx004.txt",
is( ),
$output,
"--
-- issue_519.t
--
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` >= ?)) AND ((`y` <= ?)) AND (y > 2009) ORDER BY `y` /*checksum chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `y` FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` >= ?)) AND (y > 2009) ORDER BY `y` LIMIT ?, 2 /*next chunk boundary*/
1 2010 2010
",
"Auto-chosen --chunk-index for --where (issue 378)" "Auto-chosen --chunk-index for --where (issue 378)"
); );
# If user specifies --chunk-index, then ignore the index MySQL wants to # If user specifies --chunk-index, then ignore the index MySQL wants to
# use (y in this case) and use the user's index. # use (y in this case) and use the user's index.
$output = output( ok(
sub { pt_table_checksum::main(@args, qw(--chunk-index PRIMARY), no_diff(
"--where", "y > 2009") }, sub { pt_table_checksum::main(@args, qw(--chunk-index PRIMARY),
); "--where", "y > 2009") },
"$out/chunkidx005.txt",
is( ),
$output,
"--
-- issue_519.t
--
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` >= ?)) AND ((`i` <= ?)) AND (y > 2009) ORDER BY `i` /*checksum chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `i` FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` >= ?)) AND (y > 2009) ORDER BY `i` LIMIT ?, 2 /*next chunk boundary*/
1 11 11
",
"Explicit --chunk-index overrides MySQL's index for --where" "Explicit --chunk-index overrides MySQL's index for --where"
); );

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);
@@ -81,11 +83,12 @@ is_deeply(
[301, 400], [301, 400],
[401, 500], [401, 500],
[501, 600], [501, 600],
[undef, 1], # lower oob
[600, undef], # upper oob
], ],
"--chunk-time=0 disables auto-adjusting --chunk-size" "--chunk-time=0 disables auto-adjusting --chunk-size"
); );
# ############################################################################ # ############################################################################
# Sub-second chunk-time. # Sub-second chunk-time.
# ############################################################################ # ############################################################################

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -14,6 +14,8 @@ use Test::More;
use Data::Dumper; use Data::Dumper;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $vp = new VersionParser(); my $vp = new VersionParser();

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);
@@ -60,6 +62,8 @@ is_deeply(
[ '1', '300' ], [ '1', '300' ],
[ '1000', '2220293' ], [ '1000', '2220293' ],
[ '65553510', '18446744073709551615' ], [ '65553510', '18446744073709551615' ],
[ undef, '1' ], # lower oob
[ '18446744073709551615', undef ], # upper oob
], ],
"Uses very large int as chunk boundary" "Uses very large int as chunk boundary"
); );
@@ -67,5 +71,5 @@ is_deeply(
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################
#$sb->wipe_clean($master_dbh); $sb->wipe_clean($master_dbh);
exit; exit;

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);
@@ -44,9 +46,9 @@ $output = output(
stderr => 1, stderr => 1,
); );
like( is(
$output, PerconaTest::count_checksum_results($output, 'rows'),
qr/^\S+\s+0\s+0\s+11\s+2\s+/m, 11,
"Checksums table despite invalid datetime" "Checksums table despite invalid datetime"
); );

View File

@@ -12,6 +12,8 @@ use English qw(-no_match_vars);
use Test::More tests => 17; use Test::More tests => 17;
use PerconaTest; use PerconaTest;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $output; my $output;

View File

@@ -19,6 +19,8 @@ $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -19,7 +19,10 @@ $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $master_dbh = $sb->get_dbh_for('master'); my $master_dbh = $sb->get_dbh_for('master');

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -4,6 +4,10 @@
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('#', `i`, `c`)) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `test`.`ascii` FORCE INDEX(`c`) WHERE ((`c` >= ?)) AND ((`c` <= ?)) ORDER BY `c` /*checksum chunk*/ 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('#', `i`, `c`)) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `test`.`ascii` FORCE INDEX(`c`) WHERE ((`c` >= ?)) AND ((`c` <= ?)) ORDER BY `c` /*checksum chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `test`.`ascii` FORCE INDEX(`c`) WHERE ((`c` < ?)) ORDER BY `c` /*past lower chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `test`.`ascii` FORCE INDEX(`c`) WHERE ((`c` > ?)) ORDER BY `c` /*past upper chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `c` FROM `test`.`ascii` FORCE INDEX(`c`) WHERE ((`c` >= ?)) ORDER BY `c` LIMIT ?, 2 /*next chunk boundary*/ SELECT /*!40001 SQL_NO_CACHE */ `c` FROM `test`.`ascii` FORCE INDEX(`c`) WHERE ((`c` >= ?)) ORDER BY `c` LIMIT ?, 2 /*next chunk boundary*/
1 burt 1 burt
@@ -14,4 +18,6 @@ SELECT /*!40001 SQL_NO_CACHE */ `c` FROM `test`.`ascii` FORCE INDEX(`c`) WHERE (
6 Natalie Sean 6 Natalie Sean
7 sidney Zesus! 7 sidney Zesus!
8 Zesus!! ZESUS!!! 8 Zesus!! ZESUS!!!
9
10 ZESUS!!!

View File

@@ -1,2 +1,2 @@
ERRORS DIFFS ROWS CHUNKS SKIPPED TABLE ERRORS DIFFS ROWS CHUNKS SKIPPED TABLE
0 0 142 8 0 test.ascii 0 0 142 10 0 test.ascii

View File

@@ -0,0 +1,19 @@
--
-- issue_519.t
--
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` >= ?)) AND ((`i` <= ?)) ORDER BY `i` /*checksum chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` < ?)) ORDER BY `i` /*past lower chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` > ?)) ORDER BY `i` /*past upper chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `i` FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` >= ?)) ORDER BY `i` LIMIT ?, 2 /*next chunk boundary*/
1 1 3
2 4 6
3 7 9
4 10 11
5 1
6 11

View File

@@ -0,0 +1,19 @@
--
-- issue_519.t
--
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`myidx`) WHERE ((`i` > ?) OR (`i` = ? AND `y` >= ?)) AND ((`i` < ?) OR (`i` = ? AND `y` <= ?)) ORDER BY `i`, `y` /*checksum chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`myidx`) WHERE ((`i` < ?) OR (`i` = ? AND `y` < ?)) ORDER BY `i`, `y` /*past lower chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`myidx`) WHERE ((`i` > ?) OR (`i` = ? AND `y` > ?)) ORDER BY `i`, `y` /*past upper chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `i`, `i`, `y` FROM `issue_519`.`t` FORCE INDEX(`myidx`) WHERE ((`i` > ?) OR (`i` = ? AND `y` >= ?)) ORDER BY `i`, `y` LIMIT ?, 2 /*next chunk boundary*/
1 1,1,2000 3,3,2002
2 4,4,2003 6,6,2005
3 7,7,2006 9,9,2008
4 10,10,2009 11,11,2010
5 1,1,2000
6 11,11,2010

View File

@@ -0,0 +1,19 @@
--
-- issue_519.t
--
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` >= ?)) AND ((`y` <= ?)) ORDER BY `y` /*checksum chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` < ?)) ORDER BY `y` /*past lower chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` > ?)) ORDER BY `y` /*past upper chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `y` FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` >= ?)) ORDER BY `y` LIMIT ?, 2 /*next chunk boundary*/
1 2000 2002
2 2003 2005
3 2006 2008
4 2009 2010
5 2000
6 2010

View File

@@ -0,0 +1,16 @@
--
-- issue_519.t
--
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` >= ?)) AND ((`y` <= ?)) AND (y > 2009) ORDER BY `y` /*checksum chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` < ?)) AND (y > 2009) ORDER BY `y` /*past lower chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` > ?)) AND (y > 2009) ORDER BY `y` /*past upper chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `y` FROM `issue_519`.`t` FORCE INDEX(`y`) WHERE ((`y` >= ?)) AND (y > 2009) ORDER BY `y` LIMIT ?, 2 /*next chunk boundary*/
1 2010 2010
2 2010
3 2010

View File

@@ -0,0 +1,16 @@
--
-- issue_519.t
--
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('#', `i`, `y`, `t`, CONCAT(ISNULL(`t`)))) AS UNSIGNED)), 10, 16)), 0) AS crc FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` >= ?)) AND ((`i` <= ?)) AND (y > 2009) ORDER BY `i` /*checksum chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` < ?)) AND (y > 2009) ORDER BY `i` /*past lower chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` > ?)) AND (y > 2009) ORDER BY `i` /*past upper chunk*/
SELECT /*!40001 SQL_NO_CACHE */ `i` FROM `issue_519`.`t` FORCE INDEX(`PRIMARY`) WHERE ((`i` >= ?)) AND (y > 2009) ORDER BY `i` LIMIT ?, 2 /*next chunk boundary*/
1 11 11
2 11
3 11

View File

@@ -4,9 +4,15 @@
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*/ 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*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `osc`.`t2` FORCE INDEX(`c`) WHERE ((((? IS NOT NULL AND `c` IS NULL) OR (`c` < ?)))) ORDER BY `c` /*past lower chunk*/
REPLACE INTO `percona`.`checksums` (db, tbl, chunk, chunk_index, lower_boundary, upper_boundary, this_cnt, this_crc) SELECT ?, ?, ?, ?, ?, ?, COUNT(*), '0' FROM `osc`.`t2` FORCE INDEX(`c`) WHERE ((((? IS NULL AND `c` IS NOT NULL) OR (`c` > ?)))) ORDER BY `c` /*past upper 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*/ 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 1 a,a b,b
2 b,b d,d 2 b,b d,d
3 d,d g,g 3 d,d g,g
4 a,a
5 g,g

View File

@@ -27,12 +27,12 @@ ERRORS DIFFS ROWS CHUNKS SKIPPED TABLE
0 0 109 1 0 sakila.country 0 0 109 1 0 sakila.country
0 0 599 1 0 sakila.customer 0 0 599 1 0 sakila.customer
0 0 1000 1 0 sakila.film 0 0 1000 1 0 sakila.film
0 0 5462 6 0 sakila.film_actor 0 0 5462 8 0 sakila.film_actor
0 0 1000 1 0 sakila.film_category 0 0 1000 1 0 sakila.film_category
0 0 1000 1 0 sakila.film_text 0 0 1000 1 0 sakila.film_text
0 0 4581 5 0 sakila.inventory 0 0 4581 7 0 sakila.inventory
0 0 6 1 0 sakila.language 0 0 6 1 0 sakila.language
0 0 16049 17 0 sakila.payment 0 0 16049 19 0 sakila.payment
0 0 16044 17 0 sakila.rental 0 0 16044 19 0 sakila.rental
0 0 2 1 0 sakila.staff 0 0 2 1 0 sakila.staff
0 0 2 1 0 sakila.store 0 0 2 1 0 sakila.store

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);

View File

@@ -13,6 +13,8 @@ use Test::More;
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
shift @INC; # our unshift (above)
shift @INC; # PerconaTest's unshift
require "$trunk/bin/pt-table-checksum"; require "$trunk/bin/pt-table-checksum";
my $dp = new DSNParser(opts=>$dsn_opts); my $dp = new DSNParser(opts=>$dsn_opts);