diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 08be61f7..b423de98 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -4167,18 +4167,16 @@ sub make_checksum_query { sub find_replication_differences { my ( $self, $dbh, $table ) = @_; - (my $sql = <<" EOF") =~ s/\s+/ /gm; - SELECT db, tbl, chunk, boundaries, - COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, - COALESCE( - this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), - 0 - ) AS crc_diff, - this_cnt, master_cnt, this_crc, master_crc - FROM $table - WHERE master_cnt <> this_cnt OR master_crc <> this_crc - OR ISNULL(master_crc) <> ISNULL(this_crc) - EOF + my $sql + = "SELECT db, tbl, CONCAT(db, '.', tbl) AS `table`, " + . "chunk, chunk_index, lower_boundary, upper_boundary, " + . "COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, " + . "COALESCE(" + . "this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0" + . ") AS crc_diff, this_cnt, master_cnt, this_crc, master_crc " + . "FROM $table " + . "WHERE master_cnt <> this_cnt OR master_crc <> this_crc " + . "OR ISNULL(master_crc) <> ISNULL(this_crc)"; MKDEBUG && _d($sql); my $diffs = $dbh->selectall_arrayref($sql, { Slice => {} }); @@ -7248,6 +7246,7 @@ package pt_table_sync; use English qw(-no_match_vars); use List::Util qw(sum max min); use POSIX qw(ceil); +use Data::Dumper; Transformers->import(qw(time_to_secs any_unix_timestamp)); @@ -7256,6 +7255,7 @@ use constant MKDEBUG => $ENV{MKDEBUG} || 0; $OUTPUT_AUTOFLUSH = 1; my %dsn_for; +my $q = new Quoter(); sub main { @ARGV = @_; # set global ARGV for this package @@ -7375,7 +7375,6 @@ sub main { # ######################################################################## # Do the work. # ######################################################################## - my $q = new Quoter(); my $tp = new TableParser( Quoter => $q ); my $vp = new VersionParser(); my $ms = new MasterSlave(VersionParser => $vp); @@ -7743,7 +7742,8 @@ sub sync_via_replication { $exit_status |= sync_a_table( src => $src, dst => $dst, - where => $diff->{boundaries}, + where => 1, # prevents --where from being used + diff => $diff, %args, ); } @@ -7811,7 +7811,8 @@ sub sync_via_replication { $exit_status |= sync_a_table( src => $src, dst => $dst, - where => $diff->{boundaries}, + where => 1, # prevents --where from being used + diff => $diff, %args, ); } @@ -8065,6 +8066,14 @@ sub sync_a_table { # This will either die if there's a problem or return the tbl struct. my $tbl_struct = ok_to_sync($src, $dst, %args); + + if ( my $diff = $args{diff} ) { + MKDEBUG && _d('Converting checksum diff to WHERE:', Dumper($diff)); + $args{where} = diff_where( + %args, + tbl_struct => $tbl_struct, + ); + } # If the table is InnoDB, prefer to sync it with transactions, unless # the user explicitly said not to. @@ -8510,13 +8519,13 @@ sub ok_to_sync { sub filter_diffs { my ( $skip_table, $databases, $tables, @diffs ) = @_; return grep { - !$skip_table->{$_->{db}}->{$_->{tbl}} - && (!$databases || $databases->{$_->{db}}) - && (!$tables || ($tables->{$_->{tbl}} || $tables->{"$_->{db}.$_->{tbl}"})) + my ($db, $tbl) = $q->split_unquote($_->{table}); + !$skip_table->{$db}->{$tbl} + && (!$databases || $databases->{$db}) + && (!$tables || ($tables->{$tbl} || $tables->{$_->{table}})) } @diffs; } - # Sub: disconnect # Disconnect host dbhs created by . To make sure all dbh # are closed, pt-table-sync keeps track of the dbh it opens and this @@ -8804,6 +8813,58 @@ sub get_current_user { return $user; } +{ +my %asc_for_table; + +sub diff_where { + my (%args) = @_; + my @required_args = qw(diff tbl_struct TableNibbler); + foreach my $arg ( @required_args ) { + die "I need a $arg argument" unless $args{$arg}; + } + my ($diff, $tbl_struct, $tn) = @args{@required_args}; + + my $key = $diff->{chunk_index}; + if ( !$key ) { + MKDEBUG && _d('One nibble checksum'); + return; + } + my $cols = $tbl_struct->{keys}->{$key}->{cols}; + my $asc = $asc_for_table{$diff->{table}}; + if ( !$asc ) { + die "Index $key does not exist in table" unless $cols && @$cols; + + # NibbleIterator does this to make the boundary statements. + $asc = $args{TableNibbler}->generate_asc_stmt( + %args, + tbl_struct => $tbl_struct, + index => $key, + cols => $cols, + asc_only => 1, + ); + + $asc_for_table{$diff->{table}} = $asc; + MKDEBUG && _d('Ascend params:', Dumper($asc)); + } + + my @lb = split ',', $diff->{lower_boundary}; + my $lb_sql = $asc->{boundaries}->{'>='}; + foreach my $val (@lb) { + my $quoted_val = $q->quote_val($val); + $lb_sql =~ s/\?/$val/; + } + + my @ub = split ',', $diff->{upper_boundary}; + my $ub_sql = $asc->{boundaries}->{'<='}; + foreach my $val (@ub) { + my $quoted_val = $q->quote_val($val); + $ub_sql =~ s/\?/$val/; + } + + return "$lb_sql AND $ub_sql"; +} +} + sub _d { my ($package, undef, $line) = caller 0; @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; } diff --git a/lib/Sandbox.pm b/lib/Sandbox.pm index fb56a31a..8bb9fca0 100644 --- a/lib/Sandbox.pm +++ b/lib/Sandbox.pm @@ -41,6 +41,8 @@ my %port_for = ( slave2 => 12347, master1 => 12348, # master-master master2 => 12349, # master-master + master3 => 2900, + master4 => 2901, ); sub new { diff --git a/lib/TableChecksum.pm b/lib/TableChecksum.pm index acbc42ef..fcc7f245 100644 --- a/lib/TableChecksum.pm +++ b/lib/TableChecksum.pm @@ -470,18 +470,16 @@ sub make_checksum_query { sub find_replication_differences { my ( $self, $dbh, $table ) = @_; - (my $sql = <<" EOF") =~ s/\s+/ /gm; - SELECT db, tbl, chunk, boundaries, - COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, - COALESCE( - this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), - 0 - ) AS crc_diff, - this_cnt, master_cnt, this_crc, master_crc - FROM $table - WHERE master_cnt <> this_cnt OR master_crc <> this_crc - OR ISNULL(master_crc) <> ISNULL(this_crc) - EOF + my $sql + = "SELECT db, tbl, CONCAT(db, '.', tbl) AS `table`, " + . "chunk, chunk_index, lower_boundary, upper_boundary, " + . "COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, " + . "COALESCE(" + . "this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0" + . ") AS crc_diff, this_cnt, master_cnt, this_crc, master_crc " + . "FROM $table " + . "WHERE master_cnt <> this_cnt OR master_crc <> this_crc " + . "OR ISNULL(master_crc) <> ISNULL(this_crc)"; MKDEBUG && _d($sql); my $diffs = $dbh->selectall_arrayref($sql, { Slice => {} }); diff --git a/t/pt-table-sync/bidirectional.t b/t/pt-table-sync/bidirectional.t index 2112c6b0..6d7bd0de 100644 --- a/t/pt-table-sync/bidirectional.t +++ b/t/pt-table-sync/bidirectional.t @@ -25,11 +25,11 @@ my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); my $c1_dbh = $sb->get_dbh_for('master'); -diag(`$trunk/sandbox/start-sandbox master 12347 >/dev/null`); -my $r1_dbh = $sb->get_dbh_for('slave2'); +diag(`$trunk/sandbox/start-sandbox master 2900 >/dev/null`); +my $r1_dbh = $sb->get_dbh_for('master3'); -diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`); -my $r2_dbh = $sb->get_dbh_for('master1'); +diag(`$trunk/sandbox/start-sandbox master 2901 >/dev/null`); +my $r2_dbh = $sb->get_dbh_for('master4'); if ( !$c1_dbh ) { plan skip_all => 'Cannot connect to sandbox master'; @@ -44,16 +44,16 @@ else { my $output; my $cnf = '/tmp/12345/my.sandbox.cnf'; -my @args = ('-F', $cnf, 'h=127.1,P=12345', 'P=12347', qw(-d bidi --bidirectional)); +my @args = ('-F', $cnf, 'h=127.1,P=12345', 'P=2900', qw(-d bidi --bidirectional)); $sb->wipe_clean($c1_dbh); $sb->wipe_clean($r1_dbh); sub load_bidi_data { $sb->load_file('master', 't/pt-table-sync/samples/bidirectional/table.sql'); - $sb->load_file('slave2', 't/pt-table-sync/samples/bidirectional/table.sql'); + $sb->load_file('master3', 't/pt-table-sync/samples/bidirectional/table.sql'); $sb->load_file('master', 't/pt-table-sync/samples/bidirectional/master-data.sql'); - $sb->load_file('slave2', 't/pt-table-sync/samples/bidirectional/remote-1.sql'); + $sb->load_file('master3', 't/pt-table-sync/samples/bidirectional/remote-1.sql'); } my $r1_data_synced = [ @@ -135,13 +135,13 @@ $output = output( is( $output, -"/*127.1:12347*/ UPDATE `bidi`.`t` SET `c`='ghi', `d`='5', `ts`='2010-02-01 09:17:52' WHERE `id`='3' LIMIT 1; +"/*127.1:2900*/ UPDATE `bidi`.`t` SET `c`='ghi', `d`='5', `ts`='2010-02-01 09:17:52' WHERE `id`='3' LIMIT 1; /*127.1:12345*/ UPDATE `bidi`.`t` SET `c`=NULL, `d`='0', `ts`='2010-02-02 05:10:00' WHERE `id`='5' LIMIT 1; /*127.1:12345*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('11', '?', '0', '2010-01-29 11:17:12'); /*127.1:12345*/ UPDATE `bidi`.`t` SET `c`='hmm', `d`='1', `ts`='2010-02-02 12:17:31' WHERE `id`='13' LIMIT 1; /*127.1:12345*/ UPDATE `bidi`.`t` SET `c`='gtg', `d`='7', `ts`='2010-02-02 06:01:08' WHERE `id`='15' LIMIT 1; /*127.1:12345*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('17', 'good', '1', '2010-02-02 21:38:03'); -/*127.1:12347*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('20', 'new', '100', '2010-02-01 04:15:36'); +/*127.1:2900*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('20', 'new', '100', '2010-02-01 04:15:36'); ", '--print correct SQL for c1<->r1 bidirectional sync' ); @@ -181,7 +181,7 @@ is( /*127.1:12345*/ UPDATE `bidi`.`t` SET `c`='hmm', `d`='1', `ts`='2010-02-02 12:17:31' WHERE `id`='13' LIMIT 1; /*127.1:12345*/ UPDATE `bidi`.`t` SET `c`='gtg', `d`='7', `ts`='2010-02-02 06:01:08' WHERE `id`='15' LIMIT 1; /*127.1:12345*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('17', 'good', '1', '2010-02-02 21:38:03'); -/*127.1:12347*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('20', 'new', '100', '2010-02-01 04:15:36'); +/*127.1:2900*/ INSERT INTO `bidi`.`t`(`id`, `c`, `d`, `ts`) VALUES ('20', 'new', '100', '2010-02-01 04:15:36'); ", 'SQL for c1<->r1 with conflict' ); @@ -324,14 +324,14 @@ is_deeply( # Test bidirectional sync with 3 servers. # ############################################################################# -# It's confusing but master1 = 12348, aka our 3rd master server. +# It's confusing but master4 = 2901, aka our 3rd master server. SKIP: { skip 'Cannot connect to third sandbox master', 9 unless $r2_dbh; load_bidi_data(); - $sb->load_file('master1', 't/pt-table-sync/samples/bidirectional/table.sql'); - $sb->load_file('master1', 't/pt-table-sync/samples/bidirectional/remote-2.sql'); + $sb->load_file('master4', 't/pt-table-sync/samples/bidirectional/table.sql'); + $sb->load_file('master4', 't/pt-table-sync/samples/bidirectional/remote-2.sql'); $res = $r2_dbh->selectall_arrayref('select * from bidi.t order by id'); is_deeply( @@ -361,7 +361,7 @@ SKIP: { local *STDERR; open STDERR, '>', \$err; $output = output( - sub { pt_table_sync::main(@args, 'h=127.1,P=12348', + sub { pt_table_sync::main(@args, 'h=127.1,P=2901', qw(--print --execute --chunk-size 2), qw(--conflict-column ts --conflict-comparison newest)) } ); @@ -456,7 +456,7 @@ SKIP: { local *STDERR; open STDERR, '>', \$err; $output = output( - sub { pt_table_sync::main(@args, 'h=127.1,P=12348', + sub { pt_table_sync::main(@args, 'h=127.1,P=2901', qw(--print --execute --chunk-size 2), qw(--conflict-column ts --conflict-comparison newest)) } ); @@ -534,7 +534,6 @@ SKIP: { # ############################################################################# # Done. # ############################################################################# -diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`); -diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`); -$sb->wipe_clean($c1_dbh); +diag(`$trunk/sandbox/stop-sandbox 2900 >/dev/null`); +diag(`$trunk/sandbox/stop-sandbox 2901 >/dev/null`); exit; diff --git a/t/pt-table-sync/diff_where.t b/t/pt-table-sync/diff_where.t new file mode 100644 index 00000000..bcf86f1d --- /dev/null +++ b/t/pt-table-sync/diff_where.t @@ -0,0 +1,63 @@ +#!/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 tests => 1; + +use PerconaTest; +use Sandbox; +require "$trunk/bin/pt-table-sync"; + +my $q = new Quoter(); +my $tp = new TableParser(Quoter => $q); +my $tn = new TableNibbler(Quoter => $q, TableParser => $tp); + +my $sample = "t/pt-table-sync/samples"; + +sub test_diff_where { + my (%args) = @_; + + my $ddl = load_file($args{file}); + my $tbl_struct = $tp->parse($ddl); + my $where = pt_table_sync::diff_where( + tbl_struct => $tbl_struct, + diff => $args{diff}, + TableNibbler => $tn, + ); + is( + $where, + $args{where}, + $args{name}, + ); +} + +test_diff_where( + name => "Single int col", + file => "$sample/simple-tbl-ddl.sql", + diff => { + chunk => '3', + chunk_index => 'PRIMARY', + cnt_diff => '-1', + crc_diff => '1', + lower_boundary => '7', + master_cnt => '3', + master_crc => '1ddd6c71', + table => 'test.mt1', + this_cnt => '2', + this_crc => '4a57d814', + upper_boundary => '9' + }, + where => "((`id` >= 7)) AND ((`id` <= 9))", +); + +# ############################################################################# +# Done. +# ############################################################################# +exit; diff --git a/t/pt-table-sync/filters.t b/t/pt-table-sync/filters.t index ee083b78..f8a3c49e 100644 --- a/t/pt-table-sync/filters.t +++ b/t/pt-table-sync/filters.t @@ -36,8 +36,8 @@ else { # complain that it cannot connect to 12347 for checking repl filters # and such. 12347 isn't present but SHOW SLAVE HOSTS on 12346 hasn't # figured that out yet, so we restart 12346 to refresh this list. -diag(`/tmp/12346/stop >/dev/null`); -diag(`/tmp/12346/start >/dev/null`); +#diag(`/tmp/12346/stop >/dev/null`); +#diag(`/tmp/12346/start >/dev/null`); $slave_dbh = $sb->get_dbh_for('slave1'); my $output; @@ -64,23 +64,21 @@ is( # ############################################################################# $master_dbh->do('DROP DATABASE IF EXISTS test'); $master_dbh->do('CREATE DATABASE test'); -$sb->load_file('master', 't/pt-table-sync/samples/checksum_tbl.sql', 'test'); $slave_dbh->do('insert into issue_806_1.t1 values (41)'); $slave_dbh->do('insert into issue_806_2.t2 values (42)'); -my $mk_table_checksum = "$trunk/bin/pt-table-checksum"; +my $mk_table_checksum = "$trunk/bin/pt-table-checksum --lock-wait-time 3"; -`$mk_table_checksum -F $cnf --replicate test.checksum h=127.1,P=12345 -d issue_806_1,issue_806_2 --quiet`; -`$mk_table_checksum -F $cnf --replicate test.checksum h=127.1,P=12345 -d issue_806_1,issue_806_2 --replicate-check 1 --quiet`; +`$mk_table_checksum --replicate test.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_806_1,issue_806_2 --quiet`; $output = `$cmd h=127.1,P=12345 --replicate test.checksum --dry-run | tail -n 2`; $output =~ s/$t/00:00:00/g; $output =~ s/[ ]{2,}/ /g; is( $output, -"# 0 0 0 0 Chunk 00:00:00 00:00:00 0 issue_806_2.t2 -# 0 0 0 0 Chunk 00:00:00 00:00:00 0 issue_806_1.t1 +"# 0 0 0 0 Chunk 00:00:00 00:00:00 0 issue_806_1.t1 +# 0 0 0 0 Chunk 00:00:00 00:00:00 0 issue_806_2.t2 ", "--replicate with no filters" ); diff --git a/t/pt-table-sync/issue_560.t b/t/pt-table-sync/issue_560.t index 9fe850fe..77f3f674 100644 --- a/t/pt-table-sync/issue_560.t +++ b/t/pt-table-sync/issue_560.t @@ -39,22 +39,17 @@ $sb->create_dbs($master_dbh, [qw(test)]); # Issue 560: mk-table-sync generates impossible WHERE # ############################################################################# diag(`/tmp/12345/use < $trunk/t/pt-table-sync/samples/issue_560.sql`); -sleep 1; +PerconaTest::wait_for_table($slave_dbh, "issue_560.buddy_list", "player_id=353"); # Make slave differ. $slave_dbh->do('UPDATE issue_560.buddy_list SET buddy_id=0 WHERE player_id IN (333,334)'); $slave_dbh->do('UPDATE issue_560.buddy_list SET buddy_id=0 WHERE player_id=486'); -diag(`$trunk/bin/pt-table-checksum --replicate issue_560.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_560 --chunk-size 50 > /dev/null`); -sleep 1; -$output = `$trunk/bin/pt-table-checksum --replicate issue_560.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_560 --replicate-check 1 --chunk-size 50`; -$output =~ s/\d\d:\d\d:\d\d/00:00:00/g; -ok( - no_diff( - $output, - "t/pt-table-sync/samples/issue_560_output_1.txt", - cmd_output => 1, - ), +$output = `$trunk/bin/pt-table-checksum --replicate issue_560.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_560 --chunk-size 50 --lock-wait-time 3`; + +is( + PerconaTest::count_checksum_results($output, 'diffs'), + 2, 'Found checksum differences (issue 560)' ); diff --git a/t/pt-table-sync/issue_627.t b/t/pt-table-sync/issue_627.t index 2309d1ba..cd2ba9e4 100644 --- a/t/pt-table-sync/issue_627.t +++ b/t/pt-table-sync/issue_627.t @@ -48,8 +48,7 @@ $slave_dbh->do('UPDATE issue_375.t SET foo="z" WHERE id=10'); $slave_dbh->do('UPDATE issue_375.t SET foo="zz" WHERE id=100'); # Checksum and replicate. -diag(`$trunk/bin/pt-table-checksum --create-replicate-table --replicate issue_375.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 -t t > /dev/null`); -diag(`$trunk/bin/pt-table-checksum --replicate issue_375.checksum h=127.1,P=12345,u=msandbox,p=msandbox --replicate-check 1 > /dev/null`); +diag(`$trunk/bin/pt-table-checksum --create-replicate-table --replicate issue_375.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 -t t --lock-wait-time 3 > /dev/null`); # And now sync using the replicated checksum results/differences. $output = output( diff --git a/t/pt-table-sync/issue_79.t b/t/pt-table-sync/issue_79.t index a70894c5..c2d568d3 100644 --- a/t/pt-table-sync/issue_79.t +++ b/t/pt-table-sync/issue_79.t @@ -35,7 +35,6 @@ $sb->wipe_clean($master_dbh); $sb->wipe_clean($slave_dbh); $sb->create_dbs($master_dbh, [qw(test)]); $sb->load_file('master', 't/pt-table-sync/samples/before.sql'); -$sb->load_file('master', 't/pt-table-sync/samples/checksum_tbl.sql'); # ############################################################################# # Issue 79: mk-table-sync with --replicate doesn't honor --tables @@ -49,7 +48,7 @@ $slave_dbh->do('insert into test.messages values (1), (2), (3)'); # out of sync. Now we also unsync test2 on the slave and then re-sync only # it. If --tables is honored, only test2 on the slave will be synced. $sb->use('master', "-D test -e \"SET SQL_LOG_BIN=0; INSERT INTO test2 VALUES (1,'a'),(2,'b')\""); -diag(`$trunk/bin/pt-table-checksum --replicate=test.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test > /dev/null`); +diag(`$trunk/bin/pt-table-checksum --replicate=test.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --lock-wait-time 3 > /dev/null`); is_deeply( $master_dbh->selectall_arrayref('select * from test.messages'), @@ -72,7 +71,7 @@ like($output, qr/test2/, '--replicate honors --tables (2/4)'); # Now we'll test with a qualified db.tbl name. $sb->use('slave1', '-D test -e "TRUNCATE TABLE test2; TRUNCATE TABLE messages"'); -diag(`$trunk/bin/pt-table-checksum --replicate=test.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test > /dev/null`); +diag(`$trunk/bin/pt-table-checksum --replicate=test.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --lock-wait-time 3 > /dev/null`); $output = `$trunk/bin/pt-table-sync h=127.1,P=12345,u=msandbox,p=msandbox --replicate test.checksum --execute -d test -t test.test2 -v`; unlike($output, qr/messages/, '--replicate honors --tables (3/4)'); diff --git a/t/pt-table-sync/issue_996.t b/t/pt-table-sync/issue_996.t index ce79b256..41310042 100644 --- a/t/pt-table-sync/issue_996.t +++ b/t/pt-table-sync/issue_996.t @@ -33,7 +33,7 @@ else { my $output; my @args = ('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(-d issue_375 --replicate issue_375.checksums --print)); -my $mk_table_checksum = "$trunk/bin/pt-table-checksum F=/tmp/12345/my.sandbox.cnf -d issue_375 --chunk-size 20 --chunk-size-limit 0"; +my $pt_table_checksum = "$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 --chunk-size 20 --chunk-size-limit 0 --lock-wait-time 3"; # ############################################################################# # Issue 996: might not chunk inside of mk-table-checksum's boundaries @@ -65,13 +65,10 @@ wait_until( ); # mk-table-checksum the table with 5 chunks of 20 rows. -$output = `$mk_table_checksum --replicate issue_375.checksums --create-replicate-table`; -sleep 1; - -$output = `$mk_table_checksum --replicate issue_375.checksums --replicate-check 1`; -like( - $output, - qr/issue_375\s+t\s+2\s+0\s+1\s+`id` >= '21' AND `id` < '41'/, +$output = `$pt_table_checksum --replicate issue_375.checksums`; +is( + PerconaTest::count_checksum_results($output, 'diffs'), + 1, "Chunk checksum diff" ); diff --git a/t/pt-table-sync/samples/issue_560.sql b/t/pt-table-sync/samples/issue_560.sql index e328d499..c3d3663d 100644 --- a/t/pt-table-sync/samples/issue_560.sql +++ b/t/pt-table-sync/samples/issue_560.sql @@ -7,17 +7,4 @@ CREATE TABLE `buddy_list` ( `buddy_id` int(10) unsigned NOT NULL default '0', PRIMARY KEY (`player_id`,`buddy_id`) ) ENGINE=InnoDB; -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) -); INSERT INTO buddy_list VALUES (1,9559),(2,3558),(3,6164),(4,9386),(5,7431),(6,1660),(7,6861),(8,8833),(9,509),(10,1885),(11,9862),(12,2456),(13,8556),(14,7147),(15,7523),(16,1418),(17,7872),(18,4321),(19,7354),(20,448),(21,5238),(22,8700),(23,4560),(24,8640),(25,1403),(26,4459),(27,668),(28,4239),(29,3621),(30,5248),(31,7625),(32,9037),(33,8016),(34,7086),(35,1830),(36,811),(37,5267),(38,8492),(39,5235),(40,9067),(41,2565),(42,6776),(43,5243),(44,8985),(45,2465),(46,1214),(47,3045),(48,5884),(49,4661),(50,2551),(51,2165),(52,1824),(53,132),(54,8478),(55,8251),(56,2434),(57,2361),(58,8280),(59,5080),(60,5157),(61,6652),(62,9085),(63,4753),(64,5333),(65,3804),(66,5820),(67,6293),(68,8777),(69,6959),(70,7161),(71,2246),(72,4523),(73,2128),(74,8104),(75,8169),(76,9319),(77,1229),(78,4078),(79,2559),(80,2530),(81,7322),(82,2319),(83,2103),(84,1541),(85,1653),(86,9031),(87,8224),(88,305),(89,1066),(90,9152),(91,9513),(92,7824),(93,7942),(94,2567),(95,1536),(96,6074),(97,7074),(98,2637),(99,951),(100,4034),(101,9455),(102,1087),(103,7159),(104,3441),(105,9970),(106,6601),(107,8767),(108,3607),(109,8116),(110,1953),(111,7727),(112,5024),(113,284),(114,7894),(115,4647),(116,691),(117,1690),(118,8178),(119,9804),(120,8332),(121,1839),(122,3660),(123,5854),(124,7491),(125,1361),(126,8908),(127,7103),(128,1314),(129,478),(130,9738),(131,3008),(132,590),(133,1084),(134,6890),(135,8898),(136,6010),(137,9834),(138,9957),(139,7841),(140,5930),(141,8716),(142,6959),(143,4201),(144,81),(145,731),(146,1575),(147,1529),(148,2410),(149,524),(150,200),(151,6476),(152,7668),(153,5620),(154,385),(155,2921),(156,9591),(157,1381),(158,6899),(159,9394),(160,2955),(161,8479),(162,130),(163,1253),(164,5873),(165,2659),(166,7639),(167,1461),(168,2109),(169,3584),(170,4779),(171,9814),(172,9704),(173,8651),(174,5999),(175,6234),(176,1865),(177,3647),(178,8942),(179,5402),(180,7846),(181,210),(182,8166),(183,5249),(184,5901),(185,8953),(186,1256),(187,3402),(188,1576),(189,1203),(190,4491),(191,2828),(192,3376),(193,4369),(194,7898),(195,9851),(196,3754),(197,9387),(198,5510),(199,5470),(200,7538),(201,295),(202,8589),(203,9928),(204,7199),(205,8354),(206,307),(207,3663),(208,6115),(209,7041),(210,5397),(211,7004),(212,7481),(213,1280),(214,8175),(215,637),(216,9390),(217,9435),(218,5447),(219,7566),(220,1358),(221,438),(222,5547),(223,862),(224,6308),(225,9970),(226,2263),(227,5145),(228,5414),(229,8615),(230,8861),(231,853),(232,3721),(233,4286),(234,6868),(235,701),(236,8152),(237,9916),(238,653),(239,6283),(240,8994),(241,2382),(242,8991),(243,7841),(244,2797),(245,7766),(246,511),(247,2295),(248,1587),(249,2591),(250,809),(251,8716),(252,7347),(253,7374),(254,4759),(255,8430),(256,4918),(257,3039),(258,437),(259,458),(260,3062),(261,8384),(262,8716),(263,5658),(264,5880),(265,7106),(266,127),(267,2636),(268,2476),(269,1013),(270,3215),(271,604),(272,5675),(273,5223),(274,4549),(275,3367),(276,3298),(277,5548),(278,2710),(279,1262),(280,2323),(281,5210),(282,7843),(283,5411),(284,5090),(285,802),(286,5725),(287,9258),(288,2128),(289,7360),(290,4253),(291,3907),(292,1515),(293,1809),(294,9668),(295,6003),(296,4695),(297,8461),(298,6032),(299,4200),(300,2085),(301,887),(302,1116),(303,3983),(304,3641),(305,1016),(306,4071),(307,1678),(308,3887),(309,9012),(310,9547),(311,9862),(312,3082),(313,112),(314,1212),(315,5442),(316,5516),(317,6419),(318,7189),(319,3076),(320,8163),(321,543),(322,5600),(323,4229),(324,2614),(325,2280),(326,193),(327,2154),(328,6436),(329,1079),(330,1554),(331,6052),(332,6806),(333,3414),(334,6626),(335,1148),(336,5719),(337,1129),(338,8434),(339,2717),(340,7587),(341,1039),(342,4931),(343,219),(344,3242),(345,7378),(346,3791),(347,6564),(348,9777),(349,2796),(350,2454),(351,7697),(352,317),(353,4503),(354,5638),(355,9606),(356,7505),(357,4478),(358,7382),(359,5742),(360,6568),(361,4538),(362,164),(363,4528),(364,9400),(365,2232),(366,9018),(367,8102),(368,7841),(369,4058),(370,5378),(371,2975),(372,8621),(373,1308),(374,715),(375,6413),(376,2301),(377,7004),(378,8256),(379,8991),(380,5697),(381,1920),(382,6950),(383,989),(384,9952),(385,3651),(386,2801),(387,4506),(388,1766),(389,6219),(390,1081),(391,3104),(392,1842),(393,3019),(394,9073),(395,9388),(396,4689),(397,2941),(398,3109),(399,8402),(400,6530),(401,6830),(402,8776),(403,717),(404,836),(405,7918),(406,7426),(407,5270),(408,3072),(409,8019),(410,1215),(411,4643),(412,820),(413,9309),(414,8969),(415,7730),(416,1724),(417,5764),(418,4592),(419,9525),(420,8381),(421,6112),(422,2451),(423,9767),(424,5851),(425,2021),(426,1499),(427,824),(428,7769),(429,7377),(430,3438),(431,6837),(432,1109),(433,1605),(434,4207),(435,6695),(436,6485),(437,7342),(438,1899),(439,781),(440,862),(441,9039),(442,4873),(443,8155),(444,7052),(445,8688),(446,8565),(447,6339),(448,31),(449,567),(450,8170),(451,9245),(452,3578),(453,2039),(454,1938),(455,1059),(456,3073),(457,9010),(458,8983),(459,714),(460,6343),(461,4952),(462,9134),(463,5472),(464,5641),(465,2469),(466,5800),(467,5390),(468,361),(469,7684),(470,6834),(471,7153),(472,3619),(473,5265),(474,1240),(475,4638),(476,1919),(477,6244),(478,9615),(479,495),(480,7691),(481,993),(482,4722),(483,3087),(484,503),(485,5458),(486,1660),(487,3850),(488,6382),(489,3022),(490,8738),(491,3146),(492,2145),(493,6070),(494,4431),(495,7083),(496,5597),(497,7429),(498,9383),(499,1746),(500,4272); diff --git a/t/pt-table-sync/samples/simple-tbl-ddl.sql b/t/pt-table-sync/samples/simple-tbl-ddl.sql new file mode 100644 index 00000000..6f2feabe --- /dev/null +++ b/t/pt-table-sync/samples/simple-tbl-ddl.sql @@ -0,0 +1,10 @@ +CREATE TABLE `it1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `a` int(11) NOT NULL, + `b` int(11) NOT NULL, + `c` varchar(16) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `c` (`c`), + UNIQUE KEY `id` (`id`,`c`), + KEY `a` (`a`) +) ENGINE=InnoDB diff --git a/t/pt-table-sync/triggers.t b/t/pt-table-sync/triggers.t index 09e163bd..6c91f306 100644 --- a/t/pt-table-sync/triggers.t +++ b/t/pt-table-sync/triggers.t @@ -44,8 +44,8 @@ $sb->create_dbs($master_dbh, [qw(test)]); # ############################################################################# $sb->load_file('master', 't/pt-table-sync/samples/issue_37.sql'); $sb->use('master', '-e "SET SQL_LOG_BIN=0; INSERT INTO test.issue_37 VALUES (1), (2);"'); -$sb->load_file('master', 't/pt-table-sync/samples/checksum_tbl.sql'); -`$trunk/bin/pt-table-checksum h=127.0.0.1,P=12345,u=msandbox,p=msandbox --replicate test.checksum -d test 2>&1 > /dev/null`; + +`$trunk/bin/pt-table-checksum h=127.0.0.1,P=12345,u=msandbox,p=msandbox --replicate test.checksum -d test --lock-wait-time 3 2>&1 > /dev/null`; $output = `$trunk/bin/pt-table-sync --no-check-slave --execute u=msandbox,p=msandbox,h=127.0.0.1,P=12345,D=test,t=issue_37 h=127.1,P=12346 2>&1`; like($output, @@ -117,10 +117,10 @@ $slave_dbh->do('INSERT INTO db1.t1 VALUES (9)'); $slave_dbh->do('DELETE FROM db2.t1 WHERE i > 4'); # Replicate checksum of db2.t1. -$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --replicate db1.checksum --create-replicate-table --databases db1,db2 2>&1`; +$output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --replicate db1.checksum --create-replicate-table --databases db1,db2 --lock-wait-time 3 2>&1`; like( $output, - qr/db2\s+t1\s+0\s+127\.1\s+MyISAM\s+5/, + qr/db2.t1/, 'Replicated checksums (issue 367)' );