mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-04-17 01:01:39 +08:00
Fix, simplify, enhance, and make pt-table-checksum/throttle.t stable.
This commit is contained in:
@@ -11,6 +11,8 @@ use warnings FATAL => 'all';
|
|||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
|
||||||
|
$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
|
||||||
|
|
||||||
use PerconaTest;
|
use PerconaTest;
|
||||||
use Sandbox;
|
use Sandbox;
|
||||||
shift @INC; # our unshift (above)
|
shift @INC; # our unshift (above)
|
||||||
@@ -33,41 +35,50 @@ elsif ( !$slave2_dbh ) {
|
|||||||
plan skip_all => 'Cannot connect to sandbox slave2';
|
plan skip_all => 'Cannot connect to sandbox slave2';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 5;
|
plan tests => 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||||
# so we need to specify --lock-wait-timeout=3 else the tool will die.
|
# so we need to specify --lock-wait-timeout=3 else the tool will die.
|
||||||
# And --max-load "" prevents waiting for status variables.
|
# And --max-load "" prevents waiting for status variables.
|
||||||
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
||||||
my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '');
|
my @args = ($master_dsn, qw(--lock-wait-timeout 3), '--max-load', '',
|
||||||
|
'--progress', 'time,1');
|
||||||
my $output;
|
my $output;
|
||||||
my $row;
|
my $row;
|
||||||
my $exit_status;
|
my $exit_status;
|
||||||
|
|
||||||
wait_until( # slaves aren't lagging
|
# Create the checksum table, else stopping the slave below
|
||||||
sub {
|
# will cause the tool to wait forever for the --replicate
|
||||||
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
# table to replicate to the stopped slave.
|
||||||
return 0 if $row->{Seconds_Behind_Master};
|
pt_table_checksum::main(@args, qw(-t sakila.city --quiet));
|
||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
|
||||||
return 0 if $row->{Seconds_Behind_Master};
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
) or die "Slaves are still lagging";
|
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# --check-slave-lag
|
# --check-slave-lag
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
|
|
||||||
|
# Stop slave1.
|
||||||
|
PerconaTest::wait_until_no_lag($slave1_dbh, $slave2_dbh);
|
||||||
$slave1_dbh->do('stop slave sql_thread');
|
$slave1_dbh->do('stop slave sql_thread');
|
||||||
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
wait_until(sub {
|
||||||
is(
|
my $ss = $slave1_dbh->selectrow_hashref("SHOW SLAVE STATUS");
|
||||||
$row->{slave_sql_running},
|
return $ss->{slave_sql_running} eq 'Yes';
|
||||||
'No',
|
});
|
||||||
'Stopped slave SQL thread on slave1'
|
|
||||||
|
# Try to checksum, but since slave1 is stopped, the tool should
|
||||||
|
# wait for it to stop "lagging".
|
||||||
|
($output) = PerconaTest::full_output(
|
||||||
|
sub { pt_table_checksum::main(@args, qw(-t sakila.city)) },
|
||||||
|
wait_for => 3,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/Replica h=127.0.0.1,P=12346 is stopped/,
|
||||||
|
"Waits for stopped replica"
|
||||||
|
);
|
||||||
|
|
||||||
|
# Checksum but only use slave2 to check for lag.
|
||||||
$exit_status = pt_table_checksum::main(@args, qw(-t sakila.city --quiet),
|
$exit_status = pt_table_checksum::main(@args, qw(-t sakila.city --quiet),
|
||||||
qw(--no-replicate-check), '--check-slave-lag', 'P=12347');
|
qw(--no-replicate-check), '--check-slave-lag', 'P=12347');
|
||||||
|
|
||||||
@@ -84,15 +95,10 @@ is(
|
|||||||
"Checksummed table"
|
"Checksummed table"
|
||||||
);
|
);
|
||||||
|
|
||||||
# Start slave2 sql_thread and stop slave1 sql_thread and test that
|
$slave1_dbh->do('START SLAVE sql_thread');
|
||||||
# mk-table-checksum is really checking and waiting for just --slave-lag-dbh.
|
$slave2_dbh->do('STOP SLAVE');
|
||||||
$slave1_dbh->do('start slave sql_thread');
|
$slave2_dbh->do('START SLAVE');
|
||||||
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
PerconaTest::wait_until_slave_running($slave1_dbh, $slave2_dbh);
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'Yes',
|
|
||||||
'Started slave SQL thread on slave1'
|
|
||||||
) or BAIL_OUT("Failed to restart SQL thread on slave2 (12347)");
|
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
|
|||||||
Reference in New Issue
Block a user