From d8ec16f2132bca970d348a157cc33fc1825668a9 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Fri, 16 Feb 2018 14:27:16 -0300 Subject: [PATCH] PMM-1455 pt-osc is stuck when the table that is being altered is filtered out in the slave --- bin/pt-online-schema-change | 2 +- .../alter_active_table.t | 4 +- t/pt-online-schema-change/issue-1646713.t | 14 +++++- t/pt-online-schema-change/pt-1455.t | 39 +++++++--------- .../samples/issue-1646713.sql | 44 +------------------ .../samples/pt-1455_master.sql | 2 + .../samples/pt-1455_reset_slave.sql | 6 +++ .../samples/pt-1455_slave.sql | 4 +- 8 files changed, 44 insertions(+), 71 deletions(-) create mode 100644 t/pt-online-schema-change/samples/pt-1455_reset_slave.sql diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 3d6cfccd..0804bb84 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -5002,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 { 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 index 7a961646..3861019d 100644 --- a/t/pt-online-schema-change/pt-1455.t +++ b/t/pt-online-schema-change/pt-1455.t @@ -21,7 +21,7 @@ use Sandbox; use SqlModes; use File::Temp qw/ tempdir /; -plan tests => 4; +plan tests => 3; require "$trunk/bin/pt-online-schema-change"; @@ -41,26 +41,26 @@ my @args = (qw(--set-vars innodb_lock_wait_timeout=3)); my $output; my $exit_status; -$sb->load_file('slave1', "t/pt-online-schema-change/samples/pt-1455_slave.sql"); +diag("Setting replication filters on slave 2"); $sb->load_file('slave2', "t/pt-online-schema-change/samples/pt-1455_slave.sql"); -$sb->load_file('master', "t/pt-online-schema-change/samples/pt-1455_master.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 = $Sandbox::port_for{master}; +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 ignored_db t1 $num_rows`); +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"); -my $new_dir='/tmp/tdir'; -diag(`rm -rf $new_dir`); -diag(`mkdir $new_dir`); - ($output, $exit_status) = full_output( - sub { pt_online_schema_change::main(@args, "$master_dsn,D=ignored_db,t=t1", - '--execute', + sub { pt_online_schema_change::main(@args, "$master_dsn,D=employees,t=t1", + '--execute', '--no-check-replication-filters', '--alter', "engine=innodb", ), }, @@ -79,19 +79,12 @@ like( "PT-1455 Got successfully altered message.", ); +$master_dbh->do("DROP DATABASE IF EXISTS employees"); -my $db_dir="$new_dir/test/"; -opendir(my $dh, $db_dir) || die "Can't opendir $db_dir: $!"; -my @files = grep { /^t3#P#p/ } readdir($dh); -closedir $dh; - -is( - scalar @files, - 4, - "PT-1455 Number of files is correct", -); - -$master_dbh->do("DROP DATABASE IF EXISTS ignored_db"); +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. 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 index ca5967ac..fd6bed3a 100644 --- a/t/pt-online-schema-change/samples/pt-1455_master.sql +++ b/t/pt-online-schema-change/samples/pt-1455_master.sql @@ -1,6 +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 index fbb9b928..86ee176a 100644 --- a/t/pt-online-schema-change/samples/pt-1455_slave.sql +++ b/t/pt-online-schema-change/samples/pt-1455_slave.sql @@ -1,4 +1,6 @@ STOP SLAVE; -CHANGE REPLICATION FILTER REPLICATE_WILD_IGNORE_TABLE = ('employees.%'); +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;