From 8549fe5d99e43018fddf6fcd1c573fa359452f58 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Thu, 29 Nov 2012 23:26:53 +0000 Subject: [PATCH] Test and require wsrep_OSU_method=TOI. --- bin/pt-online-schema-change | 24 +++++++++++++----- lib/Sandbox.pm | 3 ++- t/pt-online-schema-change/pxc.t | 45 ++++++++++++++++++++++++++++----- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index bf10d304..0033fb89 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -7840,6 +7840,19 @@ sub main { . ". Please upgrade the node, or run the tool on a newer node, " . "or contact Percona for support.\n"; } + + # If wsrep_OSU_method=RSU the "DDL will be only processed locally at + # the node." So _table_new (the altered version of table) will not + # replicate to other nodes but our INSERT..SELECT operations on it + # will, thereby crashing all other nodes. + my (undef, $wsrep_osu_method) = $cxn->dbh->selectrow_array( + "SHOW VARIABLES LIKE 'wsrep\_OSU\_method'"); + if ( lc($wsrep_osu_method || '') ne 'toi' ) { + die "wsrep_OSU_method=TOI is required because " + . $cxn->name . " is a cluster node. wsrep_OSU_method is " + . "currently set to " . ($wsrep_osu_method || '') . ". " + . "Set it to TOI, or contact Percona for support.\n"; + } } # ######################################################################## @@ -9996,14 +10009,11 @@ The tool cannot alter MyISAM tables on L<"Percona XtraDB Cluster"> nodes. =head1 Percona XtraDB Cluster pt-online-schema-change works with Percona XtraDB Cluster (PXC) 5.5.28-23.7 -and newer, but there is one limitation: only InnoDB tables can be altered. +and newer, but there are two limitations: only InnoDB tables can be altered, +and C must be set to C (total order isolation). The tool exits with an error if the host is a cluster node and the table -is MyISAM or is being converted to MyISAM (C). There is no -way to disable this check. - -pt-online-schema-change is not the same as and does not require that -C be set to C (rolling schema upgrade). The tool -can be used in either mode, C or C (total order isolation). +is MyISAM or is being converted to MyISAM (C), or if +C is not C. There is no way to disable these checks. =head1 OUTPUT diff --git a/lib/Sandbox.pm b/lib/Sandbox.pm index a29c9528..954e50e6 100644 --- a/lib/Sandbox.pm +++ b/lib/Sandbox.pm @@ -134,11 +134,12 @@ sub get_dbh_for { my $dbh; # This is primarily for the benefit of CompareResults, but it's # also quite convenient when using an affected OS + # TODO: this fails if the server isn't started yet. $cxn_ops->{L} = 1 if !exists $cxn_ops->{L} && !$self->can_load_data('master'); eval { $dbh = $dp->get_dbh($dp->get_cxn_params($dsn), $cxn_ops) }; if ( $EVAL_ERROR ) { - die 'Failed to get dbh for' . $server . ': ' . $EVAL_ERROR; + die 'Failed to get dbh for ' . $server . ': ' . $EVAL_ERROR; } $dbh->{InactiveDestroy} = 1; # Prevent destroying on fork. $dbh->{FetchHashKeyName} = 'NAME_lc' unless $cxn_ops && $cxn_ops->{no_lc}; diff --git a/t/pt-online-schema-change/pxc.t b/t/pt-online-schema-change/pxc.t index 155ae10b..38b83759 100644 --- a/t/pt-online-schema-change/pxc.t +++ b/t/pt-online-schema-change/pxc.t @@ -31,12 +31,7 @@ my $node1 = $sb->get_dbh_for('node1'); my $node2 = $sb->get_dbh_for('node2'); my $node3 = $sb->get_dbh_for('node3'); -my $db_flavor = VersionParser->new($node1)->flavor(); - -if ( $db_flavor !~ /XtraDB Cluster/ ) { - plan skip_all => "PXC tests"; -} -elsif ( !$node1 ) { +if ( !$node1 ) { plan skip_all => 'Cannot connect to cluster node1'; } elsif ( !$node2 ) { @@ -46,10 +41,14 @@ elsif ( !$node3 ) { plan skip_all => 'Cannot connect to cluster node3'; } +my $db_flavor = VersionParser->new($node1)->flavor(); +if ( $db_flavor !~ /XtraDB Cluster/ ) { + plan skip_all => "PXC tests"; +} + # The sandbox servers run with lock_wait_timeout=3 and it's not dynamic # so we need to specify --lock-wait-timeout=3 else the tool will die. my $node1_dsn = $sb->dsn_for('node1'); -my @args = ($node1_dsn, qw(--lock-wait-timeout 3)); my $output; my $exit; my $sample = "t/pt-online-schema-change/samples/"; @@ -104,6 +103,38 @@ like( "Convert table to MyISAM: error message" ); +# ############################################################################# +# Require wsrep_OSU_method=TOI +# ############################################################################# + +$node1->do("SET GLOBAL wsrep_OSU_method='RSU'"); + +($output, $exit) = full_output( + sub { pt_online_schema_change::main( + "$node1_dsn,D=pt_osc,t=t", + qw(--lock-wait-timeout 5), + qw(--print --execute --alter ENGINE=MyISAM)) }, + stderr => 1, +); + +ok( + $exit, + "wsrep_OSU_method=RSU: non-zero exit" +) or diag($output); +print $output; +like( + $output, + qr/wsrep_OSU_method=TOI is required.+?currently set to RSU/, + "wsrep_OSU_method=RSU: error message" +); + +$node1->do("SET GLOBAL wsrep_OSU_method='TOI'"); +is_deeply( + $node1->selectrow_arrayref("SHOW VARIABLES LIKE 'wsrep_OSU_method'"), + [qw(wsrep_OSU_method TOI)], + "Restored wsrep_OSU_method=TOI" +) or BAIL_OUT("Failed to restore wsrep_OSU_method=TOI"); + # ############################################################################# # Done. # #############################################################################