mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-19 01:09:21 +08:00
Use md5 "pings" in percona_test.sentinel for sub-second tests that call wipe_clean() twice. Update t/lib/samples/SchemaIterator/all-dbs-tbls-5.0.txt for percona_test.sentinel. Restart slaves in pt-table-checksum/replication_filters.t. Modernize and make pt-table-sync/replicate_do_db.t stable.
This commit is contained in:
@@ -313,15 +313,15 @@ sub ok {
|
|||||||
# Dings a heartbeat on the master, and waits until the slave catches up fully.
|
# Dings a heartbeat on the master, and waits until the slave catches up fully.
|
||||||
sub wait_for_slaves {
|
sub wait_for_slaves {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $now = time();
|
|
||||||
my $master_dbh = $self->get_dbh_for('master');
|
my $master_dbh = $self->get_dbh_for('master');
|
||||||
my $slave2_dbh = $self->get_dbh_for('slave2');
|
my $slave2_dbh = $self->get_dbh_for('slave2');
|
||||||
$master_dbh->do("update percona_test.sentinel set a=$now where id = 1");
|
my ($ping) = $master_dbh->selectrow_array("SELECT MD5(RAND() + NOW())");
|
||||||
|
$master_dbh->do("UPDATE percona_test.sentinel SET ping='$ping' WHERE id=1");
|
||||||
PerconaTest::wait_until(
|
PerconaTest::wait_until(
|
||||||
sub {
|
sub {
|
||||||
my $then = $slave2_dbh->selectall_arrayref(
|
my ($pong) = $slave2_dbh->selectrow_array(
|
||||||
"select a from percona_test.sentinel where id = 1")->[0]->[0];
|
"SELECT ping FROM percona_test.sentinel WHERE id=1");
|
||||||
return $now == $then;
|
return $ping eq $pong;
|
||||||
}, undef, 300
|
}, undef, 300
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,15 +291,13 @@ case $opt in
|
|||||||
echo "OK"
|
echo "OK"
|
||||||
fi
|
fi
|
||||||
../util/checksum-test-dataset
|
../util/checksum-test-dataset
|
||||||
now=$(date +%s);
|
ping=$(/tmp/12345/use -ss -e "SELECT MD5(RAND() + NOW())")
|
||||||
/tmp/12345/use -e 'create table percona_test.sentinel(id int primary key, a int unsigned)';
|
/tmp/12345/use -e "create table percona_test.sentinel(id int primary key, ping varchar(64) not null default '')"
|
||||||
/tmp/12345/use -e "insert into percona_test.sentinel(id, a) values(1, $now)";
|
/tmp/12345/use -e "insert into percona_test.sentinel(id, ping) values(1, '$ping')";
|
||||||
echo -n "Waiting for replication to finish..."
|
echo -n "Waiting for replication to finish..."
|
||||||
while true; do
|
while true; do
|
||||||
found=$(/tmp/12347/use -ss -e 'select a from percona_test.sentinel where id = 1' 2>/dev/null)
|
pong=$(/tmp/12347/use -ss -e 'select ping from percona_test.sentinel where id=1' 2>/dev/null)
|
||||||
if [ "$found" = "$now" ]; then
|
[ "$ping" = "$pong" ] && break
|
||||||
break
|
|
||||||
fi
|
|
||||||
echo -n '.'
|
echo -n '.'
|
||||||
sleep 1
|
sleep 1
|
||||||
done
|
done
|
||||||
|
|||||||
@@ -243,6 +243,13 @@ CREATE TABLE `checksums` (
|
|||||||
PRIMARY KEY (`db_tbl`)
|
PRIMARY KEY (`db_tbl`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||||
|
|
||||||
|
percona_test.sentinel
|
||||||
|
CREATE TABLE `sentinel` (
|
||||||
|
`id` int(11) NOT NULL,
|
||||||
|
`a` int(10) unsigned default NULL,
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE=MyISAM DEFAULT CHARSET=latin1
|
||||||
|
|
||||||
sakila.actor
|
sakila.actor
|
||||||
CREATE TABLE `actor` (
|
CREATE TABLE `actor` (
|
||||||
`actor_id` smallint(5) unsigned NOT NULL auto_increment,
|
`actor_id` smallint(5) unsigned NOT NULL auto_increment,
|
||||||
|
|||||||
@@ -263,6 +263,8 @@ $master_dbh->disconnect();
|
|||||||
diag(`/tmp/12345/stop >/dev/null`);
|
diag(`/tmp/12345/stop >/dev/null`);
|
||||||
diag(`mv /tmp/12345/orig.cnf /tmp/12345/my.sandbox.cnf`);
|
diag(`mv /tmp/12345/orig.cnf /tmp/12345/my.sandbox.cnf`);
|
||||||
diag(`/tmp/12345/start >/dev/null`);
|
diag(`/tmp/12345/start >/dev/null`);
|
||||||
|
# Restart the slaves so they reconnect immediately.
|
||||||
|
restart_slave_threads();
|
||||||
$master_dbh = $sb->get_dbh_for('master');
|
$master_dbh = $sb->get_dbh_for('master');
|
||||||
|
|
||||||
# Get the master's binlog pos so we can check its binlogs for USE statements
|
# Get the master's binlog pos so we can check its binlogs for USE statements
|
||||||
|
|||||||
@@ -21,16 +21,8 @@ my $dp = new DSNParser(opts=>$dsn_opts);
|
|||||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||||
my $master_dbh = $sb->get_dbh_for('master');
|
my $master_dbh = $sb->get_dbh_for('master');
|
||||||
|
|
||||||
# Reset master and slave relay logs so the second slave
|
|
||||||
# starts faster (i.e. so it doesn't have to replay the
|
|
||||||
# masters logs which is stuff from previous tests that we
|
|
||||||
# don't care about).
|
|
||||||
diag(`$trunk/sandbox/test-env reset >/dev/null`);
|
|
||||||
|
|
||||||
# It's not really master1, we just use its port 12348.
|
# It's not really master1, we just use its port 12348.
|
||||||
# diag(`/tmp/12348/stop >/dev/null 2>&1`);
|
diag(`$trunk/sandbox/start-sandbox slave 12348 12345`);
|
||||||
# diag(`rm -rf /tmp/12348/ >/dev/null 2>&1`);
|
|
||||||
diag(`$trunk/sandbox/start-sandbox slave 12348 12345 >/dev/null`);
|
|
||||||
my $dbh3 = $sb->get_dbh_for('master1');
|
my $dbh3 = $sb->get_dbh_for('master1');
|
||||||
|
|
||||||
if ( !$master_dbh ) {
|
if ( !$master_dbh ) {
|
||||||
@@ -40,7 +32,7 @@ elsif ( !$dbh3 ) {
|
|||||||
plan skip_all => 'Cannot connect to second sandbox slave';
|
plan skip_all => 'Cannot connect to second sandbox slave';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 5;
|
plan tests => 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sb->wipe_clean($master_dbh);
|
$sb->wipe_clean($master_dbh);
|
||||||
@@ -59,26 +51,8 @@ $master_dbh->do('CREATE DATABASE test');
|
|||||||
$master_dbh->do('CREATE TABLE test.foo (i INT, UNIQUE INDEX (i))');
|
$master_dbh->do('CREATE TABLE test.foo (i INT, UNIQUE INDEX (i))');
|
||||||
$master_dbh->do('INSERT INTO test.foo VALUES (1),(2),(9)');
|
$master_dbh->do('INSERT INTO test.foo VALUES (1),(2),(9)');
|
||||||
diag(`/tmp/12345/use < $trunk/t/pt-table-sync/samples/issue_533.sql`);
|
diag(`/tmp/12345/use < $trunk/t/pt-table-sync/samples/issue_533.sql`);
|
||||||
|
PerconaTest::wait_for_table($dbh3, "test.foo", "i=9");
|
||||||
# My box acts weird so I double check that this is ok.
|
PerconaTest::wait_for_table($dbh3, "onlythisdb.t", "i=3");
|
||||||
my $r;
|
|
||||||
my $i = 0;
|
|
||||||
PerconaTest::wait_until(
|
|
||||||
sub {
|
|
||||||
eval {
|
|
||||||
$r = $dbh3->selectrow_arrayref('SHOW TABLES FROM test');
|
|
||||||
};
|
|
||||||
return 1 if ($r->[0] || '') eq 'foo';
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
0.5,
|
|
||||||
30,
|
|
||||||
);
|
|
||||||
is_deeply(
|
|
||||||
$r,
|
|
||||||
['foo'],
|
|
||||||
'Slave has other db.tbl'
|
|
||||||
) or die "Timeout waiting for slave";
|
|
||||||
|
|
||||||
# Stop the slave, add replicate-do-db to its config, and restart it.
|
# Stop the slave, add replicate-do-db to its config, and restart it.
|
||||||
$dbh3->disconnect();
|
$dbh3->disconnect();
|
||||||
@@ -87,24 +61,26 @@ diag(`echo "replicate-do-db = onlythisdb" >> /tmp/12348/my.sandbox.cnf`);
|
|||||||
diag(`/tmp/12348/start >/dev/null`);
|
diag(`/tmp/12348/start >/dev/null`);
|
||||||
$dbh3 = $sb->get_dbh_for('master1');
|
$dbh3 = $sb->get_dbh_for('master1');
|
||||||
|
|
||||||
die "Second sandbox master lost test.foo"
|
|
||||||
unless -f '/tmp/12348/data/test/foo.frm';
|
|
||||||
|
|
||||||
# Make master and slave differ. Because we USE test, this DELETE on
|
# 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
|
# the master won't replicate to the slave now that replicate-do-db
|
||||||
# is set.
|
# is set.
|
||||||
$master_dbh->do('USE test');
|
$master_dbh->do("USE test");
|
||||||
$master_dbh->do('DELETE FROM onlythisdb.t WHERE i = 2');
|
$master_dbh->do("DELETE FROM onlythisdb.t WHERE i = 2");
|
||||||
$dbh3->do('INSERT INTO test.foo VALUES (5)');
|
$dbh3->do("INSERT INTO test.foo VALUES (5)");
|
||||||
|
|
||||||
$r = $dbh3->selectall_arrayref('SELECT * FROM onlythisdb.t ORDER BY i');
|
my $r = $dbh3->selectall_arrayref('SELECT * FROM onlythisdb.t ORDER BY i');
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$r,
|
$r,
|
||||||
[[1],[2],[3]],
|
[[1],[2],[3]],
|
||||||
'do-replicate-db is out of sync before sync'
|
'do-replicate-db is out of sync before sync'
|
||||||
);
|
);
|
||||||
|
|
||||||
`$trunk/bin/pt-table-sync h=127.1,P=12348,u=msandbox,p=msandbox --sync-to-master --execute --no-check-triggers --ignore-databases sakila,mysql 2>&1`;
|
output(
|
||||||
|
sub { pt_table_sync::main("h=127.1,P=12348,u=msandbox,p=msandbox",
|
||||||
|
qw(--sync-to-master --execute --no-check-triggers),
|
||||||
|
"--ignore-databases", "sakila,mysql") },
|
||||||
|
stderr => 1,
|
||||||
|
);
|
||||||
|
|
||||||
$r = $dbh3->selectall_arrayref('SELECT * FROM onlythisdb.t ORDER BY i');
|
$r = $dbh3->selectall_arrayref('SELECT * FROM onlythisdb.t ORDER BY i');
|
||||||
is_deeply(
|
is_deeply(
|
||||||
@@ -121,7 +97,7 @@ is_deeply(
|
|||||||
);
|
);
|
||||||
|
|
||||||
$dbh3->disconnect();
|
$dbh3->disconnect();
|
||||||
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
|
diag(`$trunk/sandbox/stop-sandbox 12348`);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
|
|||||||
Reference in New Issue
Block a user