mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 15:31:55 +00:00
Unset src tbl_struct when the db or tbl changes. Add test for just --replicate.
This commit is contained in:
@@ -8035,6 +8035,16 @@ sub sync_via_replication {
|
||||
lock_server(src => $src, dst => $dst, %args);
|
||||
|
||||
foreach my $diff ( @$diffs ) {
|
||||
# Clear the tbl_struct if this is a new table. The tbl_struct
|
||||
# is fetched and parsed in ok_to_sync() if not set. We only
|
||||
# need to set it once per table to avoid doing this for every
|
||||
# diff in the same table.
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1003014
|
||||
if ( ($src->{db} || '') ne $diff->{db}
|
||||
|| ($src->{tbl} || '') ne $diff->{tbl} ) {
|
||||
PTDEBUG && _d('New table:', $diff->{db}, $diff->{tbl});
|
||||
$src->{tbl_struct} = undef;
|
||||
}
|
||||
$src->{db} = $dst->{db} = $diff->{db};
|
||||
$src->{tbl} = $dst->{tbl} = $diff->{tbl};
|
||||
|
||||
@@ -8103,6 +8113,14 @@ sub sync_via_replication {
|
||||
lock_server(src => $src, dst => $dst, %args);
|
||||
|
||||
foreach my $diff ( @$diffs ) {
|
||||
# Clear the tbl_struct if this is a new table.
|
||||
# See the same code block above.
|
||||
if ( ($src->{db} || '') ne $diff->{db}
|
||||
|| ($src->{tbl} || '') ne $diff->{tbl} ) {
|
||||
PTDEBUG && _d('New table:',
|
||||
$diff->{db}, $diff->{tbl});
|
||||
$src->{tbl_struct} = undef;
|
||||
}
|
||||
$src->{db} = $dst->{db} = $diff->{db};
|
||||
$src->{tbl} = $dst->{tbl} = $diff->{tbl};
|
||||
|
||||
|
@@ -29,7 +29,7 @@ elsif ( !$slave_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave';
|
||||
}
|
||||
else {
|
||||
plan tests => 4;
|
||||
plan tests => 8;
|
||||
}
|
||||
|
||||
my $sample = "t/pt-table-sync/samples";
|
||||
@@ -55,10 +55,7 @@ is(
|
||||
"Bug 1003014 (wrong tbl_struct): 2 diffs"
|
||||
) or print STDERR $output;
|
||||
|
||||
my $rows = $master_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[
|
||||
my $checksums = [
|
||||
[qw( test aaa 1 )],
|
||||
[qw( test zzz 1 )],
|
||||
[qw( test zzz 2 )],
|
||||
@@ -74,14 +71,19 @@ is_deeply(
|
||||
[qw( test zzz 12 )],
|
||||
[qw( test zzz 13 )],
|
||||
[qw( test zzz 14 )],
|
||||
],
|
||||
];
|
||||
|
||||
my $rows = $master_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk");
|
||||
is_deeply(
|
||||
$rows,
|
||||
$checksums,
|
||||
"Bug 1003014 (wrong tbl_struct): checksums"
|
||||
);
|
||||
|
||||
my $exit_status;
|
||||
$output = output(
|
||||
sub { $exit_status = pt_table_sync::main($slave_dsn,
|
||||
qw(--replicate percona.checksums --sync-to-master --print),
|
||||
qw(--replicate percona.checksums --sync-to-master --print --execute),
|
||||
"--tables", "test.aaa,test.zzz") },
|
||||
stderr => 1,
|
||||
);
|
||||
@@ -99,6 +101,54 @@ is_deeply(
|
||||
"Bug 1003014 (wrong tbl_struct): synced rows"
|
||||
);
|
||||
|
||||
# #########################################################################
|
||||
# Repeat the whole process without --sync-to-master so the second code path
|
||||
# in sync_via_replication() is tested.
|
||||
# #########################################################################
|
||||
|
||||
$sb->wipe_clean($master_dbh);
|
||||
|
||||
$sb->load_file('master', "$sample/wrong-tbl-struct-bug-1003014.sql");
|
||||
PerconaTest::wait_for_table($slave_dbh, "test.zzz", "id=111");
|
||||
|
||||
$slave_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)");
|
||||
$slave_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)");
|
||||
|
||||
$output = `$trunk/bin/pt-table-checksum $master_dsn --lock-wait-timeout 3 --max-load '' -d test --chunk-size 10 2>&1`;
|
||||
|
||||
is(
|
||||
PerconaTest::count_checksum_results($output, 'diffs'),
|
||||
2,
|
||||
"Bug 1003014 (wrong tbl_struct): 2 diffs (just replicate)"
|
||||
) or print STDERR $output;
|
||||
|
||||
$rows = $master_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk");
|
||||
is_deeply(
|
||||
$rows,
|
||||
$checksums,
|
||||
"Bug 1003014 (wrong tbl_struct): checksums (just replicate)"
|
||||
);
|
||||
|
||||
$output = output(
|
||||
sub { $exit_status = pt_table_sync::main($master_dsn,
|
||||
qw(--replicate percona.checksums --print --execute),
|
||||
"--tables", "test.aaa,test.zzz") },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
is(
|
||||
$exit_status,
|
||||
2, # rows synced OK; 3=error (1) & rows synced (2)
|
||||
"Bug 1003014 (wrong tbl_struct): 0 exit (just replicate)"
|
||||
) or diag($output);
|
||||
|
||||
$rows = $slave_dbh->selectall_arrayref("SELECT c FROM test.zzz WHERE id IN (44,45,46)");
|
||||
is_deeply(
|
||||
$rows,
|
||||
[ ['a'], ['a'], ['a'] ],
|
||||
"Bug 1003014 (wrong tbl_struct): synced rows (just replicate)"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
|
Reference in New Issue
Block a user