From 8f23c5a35325c2965448acef1029f8e126901e94 Mon Sep 17 00:00:00 2001 From: "Brian Fraser fraserb@gmail.com" <> Date: Wed, 17 Oct 2012 11:54:16 -0300 Subject: [PATCH 1/2] Fix for 938068: pt-table-checksum doesn't warn if binlog_format=row or mixed on slaves --- bin/pt-table-checksum | 22 ++++++++++++++++++++++ t/pt-table-checksum/bugs.t | 29 +++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index c783e2bb..3f968fcd 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -8586,6 +8586,22 @@ sub main { ); PTDEBUG && _d(scalar @$slaves, 'slaves found'); + if ( $o->get('check-binlog-format') ) { + my ($master_binlog) = $master_dbh->selectrow_array('SELECT @@binlog_format'); + my $err = ''; + for my $slave_cxn (@$slaves) { + my ($slave_binlog) = $slave_cxn->dbh->selectrow_array('SELECT @@binlog_format'); + if ( $master_binlog ne $slave_binlog ) { + $err .= $master_cxn->name() . " has binlog_format $master_binlog " + . "but its slave " . $slave_cxn->name() . " has format " + . $slave_binlog . ". This can break replication. If you " + . "understand the risks, you can specify " + . "--no-check-binlog-format to avoid this error.\n" + } + } + die $err if $err; + } + if ( $master_cxn->is_cluster_node() && !@$slaves ) { die $master_cxn->name() . " is a cluster node but no other nodes " . "or regular replicas were found. Use --recursion-method=dsn " @@ -10506,6 +10522,12 @@ type: time; default: 1; group: Throttle Sleep time between checks for L<"--max-lag">. +=item --[no]check-binlog-format + +default: yes + +Check that the binlog_format is the same in all servers. + =item --[no]check-plan default: yes diff --git a/t/pt-table-checksum/bugs.t b/t/pt-table-checksum/bugs.t index 7262cdff..7963ca2d 100644 --- a/t/pt-table-checksum/bugs.t +++ b/t/pt-table-checksum/bugs.t @@ -191,6 +191,35 @@ like( "Bug 1016131: ptc should skip tables where all columns are excluded" ); +# ############################################################################# +# pt-table-checksum doesn't warn if binlog_format=row or mixed on slaves +# https://bugs.launchpad.net/percona-toolkit/+bug/938068 +# ############################################################################# + +{ +diag("Adding two new slaves to master"); +local $ENV{BINLOG_FORMAT} = 'ROW'; +diag(`$trunk/sandbox/start-sandbox slave 12348 12345`); +local $ENV{BINLOG_FORMAT} = 'MIXED'; +diag(`$trunk/sandbox/start-sandbox slave 12349 12348`); + +$output = output( sub { pt_table_checksum::main(@args) }, stderr => 1 ); + +my $re = qr/ has binlog_format .*? has format (\S+)\. This can break replication/msi; +like( + $output, + $re, + "Bug 938068: doesn't warn if binlog_format=row or mixed on slaves" +); + +is_deeply( + [ $output =~ /$re/g ], + [ 'ROW', 'MIXED' ], + "...and warns for both level 1 and level 2 slaves" +) or diag($output); + +diag(`$trunk/sandbox/stop-sandbox slave 12348 12349`); +} # ############################################################################# # Done. # ############################################################################# From d7bfcc8fd9e333a69fdab725f22a2631600140fe Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Fri, 19 Oct 2012 16:57:53 -0600 Subject: [PATCH 2/2] Tweak warning. Enhance docu around --check-binlog-format. --- bin/pt-table-checksum | 29 ++++++++++++++++++++--------- t/pt-table-checksum/bugs.t | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 3f968fcd..ba9cafd1 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -8586,17 +8586,21 @@ sub main { ); PTDEBUG && _d(scalar @$slaves, 'slaves found'); + # https://bugs.launchpad.net/percona-toolkit/+bug/938068 if ( $o->get('check-binlog-format') ) { - my ($master_binlog) = $master_dbh->selectrow_array('SELECT @@binlog_format'); + my ($master_binlog) = $master_dbh->selectrow_array( + 'SELECT @@binlog_format'); my $err = ''; for my $slave_cxn (@$slaves) { - my ($slave_binlog) = $slave_cxn->dbh->selectrow_array('SELECT @@binlog_format'); + my ($slave_binlog) = $slave_cxn->dbh->selectrow_array( + 'SELECT @@binlog_format'); if ( $master_binlog ne $slave_binlog ) { - $err .= $master_cxn->name() . " has binlog_format $master_binlog " - . "but its slave " . $slave_cxn->name() . " has format " - . $slave_binlog . ". This can break replication. If you " - . "understand the risks, you can specify " - . "--no-check-binlog-format to avoid this error.\n" + $err .= $master_cxn->name() . " has binlog_format " + . $master_binlog . " but replica " . $slave_cxn->name() + . " has binlog_format $slave_binlog. This could cause " + . "pt-table-checksum to break replication. " + . "If understand the risks, specify " + . "--no-check-binlog-format to disable this check.\n"; } } die $err if $err; @@ -10526,7 +10530,9 @@ Sleep time between checks for L<"--max-lag">. default: yes -Check that the binlog_format is the same in all servers. +Check that the C is the same on all servers. + +See "Replicas using row-based replication" under L<"LIMITATIONS">. =item --[no]check-plan @@ -11344,7 +11350,12 @@ pt-table-checksum requires statement-based replication, and it sets C on the master, but due to a MySQL limitation replicas do not honor this change. Therefore, checksums will not replicate past any replicas using row-based replication that are masters for -further replicas. (L) +further replicas. + +The tool automatically checks the C on all servers. +See L<"--[no]check-binlog-format"> + +(L) =item Percona XtraDB Cluster diff --git a/t/pt-table-checksum/bugs.t b/t/pt-table-checksum/bugs.t index 7963ca2d..11989c27 100644 --- a/t/pt-table-checksum/bugs.t +++ b/t/pt-table-checksum/bugs.t @@ -205,7 +205,7 @@ diag(`$trunk/sandbox/start-sandbox slave 12349 12348`); $output = output( sub { pt_table_checksum::main(@args) }, stderr => 1 ); -my $re = qr/ has binlog_format .*? has format (\S+)\. This can break replication/msi; +my $re = qr/ has binlog_format .*? has binlog_format (\S+)\./msi; like( $output, $re, @@ -218,7 +218,7 @@ is_deeply( "...and warns for both level 1 and level 2 slaves" ) or diag($output); -diag(`$trunk/sandbox/stop-sandbox slave 12348 12349`); +diag(`$trunk/sandbox/stop-sandbox 12348 12349`); } # ############################################################################# # Done.