mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-26 05:58:16 +00:00
rewrite t/pt-table-sync/replicate_do_db.t test -- but it's not 100% complete
This commit is contained in:
@@ -15,89 +15,102 @@ use PerconaTest;
|
||||
use Sandbox;
|
||||
require "$trunk/bin/pt-table-sync";
|
||||
|
||||
my $output;
|
||||
my $vp = new VersionParser();
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
|
||||
# It's not really master1, we just use its port 12348.
|
||||
diag(`$trunk/sandbox/start-sandbox slave 12348 12345`);
|
||||
my $dbh3 = $sb->get_dbh_for('master1');
|
||||
|
||||
if ( !$master_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
elsif ( !$dbh3 ) {
|
||||
plan skip_all => 'Cannot connect to second sandbox slave';
|
||||
}
|
||||
else {
|
||||
plan tests => 4;
|
||||
plan tests => 9;
|
||||
}
|
||||
|
||||
$sb->wipe_clean($master_dbh);
|
||||
|
||||
# #############################################################################
|
||||
# Issue 533: mk-table-sync does not work with replicate-do-db
|
||||
# Maatkit issue 533: mk-table-sync needs to work with replicate-do-db. It should
|
||||
# do a USE <db> as it moves through the tables. We test this by setting
|
||||
# replicate-do-db=test1, and then making sure that changes in the test1 database
|
||||
# get replicated, but test2 doesn't.
|
||||
# #############################################################################
|
||||
|
||||
# This slave is new so it doesn't have the dbs and tbls
|
||||
# created above. We create some so that the current db
|
||||
# will change as they get checked. It should stop at
|
||||
# something other than onlythisdb. Since SHOW DATABSES
|
||||
# returns sorted, test should be checked after onlythisdb.
|
||||
$master_dbh->do('DROP DATABASE IF EXISTS test');
|
||||
$master_dbh->do('CREATE DATABASE test');
|
||||
$master_dbh->do('CREATE TABLE test.foo (i INT, UNIQUE INDEX (i))');
|
||||
$master_dbh->do('INSERT INTO test.foo VALUES (1),(2),(9)');
|
||||
diag(`/tmp/12345/use < $trunk/t/pt-table-sync/samples/issue_533.sql`);
|
||||
PerconaTest::wait_for_table($dbh3, "test.foo", "i=9");
|
||||
PerconaTest::wait_for_table($dbh3, "onlythisdb.t", "i=3");
|
||||
# Add two new test databases with a simple table. IMPORTANT: we do this before
|
||||
# reconfiguring the server, so this gets replicated!
|
||||
foreach my $db (qw(test1 test2)) {
|
||||
$master_dbh->do("DROP DATABASE IF EXISTS $db");
|
||||
$master_dbh->do("CREATE DATABASE $db");
|
||||
$master_dbh->do("CREATE TABLE $db.foo (i INT NOT NULL PRIMARY KEY)");
|
||||
$master_dbh->do("INSERT INTO $db.foo VALUES (1),(2),(9)");
|
||||
}
|
||||
|
||||
# Stop the slave, add replicate-do-db to its config, and restart it.
|
||||
$dbh3->disconnect();
|
||||
diag(`/tmp/12348/stop >/dev/null`);
|
||||
diag(`echo "replicate-do-db = onlythisdb" >> /tmp/12348/my.sandbox.cnf`);
|
||||
diag(`/tmp/12348/start >/dev/null`);
|
||||
$dbh3 = $sb->get_dbh_for('master1');
|
||||
# Stop slave 12346, add replicate-do-db to its config, and restart it.
|
||||
diag('Restarting slave 12346 with replicate-do-db=test1');
|
||||
diag(`/tmp/12346/stop >/dev/null`);
|
||||
diag(`echo "replicate-do-db = test1" >> /tmp/12346/my.sandbox.cnf`);
|
||||
diag(`/tmp/12346/start >/dev/null`);
|
||||
my $slave1_dbh = $sb->get_dbh_for('slave1');
|
||||
|
||||
# Make master and slave differ. Because we USE test, this DELETE on
|
||||
# the master won't replicate to the slave now that replicate-do-db
|
||||
# is set.
|
||||
$master_dbh->do("USE test");
|
||||
$master_dbh->do("DELETE FROM onlythisdb.t WHERE i = 2");
|
||||
$dbh3->do("INSERT INTO test.foo VALUES (5)");
|
||||
my $r = $slave1_dbh->selectrow_hashref('show slave status');
|
||||
is($r->{replicate_do_db}, 'test1', 'Server reconfigured');
|
||||
|
||||
my $r = $dbh3->selectall_arrayref('SELECT * FROM onlythisdb.t ORDER BY i');
|
||||
is_deeply(
|
||||
$r,
|
||||
[[1],[2],[3]],
|
||||
'do-replicate-db is out of sync before sync'
|
||||
);
|
||||
my $slave2_dbh = $sb->get_dbh_for('slave2');
|
||||
$slave2_dbh->do("stop slave");
|
||||
$slave2_dbh->do("start slave");
|
||||
PerconaTest::wait_for_table($slave2_dbh, "test2.foo", "i=9");
|
||||
|
||||
output(
|
||||
sub { pt_table_sync::main("h=127.1,P=12348,u=msandbox,p=msandbox",
|
||||
# #############################################################################
|
||||
# IMPORTANT: anything you want to replicate must now USE test1 first!
|
||||
# IMPORTANT: $sb->wait_for_slaves won't work now!
|
||||
# #############################################################################
|
||||
|
||||
# Make master and slave differ. Because we USE test2, this DELETE on
|
||||
# the master won't replicate to the slave in either case.
|
||||
$master_dbh->do("USE test2");
|
||||
$master_dbh->do("DELETE FROM test1.foo WHERE i = 2");
|
||||
$master_dbh->do("DELETE FROM test2.foo WHERE i = 2");
|
||||
$master_dbh->do("COMMIT");
|
||||
|
||||
# NOTE: $sb->wait_for_slaves() won't work! Hence we do our own way...
|
||||
$master_dbh->do('USE test1');
|
||||
$master_dbh->do('INSERT INTO test2.foo(i) VALUES(10)');
|
||||
PerconaTest::wait_for_table($slave2_dbh, "test2.foo", "i=9");
|
||||
|
||||
# Prove that the slave (12347, not 12346) still has i=2 in test2.foo, and the
|
||||
# master doesn't. That is, both test1 and test2 are out-of-sync on the slave.
|
||||
$r = $master_dbh->selectall_arrayref('select * from test1.foo where i=2');
|
||||
is_deeply( $r, [], 'master has no test1.foo.i=2');
|
||||
$r = $master_dbh->selectall_arrayref('select * from test2.foo where i=2');
|
||||
is_deeply( $r, [], 'master has no test2.foo.i=2');
|
||||
$r = $slave2_dbh->selectall_arrayref('select * from test1.foo where i=2');
|
||||
is_deeply( $r, [[2]], 'slave2 has test1.foo.i=2');
|
||||
$r = $slave2_dbh->selectall_arrayref('select * from test2.foo where i=2'),
|
||||
is_deeply( $r, [[2]], 'slave2 has test2.foo.i=2');
|
||||
|
||||
# Now we sync, and if pt-table-sync USE's the db it's syncing, then test1 should
|
||||
# be in sync afterwards, and test2 shouldn't.
|
||||
|
||||
my $output = output(
|
||||
sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox",
|
||||
qw(--sync-to-master --execute --no-check-triggers),
|
||||
"--ignore-databases", "sakila,mysql") },
|
||||
"--databases", "test1,test2") },
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
$r = $dbh3->selectall_arrayref('SELECT * FROM onlythisdb.t ORDER BY i');
|
||||
is_deeply(
|
||||
$r,
|
||||
[[1],[3]],
|
||||
'do-replicate-db is in sync after sync'
|
||||
);
|
||||
$r = $slave2_dbh->selectall_arrayref('select * from test1.foo where i=2');
|
||||
is_deeply( $r, [], 'slave2 has NO test1.foo.i=2 after sync');
|
||||
$r = $slave2_dbh->selectall_arrayref('select * from test2.foo where i=2'),
|
||||
is_deeply( $r, [[2]], 'slave2 has test2.foo.i=2 after sync');
|
||||
|
||||
$r = $dbh3->selectall_arrayref('SELECT * FROM test.foo');
|
||||
is_deeply(
|
||||
$r,
|
||||
[[1],[2],[5],[9]],
|
||||
'db not allowed by do-replicate-db was not synced'
|
||||
);
|
||||
diag('Reconfiguring instance 12346 without replication filters');
|
||||
diag(`grep -v replicate.do.db /tmp/12346/my.sandbox.cnf > /tmp/new.cnf`);
|
||||
diag(`mv /tmp/new.cnf /tmp/12346/my.sandbox.cnf`);
|
||||
diag(`/tmp/12346/stop >/dev/null`);
|
||||
diag(`/tmp/12346/start >/dev/null`);
|
||||
$slave2_dbh->do("stop slave");
|
||||
$slave2_dbh->do("start slave");
|
||||
|
||||
$dbh3->disconnect();
|
||||
diag(`$trunk/sandbox/stop-sandbox 12348`);
|
||||
$slave1_dbh = $sb->get_dbh_for('slave1');
|
||||
$r = $slave1_dbh->selectrow_hashref('show slave status');
|
||||
is($r->{replicate_do_db}, '', 'Replication filter removed');
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
|
Reference in New Issue
Block a user