Merge pull request #246 from percona/PT-181

PT-181 bin/pt-online-schema-change not in sync with modules
This commit is contained in:
Carlos Salguero
2017-07-27 11:34:44 -03:00
committed by GitHub
5 changed files with 35 additions and 16 deletions

View File

@@ -1,6 +1,7 @@
Changelog for Percona Toolkit
* Fixed bug PT-181 : pt-online-schema-change not in sync with modules (Thanks Daniël van Eeden)
* Fixed bug PT-180 : pt-online-schema-change --skip-check-slave-lag doesn't work
* Fixed bug PT-178 : pt-online-schema-change appears to ignore the --check-slave-lag option
* Fixed bug PT-162 : Updated pt-table-checksum ignored dbs (Thanks Agustin Gallego)

View File

@@ -2199,7 +2199,7 @@ sub parse {
foreach my $key ( keys %$opts ) {
PTDEBUG && _d('Finding value for', $key);
$final_props{$key} = $given_props{$key};
if ( !defined $final_props{$key}
if ( !defined $final_props{$key}
&& defined $prev->{$key} && $opts->{$key}->{copy} )
{
$final_props{$key} = $prev->{$key};
@@ -2316,7 +2316,6 @@ sub get_dbh {
PrintError => 0,
ShowErrorStatement => 1,
mysql_enable_utf8 => ($cxn_string =~ m/charset=utf8/i ? 1 : 0),
# mysql_multi_statements => 1,
};
@{$defaults}{ keys %$opts } = values %$opts;
if (delete $defaults->{L}) { # L for LOAD DATA LOCAL INFILE, our own extension
@@ -3444,7 +3443,6 @@ sub check_table {
$self->{check_table_error} = $e;
return 0;
}
if ( !$row->[0] || $row->[0] ne $tbl ) {
PTDEBUG && _d('Table does not exist');
return 0;
@@ -4988,9 +4986,6 @@ sub wait {
sub _d {
my ($package, undef, $line) = caller 0;
# Backslash found where operator expected at ./pt-online-schema-change line 4933, near "@_ = map { (my $temp = $_) =~ s/\"
# (Might be a runaway multi-line // string starting on line 4889)
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
map { defined $_ ? $_ : 'undef' }
@_;
@@ -5821,23 +5816,26 @@ sub _find_best_index {
my $tbl_struct = $tbl->{tbl_struct};
my $indexes = $tbl_struct->{keys};
my $best_index;
my $want_index = $args{chunk_index};
if ( $want_index ) {
PTDEBUG && _d('User wants to use index', $want_index);
if ( !exists $indexes->{$want_index} ) {
PTDEBUG && _d('Cannot use user index because it does not exist');
$want_index = undef;
} else {
$best_index = $want_index;
}
}
if ( !$want_index && $args{mysql_index} ) {
if ( !$best_index && !$want_index && $args{mysql_index} ) {
PTDEBUG && _d('MySQL wants to use index', $args{mysql_index});
$want_index = $args{mysql_index};
}
my $best_index;
my @possible_indexes;
if ( $want_index ) {
if ( !$best_index && $want_index ) {
if ( $indexes->{$want_index}->{is_unique} ) {
PTDEBUG && _d('Will use wanted index');
$best_index = $want_index;
@@ -5847,7 +5845,8 @@ sub _find_best_index {
push @possible_indexes, $want_index;
}
}
else {
if (!$best_index) {
PTDEBUG && _d('Auto-selecting best index');
foreach my $index ( $tp->sort_indexes($tbl_struct) ) {
if ( $index eq 'PRIMARY' || $indexes->{$index}->{is_unique} ) {

View File

@@ -57,7 +57,7 @@ sub start_thread {
$dbh->do("UPDATE `test`.`o1` SET id=0 WHERE id=1");
diag("Row updated");
}
my $thr = threads->create('start_thread', $dsn_opts, 3);
my $thr = threads->create('start_thread', $dsn_opts, 1);
$thr->detach();
threads->yield();
@@ -72,7 +72,6 @@ $output = output(
},
);
like(
$output,
qr/Successfully altered/s,

View File

@@ -37,7 +37,7 @@ DROP TABLE IF EXISTS `pt178`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `pt178` (
`id` int(11) NOT NULL AUTO_INCREMENT,
f1 VARCHAR(30) NULL,
f1 VARCHAR(30) DEFAULT '',
f2 BIGINT(11) DEFAULT 0,
PRIMARY KEY(id)
) ENGINE=InnoDB;

View File

@@ -42,15 +42,20 @@ $slave_dbh->do('STOP SLAVE');
$slave_dbh->do('RESET SLAVE');
$slave_dbh->do('START SLAVE');
diag('Loading test data');
$sb->load_file('master', "t/pt-online-schema-change/samples/slave_lag.sql");
diag("Setting slave delay to $delay seconds");
$slave_dbh->do('STOP SLAVE');
$slave_dbh->do("CHANGE MASTER TO MASTER_DELAY=$delay");
$slave_dbh->do('START SLAVE');
diag('Loading test data');
$sb->load_file('master', "t/pt-online-schema-change/samples/slave_lag.sql");
# Run a full table scan query to ensure the slave is behind the master
$master_dbh->do('RESET QUERY CACHE');
$slave_dbh->do('RESET QUERY CACHE');
$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
# pt-online-schema-change will wait on the slave at port 12346
@@ -69,6 +74,11 @@ like(
$args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 1 --max-lag 5 --alter 'ENGINE=InnoDB' "
. "--check-slave-lag h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=sbtest";
# Run a full table scan query to ensure the slave is behind the master
$master_dbh->do('RESET QUERY CACHE');
$slave_dbh->do('RESET QUERY CACHE');
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 WHERE f1 = ""');
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`;
@@ -79,6 +89,11 @@ like(
);
# Repeat the test now using --skip-check-slave-lag
# Run a full table scan query to ensure the slave is behind the master
$master_dbh->do('RESET QUERY CACHE');
$slave_dbh->do('RESET QUERY CACHE');
$master_dbh->do('UPDATE `test`.`pt178` SET f2 = f2 + 1 WHERE f1 = ""');
$args = "$master_dsn,D=test,t=pt178 --execute --chunk-size 1 --max-lag 5 --alter 'ENGINE=InnoDB' "
. "--skip-check-slave-lag h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=sbtest";
@@ -91,6 +106,11 @@ unlike(
"--skip-check-slave-lag is really skipping the slave",
);
diag("Setting slave delay to 0 seconds");
$slave_dbh->do('STOP SLAVE');
$slave_dbh->do('RESET SLAVE');
$slave_dbh->do('START SLAVE');
$master_dbh->do("DROP DATABASE IF EXISTS test");
# #############################################################################