Change SQL for --resume last chunk to fix bug 898318.

This commit is contained in:
Daniel Nichter
2011-12-19 15:48:52 -07:00
parent d3b074b14e
commit 6fad44d58c
3 changed files with 60 additions and 27 deletions
+7 -26
View File
@@ -7168,38 +7168,19 @@ sub last_chunk {
my ($dbh, $repl_table, $q) = @args{@required_args};
MKDEBUG && _d('Getting last chunk for --resume');
my $sql = "SELECT MAX(ts) FROM $repl_table WHERE master_crc IS NOT NULL";
MKDEBUG && _d($sql);
my ($max_ts) = $dbh->selectrow_array($sql);
if ( !$max_ts ) {
MKDEBUG && _d('Replicate table is empty; will not resume');
return;
}
$sql = "SELECT * FROM $repl_table "
. "WHERE ts<=? "
. "ORDER BY db DESC, tbl DESC, chunk DESC LIMIT 1";
my $sql = "SELECT * FROM $repl_table "
. "WHERE master_cnt IS NOT NULL "
. "ORDER BY ts DESC, db DESC, tbl DESC LIMIT 1";
MKDEBUG && _d($sql);
my $sth = $dbh->prepare($sql);
$sth->execute($max_ts);
$sth->execute();
my $last_chunk = $sth->fetchrow_hashref();
$sth->finish();
MKDEBUG && _d('Last chunk:', Dumper($last_chunk));
$sql = "SELECT MAX(chunk) FROM $repl_table "
. "WHERE db=? AND tbl=? AND master_crc IS NOT NULL";
MKDEBUG && _d($sql);
$sth = $dbh->prepare($sql);
$sth->execute($last_chunk->{db}, $last_chunk->{tbl});
my ($max_chunk) = $sth->fetchrow_array();
$sth->finish();
MKDEBUG && _d('Max chunk:', $max_chunk);
if ( ($last_chunk->{chunk} || 0) ne ($max_chunk || 0) ) {
warn ts("Not resuming from max chunk ("
. ($last_chunk->{chunk} || 0)
. " != "
. ($max_chunk || 0)
. "); resuming may not work correctly.\n");
if ( !$last_chunk || !$last_chunk->{ts} ) {
MKDEBUG && _d('Replicate table is empty; will not resume');
return;
}
return $last_chunk;
+42 -1
View File
@@ -29,7 +29,7 @@ elsif ( !$slave1_dbh ) {
plan skip_all => 'Cannot connect to sandbox slave';
}
else {
plan tests => 45;
plan tests => 47;
}
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
@@ -651,6 +651,47 @@ is(
"Resumed 17 chunks"
);
# ###########################################################################
# Resume from earlier table when latter tables are complete.
# ###########################################################################
# See https://bugs.launchpad.net/percona-toolkit/+bug/898318
$sb->load_file('master', "t/pt-table-checksum/samples/3tbl-resume.sql");
load_data_infile("3tbl-resume-bar", "ts='2011-11-08 00:01:08'");
is_deeply(
$master_dbh->selectall_arrayref("select db, tbl, chunk, ts from percona.checksums order by db, tbl"),
[
[qw(test t1 1), '2011-11-08 00:02:01'],
[qw(test t1 2), '2011-11-08 00:02:02'],
[qw(test t1 3), '2011-11-08 00:02:03'],
# t1 not finish but
[qw(test t2 1), '2011-11-08 00:01:01'],
[qw(test t2 2), '2011-11-08 00:01:02'],
[qw(test t2 3), '2011-11-08 00:01:03'],
[qw(test t2 4), '2011-11-08 00:01:04'],
[qw(test t2 5), '2011-11-08 00:01:05'],
[qw(test t2 6), '2011-11-08 00:01:06'],
[qw(test t2 7), '2011-11-08 00:01:07'],
[qw(test t2 8), '2011-11-08 00:01:08'],
# t2 is finished
],
"Checksum results partial t1, full t2"
);
$output = output(
sub { pt_table_checksum::main(@args, qw(-d test --resume --tables t1),
qw(--chunk-size 5)) },
);
like(
$output,
qr/Resuming from test.t1 chunk 3, timestamp 2011-11-08 00:02:03/,
"Resume from t1 when t2 is done"
);
# #############################################################################
# Done.
# #############################################################################
@@ -0,0 +1,11 @@
test t1 1 0.001062 PRIMARY 1 5 5ef4701a 5 5ef4701a 5 2011-11-08 00:02:01
test t1 2 0.000908 PRIMARY 6 10 5e765a6f 5 5e765a6f 5 2011-11-08 00:02:02
test t1 3 0.000890 PRIMARY 11 15 28b300ce 5 28b300ce 5 2011-11-08 00:02:03
test t2 1 0.000983 PRIMARY 1 5 5ef4701a 5 5ef4701a 5 2011-11-08 00:01:01
test t2 2 0.000734 PRIMARY 6 10 5e765a6f 5 5e765a6f 5 2011-11-08 00:01:02
test t2 3 0.000938 PRIMARY 11 15 28b300ce 5 28b300ce 5 2011-11-08 00:01:03
test t2 4 0.000889 PRIMARY 16 20 b6ccc8e2 5 b6ccc8e2 5 2011-11-08 00:01:04
test t2 5 0.000916 PRIMARY 21 25 c0099243 5 c0099243 5 2011-11-08 00:01:05
test t2 6 0.000908 PRIMARY 26 26 55f99957 1 55f99957 1 2011-11-08 00:01:06
test t2 7 0.000662 PRIMARY \N 1 0 0 0 0 2011-11-08 00:01:07
test t2 8 0.000855 PRIMARY 26 \N 0 0 0 0 2011-11-08 00:01:08