From d9142df0f6d98e707651feaecc8e455769d7ff97 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Fri, 22 Jun 2018 13:00:41 -0300 Subject: [PATCH] PT-1551 New wait for master method to pt-table-checksum This is part of PT-1554. While I was testing pt-table-checksum ignore_columns.t was failing and it was because the original method in pt-table-checksum to wait for the slaves to catch up, wasn't enough. I added a new method who calls MySQL's SELECT MASTER_POS_WAIT from the MasterSlave package. --- bin/pt-table-checksum | 22 ++++++++++++++++++++-- t/pt-table-checksum/ignore_columns.t | 6 +++--- t/pt-table-checksum/samples/issue_94.sql | 1 + 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index f7fe1323..bd59df4c 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -6238,9 +6238,9 @@ sub find_replication_differences { } my ($dbh, $repl_table) = @args{@required_args}; - my $tries = $self->{'OptionParser'}->get('replicate-check-retries') || 1; my $diffs; + while ($tries--) { my $sql = "SELECT CONCAT(db, '.', tbl) AS `table`, " @@ -6258,7 +6258,7 @@ sub find_replication_differences { if (!@$diffs || !$tries) { # if no differences are found OR we are out of tries left... last; # get out now } - sleep 1; + sleep 1; } return $diffs; } @@ -11271,6 +11271,10 @@ sub main { # Wait for the last checksum of this table to replicate # to each slave. + # MySQL 8+ replication is slower than 5.7 and the old wait_for_last_checksum alone + # was failing. The new wait_for_slaves checks that Read_Master_Log_Pos on slaves is + # greather or equal Position in the master + wait_for_slaves(master_dbh => $args{Cxn}->dbh(), master_slave => $ms, slaves => $slaves); wait_for_last_checksum( tbl => $tbl, repl_table => $repl_table, @@ -12337,6 +12341,20 @@ sub have_more_chunks { return 1; # more chunks } +sub wait_for_slaves { + my (%args) = @_; + my @required_args = qw(master_dbh master_slave slaves); + foreach my $arg ( @required_args ) { + die "I need a $arg argument" unless $args{$arg}; + } + my ($master_dbh, $ms, $slaves) = @args{@required_args}; + + my $master_status = $ms->get_master_status($master_dbh); + foreach my $slave ( @$slaves ) { + $ms->wait_for_master(master_status => $master_status, slave_dbh => $slave->dbh()); + } +} + sub wait_for_last_checksum { my (%args) = @_; my @required_args = qw(tbl repl_table slaves max_chunk have_time OptionParser); diff --git a/t/pt-table-checksum/ignore_columns.t b/t/pt-table-checksum/ignore_columns.t index 244e6268..e27cf129 100644 --- a/t/pt-table-checksum/ignore_columns.t +++ b/t/pt-table-checksum/ignore_columns.t @@ -42,14 +42,14 @@ $sb->load_file('master', 't/pt-table-checksum/samples/issue_94.sql'); $slave_dbh->do("update test.issue_94 set c=''"); $output = output( - sub { pt_table_checksum::main(@args, qw(-d test -t issue_94)) }, + sub { pt_table_checksum::main(@args, qw(-d test --ignore-databases mysql -t issue_94)) }, trf => sub { return PerconaTest::count_checksum_results(@_, 'DIFFS') }, ); is( $output, "1", "Diff when column not ignored" -); +) or diag($output); $output = output( sub { pt_table_checksum::main(@args, qw(-d test -t issue_94), @@ -60,7 +60,7 @@ is( $output, "0", "No diff when column ignored" -); +) or diag($output); $output = output( sub { pt_table_checksum::main(@args, qw(-d test -t issue_94), diff --git a/t/pt-table-checksum/samples/issue_94.sql b/t/pt-table-checksum/samples/issue_94.sql index 0d981a74..e114a87c 100644 --- a/t/pt-table-checksum/samples/issue_94.sql +++ b/t/pt-table-checksum/samples/issue_94.sql @@ -1,3 +1,4 @@ +CREATE DATABASE IF NOT EXISTS test; USE test; DROP TABLE IF EXISTS `issue_94`; CREATE TABLE `issue_94` (