mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-17 01:01:39 +08:00
Simplify how ptc checks slave tables. Move that code from TableParser to pt_table_checksum::check_slave_tables. Change --[no]check-replicate-table-columns to --[no]check-slave-tables. Move tests to error_handling.t.
This commit is contained in:
@@ -473,48 +473,9 @@ is(
|
||||
"Bug 821675 (dot): 0 errors"
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# pt-table-checksum doesn't check that tables exist on all replicas
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1009510
|
||||
# #############################################################################
|
||||
|
||||
$master_dbh->do("DROP DATABASE IF EXISTS bug_1009510");
|
||||
$master_dbh->do("CREATE DATABASE bug_1009510");
|
||||
|
||||
$sb->wait_for_slaves();
|
||||
$slave1_dbh->do("CREATE TABLE bug_1009510.bug_1009510 ( i int, b int )");
|
||||
$master_dbh->do("CREATE TABLE IF NOT EXISTS bug_1009510.bug_1009510 ( i int )");
|
||||
($output) = full_output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
qw(-t bug_1009510.bug_1009510)) },
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/has more columns than its master: b/,
|
||||
"Bug 1009510: ptc warns about extra columns"
|
||||
);
|
||||
|
||||
$slave1_dbh->do("DROP TABLE bug_1009510.bug_1009510");
|
||||
$slave1_dbh->do("CREATE TABLE bug_1009510.bug_1009510 ( b int )");
|
||||
|
||||
($output) = full_output(
|
||||
sub { $exit_status = pt_table_checksum::main(@args,
|
||||
qw(-t bug_1009510.bug_1009510)) },
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/differs from master: Columns i/,
|
||||
"Bug 1009510: ptc dies if the slave table has missing columns"
|
||||
);
|
||||
$sb->wipe_clean($master_dbh);
|
||||
$sb->wipe_clean($slave1_dbh);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
|
||||
done_testing;
|
||||
|
||||
@@ -11,6 +11,8 @@ use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
shift @INC; # our unshift (above)
|
||||
@@ -20,12 +22,13 @@ require "$trunk/bin/pt-table-checksum";
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
my $slave1_dbh = $sb->get_dbh_for('slave1');
|
||||
|
||||
if ( !$master_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 7;
|
||||
elsif ( !$slave1_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox slave';
|
||||
}
|
||||
|
||||
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||
@@ -34,6 +37,7 @@ else {
|
||||
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
||||
my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
|
||||
my $output;
|
||||
my $exit_status;
|
||||
|
||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
||||
|
||||
@@ -113,9 +117,95 @@ like(
|
||||
# Reconnect to master since we just killed ourself.
|
||||
$master_dbh = $sb->get_dbh_for('master');
|
||||
|
||||
# #############################################################################
|
||||
# pt-table-checksum breaks replication if a slave table is missing or different
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1009510
|
||||
# #############################################################################
|
||||
|
||||
# Just re-using this simple table.
|
||||
$sb->load_file('master', "t/pt-table-checksum/samples/600cities.sql");
|
||||
|
||||
$master_dbh->do("SET SQL_LOG_BIN=0");
|
||||
$master_dbh->do("ALTER TABLE test.t ADD COLUMN col3 int");
|
||||
$master_dbh->do("SET SQL_LOG_BIN=1");
|
||||
|
||||
$output = output(
|
||||
sub { $exit_status = pt_table_checksum::main(@args,
|
||||
qw(-t test.t)) },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Skipping table test.t/,
|
||||
"Skip table missing column on slave (bug 1009510)"
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/replica h=127.0.0.1,P=12346 is missing these columns: col3/,
|
||||
"Checked slave1 (bug 1009510)"
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/replica h=127.0.0.1,P=12347 is missing these columns: col3/,
|
||||
"Checked slave2 (bug 1009510)"
|
||||
);
|
||||
|
||||
is(
|
||||
$exit_status,
|
||||
1,
|
||||
"Non-zero exit status (bug 1009510)"
|
||||
);
|
||||
|
||||
$output = output(
|
||||
sub { $exit_status = pt_table_checksum::main(@args,
|
||||
qw(-t test.t), '--columns', 'id,city') },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Skipping table test.t/,
|
||||
"Doesn't skip table missing column on slave with --columns (bug 1009510)"
|
||||
);
|
||||
|
||||
is(
|
||||
$exit_status,
|
||||
0,
|
||||
"Zero exit status with --columns (bug 1009510)"
|
||||
);
|
||||
|
||||
# Use the --replicate table created by the previous ^ tests.
|
||||
|
||||
# Create a user that can't create the --replicate table.
|
||||
diag(`/tmp/12345/use -uroot -pmsandbox < $trunk/t/lib/samples/ro-checksum-user.sql`);
|
||||
diag(`/tmp/12345/use -uroot -pmsandbox -e "GRANT REPLICATION CLIENT, REPLICATION SLAVE ON *.* TO ro_checksum_user\@'%'"`);
|
||||
|
||||
# Remove the --replicate table from slave1 and slave2,
|
||||
# so it's only on the master...
|
||||
$slave1_dbh->do("DROP DATABASE percona");
|
||||
$sb->wait_for_slaves;
|
||||
|
||||
$output = output(
|
||||
sub { $exit_status = pt_table_checksum::main(
|
||||
"h=127.1,u=ro_checksum_user,p=msandbox,P=12345",
|
||||
qw(--lock-wait-timeout 3 -t mysql.user)) },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/database percona exists on the master/,
|
||||
"CREATE DATABASE error and db is missing on slaves (bug 1039569)"
|
||||
);
|
||||
|
||||
diag(`/tmp/12345/use -uroot -pmsandbox -e "DROP USER ro_checksum_user\@'%'"`);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
exit;
|
||||
done_testing;
|
||||
|
||||
Reference in New Issue
Block a user