diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index bbba173f..b7c7c64b 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -4281,7 +4281,8 @@ sub recurse_to_slaves { PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn)); }; if ( $EVAL_ERROR ) { - print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), "\n" + #TODO REMOVE DEBUG + print STDERR "1> Cannot connect to ", $dp->as_string($slave_dsn), "\n" or die "Cannot print: $OS_ERROR"; return; } @@ -5001,7 +5002,7 @@ sub wait { my $lag = $get_lag->($lagged_slaves[$i]->{cxn}); PTDEBUG && _d($lagged_slaves[$i]->{cxn}->name(), 'slave lag:', $lag); - if ( !defined $lag || $lag > $max_lag ) { + if ( defined $lag && $lag > $max_lag ) { $lagged_slaves[$i]->{lag} = $lag; } else { @@ -8734,7 +8735,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 - PTDEBUG && _d('Cannot connect to', $cxn->name(), ':', + #TODO REMOVE DEBUG + PTDEBUG && _d('2> Cannot connect to', $cxn->name(), ':', $EVAL_ERROR); # Make ReplicaLagWaiter::wait() report slave is stopped. return undef; @@ -9175,7 +9177,8 @@ sub main { } }; - if ( $slaves && scalar @$slaves ) { + my $table_is_replicated; + if ( $slaves && scalar @$slaves && $table_is_replicated) { foreach my $slave (@$slaves) { my ($pr, $pr_first_report); if ( $o->get('progress') ) { @@ -12884,7 +12887,7 @@ Default character set. =item * D -dsn: database; copy: yes +dsn: database; copy: no Database for the old and new table. @@ -13035,6 +13038,6 @@ Place, Suite 330, Boston, MA 02111-1307 USA. =head1 VERSION -pt-online-schema-change 3.0.6 +pt-online-schema-change 3.0.7 =cut diff --git a/t/pt-online-schema-change/alter_active_table.t b/t/pt-online-schema-change/alter_active_table.t index b3c42a20..f5fe7e43 100644 --- a/t/pt-online-schema-change/alter_active_table.t +++ b/t/pt-online-schema-change/alter_active_table.t @@ -165,7 +165,7 @@ else { } $master_dbh->do("USE pt_osc"); $master_dbh->do("TRUNCATE TABLE t"); -$master_dbh->do("LOAD DATA LOCAL INFILE '$trunk/t/pt-online-schema-change/samples/basic_no_fks.data' INTO TABLE t"); +$master_dbh->do("LOAD DATA INFILE '$trunk/t/pt-online-schema-change/samples/basic_no_fks.data' INTO TABLE t"); $master_dbh->do("ANALYZE TABLE t"); $sb->wait_for_slaves(); @@ -215,7 +215,7 @@ is( $master_dbh->do("USE pt_osc"); $master_dbh->do("TRUNCATE TABLE t"); -$master_dbh->do("LOAD DATA LOCAL INFILE '$trunk/t/pt-online-schema-change/samples/basic_no_fks.data' INTO TABLE t"); +$master_dbh->do("LOAD DATA INFILE '$trunk/t/pt-online-schema-change/samples/basic_no_fks.data' INTO TABLE t"); $master_dbh->do("ANALYZE TABLE t"); $sb->wait_for_slaves(); diff --git a/t/pt-online-schema-change/issue-1646713.t b/t/pt-online-schema-change/issue-1646713.t index 3d716db8..10e529f5 100644 --- a/t/pt-online-schema-change/issue-1646713.t +++ b/t/pt-online-schema-change/issue-1646713.t @@ -46,6 +46,11 @@ my $exit_status; my $sample = "t/pt-online-schema-change/samples/"; $sb->load_file('master', "$sample/issue-1646713.sql"); +my $num_rows = 1000; +my $master_port = 12345; + +$master_dbh->do("FLUSH TABLES"); +$sb->wait_for_slaves(); sub start_thread { my ($dsn_opts, $sleep_time) = @_; @@ -53,14 +58,18 @@ sub start_thread { my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); my $dbh = $sb->get_dbh_for('master'); diag("Thread started: Sleeping $sleep_time seconds before updating the PK field for row with id=1 in test.sbtest"); - sleep($sleep_time); + # We need to lock the tables to prevent osc to really start before we are able to write the row to the table + $dbh->do("LOCK TABLES `test`.`o1` WRITE"); + select(undef, undef, undef, $sleep_time); $dbh->do("UPDATE `test`.`o1` SET id=0 WHERE id=1"); + $dbh->do("UNLOCK TABLES"); diag("Row updated"); } -my $thr = threads->create('start_thread', $dsn_opts, 1); +my $thr = threads->create('start_thread', $dsn_opts, 0.50); $thr->detach(); threads->yield(); + diag("Starting osc. A row will be updated in a different thread."); my $dir = tempdir( CLEANUP => 1 ); $output = output( @@ -71,6 +80,7 @@ $output = output( ), }, ); +diag($output); like( $output, diff --git a/t/pt-online-schema-change/pt-1455.t b/t/pt-online-schema-change/pt-1455.t new file mode 100644 index 00000000..3861019d --- /dev/null +++ b/t/pt-online-schema-change/pt-1455.t @@ -0,0 +1,94 @@ +#!/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 threads::shared; +use Thread::Semaphore; + +use English qw(-no_match_vars); +use Test::More; + +use Data::Dumper; +use PerconaTest; +use Sandbox; +use SqlModes; +use File::Temp qw/ tempdir /; + +plan tests => 3; + +require "$trunk/bin/pt-online-schema-change"; + +my $dp = new DSNParser(opts=>$dsn_opts); +my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); + +my $master_dbh = $sb->get_dbh_for("master"); +my $master_dsn = $sb->dsn_for("master"); + +my $slave1_dbh = $sb->get_dbh_for("slave1"); +my $slave1_dsn = $sb->dsn_for("slave1"); + +# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic +# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the +# tool will die. +my @args = (qw(--set-vars innodb_lock_wait_timeout=3)); +my $output; +my $exit_status; + +diag("Setting replication filters on slave 2"); +$sb->load_file('slave2', "t/pt-online-schema-change/samples/pt-1455_slave.sql"); +diag("Setting replication filters on slave 1"); +$sb->load_file('slave1', "t/pt-online-schema-change/samples/pt-1455_slave.sql"); +diag("Setting replication filters on master"); +$sb->load_file('master', "t/pt-online-schema-change/samples/pt-1455_master.sql",undef, no_wait => 1); +diag("replication filters set"); + +my $num_rows = 1000; +my $master_port = 12345; + +diag("Loading $num_rows into the table. This might take some time."); +diag(`util/mysql_random_data_load_linux_amd64 --host=127.1 --port=$master_port --user=msandbox --password=msandbox employees t1 $num_rows`); +diag("$num_rows rows loaded. Starting tests."); + +$master_dbh->do("FLUSH TABLES"); + +($output, $exit_status) = full_output( + sub { pt_online_schema_change::main(@args, "$master_dsn,D=employees,t=t1", + '--execute', '--no-check-replication-filters', + '--alter', "engine=innodb", + ), + }, + stderr => 1, +); + +is( + $exit_status, + 0, + "PT-1455 Successfully altered. Exit status = 0", +); + +like( + $output, + qr/Successfully altered/s, + "PT-1455 Got successfully altered message.", +); + +$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"); +diag("Resetting replication filters on slave 1"); +$sb->load_file('slave1', "t/pt-online-schema-change/samples/pt-1455_reset_slave.sql"); + +# ############################################################################# +# Done. +# ############################################################################# +$sb->wipe_clean($master_dbh); +ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); +done_testing; diff --git a/t/pt-online-schema-change/samples/issue-1646713.sql b/t/pt-online-schema-change/samples/issue-1646713.sql index e4ac06e0..5f44e4e7 100644 --- a/t/pt-online-schema-change/samples/issue-1646713.sql +++ b/t/pt-online-schema-change/samples/issue-1646713.sql @@ -2,40 +2,12 @@ DROP DATABASE IF EXISTS `test`; CREATE DATABASE IF NOT EXISTS `test`; USE test; --- MySQL dump 10.13 Distrib 5.7.14-8, for debian-linux-gnu (x86_64) --- --- Host: localhost Database: test --- ------------------------------------------------------ --- Server version 5.7.14-8-log - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `sbtest` --- - DROP TABLE IF EXISTS `o1`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; CREATE TABLE `o1` ( - `id` int -(10) unsigned NOT NULL AUTO_INCREMENT, + `id` int (10) unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) -) ENGINE=InnoDB AUTO_INCREMENT=1100001 DEFAULT CHARSET=latin1; -/*!40101 SET character_set_client = @saved_cs_client */; +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; --- --- Dumping data for table `sbtest` --- LOCK TABLES `o1` WRITE; /*!40000 ALTER TABLE `o1` DISABLE KEYS */; @@ -140,16 +112,4 @@ INSERT INTO `o1` VALUES (1),(2),(3),(4),(5),(6),(7),(8),(9), (980),(981),(982),(983),(984),(985),(986),(987),(988),(989), (990),(991),(992),(993),(994),(995),(996),(997),(998),(999), (10000); -/*!40000 ALTER TABLE `o1` ENABLE KEYS */; UNLOCK TABLES; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2017-03-14 15:19:26 diff --git a/t/pt-online-schema-change/samples/pt-1455_master.sql b/t/pt-online-schema-change/samples/pt-1455_master.sql new file mode 100644 index 00000000..fd6bed3a --- /dev/null +++ b/t/pt-online-schema-change/samples/pt-1455_master.sql @@ -0,0 +1,8 @@ +DROP DATABASE IF EXISTS employees; +CREATE DATABASE employees; +-- This table should be replicated +CREATE TABLE employees.t1 ( + id INT AUTO_INCREMENT PRIMARY KEY, + f2 INT +) ENGINE=InnoDB; + diff --git a/t/pt-online-schema-change/samples/pt-1455_reset_slave.sql b/t/pt-online-schema-change/samples/pt-1455_reset_slave.sql new file mode 100644 index 00000000..59c207b0 --- /dev/null +++ b/t/pt-online-schema-change/samples/pt-1455_reset_slave.sql @@ -0,0 +1,6 @@ +STOP SLAVE; +CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (); +CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE = (); +CHANGE REPLICATION FILTER REPLICATE_WILD_IGNORE_TABLE = (); +RESET SLAVE; +START SLAVE; diff --git a/t/pt-online-schema-change/samples/pt-1455_slave.sql b/t/pt-online-schema-change/samples/pt-1455_slave.sql new file mode 100644 index 00000000..86ee176a --- /dev/null +++ b/t/pt-online-schema-change/samples/pt-1455_slave.sql @@ -0,0 +1,6 @@ +STOP SLAVE; +CHANGE REPLICATION FILTER REPLICATE_IGNORE_DB = (`ignored_db`); +CHANGE REPLICATION FILTER REPLICATE_IGNORE_TABLE = (`idb1`.`it1`, `idb1`.`it2`); +CHANGE REPLICATION FILTER REPLICATE_WILD_IGNORE_TABLE = ('employees.eit%'); +RESET SLAVE; +START SLAVE;