mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-27 16:12:04 +00:00
PT-178 Fixed regression in --check-slave-lag option
Reverted PR #119 https://github.com/percona/percona-toolkit/pull/119 and Added new tests to prevent this happening again.
This commit is contained in:
@@ -12019,7 +12019,9 @@ if you change the contents of the DSN table, OSC will pick it up very soon.
|
||||
type: DSN; repeatable: yes
|
||||
|
||||
DSN to skip when checking slave lag. It can be used multiple times.
|
||||
Example: --skip-check-slave-lag h=127.1,P=12345 --skip-check-slave-lag h=127.1,P=12346
|
||||
Example: --skip-check-slave-lag h=127.0.0.1,P=12345 --skip-check-slave-lag h=127.0.0.1,P=12346
|
||||
Plase take into consideration that even when for the MySQL driver h=127.1 is equal to h=127.0.0.1,
|
||||
for this parameter you need to specify the full IP address.
|
||||
|
||||
=item --slave-user
|
||||
|
||||
|
99
t/pt-online-schema-change/samples/slave_lag.sql
Normal file
99
t/pt-online-schema-change/samples/slave_lag.sql
Normal file
File diff suppressed because one or more lines are too long
101
t/pt-online-schema-change/slave_lag.t
Normal file
101
t/pt-online-schema-change/slave_lag.t
Normal file
@@ -0,0 +1,101 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
BEGIN {
|
||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use threads;
|
||||
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use Data::Dumper;
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use SqlModes;
|
||||
use File::Temp qw/ tempdir /;
|
||||
|
||||
plan tests => 4;
|
||||
our $delay = 30;
|
||||
|
||||
require "$trunk/bin/pt-online-schema-change";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
my $slave_dbh = $sb->get_dbh_for('slave1');
|
||||
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
||||
|
||||
if ( !$master_dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
|
||||
# 1) Set the slave delay to 0 just in case we are re-running the tests without restarting the sandbox.
|
||||
# 2) Load sample data
|
||||
# 3) Set the slave delay to 30 seconds to be able to see the 'waiting' message.
|
||||
diag("Setting slave delay to 0 seconds");
|
||||
$slave_dbh->do('STOP SLAVE');
|
||||
$slave_dbh->do('RESET SLAVE');
|
||||
$slave_dbh->do('START SLAVE');
|
||||
|
||||
diag('Loading test data');
|
||||
$sb->load_file('master', "t/pt-online-schema-change/samples/slave_lag.sql");
|
||||
|
||||
diag("Setting slave delay to $delay seconds");
|
||||
|
||||
$slave_dbh->do('STOP SLAVE');
|
||||
$slave_dbh->do("CHANGE MASTER TO MASTER_DELAY=$delay");
|
||||
$slave_dbh->do('START SLAVE');
|
||||
|
||||
# This is the base test, ust to ensure that without using --check-slave-lag nor --skip-check-slave-lag
|
||||
# pt-online-schema-change will wait on the slave at port 12346
|
||||
|
||||
my $max_lag = $delay / 2;
|
||||
my $args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 1 --max-lag 5 --alter 'ENGINE=InnoDB' ";
|
||||
diag("Starting base test. This is going to take some time due to the delay in the slave");
|
||||
my $output = `$trunk/bin/pt-online-schema-change $args 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Replica lag is \d+ seconds on .* Waiting/s,
|
||||
"Base test waits on the correct slave",
|
||||
);
|
||||
|
||||
# Repeat the test now using --check-slave-lag
|
||||
$args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 1 --max-lag 5 --alter 'ENGINE=InnoDB' "
|
||||
. "--check-slave-lag h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=sbtest";
|
||||
|
||||
diag("Starting --check-slave-lag test. This is going to take some time due to the delay in the slave");
|
||||
$output = `$trunk/bin/pt-online-schema-change $args 2>&1`;
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Replica lag is \d+ seconds on .* Waiting/s,
|
||||
"--check-slave-lag waits on the correct slave",
|
||||
);
|
||||
|
||||
# Repeat the test now using --skip-check-slave-lag
|
||||
$args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 1 --max-lag 5 --alter 'ENGINE=InnoDB' "
|
||||
. "--skip-check-slave-lag h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=sbtest";
|
||||
|
||||
diag("Starting --skip-check-slave-lag test. This is going to take some time due to the delay in the slave");
|
||||
$output = `$trunk/bin/pt-online-schema-change $args 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Replica lag is \d+ seconds on .* Waiting/s,
|
||||
"--skip-check-slave-lag is really skipping the slave",
|
||||
);
|
||||
|
||||
$master_dbh->do("DROP DATABASE IF EXISTS test");
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
Reference in New Issue
Block a user