mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-01 18:25:59 +00:00
PT-2168 pt-osc shouldnt fail while unable to monitor a replica node (#676)
* PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Proof of concept - Fixed regular expression in lib/TableParser.pm mistakenly chaged in the tool's code * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Added basic test case for PT-2168 - Added more details for replica lag information - Disconnecting replica if lag is not checked. This prevents "Too many connections" error * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Implemented option --wait-lost-replicas for pt-osc, added test case * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Added more tests for situations where connection to the replica can fail * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Removed extra checks for wait_no_die variable - Added test cases for SQL queries that pt-osc sends to replicas * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Allow to reload dsns table while waiting for missed replica if --recursion-method is dsn - Fixed logic in replica rediscovery, so it works with replicas on the same host but with different ports - Renamed option wait-lost-replicas to fail-on-stopped-replication, so it is in line with pt-table-checksum - Adjusted tests - Removed debug code for PT-1760 - Added test case for PT-1760 - Added exception for variable Open_tables_with_triggers in lib/bash/collect.sh due to failed test in Percona Server 8.0.34+ - Updated pt-stalk * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Updated modules - Fixed typo in t/pt-table-sync/bidirectional.t - Removed trailing whitespaces in lib/MasterSlave.pm * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Help for option --fail-on-stopped-replication * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Added check for availability of the simple_rewrite_plugin in t/pt-online-schema-change/pt-2168.t * PT-2168 - PT-OSC shouldn't fail while unable to monitor a replica node - Added link to the simple_rewrite_plugin source code - Removed tests for code that runs only in the beginning of pt-osc action, so should not be affected by the option fail-on-stopped-replication
This commit is contained in:
@@ -3692,6 +3692,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -3699,6 +3700,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -3754,6 +3756,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -3763,23 +3779,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -4401,18 +4423,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
|
@@ -187,6 +187,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -194,6 +195,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -249,6 +251,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -258,23 +274,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -896,18 +918,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
|
79
bin/pt-kill
79
bin/pt-kill
@@ -3969,6 +3969,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -3976,6 +3977,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -4031,6 +4033,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -4040,23 +4056,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -4678,18 +4700,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
|
@@ -4255,6 +4255,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -4262,6 +4263,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -4317,6 +4319,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -4326,23 +4342,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -4964,18 +4986,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
@@ -5048,9 +5091,9 @@ sub wait {
|
||||
my ($self) = @_;
|
||||
my ($slaves, $refresher) = ($self->{slaves}, $self->{get_slaves_cb});
|
||||
return $slaves if ( not defined $refresher );
|
||||
my $before = join ' ', sort map {$_->name()} @$slaves;
|
||||
my $before = join ' ', sort map {$_->description()} @$slaves;
|
||||
$slaves = $refresher->();
|
||||
my $after = join ' ', sort map {$_->name()} @$slaves;
|
||||
my $after = join ' ', sort map {$_->description()} @$slaves;
|
||||
if ($before ne $after) {
|
||||
$self->{slaves} = $slaves;
|
||||
printf STDERR "Slave set to watch has changed\n Was: %s\n Now: %s\n",
|
||||
@@ -5065,9 +5108,10 @@ sub wait {
|
||||
$pr_callback = sub {
|
||||
my ($fraction, $elapsed, $remaining, $eta, $completed) = @_;
|
||||
my $dsn_name = $worst->{cxn}->name();
|
||||
my $dsn_description = $worst->{cxn}->description();
|
||||
if ( defined $worst->{lag} ) {
|
||||
print STDERR "Replica lag is " . ($worst->{lag} || '?')
|
||||
. " seconds on $dsn_name. Waiting.\n";
|
||||
. " seconds on $dsn_description. Waiting.\n";
|
||||
}
|
||||
else {
|
||||
if ($self->{fail_on_stopped_replication}) {
|
||||
@@ -8702,10 +8746,21 @@ sub main {
|
||||
OptionParser => $o,
|
||||
set => $set_on_connect,
|
||||
);
|
||||
eval { $cxn->connect() }; # connect or die trying
|
||||
if ( $EVAL_ERROR ) {
|
||||
_die("Cannot connect to MySQL: $EVAL_ERROR", MYSQL_CONNECTION_ERROR);
|
||||
}
|
||||
my $done = 0;
|
||||
do {
|
||||
eval { $cxn->connect() }; # connect or die trying
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ($args{'wait_no_die'} && ($cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
} else {
|
||||
die("Cannot connect to MySQL: $EVAL_ERROR", MYSQL_CONNECTION_ERROR);
|
||||
}
|
||||
} else {
|
||||
$done = 1;
|
||||
}
|
||||
} until $done;
|
||||
return $cxn;
|
||||
};
|
||||
|
||||
@@ -8860,6 +8915,7 @@ sub main {
|
||||
errok => (not $intolerant)
|
||||
);
|
||||
},
|
||||
wait_no_die => !$o->get('fail-on-stopped-replication'),
|
||||
);
|
||||
|
||||
if ($slaves_to_skip) {
|
||||
@@ -8870,6 +8926,7 @@ sub main {
|
||||
if ($slave->{dsn}->{h} eq $slave_to_skip->{h} && $slave->{dsn}->{P} eq $slave_to_skip->{P}) {
|
||||
print "Skipping slave " . $slave->description() . "\n";
|
||||
$is_skip = 1;
|
||||
$slave->{dbh}->disconnect();
|
||||
last;
|
||||
}
|
||||
}
|
||||
@@ -9009,10 +9066,8 @@ sub main {
|
||||
# to stop lagging. If any replica is stopped, the tool
|
||||
# waits forever until the replica is started."
|
||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1402051
|
||||
#TODO REMOVE DEBUG
|
||||
PTDEBUG && _d('2> Cannot connect to', $cxn->name(), ':',
|
||||
$EVAL_ERROR);
|
||||
die '2> Cannot connect to '. $cxn->name() . ':' . $EVAL_ERROR;
|
||||
# Make ReplicaLagWaiter::wait() report slave is stopped.
|
||||
return undef;
|
||||
}
|
||||
@@ -9023,7 +9078,6 @@ sub main {
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
PTDEBUG && _d('Cannot get lag for', $cxn->name(), ':', $EVAL_ERROR);
|
||||
die '2> Cannot connect to '. $cxn->name() . ':' . $EVAL_ERROR;
|
||||
}
|
||||
return $lag; # undef if error
|
||||
};
|
||||
@@ -10011,7 +10065,19 @@ sub main {
|
||||
|
||||
# Wait forever for slaves to catch up.
|
||||
$replica_lag_pr->start() if $replica_lag_pr;
|
||||
$replica_lag->wait(Progress => $replica_lag_pr);
|
||||
LAG:
|
||||
{
|
||||
eval { $replica_lag->wait(Progress => $replica_lag_pr) };
|
||||
if ( $EVAL_ERROR ) {
|
||||
if (!$o->get('fail-on-stopped-replication')) {
|
||||
PTDEBUG && _d($EVAL_ERROR);
|
||||
sleep 1;
|
||||
next LAG;
|
||||
} else {
|
||||
_die("Error while waiting for replica lag: " . $EVAL_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Wait forever for system load to abate. wait() will die if
|
||||
# --critical load is reached.
|
||||
@@ -13093,6 +13159,13 @@ tool.
|
||||
|
||||
For more information, visit L<https://www.percona.com/doc/percona-toolkit/LATEST/version-check.html>.
|
||||
|
||||
=item --[no]fail-on-stopped-replication
|
||||
|
||||
default: yes
|
||||
|
||||
If replication is stopped, fail with an error (exit status 128) instead of waiting
|
||||
until replication is restarted.
|
||||
|
||||
=back
|
||||
|
||||
=head1 PLUGIN
|
||||
|
@@ -10560,6 +10560,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -10567,6 +10568,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -10622,6 +10624,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -10631,23 +10647,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -11269,18 +11291,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
|
@@ -2323,6 +2323,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -2330,6 +2331,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -2385,6 +2387,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -2394,23 +2410,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -3032,18 +3054,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
|
@@ -2734,6 +2734,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -2741,6 +2742,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -2796,6 +2798,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -2805,23 +2821,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -3443,18 +3465,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
|
@@ -1103,7 +1103,7 @@ collect_mysql_data_two() {
|
||||
}
|
||||
|
||||
open_tables() {
|
||||
local open_tables=$($CMD_MYSQLADMIN $EXT_ARGV ext | grep "Open_tables" | awk '{print $4}')
|
||||
local open_tables=$($CMD_MYSQLADMIN $EXT_ARGV ext | grep "Open_tables" | grep -v "Open_tables_with_triggers" | awk '{print $4}')
|
||||
if [ -n "$open_tables" -a $open_tables -le 1000 ]; then
|
||||
$CMD_MYSQL $EXT_ARGV -e 'SHOW OPEN TABLES' &
|
||||
else
|
||||
|
@@ -5218,6 +5218,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -5225,6 +5226,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -5280,6 +5282,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -5289,23 +5305,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -5927,18 +5949,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
@@ -8719,9 +8762,9 @@ sub wait {
|
||||
my ($self) = @_;
|
||||
my ($slaves, $refresher) = ($self->{slaves}, $self->{get_slaves_cb});
|
||||
return $slaves if ( not defined $refresher );
|
||||
my $before = join ' ', sort map {$_->name()} @$slaves;
|
||||
my $before = join ' ', sort map {$_->description()} @$slaves;
|
||||
$slaves = $refresher->();
|
||||
my $after = join ' ', sort map {$_->name()} @$slaves;
|
||||
my $after = join ' ', sort map {$_->description()} @$slaves;
|
||||
if ($before ne $after) {
|
||||
$self->{slaves} = $slaves;
|
||||
printf STDERR "Slave set to watch has changed\n Was: %s\n Now: %s\n",
|
||||
@@ -8736,9 +8779,10 @@ sub wait {
|
||||
$pr_callback = sub {
|
||||
my ($fraction, $elapsed, $remaining, $eta, $completed) = @_;
|
||||
my $dsn_name = $worst->{cxn}->name();
|
||||
my $dsn_description = $worst->{cxn}->description();
|
||||
if ( defined $worst->{lag} ) {
|
||||
print STDERR "Replica lag is " . ($worst->{lag} || '?')
|
||||
. " seconds on $dsn_name. Waiting.\n";
|
||||
. " seconds on $dsn_description. Waiting.\n";
|
||||
}
|
||||
else {
|
||||
if ($self->{fail_on_stopped_replication}) {
|
||||
|
@@ -6734,6 +6734,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -6741,6 +6742,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -6796,6 +6798,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -6805,23 +6821,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -7443,18 +7465,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
|
@@ -104,6 +104,7 @@ sub get_slaves {
|
||||
push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent);
|
||||
return;
|
||||
},
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
}
|
||||
);
|
||||
} elsif ( $methods->[0] =~ m/^dsn=/i ) {
|
||||
@@ -111,6 +112,7 @@ sub get_slaves {
|
||||
$slaves = $self->get_cxn_from_dsn_table(
|
||||
%args,
|
||||
dsn_table_dsn => $dsn_table_dsn,
|
||||
wait_no_die => $args{'wait_no_die'},
|
||||
);
|
||||
}
|
||||
elsif ( $methods->[0] =~ m/none/i ) {
|
||||
@@ -188,6 +190,20 @@ sub recurse_to_slaves {
|
||||
|
||||
my $dbh = $args->{dbh};
|
||||
|
||||
my $get_dbh = sub {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
DBH: {
|
||||
if ( !defined $dbh ) {
|
||||
foreach my $known_slave ( @{$args->{slaves}} ) {
|
||||
@@ -197,23 +213,29 @@ sub recurse_to_slaves {
|
||||
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;
|
||||
}
|
||||
$get_dbh->();
|
||||
}
|
||||
}
|
||||
|
||||
my $sql = 'SELECT @@SERVER_ID';
|
||||
PTDEBUG && _d($sql);
|
||||
my ($id) = $dbh->selectrow_array($sql);
|
||||
my $id = undef;
|
||||
do {
|
||||
eval {
|
||||
($id) = $dbh->selectrow_array($sql);
|
||||
};
|
||||
if ( $EVAL_ERROR ) {
|
||||
if ( $args->{wait_no_die} ) {
|
||||
print STDERR "Error getting server id: ", $EVAL_ERROR,
|
||||
"\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n";
|
||||
sleep 1;
|
||||
$dbh->disconnect();
|
||||
$get_dbh->();
|
||||
} else {
|
||||
die $EVAL_ERROR;
|
||||
}
|
||||
}
|
||||
} until ($id);
|
||||
PTDEBUG && _d('Working on server ID', $id);
|
||||
my $master_thinks_i_am = $dsn->{server_id};
|
||||
if ( !defined $id
|
||||
@@ -994,18 +1016,39 @@ sub get_cxn_from_dsn_table {
|
||||
. "or a database-qualified table (t)";
|
||||
}
|
||||
|
||||
my $done = 0;
|
||||
my $dsn_tbl_cxn = $make_cxn->(dsn => $dsn);
|
||||
my $dbh = $dsn_tbl_cxn->connect();
|
||||
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
|
||||
PTDEBUG && _d($sql);
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
my @cxn;
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
use Data::Dumper;
|
||||
DSN:
|
||||
do {
|
||||
@cxn = ();
|
||||
my $dsn_strings = $dbh->selectcol_arrayref($sql);
|
||||
if ( $dsn_strings ) {
|
||||
foreach my $dsn_string ( @$dsn_strings ) {
|
||||
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
|
||||
if ($args{wait_no_die}) {
|
||||
my $lcxn;
|
||||
eval {
|
||||
$lcxn = $make_cxn->(dsn_string => $dsn_string);
|
||||
};
|
||||
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
|
||||
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
|
||||
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
|
||||
sleep(1);
|
||||
goto DSN;
|
||||
}
|
||||
push @cxn, $lcxn;
|
||||
} else {
|
||||
push @cxn, $make_cxn->(dsn_string => $dsn_string);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$done = 1;
|
||||
} until $done;
|
||||
return \@cxn;
|
||||
}
|
||||
|
||||
|
@@ -87,9 +87,9 @@ sub wait {
|
||||
my ($self) = @_;
|
||||
my ($slaves, $refresher) = ($self->{slaves}, $self->{get_slaves_cb});
|
||||
return $slaves if ( not defined $refresher );
|
||||
my $before = join ' ', sort map {$_->name()} @$slaves;
|
||||
my $before = join ' ', sort map {$_->description()} @$slaves;
|
||||
$slaves = $refresher->();
|
||||
my $after = join ' ', sort map {$_->name()} @$slaves;
|
||||
my $after = join ' ', sort map {$_->description()} @$slaves;
|
||||
if ($before ne $after) {
|
||||
$self->{slaves} = $slaves;
|
||||
printf STDERR "Slave set to watch has changed\n Was: %s\n Now: %s\n",
|
||||
@@ -106,9 +106,10 @@ sub wait {
|
||||
$pr_callback = sub {
|
||||
my ($fraction, $elapsed, $remaining, $eta, $completed) = @_;
|
||||
my $dsn_name = $worst->{cxn}->name();
|
||||
my $dsn_description = $worst->{cxn}->description();
|
||||
if ( defined $worst->{lag} ) {
|
||||
print STDERR "Replica lag is " . ($worst->{lag} || '?')
|
||||
. " seconds on $dsn_name. Waiting.\n";
|
||||
. " seconds on $dsn_description. Waiting.\n";
|
||||
}
|
||||
else {
|
||||
if ($self->{fail_on_stopped_replication}) {
|
||||
|
@@ -392,7 +392,7 @@ collect_mysql_data_two() {
|
||||
}
|
||||
|
||||
open_tables() {
|
||||
local open_tables=$($CMD_MYSQLADMIN $EXT_ARGV ext | grep "Open_tables" | awk '{print $4}')
|
||||
local open_tables=$($CMD_MYSQLADMIN $EXT_ARGV ext | grep "Open_tables" | grep -v "Open_tables_with_triggers" | awk '{print $4}')
|
||||
if [ -n "$open_tables" -a $open_tables -le 1000 ]; then
|
||||
$CMD_MYSQL $EXT_ARGV -e 'SHOW OPEN TABLES' &
|
||||
else
|
||||
|
@@ -30,6 +30,8 @@ collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1
|
||||
|
||||
wait_for_files "$p-hostname" "$p-opentables2" "$p-variables" "$p-df" "$p-innodbstatus2"
|
||||
|
||||
cat "$p-opentables2" > /tmp/collect.test
|
||||
|
||||
# Even if this system doesn't have all the cmds, collect should still
|
||||
# have created some files for cmds that (hopefully) all systems have.
|
||||
ls -1 $PT_TMPDIR/collect | sort > $PT_TMPDIR/collect-files
|
||||
|
83
t/pt-online-schema-change/pt-1760.t
Normal file
83
t/pt-online-schema-change/pt-1760.t
Normal file
@@ -0,0 +1,83 @@
|
||||
#!/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 tempfile /;
|
||||
|
||||
our $delay = 10;
|
||||
|
||||
my $tmp_file = File::Temp->new();
|
||||
my $tmp_file_name = $tmp_file->filename;
|
||||
unlink $tmp_file_name;
|
||||
|
||||
require "$trunk/bin/pt-online-schema-change";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
if ($sb->is_cluster_mode) {
|
||||
plan skip_all => 'Not for PXC';
|
||||
}
|
||||
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
my $slave_dbh1 = $sb->get_dbh_for('slave1');
|
||||
my $slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
my $master_dsn = 'h=127.0.0.1,P=12345,u=msandbox,p=msandbox';
|
||||
my $slave_dsn1 = 'h=127.0.0.1,P=12346,u=msandbox,p=msandbox';
|
||||
my $slave_dsn2 = 'h=127.0.0.1,P=12347,u=msandbox,p=msandbox';
|
||||
my $sample = "t/pt-online-schema-change/samples";
|
||||
|
||||
$slave_dbh1->do("stop slave");
|
||||
$slave_dbh1->do("reset slave all");
|
||||
$slave_dbh1->do("CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=12345, MASTER_USER = 'msandbox', MASTER_PASSWORD='msandbox' FOR CHANNEL 'channel1';");
|
||||
$slave_dbh1->do("start slave");
|
||||
|
||||
diag('Loading test data');
|
||||
$sb->load_file('master', "t/pt-online-schema-change/samples/slave_lag.sql");
|
||||
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`);
|
||||
|
||||
my $output = output(
|
||||
sub { pt_online_schema_change::main("$master_dsn,D=test,t=pt178",
|
||||
'--execute',
|
||||
'--alter', "force",
|
||||
'--recurse', '1',
|
||||
'--max-lag', '2',
|
||||
'--channel', 'channel1')
|
||||
},
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
'pt-osc completes successfully when replication channel used',
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$slave_dbh1->do('STOP SLAVE');
|
||||
$master_dbh->do("RESET MASTER");
|
||||
$slave_dbh1->do('RESET SLAVE ALL');
|
||||
$slave_dbh1->do("CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=12345, MASTER_USER = 'msandbox', MASTER_PASSWORD='msandbox';");
|
||||
$slave_dbh1->do('START SLAVE');
|
||||
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
||||
|
188
t/pt-online-schema-change/pt-2168-cancel.t
Normal file
188
t/pt-online-schema-change/pt-2168-cancel.t
Normal file
@@ -0,0 +1,188 @@
|
||||
#!/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 tempfile /;
|
||||
|
||||
our $delay = 10;
|
||||
|
||||
my $tmp_file = File::Temp->new();
|
||||
my $tmp_file_name = $tmp_file->filename;
|
||||
unlink $tmp_file_name;
|
||||
|
||||
require "$trunk/bin/pt-online-schema-change";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
if ($sb->is_cluster_mode) {
|
||||
plan skip_all => 'Not for PXC';
|
||||
}
|
||||
|
||||
# We need third slave to redirect pt-osc in case of one or standard disconnects
|
||||
diag(`$trunk/sandbox/start-sandbox slave 12348 12345`);
|
||||
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
my $slave_dbh1 = $sb->get_dbh_for('slave1');
|
||||
my $slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
my $slave_dbh3 = $sb->get_dbh_for('master1');
|
||||
my $master_dsn = 'h=127.0.0.1,P=12345,u=msandbox,p=msandbox';
|
||||
my $slave_dsn1 = 'h=127.0.0.1,P=12346,u=msandbox,p=msandbox';
|
||||
my $slave_dsn2 = 'h=127.0.0.1,P=12347,u=msandbox,p=msandbox';
|
||||
my $sample = "t/pt-online-schema-change/samples";
|
||||
|
||||
# We need sync_relay_log=1 to have
|
||||
my $cnf = '/tmp/12347/my.sandbox.cnf';
|
||||
diag(`cp $cnf $cnf.bak`);
|
||||
diag(`echo "[mysqld]" > /tmp/12347/my.sandbox.2.cnf`);
|
||||
diag(`echo "sync_relay_log=1" >> /tmp/12347/my.sandbox.2.cnf`);
|
||||
diag(`echo "sync_relay_log_info=1" >> /tmp/12347/my.sandbox.2.cnf`);
|
||||
diag(`echo "relay_log_recovery=1" >> /tmp/12347/my.sandbox.2.cnf`);
|
||||
diag(`echo "!include /tmp/12347/my.sandbox.2.cnf" >> $cnf`);
|
||||
diag(`/tmp/12347/stop >/dev/null`);
|
||||
sleep 1;
|
||||
diag(`/tmp/12347/start >/dev/null`);
|
||||
|
||||
# DSN table for further tests
|
||||
$sb->load_file('master', "$sample/create_dsns.sql");
|
||||
|
||||
#diag(`mysql -h127.0.0.1 -P12345 -umsandbox -pmsandbox -e "show databases"`);
|
||||
#diag(`mysql -h127.0.0.1 -P12347 -umsandbox -pmsandbox -e "show databases"`);
|
||||
#diag(`mysql -h127.0.0.1 -P12348 -umsandbox -pmsandbox -e "show databases"`);
|
||||
#diag(`mysql -h127.0.0.1 -P12348 -umsandbox -pmsandbox -E -e "show slave status"`);
|
||||
|
||||
sub reset_query_cache {
|
||||
my @dbhs = @_;
|
||||
return if ($sandbox_version >= '8.0');
|
||||
foreach my $dbh (@dbhs) {
|
||||
$dbh->do('RESET QUERY CACHE');
|
||||
}
|
||||
}
|
||||
|
||||
# 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");
|
||||
$sb->wait_for_slaves(slave => 'master1');
|
||||
$slave_dbh1->do('STOP SLAVE');
|
||||
$slave_dbh3->do('STOP SLAVE');
|
||||
$master_dbh->do("RESET MASTER");
|
||||
$slave_dbh1->do('RESET SLAVE');
|
||||
$slave_dbh1->do('START SLAVE');
|
||||
$slave_dbh3->do('RESET SLAVE');
|
||||
$slave_dbh3->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();
|
||||
$sb->wait_for_slaves(slave => 'master1');
|
||||
|
||||
# Plan for tests
|
||||
# 1. Basic test: start tool on some huge table, stop slave, wait few seconds, start slave. Check if tool restarted with option and failed with error without.
|
||||
# 2. Delayed slaves
|
||||
# 3. Places to test:
|
||||
# - get_dbh
|
||||
# - SELECT @@SERVER_ID
|
||||
# 4. Slave never returns
|
||||
# - die after timeout
|
||||
# - inject new slave
|
||||
# - ignore after timeout
|
||||
|
||||
|
||||
diag("Setting slave delay to $delay seconds");
|
||||
|
||||
$slave_dbh1->do('STOP SLAVE');
|
||||
$slave_dbh1->do("CHANGE MASTER TO MASTER_DELAY=$delay");
|
||||
$slave_dbh1->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 = ""');
|
||||
|
||||
diag("Starting tests...");
|
||||
|
||||
my $max_lag = $delay / 2;
|
||||
# We need to sleep, otherwise pt-osc can finish before slave is delayed
|
||||
sleep($max_lag);
|
||||
|
||||
my $args = "$master_dsn,D=test,t=pt178 --recursion-method=dsn=D=test_recursion_method,t=dsns,h=127.0.0.1,P=12345,u=msandbox,p=msandbox --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5 --nofail-on-stopped-replication";
|
||||
|
||||
my ($fh, $filename) = tempfile();
|
||||
my $pid = fork();
|
||||
|
||||
if (!$pid) {
|
||||
open(STDERR, '>', $filename);
|
||||
open(STDOUT, '>', $filename);
|
||||
exec("$trunk/bin/pt-online-schema-change $args");
|
||||
}
|
||||
|
||||
sleep($max_lag + $max_lag/2);
|
||||
# restart slave 12347
|
||||
diag(`/tmp/12347/stop >/dev/null`);
|
||||
sleep 1;
|
||||
$master_dbh->do("UPDATE test_recursion_method.dsns SET dsn='D=test_recursion_method,t=dsns,P=12348,h=127.0.0.1,u=root,p=msandbox' WHERE id=2");
|
||||
|
||||
waitpid($pid, 0);
|
||||
my $output = do {
|
||||
local $/ = undef;
|
||||
<$fh>;
|
||||
};
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc completes successfully when one of replicas is stopped, option --nofail-on-stopped-replication is specified, and another replica was specified in the dsns table as a replacement",
|
||||
);
|
||||
|
||||
diag(`/tmp/12347/start >/dev/null`);
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
diag("Cleaning");
|
||||
diag(`$trunk/sandbox/stop-sandbox 12348`);
|
||||
$slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
diag("Setting slave delay to 0 seconds");
|
||||
$slave_dbh1->do('STOP SLAVE');
|
||||
$slave_dbh2->do('STOP SLAVE');
|
||||
$master_dbh->do("RESET MASTER");
|
||||
$slave_dbh1->do('RESET SLAVE');
|
||||
$slave_dbh2->do('RESET SLAVE');
|
||||
$slave_dbh1->do('START SLAVE');
|
||||
$slave_dbh2->do('START SLAVE');
|
||||
#$slave_dbh2->do("uninstall plugin simple_rewrite_plugin");
|
||||
|
||||
diag(`mv $cnf.bak $cnf`);
|
||||
|
||||
diag(`/tmp/12347/stop >/dev/null`);
|
||||
diag(`/tmp/12347/start >/dev/null`);
|
||||
|
||||
diag("Dropping test database");
|
||||
$master_dbh->do("DROP DATABASE IF EXISTS test");
|
||||
$sb->wait_for_slaves();
|
||||
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
350
t/pt-online-schema-change/pt-2168.t
Normal file
350
t/pt-online-schema-change/pt-2168.t
Normal file
@@ -0,0 +1,350 @@
|
||||
#!/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 tempfile /;
|
||||
|
||||
our $delay = 10;
|
||||
|
||||
my $tmp_file = File::Temp->new();
|
||||
my $tmp_file_name = $tmp_file->filename;
|
||||
unlink $tmp_file_name;
|
||||
|
||||
require "$trunk/bin/pt-online-schema-change";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
if ($sb->is_cluster_mode) {
|
||||
plan skip_all => 'Not for PXC';
|
||||
}
|
||||
|
||||
my $master_dbh = $sb->get_dbh_for('master');
|
||||
my $slave_dbh1 = $sb->get_dbh_for('slave1');
|
||||
my $slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
my $master_dsn = 'h=127.0.0.1,P=12345,u=msandbox,p=msandbox';
|
||||
my $slave_dsn1 = 'h=127.0.0.1,P=12346,u=msandbox,p=msandbox';
|
||||
my $slave_dsn2 = 'h=127.0.0.1,P=12347,u=msandbox,p=msandbox';
|
||||
my $sample = "t/pt-online-schema-change/samples";
|
||||
|
||||
# We need sync_relay_log=1 to have
|
||||
my $cnf = '/tmp/12347/my.sandbox.cnf';
|
||||
diag(`cp $cnf $cnf.bak`);
|
||||
diag(`echo "[mysqld]" > /tmp/12347/my.sandbox.2.cnf`);
|
||||
diag(`echo "sync_relay_log=1" >> /tmp/12347/my.sandbox.2.cnf`);
|
||||
diag(`echo "sync_relay_log_info=1" >> /tmp/12347/my.sandbox.2.cnf`);
|
||||
diag(`echo "relay_log_recovery=1" >> /tmp/12347/my.sandbox.2.cnf`);
|
||||
diag(`echo "!include /tmp/12347/my.sandbox.2.cnf" >> $cnf`);
|
||||
diag(`/tmp/12347/stop >/dev/null`);
|
||||
sleep 1;
|
||||
diag(`/tmp/12347/start >/dev/null`);
|
||||
|
||||
sub reset_query_cache {
|
||||
my @dbhs = @_;
|
||||
return if ($sandbox_version >= '8.0');
|
||||
foreach my $dbh (@dbhs) {
|
||||
$dbh->do('RESET QUERY CACHE');
|
||||
}
|
||||
}
|
||||
|
||||
# 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_dbh1->do('STOP SLAVE');
|
||||
$master_dbh->do("RESET MASTER");
|
||||
$slave_dbh1->do('RESET SLAVE');
|
||||
$slave_dbh1->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`);
|
||||
|
||||
# DSN table for further tests
|
||||
$sb->load_file('master', "$sample/create_dsns.sql");
|
||||
|
||||
$sb->wait_for_slaves();
|
||||
|
||||
# Plan for tests
|
||||
# 1. Basic test: start tool on some huge table, stop slave, wait few seconds, start slave. Check if tool restarted with option and failed with error without.
|
||||
# 2. Delayed slaves
|
||||
# 3. Places to test:
|
||||
# - get_dbh
|
||||
# - SELECT @@SERVER_ID
|
||||
# 4. Slave never returns
|
||||
# - die after timeout
|
||||
# - inject new slave
|
||||
# - ignore after timeout
|
||||
|
||||
|
||||
diag("Setting slave delay to $delay seconds");
|
||||
|
||||
$slave_dbh1->do('STOP SLAVE');
|
||||
$slave_dbh1->do("CHANGE MASTER TO MASTER_DELAY=$delay");
|
||||
$slave_dbh1->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, 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;
|
||||
# We need to sleep, otherwise pt-osc can finish before slave is delayed
|
||||
sleep($max_lag);
|
||||
|
||||
# Basic test: we check if pt-osc fails if replica restarted while it is running with default options
|
||||
|
||||
sub base_test {
|
||||
my ($args) = @_;
|
||||
#diag("pid: $tmp_file_name");
|
||||
|
||||
my ($fh, $filename) = tempfile();
|
||||
my $pid = fork();
|
||||
|
||||
if (!$pid) {
|
||||
open(STDERR, '>', $filename);
|
||||
open(STDOUT, '>', $filename);
|
||||
exec("$trunk/bin/pt-online-schema-change $args");
|
||||
}
|
||||
|
||||
sleep($max_lag + $max_lag/2);
|
||||
# restart slave 12347
|
||||
diag(`/tmp/12347/stop >/dev/null`);
|
||||
sleep 1;
|
||||
diag(`/tmp/12347/start >/dev/null`);
|
||||
|
||||
waitpid($pid, 0);
|
||||
my $output = do {
|
||||
local $/ = undef;
|
||||
<$fh>;
|
||||
};
|
||||
|
||||
unlink $filename;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
sub crash_test {
|
||||
my ($args) = @_;
|
||||
#diag("pid: $tmp_file_name");
|
||||
|
||||
my ($fh, $filename) = tempfile();
|
||||
my $pid = fork();
|
||||
|
||||
if (!$pid) {
|
||||
open(STDERR, '>', $filename);
|
||||
open(STDOUT, '>', $filename);
|
||||
exec("$trunk/bin/pt-online-schema-change $args");
|
||||
}
|
||||
|
||||
sleep($max_lag + 10);
|
||||
# restart slave 12347
|
||||
diag(`/tmp/12347/start >/dev/null`);
|
||||
|
||||
waitpid($pid, 0);
|
||||
my $output = do {
|
||||
local $/ = undef;
|
||||
<$fh>;
|
||||
};
|
||||
|
||||
unlink $filename;
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
sub error_test {
|
||||
my ($test, $pattern, $query) = @_;
|
||||
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_action='rewrite'");
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_pattern='$pattern'");
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_query='$query'");
|
||||
|
||||
my $args = "$master_dsn,D=test,t=pt178,A=utf8 --recursion-method=dsn=D=test_recursion_method,t=dsns,h=127.0.0.1,P=12345,u=msandbox,p=msandbox --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5";
|
||||
|
||||
my $output = `$trunk/bin/pt-online-schema-change $args 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc fails with error if replica returns error when $test",
|
||||
);
|
||||
|
||||
$args = "$master_dsn,D=test,t=pt178,A=utf8 --recursion-method=dsn=D=test_recursion_method,t=dsns,h=127.0.0.1,P=12345,u=msandbox,p=msandbox --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5 --nofail-on-stopped-replication";
|
||||
|
||||
$output = `$trunk/bin/pt-online-schema-change $args 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc fails with error if replica returns error when $test and option --nofail-on-stopped-replication is specified",
|
||||
);
|
||||
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_pattern=''");
|
||||
$slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_pattern='$pattern'");
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_action='abort'");
|
||||
|
||||
$args = "$master_dsn,D=test,t=pt178,A=utf8 --recursion-method=dsn=D=test_recursion_method,t=dsns,h=127.0.0.1,P=12345,u=msandbox,p=msandbox --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5";
|
||||
|
||||
$output = crash_test($args);
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc fails with error if replica disconnects when $test",
|
||||
);
|
||||
|
||||
$slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_pattern='$pattern'");
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_action='abort'");
|
||||
|
||||
$args = "$master_dsn,D=test,t=pt178,A=utf8 --recursion-method=dsn=D=test_recursion_method,t=dsns,h=127.0.0.1,P=12345,u=msandbox,p=msandbox --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5 --nofail-on-stopped-replication";
|
||||
|
||||
$output = crash_test($args);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc finishes succesfully if replica disconnects when $test and option --nofail-on-stopped-replication is specified",
|
||||
);
|
||||
|
||||
$slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
$slave_dbh2->do("SET GLOBAL simple_rewrite_plugin_action='rewrite'");
|
||||
}
|
||||
|
||||
diag("Starting base tests. This is going to take some time due to the delay in the slave");
|
||||
|
||||
my $output = base_test("$master_dsn,D=test,t=pt178 --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5");
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc fails when one of replicas is restarted",
|
||||
);
|
||||
|
||||
# pt-osc doesn't fail if replica is restarted and option --nofail-on-stopped-replication specified
|
||||
$output = base_test("$master_dsn,D=test,t=pt178 --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5 --nofail-on-stopped-replication");
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc completes successfully when one of replicas is restarted and option --nofail-on-stopped-replication is specified",
|
||||
);
|
||||
|
||||
$output = base_test("$master_dsn,D=test,t=pt178 --recursion-method=dsn=D=test_recursion_method,t=dsns,h=127.0.0.1,P=12345,u=msandbox,p=msandbox --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5");
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc fails with recursion-method=dsn when one of replicas is restarted",
|
||||
);
|
||||
|
||||
$output = base_test("$master_dsn,D=test,t=pt178 --recursion-method=dsn=D=test_recursion_method,t=dsns,h=127.0.0.1,P=12345,u=msandbox,p=msandbox --execute --chunk-size 10 --max-lag $max_lag --alter 'engine=INNODB' --pid $tmp_file_name --progress time,5 --nofail-on-stopped-replication");
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/Successfully altered `test`.`pt178`/s,
|
||||
"pt-osc completes successfully with recursion-method=dsn when one of replicas is restarted and option --nofail-on-stopped-replication is specified",
|
||||
);
|
||||
|
||||
# Errors that happen while pt-osc executes SQL while checking slave availability.
|
||||
# We check few scenarios.
|
||||
# - Error not related to connection: pt-osc aborted regardless option --nofail-on-stopped-replication
|
||||
# - Error, related to connection: pt-osc behavior depends on option --nofail-on-stopped-replication
|
||||
# We work only with replica with port 12347 here.
|
||||
diag("Starting replica lost and error tests");
|
||||
|
||||
SKIP: {
|
||||
$slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
eval { $slave_dbh2->do("install plugin simple_rewrite_plugin soname 'simple_rewrite_plugin.so'") };
|
||||
if ( $EVAL_ERROR && $EVAL_ERROR !~ m/Function 'simple_rewrite_plugin' already exists/) {
|
||||
skip 'These tests require simple_rewrite_plugin. You can get it from https://github.com/svetasmirnova/simple_rewrite_plugin';
|
||||
}
|
||||
|
||||
my @res = $slave_dbh2->selectrow_array("select count(*) from information_schema.plugins where plugin_name='simple_rewrite_plugin' and PLUGIN_STATUS='ACTIVE'");
|
||||
if ( $res[0] != 1 ) {
|
||||
skip 'These tests require simple_rewrite_plugin in active status';
|
||||
}
|
||||
|
||||
# get_dbh sets character set connection
|
||||
$master_dbh->do("UPDATE test_recursion_method.dsns SET dsn='D=test_recursion_method,t=dsns,P=12346,h=127.0.0.1,u=root,p=msandbox,A=utf8' WHERE id=1");
|
||||
$master_dbh->do("UPDATE test_recursion_method.dsns SET dsn='D=test_recursion_method,t=dsns,P=12347,h=127.0.0.1,u=root,p=msandbox,A=utf8' WHERE id=2");
|
||||
|
||||
error_test("setting character set", '.*(SET NAMES) "?([[:alnum:]]+)"?.*', '$1 $2$2');
|
||||
|
||||
$master_dbh->do("UPDATE test_recursion_method.dsns SET dsn='D=test_recursion_method,t=dsns,P=12346,h=127.0.0.1,u=root,p=msandbox' WHERE id=1");
|
||||
$master_dbh->do("UPDATE test_recursion_method.dsns SET dsn='D=test_recursion_method,t=dsns,P=12347,h=127.0.0.1,u=root,p=msandbox' WHERE id=2");
|
||||
|
||||
# get_dbh selects SQL mode
|
||||
error_test("selecting SQL mode", 'SELECT @@SQL_MODE', 'SELEC @@SQL_MODE');
|
||||
|
||||
# get_dbh sets SQL mode
|
||||
error_test("setting SQL_QUOTE_SHOW_CREATE", 'SET @@SQL_QUOTE_SHOW_CREATE.*', 'SE @@SQL_QUOTE_SHOW_CREATE = 1');
|
||||
|
||||
# get_dbh selects version
|
||||
error_test("selecting MySQL version", 'SELECT VERSION.*', 'SELEC VERSION()');
|
||||
|
||||
# get_dbh queries server character set
|
||||
error_test("querying server character set", "SHOW VARIABLES LIKE \\'character_set_server\\'", "SHO VARIABLES LIKE \\'character_set_server\\'");
|
||||
|
||||
# get_dbh sets character set utf8mb4 in version 8+
|
||||
if ($sandbox_version ge '8.0') {
|
||||
error_test("setting character set utf8mb4", "SET NAMES \\'utf8mb4\\'", "SET NAMES \\'utf8mb4utf8mb4\\'");
|
||||
}
|
||||
|
||||
# recurse_to_slaves asks for SERVER_ID
|
||||
error_test("selecting server id", 'SELECT @@SERVER_ID.*', 'SELEC @@SERVER_ID');
|
||||
|
||||
$slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
$slave_dbh2->do("uninstall plugin simple_rewrite_plugin");
|
||||
}
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
diag("Cleaning");
|
||||
$slave_dbh2 = $sb->get_dbh_for('slave2');
|
||||
diag("Setting slave delay to 0 seconds");
|
||||
$slave_dbh1->do('STOP SLAVE');
|
||||
$slave_dbh2->do('STOP SLAVE');
|
||||
$master_dbh->do("RESET MASTER");
|
||||
$slave_dbh1->do('RESET SLAVE');
|
||||
$slave_dbh2->do('RESET SLAVE');
|
||||
$slave_dbh1->do('START SLAVE');
|
||||
$slave_dbh2->do('START SLAVE');
|
||||
|
||||
diag(`mv $cnf.bak $cnf`);
|
||||
|
||||
diag(`/tmp/12347/stop >/dev/null`);
|
||||
diag(`/tmp/12347/start >/dev/null`);
|
||||
|
||||
diag("Dropping test database");
|
||||
$master_dbh->do("DROP DATABASE IF EXISTS test");
|
||||
$sb->wait_for_slaves();
|
||||
|
||||
$sb->wipe_clean($master_dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
@@ -184,7 +184,7 @@ $output = `$trunk/bin/pt-online-schema-change $args 2>&1`;
|
||||
|
||||
unlike(
|
||||
$output,
|
||||
qr/Replica lag is \d+ seconds on .* Waiting/s,
|
||||
qr/Replica lag is \d+ seconds on .*:12346. Waiting/s,
|
||||
"--skip-check-slave-lag is really skipping the slave",
|
||||
);
|
||||
|
||||
|
@@ -187,7 +187,7 @@ is(
|
||||
|
||||
is(
|
||||
$err,
|
||||
"# Cannot resolve conflict WHERE `id`='3': `ts` values do not differ by the threhold, 30m.
|
||||
"# Cannot resolve conflict WHERE `id`='3': `ts` values do not differ by the threshold, 30m.
|
||||
",
|
||||
'Warns about conflict'
|
||||
);
|
||||
@@ -266,7 +266,7 @@ is(
|
||||
# syncing other tables.
|
||||
is(
|
||||
$err,
|
||||
"# Cannot resolve conflict WHERE `id`='3': `ts` values do not differ by the threhold, 30m. while doing bidi.t on 127.1
|
||||
"# Cannot resolve conflict WHERE `id`='3': `ts` values do not differ by the threshold, 30m. while doing bidi.t on 127.1
|
||||
",
|
||||
'Die/warn about conflict'
|
||||
);
|
||||
|
Reference in New Issue
Block a user