PT-2160 fix tests for pt online schema change (#602)

* PT-2160 - Fix tests for pt-online-schema-change

Re-enabled tests after MySQL bug #89441 fix in 8.0.14 and later
Updated t/pt-online-schema-change/samples/basic_no_fks_innodb.sql, so its unique index is NOT NULL
Added synchonizations when tests are waiting for too long due to slave catch up
Added innodb_directories option for t/pt-online-schema-change/pt-244.t

* PT-2160 - Fix tests for pt-online-schema-change
PT-2048 - pt-osc spans excessive connections to the replica when executing in the source

t/pt-online-schema-change/slave_lag.t was failing due to PT-2048. I added code that reuses already created connections when checks for slave in the wait loop. It fixes slave_lag.t too.
I also added that prints more detailed error when fails to connect to the replica.

* PT-2160 - Fix tests for pt-online-schema-change

Modified t/pt-online-schema-change/slave_lag.t, so it runs and clean ups faster.

* PT-2160 - Fix tests for pt-online-schema-change

Modified t/pt-online-schema-change/pt-1455.t, so it runs and clean ups faster.

* PT-2160 - Fix tests for pt-online-schema-change

Fixed search for HASH and BTREE keys broken by fix for PT-2123
Updated modules for pt-archiver
Fixed die message for sandbox/start-sandbox
Added global_grants table to list of exceptions for the ok function in lib/Sandbox.pm
Added wait_for_slaves to bugs.t, so changes on the source are copied to replica before pt-osc starts working
Updated PXC tests
Added wait_for_slaves to pt-1455.t
Fixed regular expression in pt-229.t, so it works with both 5.x and 8.0 versions
Added innodb_directories option for pt-244.t, so it does not fail on 8.0
Modified slave_lag.t, so it is more stable and slow enough, so pt-osc can print message about delayed replicas
This commit is contained in:
Sveta Smirnova
2023-02-27 01:19:11 +03:00
committed by GitHub
parent 7ecdae6ef6
commit bfc00b93a8
20 changed files with 165 additions and 73 deletions

View File

@@ -2139,7 +2139,7 @@ sub get_keys {
my $clustered_key = undef;
KEY:
foreach my $key ( $ddl =~ m/^ ((?:[A-Z]+ )?KEY \(?`[\s\S]*?`\),?)$/gm ) {
foreach my $key ( $ddl =~ m/^ ((?:[A-Z]+ )?KEY \(?`[\s\S]*?`\)[\s\S]*?,?)$/gm ) {
next KEY if $key =~ m/FOREIGN/;
@@ -3674,6 +3674,7 @@ sub get_slaves {
dsn => $dsn,
slave_user => $o->got('slave-user') ? $o->get('slave-user') : '',
slave_password => $o->got('slave-password') ? $o->get('slave-password') : '',
slaves => $args{slaves},
callback => sub {
my ( $dsn, $dbh, $level, $parent ) = @_;
return unless $level;
@@ -3750,16 +3751,29 @@ sub recurse_to_slaves {
PTDEBUG && _d("Slave password set");
}
my $dbh;
eval {
$dbh = $args->{dbh} || $dp->get_dbh(
$dp->get_cxn_params($slave_dsn), { AutoCommit => 1 });
PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn));
};
if ( $EVAL_ERROR ) {
print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), "\n"
or die "Cannot print: $OS_ERROR";
return;
my $dbh = $args->{dbh};
DBH: {
if ( !defined $dbh ) {
foreach my $known_slave ( @{$args->{slaves}} ) {
if ($known_slave->{dsn}->{h} eq $slave_dsn->{h} and
$known_slave->{dsn}->{P} eq $slave_dsn->{P} ) {
$dbh = $known_slave->{dbh};
last DBH;
}
}
eval {
$dbh = $dp->get_dbh(
$dp->get_cxn_params($slave_dsn), { AutoCommit => 1 });
PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn));
};
if ( $EVAL_ERROR ) {
print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), ": ", $EVAL_ERROR, "\n"
or die "Cannot print: $OS_ERROR";
return;
}
}
}
my $sql = 'SELECT @@SERVER_ID';

View File

@@ -3328,7 +3328,7 @@ sub parse {
my $engine = $self->get_engine($ddl);
my @defs = $ddl =~ m/^(\s+`.*?),?$/gm;
my @defs = $ddl =~ m/(?:(?<=,\n)|(?<=\(\n))(\s+`(?:.|\n)+?`.+?),?\n/g;
my @cols = map { $_ =~ m/`([^`]+)`/ } @defs;
PTDEBUG && _d('Table cols:', join(', ', map { "`$_`" } @cols));
@@ -3509,7 +3509,7 @@ sub get_keys {
my $clustered_key = undef;
KEY:
foreach my $key ( $ddl =~ m/^ ((?:[A-Z]+ )?KEY .*)$/gm ) {
foreach my $key ( $ddl =~ m/^ ((?:[A-Z]+ )?KEY \(?`[\s\S]*?`\)[\s\S]*?,?)$/gm ) {
next KEY if $key =~ m/FOREIGN/;
@@ -3520,7 +3520,7 @@ sub get_keys {
$key =~ s/USING HASH/USING BTREE/;
}
my ( $type, $cols ) = $key =~ m/(?:USING (\w+))? \((.+)\)/;
my ( $type, $cols ) = $key =~ m/(?:USING (\w+))? \(([\s\S]+?)\)/;
my ( $special ) = $key =~ m/(FULLTEXT|SPATIAL)/;
$type = $type || $special || 'BTREE';
my ($name) = $key =~ m/(PRIMARY|`[^`]*`)/;
@@ -4225,6 +4225,7 @@ sub get_slaves {
dsn => $dsn,
slave_user => $o->got('slave-user') ? $o->get('slave-user') : '',
slave_password => $o->got('slave-password') ? $o->get('slave-password') : '',
slaves => $args{slaves},
callback => sub {
my ( $dsn, $dbh, $level, $parent ) = @_;
return unless $level;
@@ -4301,16 +4302,29 @@ sub recurse_to_slaves {
PTDEBUG && _d("Slave password set");
}
my $dbh;
eval {
$dbh = $args->{dbh} || $dp->get_dbh(
$dp->get_cxn_params($slave_dsn), { AutoCommit => 1 });
PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn));
};
if ( $EVAL_ERROR ) {
print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), "\n"
or die "Cannot print: $OS_ERROR";
return;
my $dbh = $args->{dbh};
DBH: {
if ( !defined $dbh ) {
foreach my $known_slave ( @{$args->{slaves}} ) {
if ($known_slave->{dsn}->{h} eq $slave_dsn->{h} and
$known_slave->{dsn}->{P} eq $slave_dsn->{P} ) {
$dbh = $known_slave->{dbh};
last DBH;
}
}
eval {
$dbh = $dp->get_dbh(
$dp->get_cxn_params($slave_dsn), { AutoCommit => 1 });
PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn));
};
if ( $EVAL_ERROR ) {
print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), ": ", $EVAL_ERROR, "\n"
or die "Cannot print: $OS_ERROR";
return;
}
}
}
my $sql = 'SELECT @@SERVER_ID';
@@ -8825,6 +8839,7 @@ sub main {
my $slaves =$ms->get_slaves(
dbh => $cxn->dbh(),
dsn => $cxn->dsn(),
slaves => $slaves,
make_cxn => sub {
return $make_cxn->(
@_,

View File

@@ -87,6 +87,7 @@ sub get_slaves {
dsn => $dsn,
slave_user => $o->got('slave-user') ? $o->get('slave-user') : '',
slave_password => $o->got('slave-password') ? $o->get('slave-password') : '',
slaves => $args{slaves},
callback => sub {
my ( $dsn, $dbh, $level, $parent ) = @_;
return unless $level;
@@ -185,16 +186,29 @@ sub recurse_to_slaves {
PTDEBUG && _d("Slave password set");
}
my $dbh;
eval {
$dbh = $args->{dbh} || $dp->get_dbh(
$dp->get_cxn_params($slave_dsn), { AutoCommit => 1 });
PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn));
};
if ( $EVAL_ERROR ) {
print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), "\n"
or die "Cannot print: $OS_ERROR";
return;
my $dbh = $args->{dbh};
DBH: {
if ( !defined $dbh ) {
foreach my $known_slave ( @{$args->{slaves}} ) {
if ($known_slave->{dsn}->{h} eq $slave_dsn->{h} and
$known_slave->{dsn}->{P} eq $slave_dsn->{P} ) {
$dbh = $known_slave->{dbh};
last DBH;
}
}
eval {
$dbh = $dp->get_dbh(
$dp->get_cxn_params($slave_dsn), { AutoCommit => 1 });
PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn));
};
if ( $EVAL_ERROR ) {
print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), ": ", $EVAL_ERROR, "\n"
or die "Cannot print: $OS_ERROR";
return;
}
}
}
my $sql = 'SELECT @@SERVER_ID';

View File

@@ -372,6 +372,7 @@ sub verify_test_data {
grep { !/tables_priv$/ }
grep { !/user$/ }
grep { !/proxies_priv$/ }
grep { !/global_grants$/ }
@{$master->selectcol_arrayref('SHOW TABLES FROM mysql')};
my @tables_in_sakila = qw(actor address category city country customer
film film_actor film_category film_text inventory

View File

@@ -389,8 +389,7 @@ sub get_keys {
my $clustered_key = undef;
KEY:
#foreach my $key ( $ddl =~ m/^ ((?:[A-Z]+ )?KEY .*)$/gm ) {
foreach my $key ( $ddl =~ m/^ ((?:[A-Z]+ )?KEY \(?`[\s\S]*?`\),?)$/gm ) {
foreach my $key ( $ddl =~ m/^ ((?:[A-Z]+ )?KEY \(`[\s\S]*?`\)[\s\S]*?,?)$/gm ) {
# If you want foreign keys, use get_fks() below.
next KEY if $key =~ m/FOREIGN/;

View File

@@ -258,7 +258,7 @@ enable_tokudb=''
if [ "$type" != "master" ] && [ "$type" != "slave" ] && [ "$type" != "master-master" ] && [ "$type" != "cluster" ] && [ "$type" != "channels" ]; then
die "Invalid sandbox type: $type. Valid types are master, slave, and master-master."
die "Invalid sandbox type: $type. Valid types are master, slave, master-master, cluster, and channels."
fi
if [ $port -le 1024 ]; then

View File

@@ -51,7 +51,7 @@ ok(
);
SKIP: {
skip "Skipping in MySQL 8.0.4-rc since there is an error in the server itself. See https://bugs.mysql.com/bug.php?id=89441", 9 if ($sandbox_version ge '8.0');
skip "Skipping in MySQL 8.0.4-rc since there is an error in the server itself. See https://bugs.mysql.com/bug.php?id=89441", 9 if ($sandbox_version ge '8.0' and VersionParser->new($dbh) le'8.0.14');
($output, $exit_status) = full_output(
sub { pt_online_schema_change::main(@args,
"$master_dsn,D=issue26211,t=process_model_inst",

View File

@@ -459,7 +459,7 @@ test_alter_table(
# Somewhat dangerous, but quick. Downside: table doesn't exist for a moment.
SKIP: {
skip "MySQL error https://bugs.mysql.com/bug.php?id=89441", 2 if ($sandbox_version ge '8.0');
skip "MySQL error https://bugs.mysql.com/bug.php?id=89441", 2 if ($sandbox_version ge '8.0' and VersionParser->new($master_dbh) le '8.0.14');
test_alter_table(
name => "Basic FK drop_swap --dry-run",
@@ -576,7 +576,7 @@ SKIP: {
skip 'Sandbox master does not have the sakila database', 7
unless @{$master_dbh->selectcol_arrayref("SHOW DATABASES LIKE 'sakila'")};
skip "MySQL error https://bugs.mysql.com/bug.php?id=89441", 2 if ($sandbox_version ge '8.0');
skip "MySQL error https://bugs.mysql.com/bug.php?id=89441", 2 if ($sandbox_version ge '8.0' and VersionParser->new($master_dbh) le '8.0.14');
# This test will use the drop_swap method because the child tables
# are large. To prove this, change check_fks to rebuild_constraints

View File

@@ -232,6 +232,8 @@ for my $i ( 0..4 ) {
$master_dbh->do(qq{create table `bug_1041372`.$tbl (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY )});
$master_dbh->do(qq{insert into `bug_1041372`.$tbl values (1), (2), (3), (4), (5)});
$sb->wait_for_slaves();
($output) = full_output(sub {
pt_online_schema_change::main(@args,
'--alter', "ADD COLUMN ptosc INT",
@@ -491,7 +493,8 @@ for (my $i = 0; $i < $rows; $i++) {
$big_insert .= "(NULL, 'xx')";
$master_dbh->do($big_insert);
# This big test causes slave lag error on slow boxes
$sb->wait_for_slaves();
$output = output(
sub { pt_online_schema_change::main(@args, "$master_dsn,D=bug_1340728,t=test",

View File

@@ -29,7 +29,7 @@ if ( !$sb->is_cluster_mode ) {
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
server => 'cmaster',
type => 'master',
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
env => q/BINLOG_FORMAT="ROW"/,
);
if ( !$master_dbh ) {
@@ -47,6 +47,16 @@ my $sample = "t/pt-online-schema-change/samples/";
# This is the same test we have for bug-1613915 but using DATA-DIR
$sb->load_file('cmaster', "$sample/bug-1613915.sql");
my $dir = tempdir( CLEANUP => 1 );
my $cmaster_port=$sb->port_for('cmaster');
if ($sandbox_version ge '8.0') {
diag(`/tmp/$cmaster_port/stop >/dev/null`);
diag(`echo "innodb_directories='$dir'" >> /tmp/$cmaster_port/my.sandbox.cnf`);
diag(`/tmp/$cmaster_port/start > /dev/null`);
}
$master_dbh = $sb->get_dbh_for('cmaster');
$output = output(
sub { pt_online_schema_change::main(@args, "$master_dsn,D=test,t=o1",
'--execute',

View File

@@ -26,10 +26,6 @@ require "$trunk/bin/pt-online-schema-change";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
if ($sandbox_version ge '8.0') {
plan skip_all => 'PXC 8 does not exist yet';
}
our ($master_dbh, $master_dsn) = $sb->start_sandbox(
server => 'master',
type => 'master',

View File

@@ -47,12 +47,15 @@ my @args = (qw(--set-vars innodb_lock_wait_timeout=3));
my $output;
my $exit_status;
# We need to reset master, because otherwise later RESET SLAVE call
# will let sandbox to re-apply all previous events, executed on the sandbox.
$master_dbh->do("RESET MASTER");
diag("Setting replication filters on slave 2");
$sb->load_file('slave2', "t/pt-online-schema-change/samples/pt-1455_slave.sql");
$sb->load_file('slave2', "t/pt-online-schema-change/samples/pt-1455_slave.sql", undef, no_wait => 1);
diag("Setting replication filters on slave 1");
$sb->load_file('slave1', "t/pt-online-schema-change/samples/pt-1455_slave.sql");
$sb->load_file('slave1', "t/pt-online-schema-change/samples/pt-1455_slave.sql", undef, no_wait => 1);
diag("Setting replication filters on master");
$sb->load_file('master', "t/pt-online-schema-change/samples/pt-1455_master.sql",undef, no_wait => 1);
$sb->load_file('master', "t/pt-online-schema-change/samples/pt-1455_master.sql");
diag("replication filters set");
my $num_rows = 1000;
@@ -63,6 +66,7 @@ diag(`util/mysql_random_data_load --host=127.0.0.1 --port=$master_port --user=ms
diag("$num_rows rows loaded. Starting tests.");
$master_dbh->do("FLUSH TABLES");
$sb->wait_for_slaves();
($output, $exit_status) = full_output(
sub { pt_online_schema_change::main(@args, "$master_dsn,D=employees,t=t1",
@@ -84,13 +88,14 @@ like(
qr/Successfully altered/s,
"PT-1455 Got successfully altered message.",
);
$master_dbh->do("RESET MASTER");
$master_dbh->do("DROP DATABASE IF EXISTS employees");
diag("Resetting replication filters on slave 2");
$sb->load_file('slave2', "t/pt-online-schema-change/samples/pt-1455_reset_slave.sql");
$sb->load_file('slave2', "t/pt-online-schema-change/samples/pt-1455_reset_slave.sql", undef, no_wait => 1);
diag("Resetting replication filters on slave 1");
$sb->load_file('slave1', "t/pt-online-schema-change/samples/pt-1455_reset_slave.sql");
$sb->load_file('slave1', "t/pt-online-schema-change/samples/pt-1455_reset_slave.sql", undef, no_wait => 1);
$sb->wait_for_slaves();
# #############################################################################
# Done.

View File

@@ -29,8 +29,12 @@ my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
} elsif ($sandbox_version ge '8.0') {
plan skip_all => 'Drop swap does not work with MySQL 8.0+';
}
my $vp = VersionParser->new($master_dbh);
if ($vp->cmp('8.0') > -1 && $vp->cmp('8.0.14') < 0 && $vp->flavor() !~ m/maria/i) {
plan skip_all => 'Drop swap does not work with MySQL 8.0 - 8.0.13';
} else {
plan tests => 3;
}

View File

@@ -317,7 +317,11 @@ sub test_alter_table {
SKIP: {
skip 'Sandbox MySQL version should be >= 5.7' unless $sandbox_version ge '5.7';
# drop_swap won't work with MySQL 8.0+
skip 'Sandbox MySQL version should be < 8.0' unless $sandbox_version lt '8.0';
my $vp = VersionParser->new($master_dbh);
if ($vp->cmp('8.0') > -1 && $vp->cmp('8.0.14') < 0 && $vp->flavor() !~ m/maria/i) {
skip 'Drop swap does not work with MySQL 8.0 - 8.0.13';
}
$sb->load_file('master', "$sample/pt-1919.sql");

View File

@@ -124,7 +124,8 @@ like(
my $rows = $master_dbh->selectrow_arrayref('SHOW CREATE TABLE test.test_a');
like(
@$rows[1],
qr/ `zzz` int\(11\) DEFAULT NULL,/im,
($sandbox_version ge '8.0') ? qr/ `zzz` int DEFAULT NULL,/im :
qr/ `zzz` int\(11\) DEFAULT NULL,/im,
"PT-229 New field was added",
);

View File

@@ -38,6 +38,16 @@ my $master_basedir = "/tmp/$master3_port";
diag(`$trunk/sandbox/stop-sandbox $master3_port >/dev/null`);
diag(`$trunk/sandbox/start-sandbox master $master3_port >/dev/null`);
my $new_dir='/tmp/tdir';
diag(`rm -rf $new_dir`);
diag(`mkdir -p $new_dir`);
if ($sandbox_version ge '8.0') {
diag(`/tmp/$master3_port/stop >/dev/null`);
diag(`echo "innodb_directories='$new_dir'" >> /tmp/$master3_port/my.sandbox.cnf`);
diag(`/tmp/$master3_port/start >/dev/null`);
}
my $dbh3 = $sb->get_dbh_for("master3");
my $dsn3 = $sb->dsn_for("master3");
@@ -62,10 +72,6 @@ diag("$num_rows rows loaded. Starting tests.");
$dbh3->do("FLUSH TABLES");
my $new_dir='/tmp/tdir';
diag(`rm -rf $new_dir`);
diag(`mkdir -p $new_dir`);
diag("2");
($output, $exit_status) = full_output(
sub { pt_online_schema_change::main(@args, "$dsn3,D=test,t=t3",

View File

@@ -146,14 +146,14 @@ is_deeply(
my ($master_dbh, $master_dsn) = $sb->start_sandbox(
server => 'cmaster',
type => 'master',
env => q/FORK="pxc" BINLOG_FORMAT="ROW"/,
env => q/BINLOG_FORMAT="ROW"/,
);
$sb->set_as_slave('node1', 'cmaster');
$sb->load_file('cmaster', "$sample/basic_with_fks.sql", undef, no_wait => 1);
$master_dbh->do("SET SESSION binlog_format=STATEMENT");
$master_dbh->do('SET @@binlog_format:="STATEMENT"');
$master_dbh->do("REPLACE INTO percona_test.sentinel (id, ping) VALUES (1, '')");
$sb->wait_for_slaves(master => 'cmaster', slave => 'node1');

View File

@@ -23,7 +23,7 @@ my $master_dbh = $sb->get_dbh_for('master');
my $vp = VersionParser->new($master_dbh);
if ($vp->cmp('8.0.14') > -1 && $vp->flavor() !~ m/maria/i) {
if ($vp->cmp('8.0') > -1 && $vp->cmp('8.0.14') < 0 && $vp->flavor() !~ m/maria/i) {
plan skip_all => 'Cannot run this test under the current MySQL version';
}

View File

@@ -3,7 +3,7 @@ CREATE DATABASE pt_osc;
USE pt_osc;
CREATE TABLE t (
id int auto_increment primary key,
c char(32),
c char(32) not null,
d date,
unique index (c(32))
) ENGINE=InnoDB;

View File

@@ -22,8 +22,7 @@ use File::Temp qw/ tempdir tempfile /;
if ($ENV{PERCONA_SLOW_BOX}) {
plan skip_all => 'This test needs a fast machine';
} else {
#plan tests => 6;
plan skip_all => 'This test is taking too much time even in fast machines';
plan tests => 6;
}
our $delay = 30;
@@ -54,16 +53,19 @@ sub reset_query_cache {
# 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');
$master_dbh->do("RESET MASTER");
$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");
# Should be greater than chunk-size and big enough, so pt-osc will wait for delay
my $num_rows = 5000;
diag("Loading $num_rows into the table. This might take some time.");
diag(`util/mysql_random_data_load --host=127.0.0.1 --port=12345 --user=msandbox --password=msandbox test pt178 $num_rows`);
$sb->wait_for_slaves();
diag("Setting slave delay to $delay seconds");
$slave_dbh->do('STOP SLAVE');
@@ -73,17 +75,21 @@ $slave_dbh->do('START SLAVE');
# Run a full table scan query to ensure the slave is behind the master
# There is no query cache in MySQL 8.0+
reset_query_cache($master_dbh, $master_dbh);
# Update one row so slave is delayed
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 LIMIT 1');
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 WHERE f1 = ""');
# This is the base test, ust to ensure that without using --check-slave-lag nor --skip-check-slave-lag
# This is the base test, just 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 10 --max-lag $max_lag --alter 'ENGINE=InnoDB' --pid $tmp_file_name";
# We need to sleep, otherwise pt-osc can finish before slave is delayed
sleep($max_lag);
my $args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 10 --max-lag $max_lag --alter 'ENGINE=InnoDB' --pid $tmp_file_name --progress time,5";
diag("Starting base test. This is going to take some time due to the delay in the slave");
diag("pid: $tmp_file_name");
my $output = `$trunk/bin/pt-online-schema-change $args 2>&1`;
like(
$output,
qr/Replica lag is \d+ seconds on .* Waiting/s,
@@ -92,12 +98,16 @@ like(
# Repeat the test now using --check-slave-lag
$args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 1 --max-lag $max_lag --alter 'ENGINE=InnoDB' "
. "--check-slave-lag h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=sbtest --pid $tmp_file_name";
. "--check-slave-lag h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=sbtest --pid $tmp_file_name --progress time,5";
# Run a full table scan query to ensure the slave is behind the master
reset_query_cache($master_dbh, $master_dbh);
# Update one row so slave is delayed
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 LIMIT 1');
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 WHERE f1 = ""');
# We need to sleep, otherwise pt-osc can finish before slave is delayed
sleep($max_lag);
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`;
@@ -109,15 +119,19 @@ like(
# Repeat the test new adding and removing a slave during the process
$args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 1 --max-lag $max_lag --alter 'ENGINE=InnoDB' "
. "--recursion-method=dsn=D=test,t=dynamic_replicas --recurse 0 --pid $tmp_file_name";
. "--recursion-method=dsn=D=test,t=dynamic_replicas --recurse 0 --pid $tmp_file_name --progress time,5";
$master_dbh->do('CREATE TABLE `test`.`dynamic_replicas` (id INTEGER PRIMARY KEY, dsn VARCHAR(255) )');
$master_dbh->do("INSERT INTO `test`.`dynamic_replicas` (id, dsn) VALUES (1, '$slave_dsn')");
# Run a full table scan query to ensure the slave is behind the master
reset_query_cache($master_dbh, $master_dbh);
# Update one row so slave is delayed
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 LIMIT 1');
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 WHERE f1 = ""');
# We need to sleep, otherwise pt-osc can finish before slave is delayed
sleep($max_lag);
diag("Starting --recursion-method with changes during the process");
my ($fh, $filename) = tempfile();
my $pid = fork();
@@ -128,7 +142,7 @@ if (!$pid) {
exec("$trunk/bin/pt-online-schema-change $args");
}
sleep(60);
sleep($max_lag + 10);
$master_dbh->do("DELETE FROM `test`.`dynamic_replicas` WHERE id = 1;");
waitpid($pid, 0);
$output = do {
@@ -153,10 +167,14 @@ like(
# Repeat the test now using --skip-check-slave-lag
# Run a full table scan query to ensure the slave is behind the master
reset_query_cache($master_dbh, $master_dbh);
# Update one row so slave is delayed
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 LIMIT 1');
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 WHERE f1 = ""');
# We need to sleep, otherwise pt-osc can finish before slave is delayed
sleep($max_lag);
$args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 1 --max-lag $max_lag --alter 'ENGINE=InnoDB' "
. "--skip-check-slave-lag h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=sbtest --pid $tmp_file_name";
. "--skip-check-slave-lag h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=sbtest --pid $tmp_file_name --progress time,5";
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`;
@@ -169,10 +187,12 @@ unlike(
diag("Setting slave delay to 0 seconds");
$slave_dbh->do('STOP SLAVE');
$master_dbh->do("RESET MASTER");
$slave_dbh->do('RESET SLAVE');
$slave_dbh->do('START SLAVE');
$master_dbh->do("DROP DATABASE IF EXISTS test");
$sb->wait_for_slaves();
# #############################################################################
# Done.