16
shift @INC; # our unshift (above)
17
shift @INC; # PerconaTest's unshift
16
18
require "$trunk/bin/pt-table-checksum";
18
20
my $dp = new DSNParser(opts=>$dsn_opts);
19
21
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
20
22
my $master_dbh = $sb->get_dbh_for('master');
23
my $slave_dbh = $sb->get_dbh_for('slave1');
22
25
if ( !$master_dbh ) {
23
26
plan skip_all => 'Cannot connect to sandbox master';
32
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
33
# so we need to specify --lock-wait-timeout=3 else the tool will die.
34
# And --max-load "" prevents waiting for status variables.
35
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
36
my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
30
my $cnf='/tmp/12345/my.sandbox.cnf';
31
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
33
$sb->create_dbs($master_dbh, [qw(test)]);
34
$sb->load_file('master', 't/pt-table-checksum/samples/before.sql');
36
# Ensure chunking works
37
$output = `$cmd --function sha1 --explain --chunk-size 200 -d test -t chunk --chunk-size-limit 0`;
38
like($output, qr/test\s+chunk\s+`film_id` > 0 AND `film_id` < '\d+'/, 'chunking works');
39
my $num_chunks = scalar(map { 1 } $output =~ m/^test/gm);
40
ok($num_chunks >= 5 && $num_chunks < 8, "Found $num_chunks chunks");
42
# Ensure chunk boundaries are put into test.checksum (bug #1850243)
43
$output = `$cmd --function sha1 -d test -t chunk --chunk-size 50 --replicate test.checksum 127.0.0.1`;
44
$output = `/tmp/12345/use --skip-column-names -e "select boundaries from test.checksum where db='test' and tbl='chunk' and chunk=0"`;
46
like ( $output, qr/`film_id` = 0/, 'chunk boundaries stored right');
42
# --chunk-size is dynamic; it varies according to --chunk-time and
43
# however fast the server happens to be. So test this is difficult
44
# because it's inherently nondeterministic. However, with one table,
45
# the first chunk should equal the chunk size, and the 2nd chunk should
46
# larger, unless it takes your machine > 0.5s to select 100 rows.
48
pt_table_checksum::main(@args, qw(--quiet -t sakila.rental));
50
$row = $master_dbh->selectrow_arrayref("select lower_boundary, upper_boundary from percona.checksums where db='sakila' and tbl='rental' and chunk=1");
54
"First chunk is default size"
57
$row = $master_dbh->selectrow_arrayref("select lower_boundary, upper_boundary from percona.checksums where db='sakila' and tbl='rental' and chunk=2");
61
"2nd chunk lower boundary"
65
$row->[1] - $row->[0],
71
# ############################################################################
72
# Explicit --chunk-size should override auto-sizing.
73
# ############################################################################
75
pt_table_checksum::main(@args, qw(--quiet --chunk-size 100 -t sakila.city));
77
# There's 600 rows in sakila.city so there should be 6 chunks.
78
$row = $master_dbh->selectall_arrayref("select lower_boundary, upper_boundary from percona.checksums where db='sakila' and tbl='city'");
88
[undef, 1], # lower oob
89
[600, undef], # upper oob
91
"Explicit --chunk-size disables auto chunk sizing"
94
# ############################################################################
95
# Sub-second chunk-time.
96
# ############################################################################
99
sub { pt_table_checksum::main(@args,
100
qw(--quiet --chunk-time .001 -d mysql)) },
106
qr/Cannot checksum table/,
107
"Very small --chunk-time doesn't cause zero --chunk-size"
110
# #############################################################################
111
# Bug 921700: pt-table-checksum doesn't add --where to chunk-oversize test
113
# #############################################################################
114
$sb->load_file('master', 't/pt-table-checksum/samples/600cities.sql');
115
$master_dbh->do("LOAD DATA LOCAL INFILE '$trunk/t/pt-table-checksum/samples/600cities.data' INTO TABLE test.t");
116
$master_dbh->do("SET SQL_LOG_BIN=0");
117
$master_dbh->do("DELETE FROM test.t WHERE id > 100");
118
$master_dbh->do("SET SQL_LOG_BIN=1");
119
PerconaTest::wait_for_table($slave_dbh, "test.t", "id=600");
121
# Now there are 100 rows on the master and 600 on the slave.
123
sub { $exit_status = pt_table_checksum::main(@args,
124
qw(-t test.t --chunk-size 100 --where id<=100)); },
131
"Zero exit status (bug 185734)"
137
"Checksummed table (bug 185734)"
48
140
# #############################################################################