From a38bee6d604c9b2642c0962dfdbc0788a5127560 Mon Sep 17 00:00:00 2001 From: Sveta Smirnova Date: Sat, 3 Aug 2024 17:03:48 +0300 Subject: [PATCH] PT-2340 - Support MySQL 8.4 - Updated modules and tests for pt-table-sync, pt-table-usage, pt-upgrade, pt-variable-advisor --- bin/pt-table-sync | 947 ++++++++++-------- bin/pt-upgrade | 6 +- bin/pt-variable-advisor | 26 +- t/lib/samples/issue_616.sql | 12 +- t/pt-table-sync/basics.t | 105 +- t/pt-table-sync/bidirectional.t | 30 +- t/pt-table-sync/binlog_format.t | 62 +- t/pt-table-sync/bugs.t | 56 +- t/pt-table-sync/char_chunking.t | 26 +- t/pt-table-sync/check_privs.t | 40 +- t/pt-table-sync/columns.t | 24 +- t/pt-table-sync/diff_where.t | 8 +- t/pt-table-sync/enum_fields.t | 24 +- t/pt-table-sync/filters.t | 84 +- t/pt-table-sync/float_precision.t | 46 +- t/pt-table-sync/force_index.t | 30 +- t/pt-table-sync/hex_blob.t | 6 +- t/pt-table-sync/instrumentaiton.t | 18 +- t/pt-table-sync/issue_1052.t | 20 +- t/pt-table-sync/issue_1065.t | 26 +- t/pt-table-sync/issue_218.t | 28 +- t/pt-table-sync/issue_22.t | 22 +- t/pt-table-sync/issue_262.t | 32 +- t/pt-table-sync/issue_408.t | 20 +- t/pt-table-sync/issue_560.t | 26 +- t/pt-table-sync/issue_616.t | 40 +- t/pt-table-sync/issue_627.t | 28 +- t/pt-table-sync/issue_631.t | 12 +- t/pt-table-sync/issue_634.t | 24 +- t/pt-table-sync/issue_644.t | 26 +- t/pt-table-sync/issue_804.t | 24 +- t/pt-table-sync/issue_920.t | 6 +- t/pt-table-sync/issue_96.t | 12 +- t/pt-table-sync/issue_965.t | 6 +- t/pt-table-sync/issue_996.t | 24 +- t/pt-table-sync/lock_and_rename.t | 20 +- t/pt-table-sync/lock_level.t | 22 +- t/pt-table-sync/master_master.t | 54 +- t/pt-table-sync/pt-1194.t | 56 +- t/pt-table-sync/pt-1205.t | 28 +- t/pt-table-sync/pt-1256.t | 44 +- t/pt-table-sync/pt-2016.t | 34 +- t/pt-table-sync/pt-2309.t | 44 +- t/pt-table-sync/pt_221.t | 52 +- t/pt-table-sync/replicate.t | 38 +- t/pt-table-sync/replicate_do_db.t | 122 +-- t/pt-table-sync/safety_checks.t | 34 +- t/pt-table-sync/samples/bug-918056-master.sql | 4 +- t/pt-table-sync/samples/checksum_tbl.sql | 4 +- t/pt-table-sync/samples/pt_221.sql | 4 +- t/pt-table-sync/samples/upper-oob-master.sql | 4 +- t/pt-table-sync/specify_column_or_index.t | 24 +- t/pt-table-sync/standard_options.t | 2 +- t/pt-table-sync/sync_to_differnt_db.t | 22 +- t/pt-table-sync/sync_using_channels.t | 46 +- t/pt-table-sync/traces.t | 20 +- t/pt-table-sync/triggers.t | 50 +- t/pt-table-sync/wait.t | 38 +- t/pt-table-sync/zero_chunk.t | 16 +- t/pt-table-usage/explain_extended.t | 4 +- t/pt-upgrade/compare_hosts.t | 2 +- t/pt-upgrade/compare_results.t | 2 +- t/pt-upgrade/diff_rows.t | 6 +- t/pt-upgrade/diff_warnings.t | 8 +- t/pt-upgrade/run_time.t | 2 +- t/pt-upgrade/save_results.t | 2 +- t/pt-variable-advisor/advice.t | 6 +- t/pt-variable-advisor/show_variables_online.t | 4 +- t/pt-variable-advisor/show_variables_static.t | 2 +- 69 files changed, 1442 insertions(+), 1304 deletions(-) diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 83b7a653..8df575ac 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -2198,7 +2198,7 @@ sub get_cxn_params { $dsn = 'DBI:mysql:' . ( $info->{D} || '' ) . ';' . join(';', map { "$opts{$_}->{dsn}=$info->{$_}" } grep { defined $info->{$_} } - qw(F h P S A)) + qw(F h P S A s)) . ';mysql_read_default_group=client' . ($info->{L} ? ';mysql_local_infile=1' : ''); } @@ -5067,13 +5067,13 @@ sub find_replication_differences { my $sql = "SELECT db, tbl, CONCAT(db, '.', tbl) AS `table`, " . "chunk, chunk_index, lower_boundary, upper_boundary, " - . "COALESCE(this_cnt-master_cnt, 0) AS cnt_diff, " + . "COALESCE(this_cnt-source_cnt, 0) AS cnt_diff, " . "COALESCE(" - . "this_crc <> master_crc OR ISNULL(master_crc) <> ISNULL(this_crc), 0" - . ") AS crc_diff, this_cnt, master_cnt, this_crc, master_crc " + . "this_crc <> source_crc OR ISNULL(source_crc) <> ISNULL(this_crc), 0" + . ") AS crc_diff, this_cnt, source_cnt, this_crc, source_crc " . "FROM $table " - . "WHERE master_cnt <> this_cnt OR master_crc <> this_crc " - . "OR ISNULL(master_crc) <> ISNULL(this_crc)"; + . "WHERE source_cnt <> this_cnt OR source_crc <> this_crc " + . "OR ISNULL(source_crc) <> ISNULL(this_crc)"; PTDEBUG && _d($sql); my $diffs = $dbh->selectall_arrayref($sql, { Slice => {} }); return $diffs; @@ -6308,16 +6308,16 @@ sub lock_and_wait { my ( %args ) = @_; if ( $args{tryno} > 1 ) { - warn "Retrying MASTER_POS_WAIT() for --wait $timeout..."; + warn "Retrying SOURCE_POS_WAIT() for --wait $timeout..."; } - $wait = $ms->wait_for_master( - master_status => $ms->get_master_status($src->{misc_dbh}), - slave_dbh => $dst->{dbh}, + $wait = $ms->wait_for_source( + source_status => $ms->get_source_status($src->{misc_dbh}), + replica_dbh => $dst->{dbh}, timeout => $timeout, ); if ( defined $wait->{result} && $wait->{result} != -1 ) { - return; # slave caught up + return; # replica caught up } die; # call fail }, @@ -6326,12 +6326,12 @@ sub lock_and_wait { if ( !defined $wait->{result} ) { my $msg; if ( $wait->{waited} ) { - $msg = "The slave was stopped while waiting with " - . "MASTER_POS_WAIT()."; + $msg = "The replica was stopped while waiting with " + . "SOURCE_POS_WAIT()."; } else { - $msg = "MASTER_POS_WAIT() returned NULL. Verify that " - . "the slave is running."; + $msg = "SOURCE_POS_WAIT() returned NULL. Verify that " + . "the replica is running."; } if ( $tries - $args{tryno} ) { $msg .= " Sleeping $sleep seconds then retrying " @@ -6345,17 +6345,17 @@ sub lock_and_wait { } }, final_fail => sub { - die "Slave did not catch up to its master after $tries attempts " - . "of waiting $timeout seconds with MASTER_POS_WAIT. " - . "Check that the slave is running, increase the --wait " + die "Replica did not catch up to its source after $tries attempts " + . "of waiting $timeout seconds with SOURCE_POS_WAIT. " + . "Check that the replica is running, increase the --wait " . "time, or disable this feature by specifying --wait 0."; }, - ); # retry MasterSlave::wait_for_master() + ); # retry MasterSlave::wait_for_source() } if ( $args{changing_src} ) { PTDEBUG && _d('Not locking destination because changing source ', - '(syncing via replication or sync-to-master)'); + '(syncing via replication or sync-to-source)'); } else { if ( $args{lock} == 3 ) { @@ -6713,7 +6713,7 @@ sub new { return bless $self, $class; } -sub get_slaves { +sub get_replicas { my ($self, %args) = @_; my @required_args = qw(make_cxn); foreach my $arg ( @required_args ) { @@ -6721,11 +6721,11 @@ sub get_slaves { } my ($make_cxn) = @args{@required_args}; - my $slaves = []; + my $replicas = []; my $dp = $self->{DSNParser}; my $methods = $self->_resolve_recursion_methods($args{dsn}); - return $slaves unless @$methods; + return $replicas unless @$methods; if ( grep { m/processlist|hosts/i } @$methods ) { my @required_args = qw(dbh dsn); @@ -6735,26 +6735,26 @@ sub get_slaves { my ($dbh, $dsn) = @args{@required_args}; my $o = $self->{OptionParser}; - $self->recurse_to_slaves( - { dbh => $dbh, - dsn => $dsn, - slave_user => $o->got('slave-user') ? $o->get('slave-user') : '', - slave_password => $o->got('slave-password') ? $o->get('slave-password') : '', - slaves => $args{slaves}, + $self->recurse_to_replicas( + { dbh => $dbh, + dsn => $dsn, + replica_user => $o->got('replica-user') ? $o->get('replica-user') : '', + replica_password => $o->got('replica-password') ? $o->get('replica-password') : '', + replicas => $args{replicas}, callback => sub { my ( $dsn, $dbh, $level, $parent ) = @_; return unless $level; - PTDEBUG && _d('Found slave:', $dp->as_string($dsn)); - my $slave_dsn = $dsn; - if ($o->got('slave-user')) { - $slave_dsn->{u} = $o->get('slave-user'); - PTDEBUG && _d("Using slave user ".$o->get('slave-user')." on ".$slave_dsn->{h}.":".$slave_dsn->{P}); + PTDEBUG && _d('Found replica:', $dp->as_string($dsn)); + my $replica_dsn = $dsn; + if ($o->got('replica-user')) { + $replica_dsn->{u} = $o->get('replica-user'); + PTDEBUG && _d("Using replica user ".$o->get('replica-user')." on ".$replica_dsn->{h}.":".$replica_dsn->{P}); } - if ($o->got('slave-password')) { - $slave_dsn->{p} = $o->get('slave-password'); - PTDEBUG && _d("Slave password set"); + if ($o->got('replica-password')) { + $replica_dsn->{p} = $o->get('replica-password'); + PTDEBUG && _d("Replica password set"); } - push @$slaves, $make_cxn->(dsn => $slave_dsn, dbh => $dbh, parent => $parent); + push @$replicas, $make_cxn->(dsn => $replica_dsn, dbh => $dbh, parent => $parent); return; }, wait_no_die => $args{'wait_no_die'}, @@ -6762,20 +6762,20 @@ sub get_slaves { ); } elsif ( $methods->[0] =~ m/^dsn=/i ) { (my $dsn_table_dsn = join ",", @$methods) =~ s/^dsn=//i; - $slaves = $self->get_cxn_from_dsn_table( + $replicas = $self->get_cxn_from_dsn_table( %args, dsn_table_dsn => $dsn_table_dsn, wait_no_die => $args{'wait_no_die'}, ); } elsif ( $methods->[0] =~ m/none/i ) { - PTDEBUG && _d('Not getting to slaves'); + PTDEBUG && _d('Not getting to replicas'); } else { die "Unexpected recursion methods: @$methods"; } - return $slaves; + return $replicas; } sub _resolve_recursion_methods { @@ -6793,31 +6793,31 @@ sub _resolve_recursion_methods { } } -sub recurse_to_slaves { +sub recurse_to_replicas { my ( $self, $args, $level ) = @_; $level ||= 0; my $dp = $self->{DSNParser}; my $recurse = $args->{recurse} || $self->{OptionParser}->get('recurse'); my $dsn = $args->{dsn}; - my $slave_user = $args->{slave_user} || ''; - my $slave_password = $args->{slave_password} || ''; + my $replica_user = $args->{replica_user} || ''; + my $replica_password = $args->{replica_password} || ''; my $methods = $self->_resolve_recursion_methods($dsn); PTDEBUG && _d('Recursion methods:', @$methods); if ( lc($methods->[0]) eq 'none' ) { - PTDEBUG && _d('Not recursing to slaves'); + PTDEBUG && _d('Not recursing to replicas'); return; } - my $slave_dsn = $dsn; - if ($slave_user) { - $slave_dsn->{u} = $slave_user; - PTDEBUG && _d("Using slave user $slave_user on " - . $slave_dsn->{h} . ":" . ( $slave_dsn->{P} ? $slave_dsn->{P} : "")); + my $replica_dsn = $dsn; + if ($replica_user) { + $replica_dsn->{u} = $replica_user; + PTDEBUG && _d("Using replica user $replica_user on " + . $replica_dsn->{h} . ":" . ( $replica_dsn->{P} ? $replica_dsn->{P} : "")); } - if ($slave_password) { - $slave_dsn->{p} = $slave_password; - PTDEBUG && _d("Slave password set"); + if ($replica_password) { + $replica_dsn->{p} = $replica_password; + PTDEBUG && _d("Replica password set"); } my $dbh = $args->{dbh}; @@ -6825,12 +6825,12 @@ sub recurse_to_slaves { my $get_dbh = sub { eval { $dbh = $dp->get_dbh( - $dp->get_cxn_params($slave_dsn), { AutoCommit => 1 } + $dp->get_cxn_params($replica_dsn), { AutoCommit => 1 } ); - PTDEBUG && _d('Connected to', $dp->as_string($slave_dsn)); + PTDEBUG && _d('Connected to', $dp->as_string($replica_dsn)); }; if ( $EVAL_ERROR ) { - print STDERR "Cannot connect to ", $dp->as_string($slave_dsn), ": ", $EVAL_ERROR, "\n" + print STDERR "Cannot connect to ", $dp->as_string($replica_dsn), ": ", $EVAL_ERROR, "\n" or die "Cannot print: $OS_ERROR"; return; } @@ -6838,10 +6838,10 @@ sub recurse_to_slaves { DBH: { if ( !defined $dbh ) { - foreach my $known_slave ( @{$args->{slaves}} ) { - if ($known_slave->{dsn}->{h} eq $slave_dsn->{h} and - $known_slave->{dsn}->{P} eq $slave_dsn->{P} ) { - $dbh = $known_slave->{dbh}; + foreach my $known_replica ( @{$args->{replicas}} ) { + if ($known_replica->{dsn}->{h} eq $replica_dsn->{h} and + $known_replica->{dsn}->{P} eq $replica_dsn->{P} ) { + $dbh = $known_replica->{dbh}; last DBH; } } @@ -6859,7 +6859,7 @@ sub recurse_to_slaves { if ( $EVAL_ERROR ) { if ( $args->{wait_no_die} ) { print STDERR "Error getting server id: ", $EVAL_ERROR, - "\nRetrying query for server ", $slave_dsn->{h}, ":", $slave_dsn->{P}, "\n"; + "\nRetrying query for server ", $replica_dsn->{h}, ":", $replica_dsn->{P}, "\n"; sleep 1; $dbh->disconnect(); $get_dbh->(); @@ -6869,12 +6869,12 @@ sub recurse_to_slaves { } } until (defined $id); PTDEBUG && _d('Working on server ID', $id); - my $master_thinks_i_am = $dsn->{server_id}; + my $source_thinks_i_am = $dsn->{server_id}; if ( !defined $id - || ( defined $master_thinks_i_am && $master_thinks_i_am != $id ) + || ( defined $source_thinks_i_am && $source_thinks_i_am != $id ) || $args->{server_ids_seen}->{$id}++ ) { - PTDEBUG && _d('Server ID seen, or not what master said'); + PTDEBUG && _d('Server ID seen, or not what source said'); if ( $args->{skip_callback} ) { $args->{skip_callback}->($dsn, $dbh, $level, $args->{parent}); } @@ -6885,51 +6885,51 @@ sub recurse_to_slaves { if ( !defined $recurse || $level < $recurse ) { - my @slaves = - grep { !$_->{master_id} || $_->{master_id} == $id } # Only my slaves. - $self->find_slave_hosts($dp, $dbh, $dsn, $methods); + my @replicas = + grep { !$_->{source_id} || $_->{source_id} == $id } # Only my replicas. + $self->find_replica_hosts($dp, $dbh, $dsn, $methods); - foreach my $slave ( @slaves ) { + foreach my $replica ( @replicas ) { PTDEBUG && _d('Recursing from', - $dp->as_string($dsn), 'to', $dp->as_string($slave)); - $self->recurse_to_slaves( - { %$args, dsn => $slave, dbh => undef, parent => $dsn, slave_user => $slave_user, $slave_password => $slave_password }, $level + 1 ); + $dp->as_string($dsn), 'to', $dp->as_string($replica)); + $self->recurse_to_replicas( + { %$args, dsn => $replica, dbh => undef, parent => $dsn, replica_user => $replica_user, $replica_password => $replica_password }, $level + 1 ); } } } -sub find_slave_hosts { +sub find_replica_hosts { my ( $self, $dsn_parser, $dbh, $dsn, $methods ) = @_; - PTDEBUG && _d('Looking for slaves on', $dsn_parser->as_string($dsn), + PTDEBUG && _d('Looking for replicas on', $dsn_parser->as_string($dsn), 'using methods', @$methods); - my @slaves; + my @replicas; METHOD: foreach my $method ( @$methods ) { - my $find_slaves = "_find_slaves_by_$method"; - PTDEBUG && _d('Finding slaves with', $find_slaves); - @slaves = $self->$find_slaves($dsn_parser, $dbh, $dsn); - last METHOD if @slaves; + my $find_replicas = "_find_replicas_by_$method"; + PTDEBUG && _d('Finding replicas with', $find_replicas); + @replicas = $self->$find_replicas($dsn_parser, $dbh, $dsn); + last METHOD if @replicas; } - PTDEBUG && _d('Found', scalar(@slaves), 'slaves'); - return @slaves; + PTDEBUG && _d('Found', scalar(@replicas), 'replicas'); + return @replicas; } -sub _find_slaves_by_processlist { +sub _find_replicas_by_processlist { my ( $self, $dsn_parser, $dbh, $dsn ) = @_; - my @connected_slaves = $self->get_connected_slaves($dbh); - my @slaves = $self->_process_slaves_list($dsn_parser, $dsn, \@connected_slaves); - return @slaves; + my @connected_replicas = $self->get_connected_replicas($dbh); + my @replicas = $self->_process_replicas_list($dsn_parser, $dsn, \@connected_replicas); + return @replicas; } -sub _process_slaves_list { - my ($self, $dsn_parser, $dsn, $connected_slaves) = @_; - my @slaves = map { - my $slave = $dsn_parser->parse("h=$_", $dsn); - $slave->{source} = 'processlist'; - $slave; +sub _process_replicas_list { + my ($self, $dsn_parser, $dsn, $connected_replicas) = @_; + my @replicas = map { + my $replica = $dsn_parser->parse("h=$_", $dsn); + $replica->{source} = 'processlist'; + $replica; } grep { $_ } map { @@ -6941,22 +6941,28 @@ sub _process_slaves_list { $host = '['.$host.']'; } $host; - } @$connected_slaves; + } @$connected_replicas; - return @slaves; + return @replicas; } -sub _find_slaves_by_hosts { +sub _find_replicas_by_hosts { my ( $self, $dsn_parser, $dbh, $dsn ) = @_; - my @slaves; - my $sql = 'SHOW SLAVE HOSTS'; - PTDEBUG && _d($dbh, $sql); - @slaves = @{$dbh->selectall_arrayref($sql, { Slice => {} })}; + my @replicas; - if ( @slaves ) { - PTDEBUG && _d('Found some SHOW SLAVE HOSTS info'); - @slaves = map { + my $vp = VersionParser->new($dbh); + my $sql = 'SHOW REPLICAS'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $sql = 'SHOW SLAVE HOSTS'; + } + + PTDEBUG && _d($dbh, $sql); + @replicas = @{$dbh->selectall_arrayref($sql, { Slice => {} })}; + + if ( @replicas ) { + PTDEBUG && _d('Found some SHOW REPLICAS info'); + @replicas = map { my %hash; @hash{ map { lc $_ } keys %$_ } = values %$_; my $spec = "h=$hash{host},P=$hash{port}" @@ -6964,16 +6970,16 @@ sub _find_slaves_by_hosts { . ( $hash{password} ? ",p=$hash{password}" : ''); my $dsn = $dsn_parser->parse($spec, $dsn); $dsn->{server_id} = $hash{server_id}; - $dsn->{master_id} = $hash{master_id}; + $dsn->{source_id} = $hash{source_id}; $dsn->{source} = 'hosts'; $dsn; - } @slaves; + } @replicas; } - return @slaves; + return @replicas; } -sub get_connected_slaves { +sub get_connected_replicas { my ( $self, $dbh ) = @_; my $show = "SHOW GRANTS FOR "; @@ -7019,79 +7025,103 @@ sub get_connected_slaves { @{$dbh->selectall_arrayref($sql, { Slice => {} })}; } -sub is_master_of { - my ( $self, $master, $slave ) = @_; - my $master_status = $self->get_master_status($master) - or die "The server specified as a master is not a master"; - my $slave_status = $self->get_slave_status($slave) - or die "The server specified as a slave is not a slave"; - my @connected = $self->get_connected_slaves($master) - or die "The server specified as a master has no connected slaves"; - my (undef, $port) = $master->selectrow_array("SHOW VARIABLES LIKE 'port'"); +sub is_source_of { + my ( $self, $source, $replica ) = @_; - if ( $port != $slave_status->{master_port} ) { - die "The slave is connected to $slave_status->{master_port} " - . "but the master's port is $port"; + my $replica_version = VersionParser->new($replica); + my $source_name = 'source'; + my $source_port = 'source_port'; + if ( $replica_version < '8.1' || $replica_version->flavor() =~ m/maria/ ) { + $source_name = 'master'; + $source_port = 'master_port'; } - if ( !grep { $slave_status->{master_user} eq $_->{user} } @connected ) { - die "I don't see any slave I/O thread connected with user " - . $slave_status->{master_user}; + my $source_status = $self->get_source_status($source) + or die "The server specified as a source is not a source"; + my $replica_status = $self->get_replica_status($replica) + or die "The server specified as a replica is not a replica"; + my @connected = $self->get_connected_replicas($source) + or die "The server specified as a source has no connected replicas"; + my (undef, $port) = $source->selectrow_array("SHOW VARIABLES LIKE 'port'"); + + if ( $port != $replica_status->{$source_port} ) { + die "The replica is connected to $replica_status->{$source_port} " + . "but the source's port is $port"; } - if ( ($slave_status->{slave_io_state} || '') - eq 'Waiting for master to send event' ) + if ( !grep { $replica_status->{source_user} eq $_->{user} } @connected ) { + die "I don't see any replica I/O thread connected with user " + . $replica_status->{source_user}; + } + + if ( ($replica_status->{replica_io_state} || '') + eq 'Waiting for ${source_name} to send event' ) { - my ( $master_log_name, $master_log_num ) - = $master_status->{file} =~ m/^(.*?)\.0*([1-9][0-9]*)$/; - my ( $slave_log_name, $slave_log_num ) - = $slave_status->{master_log_file} =~ m/^(.*?)\.0*([1-9][0-9]*)$/; - if ( $master_log_name ne $slave_log_name - || abs($master_log_num - $slave_log_num) > 1 ) + my ( $source_log_name, $source_log_num ) + = $source_status->{file} =~ m/^(.*?)\.0*([1-9][0-9]*)$/; + my ( $replica_log_name, $replica_log_num ) + = $replica_status->{source_log_file} =~ m/^(.*?)\.0*([1-9][0-9]*)$/; + if ( $source_log_name ne $replica_log_name + || abs($source_log_num - $replica_log_num) > 1 ) { - die "The slave thinks it is reading from " - . "$slave_status->{master_log_file}, but the " - . "master is writing to $master_status->{file}"; + die "The replica thinks it is reading from " + . "$replica_status->{source_log_file}, but the " + . "source is writing to $source_status->{file}"; } } return 1; } -sub get_master_dsn { +sub get_source_dsn { my ( $self, $dbh, $dsn, $dsn_parser ) = @_; - my $master = $self->get_slave_status($dbh) or return undef; - my $spec = "h=$master->{master_host},P=$master->{master_port}"; + + my $vp = VersionParser->new($dbh); + my $source_host = 'source_host'; + my $source_port = 'source_port'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $source_host = 'master_host'; + $source_port = 'master_port'; + } + + my $source = $self->get_replica_status($dbh) or return undef; + my $spec = "h=$source->{${source_host}},P=$source->{${source_port}}"; return $dsn_parser->parse($spec, $dsn); } -sub get_slave_status { +sub get_replica_status { my ( $self, $dbh ) = @_; - if ( !$self->{not_a_slave}->{$dbh} ) { - my $sth = $self->{sths}->{$dbh}->{SLAVE_STATUS} - ||= $dbh->prepare('SHOW SLAVE STATUS'); - PTDEBUG && _d($dbh, 'SHOW SLAVE STATUS'); + my $server_version = VersionParser->new($dbh); + my $replica_name = 'replica'; + if ( $server_version < '8.1' || $server_version->flavor() =~ m/maria/ ) { + $replica_name = 'slave'; + } + + if ( !$self->{not_a_replica}->{$dbh} ) { + my $sth = $self->{sths}->{$dbh}->{REPLICA_STATUS} + ||= $dbh->prepare("SHOW ${replica_name} STATUS"); + PTDEBUG && _d($dbh, "SHOW ${replica_name} STATUS"); $sth->execute(); - my ($sss_rows) = $sth->fetchall_arrayref({}); # Show Slave Status rows + my ($sss_rows) = $sth->fetchall_arrayref({}); # Show Replica Status rows my $ss; if ( $sss_rows && @$sss_rows ) { if (scalar @$sss_rows > 1) { if (!$self->{channel}) { - die 'This server returned more than one row for SHOW SLAVE STATUS but "channel" was not specified on the command line'; + die 'This server returned more than one row for SHOW REPLICA STATUS but "channel" was not specified on the command line'; } - my $slave_use_channels; + my $replica_use_channels; for my $row (@$sss_rows) { $row = { map { lc($_) => $row->{$_} } keys %$row }; # lowercase the keys if ($row->{channel_name}) { - $slave_use_channels = 1; + $replica_use_channels = 1; } if ($row->{channel_name} eq $self->{channel}) { $ss = $row; last; } } - if (!$ss && $slave_use_channels) { + if (!$ss && $replica_use_channels) { die 'This server is using replication channels but "channel" was not specified on the command line'; } } else { @@ -7111,28 +7141,34 @@ sub get_slave_status { } } - PTDEBUG && _d('This server returns nothing for SHOW SLAVE STATUS'); - $self->{not_a_slave}->{$dbh}++; + PTDEBUG && _d('This server returns nothing for SHOW REPLICA STATUS'); + $self->{not_a_replica}->{$dbh}++; } } -sub get_master_status { +sub get_source_status { my ( $self, $dbh ) = @_; - if ( $self->{not_a_master}->{$dbh} ) { - PTDEBUG && _d('Server on dbh', $dbh, 'is not a master'); + if ( $self->{not_a_source}->{$dbh} ) { + PTDEBUG && _d('Server on dbh', $dbh, 'is not a source'); return; } + my $vp = VersionParser->new($dbh); + my $source_name = 'binary log'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $source_name = 'master'; + } + my $sth; if ( $self->{sths}->{$dbh} && $dbh && $self->{sths}->{$dbh} == $dbh ) { - $sth = $self->{sths}->{$dbh}->{MASTER_STATUS} - ||= $dbh->prepare('SHOW MASTER STATUS'); + $sth = $self->{sths}->{$dbh}->{SOURCE_STATUS} + ||= $dbh->prepare("SHOW ${source_name} STATUS"); } else { - $sth = $dbh->prepare('SHOW MASTER STATUS'); + $sth = $dbh->prepare("SHOW ${source_name} STATUS"); } - PTDEBUG && _d($dbh, 'SHOW MASTER STATUS'); + PTDEBUG && _d($dbh, "SHOW ${source_name} STATUS"); $sth->execute(); my ($ms) = @{$sth->fetchall_arrayref({})}; PTDEBUG && _d( @@ -7140,42 +7176,46 @@ sub get_master_status { : ''); if ( !$ms || scalar keys %$ms < 2 ) { - PTDEBUG && _d('Server on dbh', $dbh, 'does not seem to be a master'); - $self->{not_a_master}->{$dbh}++; + PTDEBUG && _d('Server on dbh', $dbh, 'does not seem to be a source'); + $self->{not_a_source}->{$dbh}++; } return { map { lc($_) => $ms->{$_} } keys %$ms }; # lowercase the keys } -sub wait_for_master { +sub wait_for_source { my ( $self, %args ) = @_; - my @required_args = qw(master_status slave_dbh); + my @required_args = qw(source_status replica_dbh); foreach my $arg ( @required_args ) { die "I need a $arg argument" unless $args{$arg}; } - my ($master_status, $slave_dbh) = @args{@required_args}; + my ($source_status, $replica_dbh) = @args{@required_args}; my $timeout = $args{timeout} || 60; my $result; my $waited; - if ( $master_status ) { - my $slave_status; + if ( $source_status ) { + my $replica_status; eval { - $slave_status = $self->get_slave_status($slave_dbh); + $replica_status = $self->get_replica_status($replica_dbh); }; if ($EVAL_ERROR) { return { result => undef, waited => 0, - error =>'Wait for master: this is a multi-master slave but "channel" was not specified on the command line', + error =>'Wait for source: this is a multi-source replica but "channel" was not specified on the command line', }; } - my $server_version = VersionParser->new($slave_dbh); - my $channel_sql = $server_version > '5.6' && $self->{channel} ? ", '$self->{channel}'" : ''; - my $sql = "SELECT MASTER_POS_WAIT('$master_status->{file}', $master_status->{position}, $timeout $channel_sql)"; - PTDEBUG && _d($slave_dbh, $sql); + my $vp = VersionParser->new($replica_dbh); + my $source_name = 'source'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $source_name = 'master'; + } + my $channel_sql = $vp > '5.6' && $self->{channel} ? ", '$self->{channel}'" : ''; + my $sql = "SELECT ${source_name}_POS_WAIT('$source_status->{file}', $source_status->{position}, $timeout $channel_sql)"; + PTDEBUG && _d($replica_dbh, $sql); my $start = time; - ($result) = $slave_dbh->selectrow_array($sql); + ($result) = $replica_dbh->selectrow_array($sql); $waited = time - $start; @@ -7183,7 +7223,7 @@ sub wait_for_master { PTDEBUG && _d("Waited", $waited, "seconds"); } else { - PTDEBUG && _d('Not waiting: this server is not a master'); + PTDEBUG && _d('Not waiting: this server is not a source'); } return { @@ -7192,75 +7232,96 @@ sub wait_for_master { }; } -sub stop_slave { +sub stop_replica { my ( $self, $dbh ) = @_; - my $sth = $self->{sths}->{$dbh}->{STOP_SLAVE} - ||= $dbh->prepare('STOP SLAVE'); + my $vp = VersionParser->new($dbh); + my $replica_name = 'replica'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $replica_name = 'slave'; + } + my $sth = $self->{sths}->{$dbh}->{STOP_REPLICA} + ||= $dbh->prepare("STOP ${replica_name}"); PTDEBUG && _d($dbh, $sth->{Statement}); $sth->execute(); } -sub start_slave { +sub start_replica { my ( $self, $dbh, $pos ) = @_; + + my $vp = VersionParser->new($dbh); + my $source_name = 'source'; + my $replica_name = 'replica'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $source_name = 'master'; + $replica_name = 'slave'; + } + if ( $pos ) { - my $sql = "START SLAVE UNTIL MASTER_LOG_FILE='$pos->{file}', " - . "MASTER_LOG_POS=$pos->{position}"; + my $sql = "START ${replica_name} UNTIL ${source_name}_LOG_FILE='$pos->{file}', " + . "${source_name}_LOG_POS=$pos->{position}"; PTDEBUG && _d($dbh, $sql); $dbh->do($sql); } else { - my $sth = $self->{sths}->{$dbh}->{START_SLAVE} - ||= $dbh->prepare('START SLAVE'); + my $sth = $self->{sths}->{$dbh}->{START_REPLICA} + ||= $dbh->prepare("START ${replica_name}"); PTDEBUG && _d($dbh, $sth->{Statement}); $sth->execute(); } } -sub catchup_to_master { - my ( $self, $slave, $master, $timeout ) = @_; - $self->stop_slave($master); - $self->stop_slave($slave); - my $slave_status = $self->get_slave_status($slave); - my $slave_pos = $self->repl_posn($slave_status); - my $master_status = $self->get_master_status($master); - my $master_pos = $self->repl_posn($master_status); - PTDEBUG && _d('Master position:', $self->pos_to_string($master_pos), - 'Slave position:', $self->pos_to_string($slave_pos)); +sub catchup_to_source { + my ( $self, $replica, $source, $timeout ) = @_; + $self->stop_replica($source); + $self->stop_replica($replica); + my $replica_status = $self->get_replica_status($replica); + my $replica_pos = $self->repl_posn($replica_status); + my $source_status = $self->get_source_status($source); + my $source_pos = $self->repl_posn($source_status); + PTDEBUG && _d('Source position:', $self->pos_to_string($source_pos), + 'Replica position:', $self->pos_to_string($replica_pos)); my $result; - if ( $self->pos_cmp($slave_pos, $master_pos) < 0 ) { - PTDEBUG && _d('Waiting for slave to catch up to master'); - $self->start_slave($slave, $master_pos); + if ( $self->pos_cmp($replica_pos, $source_pos) < 0 ) { + PTDEBUG && _d('Waiting for replica to catch up to source'); + $self->start_replica($replica, $source_pos); - $result = $self->wait_for_master( - master_status => $master_status, - slave_dbh => $slave, + $result = $self->wait_for_source( + source_status => $source_status, + replica_dbh => $replica, timeout => $timeout, - master_status => $master_status + source_status => $source_status ); if ($result->{error}) { die $result->{error}; } if ( !defined $result->{result} ) { - $slave_status = $self->get_slave_status($slave); - if ( !$self->slave_is_running($slave_status) ) { - PTDEBUG && _d('Master position:', - $self->pos_to_string($master_pos), - 'Slave position:', $self->pos_to_string($slave_pos)); - $slave_pos = $self->repl_posn($slave_status); - if ( $self->pos_cmp($slave_pos, $master_pos) != 0 ) { - die "MASTER_POS_WAIT() returned NULL but slave has not " - . "caught up to master"; + $replica_status = $self->get_replica_status($replica); + + my $vp = VersionParser->new($replica); + my $replica_name = 'replica'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $replica_name = 'slave'; + } + + if ( !$self->replica_is_running($replica_status, $replica_name) ) { + PTDEBUG && _d('Source position:', + $self->pos_to_string($source_pos), + 'Replica position:', $self->pos_to_string($replica_pos)); + $replica_pos = $self->repl_posn($replica_status); + if ( $self->pos_cmp($replica_pos, $source_pos) != 0 ) { + die "SOURCE_POS_WAIT() returned NULL but replica has not " + . "caught up to source"; } - PTDEBUG && _d('Slave is caught up to master and stopped'); + PTDEBUG && _d('Replica is caught up to source and stopped'); } else { - die "Slave has not caught up to master and it is still running"; + die "Replica has not caught up to source and it is still running"; } } } else { - PTDEBUG && _d("Slave is already caught up to master"); + PTDEBUG && _d("Replica is already caught up to source"); } return $result; @@ -7268,26 +7329,38 @@ sub catchup_to_master { sub catchup_to_same_pos { my ( $self, $s1_dbh, $s2_dbh ) = @_; - $self->stop_slave($s1_dbh); - $self->stop_slave($s2_dbh); - my $s1_status = $self->get_slave_status($s1_dbh); - my $s2_status = $self->get_slave_status($s2_dbh); + $self->stop_replica($s1_dbh); + $self->stop_replica($s2_dbh); + my $s1_status = $self->get_replica_status($s1_dbh); + my $s2_status = $self->get_replica_status($s2_dbh); my $s1_pos = $self->repl_posn($s1_status); my $s2_pos = $self->repl_posn($s2_status); if ( $self->pos_cmp($s1_pos, $s2_pos) < 0 ) { - $self->start_slave($s1_dbh, $s2_pos); + $self->start_replica($s1_dbh, $s2_pos); } elsif ( $self->pos_cmp($s2_pos, $s1_pos) < 0 ) { - $self->start_slave($s2_dbh, $s1_pos); + $self->start_replica($s2_dbh, $s1_pos); } - $s1_status = $self->get_slave_status($s1_dbh); - $s2_status = $self->get_slave_status($s2_dbh); + $s1_status = $self->get_replica_status($s1_dbh); + $s2_status = $self->get_replica_status($s2_dbh); $s1_pos = $self->repl_posn($s1_status); $s2_pos = $self->repl_posn($s2_status); - if ( $self->slave_is_running($s1_status) - || $self->slave_is_running($s2_status) + my $vp1 = VersionParser->new($s1_dbh); + my $replica1_name = 'replica'; + if ( $vp1 < '8.1' || $vp1->flavor() =~ m/maria/ ) { + $replica1_name = 'slave'; + } + + my $vp2 = VersionParser->new($s2_dbh); + my $replica2_name = 'replica'; + if ( $vp2 < '8.1' || $vp2->flavor() =~ m/maria/ ) { + $replica2_name = 'slave'; + } + + if ( $self->replica_is_running($s1_status, $replica1_name) + || $self->replica_is_running($s2_status, $replica2_name) || $self->pos_cmp($s1_pos, $s2_pos) != 0) { die "The servers aren't both stopped at the same position"; @@ -7295,14 +7368,21 @@ sub catchup_to_same_pos { } -sub slave_is_running { - my ( $self, $slave_status ) = @_; - return ($slave_status->{slave_sql_running} || 'No') eq 'Yes'; +sub replica_is_running { + my ( $self, $replica_status, $replica_name ) = @_; + return ($replica_status->{"${replica_name}_sql_running"} || 'No') eq 'Yes'; } -sub has_slave_updates { +sub has_replica_updates { my ( $self, $dbh ) = @_; - my $sql = q{SHOW VARIABLES LIKE 'log_slave_updates'}; + + my $vp = VersionParser->new($dbh); + my $replica_name = 'replica'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $replica_name = 'slave'; + } + + my $sql = qq{SHOW VARIABLES LIKE 'log_${replica_name}_updates'}; PTDEBUG && _d($dbh, $sql); my ($name, $value) = $dbh->selectrow_array($sql); return $value && $value =~ m/^(1|ON)$/; @@ -7316,6 +7396,12 @@ sub repl_posn { position => $status->{position}, }; } + elsif ( exists $status->{relay_source_log_file} && exists $status->{exec_source_log_pos} ) { + return { + file => $status->{relay_source_log_file}, + position => $status->{exec_source_log_pos}, + }; + } else { return { file => $status->{relay_master_log_file}, @@ -7324,11 +7410,18 @@ sub repl_posn { } } -sub get_slave_lag { +sub get_replica_lag { my ( $self, $dbh ) = @_; - my $stat = $self->get_slave_status($dbh); - return unless $stat; # server is not a slave - return $stat->{seconds_behind_master}; + + my $vp = VersionParser->new($dbh); + my $source_name = 'source'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $source_name = 'master'; + } + + my $stat = $self->get_replica_status($dbh); + return unless $stat; # server is not a replica + return $stat->{"seconds_behind_${source_name}"}; } sub pos_cmp { @@ -7339,9 +7432,9 @@ sub pos_cmp { sub short_host { my ( $self, $dsn ) = @_; my ($host, $port); - if ( $dsn->{master_host} ) { - $host = $dsn->{master_host}; - $port = $dsn->{master_port}; + if ( $dsn->{source_host} ) { + $host = $dsn->{source_host}; + $port = $dsn->{source_port}; } else { $host = $dsn->{h}; @@ -7356,7 +7449,7 @@ sub is_replication_thread { my $type = lc($args{type} || 'all'); die "Invalid type: $type" - unless $type =~ m/^binlog_dump|slave_io|slave_sql|all$/i; + unless $type =~ m/^binlog_dump|slave_io|slave_sql|replica_io|replica_sql|all$/i; my $match = 0; if ( $type =~ m/binlog_dump|all/i ) { @@ -7365,7 +7458,7 @@ sub is_replication_thread { } if ( !$match ) { if ( ($query->{User} || $query->{user} || '') eq "system user" ) { - PTDEBUG && _d("Slave replication thread"); + PTDEBUG && _d("Replica replication thread"); if ( $type ne 'all' ) { my $state = $query->{State} || $query->{state} || ''; @@ -7374,15 +7467,16 @@ sub is_replication_thread { $match = 1; } else { - my ($slave_sql) = $state =~ m/ + my ($replica_sql) = $state =~ m/ ^(Waiting\sfor\sthe\snext\sevent |Reading\sevent\sfrom\sthe\srelay\slog |Has\sread\sall\srelay\slog;\swaiting |Making\stemp\sfile - |Waiting\sfor\sslave\smutex\son\sexit)/xi; + |Waiting\sfor\sslave\smutex\son\sexit + |Waiting\sfor\sreplica\smutex\son\sexit)/xi; - $match = $type eq 'slave_sql' && $slave_sql ? 1 - : $type eq 'slave_io' && !$slave_sql ? 1 + $match = $type eq 'replica_sql' && $replica_sql ? 1 + : $type eq 'replica_io' && !$replica_sql ? 1 : 0; } } @@ -7423,9 +7517,15 @@ sub get_replication_filters { } my ($dbh) = @args{@required_args}; + my $vp = VersionParser->new($dbh); + my $replica_name = 'replica'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $replica_name = 'slave'; + } + my %filters = (); - my $status = $self->get_master_status($dbh); + my $status = $self->get_source_status($dbh); if ( $status ) { map { $filters{$_} = $status->{$_} } grep { defined $status->{$_} && $status->{$_} ne '' } @@ -7435,7 +7535,7 @@ sub get_replication_filters { ); } - $status = $self->get_slave_status($dbh); + $status = $self->get_replica_status($dbh); if ( $status ) { map { $filters{$_} = $status->{$_} } grep { defined $status->{$_} && $status->{$_} ne '' } @@ -7448,10 +7548,10 @@ sub get_replication_filters { replicate_wild_ignore_table ); - my $sql = "SHOW VARIABLES LIKE 'slave_skip_errors'"; + my $sql = "SHOW VARIABLES LIKE '${replica_name}_skip_errors'"; PTDEBUG && _d($dbh, $sql); my $row = $dbh->selectrow_arrayref($sql); - $filters{slave_skip_errors} = $row->[1] if $row->[1] && $row->[1] ne 'OFF'; + $filters{replica_skip_errors} = $row->[1] if $row->[1] && $row->[1] ne 'OFF'; } return \%filters; @@ -10055,7 +10155,7 @@ sub main { my $dp = $o->DSNParser(); $dp->prop('set-vars', $o->set_vars()); - if ( $o->get('replicate') || $o->get('sync-to-master') ) { + if ( $o->get('replicate') || $o->get('sync-to-source') ) { $o->set('wait', 60) unless $o->got('wait'); } if ( $o->get('wait') ) { @@ -10088,13 +10188,13 @@ sub main { } if ( !@dsns - || (@dsns ==1 && !$o->get('replicate') && !$o->get('sync-to-master'))) { + || (@dsns ==1 && !$o->get('replicate') && !$o->get('sync-to-source'))) { $o->save_error('At least one DSN is required, and at least two are ' - . 'required unless --sync-to-master or --replicate is specified'); + . 'required unless --sync-to-source or --replicate is specified'); } - if ( @dsns > 1 && $o->get('sync-to-master') && $o->get('replicate') ) { - $o->save_error('--sync-to-master and --replicate require only one DSN ', + if ( @dsns > 1 && $o->get('sync-to-source') && $o->get('replicate') ) { + $o->save_error('--sync-to-source and --replicate require only one DSN ', ' but ', scalar @dsns, ' where given'); } @@ -10106,9 +10206,9 @@ sub main { } if ( $o->get('bidirectional') ) { - if ( $o->get('replicate') || $o->get('sync-to-master') ) { + if ( $o->get('replicate') || $o->get('sync-to-source') ) { $o->save_error('--bidirectional does not work with ' - . '--replicate or --sync-to-master'); + . '--replicate or --sync-to-source'); } if ( @dsns < 2 ) { $o->save_error('--bidirectional requires at least two DSNs'); @@ -10223,24 +10323,33 @@ sub main { my $exit_status = 0; # 1: internal error, 2: tables differed, 3: both - # dsn[0] is expected to be the master (i.e. the source). So if - # --sync-to-master, then dsn[0] is a slave. Find its master and - # make the master dsn[0] and the slave dsn[1]. - if ( $o->get('sync-to-master') ) { - PTDEBUG && _d('Getting master of', $dp->as_string($dsns[0])); + # dsn[0] is expected to be the source (i.e. the source). So if + # --sync-to-source, then dsn[0] is a replica. Find its source and + # make the source dsn[0] and the replica dsn[1]. + if ( $o->get('sync-to-source') ) { + PTDEBUG && _d('Getting source of', $dp->as_string($dsns[0])); $dsns[0]->{dbh} = get_cxn($dsns[0], %modules); - my $master = $ms->get_master_dsn($dsns[0]->{dbh}, $dsns[0], $dp) - or die "Can't determine master of " . $dp->as_string($dsns[0]); - unshift @dsns, $master; # dsn[0]=master, dsn[1]=slave + my $source = $ms->get_source_dsn($dsns[0]->{dbh}, $dsns[0], $dp) + or die "Can't determine source of " . $dp->as_string($dsns[0]); + unshift @dsns, $source; # dsn[0]=source, dsn[1]=replica $dsns[0]->{dbh} = get_cxn($dsns[0], %modules); - if ( $o->get('check-master') ) { - my $is_master_of = eval { - $ms->is_master_of($dsns[0]->{dbh}, $dsns[1]->{dbh}); + + my $vp = VersionParser->new($dsns[1]->{dbh}); + my $source_name = 'source'; + my $replica_name = 'replica'; + if ( $vp < '8.1' || $vp->flavor() =~ m/maria/ ) { + $source_name = 'master'; + $replica_name = 'replica'; + } + + if ( $o->get('check-source') ) { + my $is_source_of = eval { + $ms->is_source_of($dsns[0]->{dbh}, $dsns[1]->{dbh}); }; # We should not die if replica connected via tunnel or port redirection if ( $EVAL_ERROR ) { - $EVAL_ERROR =~ m/The slave is connected to (\d+) but the master's port is \d+/; + $EVAL_ERROR =~ m/The ${replica_name} is connected to (\d+) but the ${source_name}'s port is \d+/; if ( !$1 || $1 != $dsns[0]->{P} ) { die $EVAL_ERROR; } @@ -10365,7 +10474,7 @@ sub lock_and_rename { } # We don't use lock_server() here because it does the usual stuff wrt - # waiting for slaves to catch up to master, etc, etc. + # waiting for replicas to catch up to source, etc, etc. my $src_db_tbl = $q->quote($src->{db}, $src->{tbl}); my $dst_db_tbl = $q->quote($dst->{db}, $dst->{tbl}); my $tmp_db_tbl = $q->quote($src->{db}, $src->{tbl} . "_tmp_$PID"); @@ -10477,10 +10586,10 @@ sub sync_one_table { # Sub: sync_via_replication # Sync multiple destination hosts to one source host via replication. # The first DSN in $args{dsns} specifies the source host. -# If --sync-to-master is specified, then the source host is a master -# and there is only one destination host which is its slave. +# If --sync-to-source is specified, then the source host is a source +# and there is only one destination host which is its replica. # Else, destination hosts are auto-discovered with -# . +# . # # Parameters: # %args - Arguments @@ -10534,9 +10643,9 @@ sub sync_via_replication { my %skip_table; my $exit_status = 0; - # Connect to the master and treat it as the source, then find - # differences on the slave and sync them. - if ( $o->get('sync-to-master') ) { + # Connect to the source and treat it as the source, then find + # differences on the replica and sync them. + if ( $o->get('sync-to-source') ) { my $dst = { dsn => $dsns->[1], dbh => $dsns->[1]->{dbh} || get_cxn($dsns->[1], %args), @@ -10545,13 +10654,13 @@ sub sync_via_replication { tbl => undef, # set later }; - # First, check that the master (source) has no discrepancies itself, + # First, check that the source (source) has no discrepancies itself, # and ignore tables that do. my $src_diffs = $checksum->find_replication_differences( $src->{dbh}, $o->get('replicate')); map { $skip_table{lc $_->{db}}->{lc $_->{tbl}}++ } @$src_diffs; - # Now check the slave for differences and sync them if necessary. + # Now check the replica for differences and sync them if necessary. my $dst_diffs = $checksum->find_replication_differences( $dst->{dbh}, $o->get('replicate')); my $diffs = filter_diffs( @@ -10599,12 +10708,12 @@ sub sync_via_replication { } disconnect($dst); - } # sync-to-master + } # sync-to-source - # The DSN is the master. Connect to each slave, find differences, + # The DSN is the source. Connect to each replica, find differences, # then sync them. else { - $ms->recurse_to_slaves( + $ms->recurse_to_replicas( { dbh => $src->{dbh}, dsn => $src->{dsn}, recurse => 1, @@ -10613,13 +10722,13 @@ sub sync_via_replication { my $all_diffs = $checksum->find_replication_differences( $dbh, $o->get('replicate')); if ( !$level ) { - # This is the master; don't sync any tables that are wrong + # This is the source; don't sync any tables that are wrong # here, for obvious reasons. map { $skip_table{lc $_->{db}}->{lc $_->{tbl}}++ } @$all_diffs; } else { - # This is a slave. + # This is a replica. my $diffs = filter_diffs( diffs => $all_diffs, SchemaIterator => $schema_iter, @@ -10673,13 +10782,13 @@ sub sync_via_replication { else { PTDEBUG && _d('No checksum differences'); } - } # this is a slave + } # this is a replica return; - }, # recurse_to_slaves() callback + }, # recurse_to_replicas() callback }, ); - } # DSN is master + } # DSN is source disconnect($src); return $exit_status; @@ -10959,7 +11068,7 @@ sub sync_a_table { } # get_change_dbh() may die if, for example, the destination is - # not a slave. Perhaps its work should be part of can_sync()? + # not a replica. Perhaps its work should be part of can_sync()? my $change_dbh = get_change_dbh(tbl_struct => $tbl_struct, %args); my $actions = make_action_subs(change_dbh => $change_dbh, %args); @@ -10974,7 +11083,7 @@ sub sync_a_table { queue => $o->get('buffer-to-client') ? 1 : 0, replace => $o->get('replace') || $o->get('replicate') - || $o->get('sync-to-master') + || $o->get('sync-to-source') || 0, actions => $actions, Quoter => $args{Quoter}, @@ -10994,7 +11103,7 @@ sub sync_a_table { buffer_in_mysql => $o->get('buffer-in-mysql'), buffer_to_client => $o->get('buffer-to-client'), changing_src => $o->get('replicate') - || $o->get('sync-to-master') + || $o->get('sync-to-source') || $o->get('bidirectional') || 0, float_precision => $o->get('float-precision'), @@ -11037,12 +11146,12 @@ sub sync_a_table { # Sub: get_change_dbh # Return the dbh to write to for syncing changes. Write statements -# are executed on the "change dbh". If --sync-to-master or --replicate -# is specified, the source (master) dbh is the "change dbh". This means -# changes replicate to all slaves. Else, the destination dbh is the +# are executed on the "change dbh". If --sync-to-source or --replicate +# is specified, the source (source) dbh is the "change dbh". This means +# changes replicate to all replicas. Else, the destination dbh is the # change dbh. This is the case when two independent servers (or perhaps # one table on the same server) are synced. This sub implements -# --[no]check-slave because writing to a slave is generally a bad thing. +# --[no]check-replica because writing to a replica is generally a bad thing. # # Parameters: # %args - Arguments @@ -11071,24 +11180,24 @@ sub get_change_dbh { my $change_dbh = $dst->{dbh}; # The default case: making changes on dst. - if ( $o->get('sync-to-master') || $o->get('replicate') ) { - # Is it possible to make changes on the master (i.e. the source)? + if ( $o->get('sync-to-source') || $o->get('replicate') ) { + # Is it possible to make changes on the source (i.e. the source)? # Only if REPLACE will work. my $can_replace = grep { $_->{is_unique} } values %{$tbl_struct->{keys}}; PTDEBUG && _d("This table's replace-ability:", $can_replace); - die "Can't make changes on the master because no unique index exists" + die "Can't make changes on the source because no unique index exists" unless $can_replace; $change_dbh = $src->{dbh}; # The alternate case. PTDEBUG && _d('Will make changes on source', $change_dbh); } - elsif ( $o->get('check-slave') ) { + elsif ( $o->get('check-replica') ) { # Is it safe to change data on the destination? Only if it's *not* - # a slave. We don't change tables on slaves directly. If we are - # forced to change data on a slave, we require either that 1) binary + # a replica. We don't change tables on replicas directly. If we are + # forced to change data on a replica, we require either that 1) binary # logging is disabled, or 2) the check is bypassed. By the way, just - # because the server is a slave doesn't mean it's not also the master - # of the master (master-master replication). - my $slave_status = $ms->get_slave_status($dst->{dbh}); + # because the server is a replica doesn't mean it's not also the source + # of the source (source-source replication). + my $replica_status = $ms->get_replica_status($dst->{dbh}); my (undef, $log_bin) = $dst->{dbh}->selectrow_array( q{SHOW VARIABLES LIKE 'log_bin'}); my ($sql_log_bin) = $dst->{dbh}->selectrow_array( @@ -11096,9 +11205,9 @@ sub get_change_dbh { PTDEBUG && _d('Variables on destination:', 'log_bin=', (defined $log_bin ? $log_bin : 'NULL'), ' @@SQL_LOG_BIN=', (defined $sql_log_bin ? $sql_log_bin : 'NULL')); - if ( $slave_status && $sql_log_bin && ($log_bin || 'OFF') eq 'ON' ) { + if ( $replica_status && $sql_log_bin && ($log_bin || 'OFF') eq 'ON' ) { die "Can't make changes on ", $dp->as_string($dst->{dsn}), - " because it's a slave. See the documentation section", + " because it's a replica. See the documentation section", " 'REPLICATION SAFETY' for solutions to this problem."; } PTDEBUG && _d('Will make changes on destination', $change_dbh); @@ -11246,7 +11355,7 @@ sub get_cxn { # This is because starting with MySQL 5.1.29, changing the format # requires a SUPER user. if ( VersionParser->new($dbh) >= '5.1.29' - && ($o->get('replicate') || $o->get('sync-to-master'))) { + && ($o->get('replicate') || $o->get('sync-to-source'))) { $sql = 'SELECT @@binlog_format'; PTDEBUG && _d($dbh, $sql); my ($original_binlog_format) = $dbh->selectrow_array($sql); @@ -11337,8 +11446,8 @@ sub ok_to_sync { tbl => $dst->{tbl}, ); - if ( lc($src->{tbl_struct}->{engine}) eq 'rocksdb' && ($o->get('sync-to-master')) ) { - print STDERR "Cannot sync using --sync-to-master with $dst->{db}.$dst->{tbl} ". + if ( lc($src->{tbl_struct}->{engine}) eq 'rocksdb' && ($o->get('sync-to-source')) ) { + print STDERR "Cannot sync using --sync-to-source with $dst->{db}.$dst->{tbl} ". "due to the limitations of the RocksDB engine.\n\n". "More information: https://www.percona.com/doc/percona-server/LATEST/myrocks/limitations.html\n\n"; die "Process aborted.\n"; @@ -11367,7 +11476,7 @@ sub ok_to_sync { my $replace = $o->get('replace') || $o->get('replicate') - || $o->get('sync-to-master'); + || $o->get('sync-to-source'); if ( $replace && $o->get('execute') && $o->get('check-child-tables') ) { my $child_tables = find_child_tables( tbl => $src, @@ -11430,12 +11539,12 @@ sub get_triggers { } # Sub: filter_diffs -# Filter different slave tables according to the various schema object +# Filter different replica tables according to the various schema object # filters. This sub is called in to implement # schema object filters like --databases and --tables. # # Returns: -# Arrayref of different slave tables that pass the filters +# Arrayref of different replica tables that pass the filters sub filter_diffs { my ( %args ) = @_; my @required_args = qw(diffs SchemaIterator skip_table); @@ -11881,12 +11990,12 @@ Usage: pt-table-sync [OPTIONS] DSN [DSN] pt-table-sync synchronizes data efficiently between MySQL tables. This tool changes data, so for maximum safety, you should back up your data -before using it. When synchronizing a server that is a replication slave -with the L<"--replicate"> or L<"--sync-to-master"> methods, it B -makes the changes on the replication master, B the replication slave +before using it. When synchronizing a server that is a replication replica +with the L<"--replicate"> or L<"--sync-to-source"> methods, it B +makes the changes on the replication source, B the replication replica directly. This is in general the only safe way to bring a replica back in -sync with its master; changes to the replica are usually the source of the -problems in the first place. However, the changes it makes on the master +sync with its source; changes to the replica are usually the source of the +problems in the first place. However, the changes it makes on the source should be no-op changes that set the data to their current values, and actually affect only the replica. @@ -11898,30 +12007,30 @@ Sync all tables on host1 to host2 and host3: pt-table-sync --execute host1 host2 host3 -Make slave1 have the same data as its replication master: +Make replica1 have the same data as its replication source: - pt-table-sync --execute --sync-to-master slave1 + pt-table-sync --execute --sync-to-source replica1 -Resolve differences that L found on all slaves of master1: +Resolve differences that L found on all replicas of source1: - pt-table-sync --execute --replicate percona.checksum master1 + pt-table-sync --execute --replicate percona.checksum source1 -Same as above but only resolve differences on slave1: +Same as above but only resolve differences on replica1: pt-table-sync --execute --replicate percona.checksum \ - --sync-to-master slave1 + --sync-to-source replica1 -Sync master2 in a master-master replication configuration, where master2's copy +Sync source2 in a source-source replication configuration, where source2's copy of db.tbl is known or suspected to be incorrect: - pt-table-sync --execute --sync-to-master h=master2,D=db,t=tbl + pt-table-sync --execute --sync-to-source h=source2,D=db,t=tbl -Note that in the master-master configuration, the following will NOT do what you -want, because it will make changes directly on master2, which will then flow -through replication and change master1's data: +Note that in the source-source configuration, the following will NOT do what you +want, because it will make changes directly on source2, which will then flow +through replication and change source1's data: - # Don't do this in a master-master setup! - pt-table-sync --execute h=master1,D=db,t=tbl master2 + # Don't do this in a source-source setup! + pt-table-sync --execute h=source1,D=db,t=tbl source2 =head1 RISKS @@ -11958,21 +12067,21 @@ The following is the abbreviated logic: if DSN has a t part, sync only that table: if 1 DSN: - if --sync-to-master: - The DSN is a slave. Connect to its master and sync. + if --sync-to-source: + The DSN is a replica. Connect to its source and sync. if more than 1 DSN: The first DSN is the source. Sync each DSN in turn. else if --replicate: - if --sync-to-master: - The DSN is a slave. Connect to its master, find records + if --sync-to-source: + The DSN is a replica. Connect to its source, find records of differences, and fix. else: - The DSN is the master. Find slaves and connect to each, + The DSN is the source. Find replicas and connect to each, find records of differences, and fix. else: - if only 1 DSN and --sync-to-master: - The DSN is a slave. Connect to its master, find tables and - filter with --databases etc, and sync each table to the master. + if only 1 DSN and --sync-to-source: + The DSN is a replica. Connect to its source, find tables and + filter with --databases etc, and sync each table to the source. else: find tables, filtering with --databases etc, and sync each DSN to the first. @@ -11991,34 +12100,34 @@ If you're unsure, read each tool's documentation carefully and decide for yourself, or consult with an expert. Regardless of whether L<"--replicate"> is used or not, you need to specify -which hosts to sync. There are two ways: with L<"--sync-to-master"> or -without. Specifying L<"--sync-to-master"> makes pt-table-sync expect -one and only slave DSN on the command line. The tool will automatically -discover the slave's master and sync it so that its data is the same as -its master. This is accomplished by making changes on the master which -then flow through replication and update the slave to resolve its differences. +which hosts to sync. There are two ways: with L<"--sync-to-source"> or +without. Specifying L<"--sync-to-source"> makes pt-table-sync expect +one and only replica DSN on the command line. The tool will automatically +discover the replica's source and sync it so that its data is the same as +its source. This is accomplished by making changes on the source which +then flow through replication and update the replica to resolve its differences. B: although this option specifies and syncs a single -slave, if there are other slaves on the same master, they will receive -via replication the changes intended for the slave that you're trying to +replica, if there are other replicas on the same source, they will receive +via replication the changes intended for the replica that you're trying to sync. -Alternatively, if you do not specify L<"--sync-to-master">, the first +Alternatively, if you do not specify L<"--sync-to-source">, the first DSN given on the command line is the source host. There is only ever one source host. If you do not also specify L<"--replicate">, then you must specify at least one other DSN as the destination host. There can be one or more destination hosts. Source and destination hosts must be independent; they cannot be in the same replication topology. pt-table-sync will die with an error if it detects that a destination -host is a slave because changes are written directly to destination hosts -(and it's not safe to write directly to slaves). Or, if you specify -L<"--replicate"> (but not L<"--sync-to-master">) then pt-table-sync expects -one and only one master DSN on the command line. The tool will automatically -discover all the master's slaves and sync them to the master. This is -the only way to sync several (all) slaves at once (because -L<"--sync-to-master"> only specifies one slave). +host is a replica because changes are written directly to destination hosts +(and it's not safe to write directly to replicas). Or, if you specify +L<"--replicate"> (but not L<"--sync-to-source">) then pt-table-sync expects +one and only one source DSN on the command line. The tool will automatically +discover all the source's replicas and sync them to the source. This is +the only way to sync several (all) replicas at once (because +L<"--sync-to-source"> only specifies one replica). Each host on the command line is specified as a DSN. The first DSN -(or only DSN for cases like L<"--sync-to-master">) provides default values +(or only DSN for cases like L<"--sync-to-source">) provides default values for other DSNs, whether those other DSNs are specified on the command line or auto-discovered by the tool. So in this example, @@ -12035,8 +12144,8 @@ the DSNs given on the command line. =item Replicas using row-based replication pt-table-sync requires statement-based replication when used with -the L<"--sync-to-master"> or L<"--replicate"> option. -Therefore it will set C on the master +the L<"--sync-to-source"> or L<"--replicate"> option. +Therefore it will set C on the source for its session if required. To do this user must have C privilege. @@ -12083,9 +12192,9 @@ The tool rewrites queries to C and C in this case. This is automatically handled after the first index violation, so you don't have to worry about it. -Be careful when using pt-table-sync in any master-master setup. Master-master +Be careful when using pt-table-sync in any source-source setup. Source-source replication is inherently tricky, and it's easy to make mistakes. You need to -be sure you're using the tool correctly for master-master replication. See the +be sure you're using the tool correctly for source-source replication. See the L<"SYNOPSIS"> for the overview of the correct usage. Also be careful with tables that have foreign key constraints with C @@ -12098,34 +12207,34 @@ or unique index, it might be best to synchronize that data by another means. =head1 REPLICATION SAFETY -Synchronizing a replication master and slave safely is a non-trivial problem, in +Synchronizing a replication source and replica safely is a non-trivial problem, in general. There are all sorts of issues to think about, such as other processes -changing data, trying to change data on the slave, whether the destination and -source are a master-master pair, and much more. +changing data, trying to change data on the replica, whether the destination and +source are a source-source pair, and much more. -In general, the safe way to do it is to change the data on the master, and let -the changes flow through replication to the slave like any other changes. +In general, the safe way to do it is to change the data on the source, and let +the changes flow through replication to the replica like any other changes. However, this works only if it's possible to REPLACE into the table on the -master. REPLACE works only if there's a unique index on the table (otherwise it +source. REPLACE works only if there's a unique index on the table (otherwise it just acts like an ordinary INSERT). -If your table has unique keys, you should use the L<"--sync-to-master"> and/or -L<"--replicate"> options to sync a slave to its master. This will generally do +If your table has unique keys, you should use the L<"--sync-to-source"> and/or +L<"--replicate"> options to sync a replica to its source. This will generally do the right thing. When there is no unique key on the table, there is no choice -but to change the data on the slave, and pt-table-sync will detect that you're +but to change the data on the replica, and pt-table-sync will detect that you're trying to do so. It will complain and die unless you specify -C<--no-check-slave> (see L<"--[no]check-slave">). +C<--no-check-replica> (see L<"--[no]check-replica">). -If you're syncing a table without a primary or unique key on a master-master +If you're syncing a table without a primary or unique key on a source-source pair, you must change the data on the destination server. Therefore, you need to specify C<--no-bin-log> for safety (see L<"--[no]bin-log">). If you don't, the changes you make on the destination server will replicate back to the source server and change the data there! -The generally safe thing to do on a master-master pair is to use the -L<"--sync-to-master"> option so you don't change the data on the destination -server. You will also need to specify C<--no-check-slave> to keep -pt-table-sync from complaining that it is changing data on a slave. +The generally safe thing to do on a source-source pair is to use the +L<"--sync-to-source"> option so you don't change the data on the destination +server. You will also need to specify C<--no-check-replica> to keep +pt-table-sync from complaining that it is changing data on a replica. =head1 ALGORITHMS @@ -12209,7 +12318,7 @@ reliably there are a number of strict limitations: * does not handle DELETE changes For example, suppose we have three servers: c1, r1, r2. c1 is the central -server, a pseudo-master to the other servers (viz. r1 and r2 are not slaves +server, a pseudo-source to the other servers (viz. r1 and r2 are not replicas to c1). r1 and r2 are remote servers. Rows in table foo are updated and inserted on all three servers and we want to synchronize all the changes between all the servers. Table foo has columns: @@ -12371,12 +12480,12 @@ This option is disabled when L<"--bidirectional"> is used. type: string Channel name used when connected to a server using replication channels. -Suppose you have two masters, master_a at port 12345, master_b at port 1236 and -a slave connected to both masters using channels chan_master_a and chan_master_b. -If you want to run pt-table-sync to synchronize the slave against master_a, pt-table-sync -won't be able to determine what's the correct master since SHOW SLAVE STATUS -will return 2 rows. In this case, you can use --channel=chan_master_a to specify -the channel name to use in the SHOW SLAVE STATUS command. +Suppose you have two sources, source_a at port 12345, source_b at port 1236 and +a replica connected to both sources using channels chan_source_a and chan_source_b. +If you want to run pt-table-sync to synchronize the replica against source_a, pt-table-sync +won't be able to determine what's the correct source since SHOW REPLICA STATUS +will return 2 rows. In this case, you can use --channel=chan_source_a to specify +the channel name to use in the SHOW REPLICA STATUS command. =item --charset @@ -12393,7 +12502,7 @@ connecting to MySQL. default: yes Check if L<"--execute"> will adversely affect child tables. When -L<"--replace">, L<"--replicate">, or L<"--sync-to-master"> is specified, +L<"--replace">, L<"--replicate">, or L<"--sync-to-source"> is specified, the tool may sync tables using C statements. If a table being synced has child tables with C, C, or C, the tool prints an error and skips the table because @@ -12406,31 +12515,31 @@ avoid affecting child tables, also specify C<--no-foreign-key-checks> so MySQL will not cascade any operations from the parent to child tables. This check is only preformed if L<"--execute"> and one of L<"--replace">, -L<"--replicate">, or L<"--sync-to-master"> is specified. L<"--print"> +L<"--replicate">, or L<"--sync-to-source"> is specified. L<"--print"> does not check child tables. The error message only prints the first child table found with an C, C, or C foreign key constraint. There could be other affected child tables. -=item --[no]check-master +=item --[no]check-source default: yes -With L<"--sync-to-master">, try to verify that the detected -master is the real master. +With L<"--sync-to-source">, try to verify that the detected +source is the real source. -=item --[no]check-slave +=item --[no]check-replica default: yes -Check whether the destination server is a slave. +Check whether the destination server is a replica. -If the destination server is a slave, it's generally unsafe to make changes on +If the destination server is a replica, it's generally unsafe to make changes on it. However, sometimes you have to; L<"--replace"> won't work unless there's a -unique index, for example, so you can't make changes on the master in that +unique index, for example, so you can't make changes on the source in that scenario. By default pt-table-sync will complain if you try to change data on -a slave. Specify C<--no-check-slave> to disable this check. Use it at your own +a replica. Specify C<--no-check-replica> to disable this check. Use it at your own risk. =item --[no]check-triggers @@ -12747,11 +12856,11 @@ you're examining them. The possible values are as follows: 3 Lock and unlock once for every server (DSN) synced, with C. -A replication slave is never locked if L<"--replicate"> or L<"--sync-to-master"> -is specified, since in theory locking the table on the master should prevent any -changes from taking place. (You are not changing data on your slave, right?) -If L<"--wait"> is given, the master (source) is locked and then the tool waits -for the slave to catch up to the master before continuing. +A replication replica is never locked if L<"--replicate"> or L<"--sync-to-source"> +is specified, since in theory locking the table on the source should prevent any +changes from taking place. (You are not changing data on your replica, right?) +If L<"--wait"> is given, the source (source) is locked and then the tool waits +for the replica to catch up to the source before continuing. If C<--transaction> is specified, C is not used. Instead, lock and unlock are implemented by beginning and committing transactions. @@ -12804,21 +12913,21 @@ yourself if you want to sync the tables manually. type: array; default: processlist,hosts -Preferred recursion method used to find slaves. +Preferred recursion method used to find replicas. Possible methods are: METHOD USES =========== ================== processlist SHOW PROCESSLIST - hosts SHOW SLAVE HOSTS - none Do not find slaves + hosts SHOW REPLICAS + none Do not find replicas -The processlist method is preferred because SHOW SLAVE HOSTS is not reliable. +The processlist method is preferred because SHOW REPLICAS is not reliable. However, the hosts method is required if the server uses a non-standard port (not 3306). Usually pt-table-sync does the right thing and finds -the slaves, but you may give a preferred method and it will be used first. -If it doesn't find any slaves, the other methods will be tried. +the replicas, but you may give a preferred method and it will be used first. +If it doesn't find any replicas, the other methods will be tried. =item --replace @@ -12837,48 +12946,48 @@ Sync tables listed as different in this table. Specifies that C should examine the specified table to find data that differs. The table is exactly the same as the argument of the same name to L. That is, it contains records of which tables (and ranges -of values) differ between the master and slave. +of values) differ between the source and replica. -For each table and range of values that shows differences between the master and -slave, C will sync that table, with the appropriate C -clause, to its master. +For each table and range of values that shows differences between the source and +replica, C will sync that table, with the appropriate C +clause, to its source. This automatically sets L<"--wait"> to 60 and causes changes to be made on the -master instead of the slave. +source instead of the replica. -If L<"--sync-to-master"> is specified, the tool will assume the server you -specified is the slave, and connect to the master as usual to sync. +If L<"--sync-to-source"> is specified, the tool will assume the server you +specified is the replica, and connect to the source as usual to sync. -Otherwise, it will try to use C to find slaves of the server -you specified. If it is unable to find any slaves via C, it -will inspect C instead. You must configure each slave's +Otherwise, it will try to use C to find replicas of the server +you specified. If it is unable to find any replicas via C, it +will inspect C instead. You must configure each replica's C, C and other options for this to work right. After -finding slaves, it will inspect the specified table on each slave to find data +finding replicas, it will inspect the specified table on each replica to find data that needs to be synced, and sync it. -The tool examines the master's copy of the table first, assuming that the master -is potentially a slave as well. Any table that shows differences there will -B be synced on the slave(s). For example, suppose your replication is set +The tool examines the source's copy of the table first, assuming that the source +is potentially a replica as well. Any table that shows differences there will +B be synced on the replica(s). For example, suppose your replication is set up as A->B, B->C, B->D. Suppose you use this argument and specify server B. The tool will examine server B's copy of the table. If it looks like server B's data in table C is different from server A's copy, the tool will not sync that table on servers C and D. -=item --slave-user +=item --replica-user type: string -Sets the user to be used to connect to the slaves. +Sets the user to be used to connect to the replicas. This parameter allows you to have a different user with less privileges on the -slaves but that user must exist on all slaves. +replicas but that user must exist on all replicas. -=item --slave-password +=item --replica-password type: string -Sets the password to be used to connect to the slaves. -It can be used with --slave-user and the password for the user must be the same -on all slaves. +Sets the password to be used to connect to the replicas. +It can be used with --replica-user and the password for the user must be the same +on all replicas. =item --set-vars @@ -12904,13 +13013,13 @@ short form: -S; type: string Socket file to use for connection. -=item --sync-to-master +=item --sync-to-source -Treat the DSN as a slave and sync it to its master. +Treat the DSN as a replica and sync it to its source. -Treat the server you specified as a slave. Inspect C, -connect to the server's master, and treat the master as the source and the slave -as the destination. Causes changes to be made on the master. Sets L<"--wait"> +Treat the server you specified as a replica. Inspect C, +connect to the server's source, and treat the source as the source and the replica +as the destination. Causes changes to be made on the source. Sets L<"--wait"> to 60 by default, sets L<"--lock"> to 1 by default, and disables L<"--[no]transaction"> by default. See also L<"--replicate">, which changes this option's behavior. @@ -12927,7 +13036,7 @@ Table names may be qualified with the database name. Keep going if L<"--wait"> fails. -If you specify L<"--wait"> and the slave doesn't catch up to the master's +If you specify L<"--wait"> and the replica doesn't catch up to the source's position before the wait times out, the default behavior is to abort. This option makes the tool keep going anyway. B: if you are trying to get a consistent comparison between the two servers, you probably don't want to keep @@ -13023,9 +13132,9 @@ For more information, visit L). Sets L<"--lock"> to 1 and L<"--[no]transaction"> to 0 by default. If you see an error such as the following, @@ -13038,7 +13147,7 @@ The default value of this option is influenced by other options. To see what value is in effect, run with L<"--help">. To disable waiting entirely (except for locks), specify L<"--wait"> 0. This -helps when the slave is lagging on tables that are not being synced. +helps when the replica is lagging on tables that are not being synced. =item --where @@ -13125,6 +13234,12 @@ dsn: user; copy: yes User for login if not current user. +=item * s + +dsn: mysql_ssl; copy: yes + +Create SSL connection + =back =head1 ENVIRONMENT diff --git a/bin/pt-upgrade b/bin/pt-upgrade index bff9fb96..dd28b2da 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -940,7 +940,7 @@ sub get_cxn_params { $dsn = 'DBI:mysql:' . ( $info->{D} || '' ) . ';' . join(';', map { "$opts{$_}->{dsn}=$info->{$_}" } grep { defined $info->{$_} } - qw(F h P S A)) + qw(F h P S A s)) . ';mysql_read_default_group=client' . ($info->{L} ? ';mysql_local_infile=1' : ''); } @@ -7958,7 +7958,7 @@ use constant { COM_BINLOG_DUMP => '12', COM_TABLE_DUMP => '13', COM_CONNECT_OUT => '14', - COM_REGISTER_SLAVE => '15', + COM_REGISTER_REPLICA => '15', COM_STMT_PREPARE => '16', COM_STMT_EXECUTE => '17', COM_STMT_SEND_LONG_DATA => '18', @@ -7992,7 +7992,7 @@ my %com_for = ( '12' => 'COM_BINLOG_DUMP', '13' => 'COM_TABLE_DUMP', '14' => 'COM_CONNECT_OUT', - '15' => 'COM_REGISTER_SLAVE', + '15' => 'COM_REGISTER_REPLICA', '16' => 'COM_STMT_PREPARE', '17' => 'COM_STMT_EXECUTE', '18' => 'COM_STMT_SEND_LONG_DATA', diff --git a/bin/pt-variable-advisor b/bin/pt-variable-advisor index 477b4fec..50178fca 100755 --- a/bin/pt-variable-advisor +++ b/bin/pt-variable-advisor @@ -2034,7 +2034,7 @@ sub get_cxn_params { $dsn = 'DBI:mysql:' . ( $info->{D} || '' ) . ';' . join(';', map { "$opts{$_}->{dsn}=$info->{$_}" } grep { defined $info->{$_} } - qw(F h P S A)) + qw(F h P S A s)) . ';mysql_read_default_group=client' . ($info->{L} ? ';mysql_local_infile=1' : ''); } @@ -3425,6 +3425,13 @@ sub get_rules { return $args{variables}->{init_slave} ? 1 : 0; }, }, + { + id => 'init_replica', + code => sub { + my ( %args ) = @_; + return $args{variables}->{init_replica} ? 1 : 0; + }, + }, { id => 'innodb_additional_mem_pool_size', code => sub { @@ -3671,6 +3678,13 @@ sub get_rules { return _var_gt($args{variables}->{slave_net_timeout}, 60); }, }, + { + id => 'replica_net_timeout', + code => sub { + my ( %args ) = @_; + return _var_gt($args{variables}->{replica_net_timeout}, 60); + }, + }, { id => 'slave_skip_errors', code => sub { @@ -3679,6 +3693,14 @@ sub get_rules { && $args{variables}->{slave_skip_errors} ne 'OFF' ? 1 : 0; }, }, + { + id => 'replica_skip_errors', + code => sub { + my ( %args ) = @_; + return $args{variables}->{replica_skip_errors} + && $args{variables}->{replica_skip_errors} ne 'OFF' ? 1 : 0; + }, + }, { id => 'sort_buffer_size-1', code => sub { @@ -5538,7 +5560,7 @@ verbosity, you'll see subsequent sentences. severity: note -Are you trying to write to more than one server in a dual-master or +Are you trying to write to more than one server in a dual-source or ring replication configuration? This is potentially very dangerous and in most cases is a serious mistake. Most people's reasons for doing this are actually not valid at all. diff --git a/t/lib/samples/issue_616.sql b/t/lib/samples/issue_616.sql index 05e9a727..856cd6e4 100644 --- a/t/lib/samples/issue_616.sql +++ b/t/lib/samples/issue_616.sql @@ -7,15 +7,15 @@ CREATE TABLE `t` ( PRIMARY KEY (`id`) ); INSERT INTO issue_616.t VALUES -(1, 'from master'), -(11, 'from master'), -(21, 'from master'), +(1, 'from source'), +(11, 'from source'), +(21, 'from source'), (22, 'from slave'), (32, 'from slave'), (42, 'from slave'), -(31, 'from master'), -(41, 'from master'), -(51, 'from master'); +(31, 'from source'), +(41, 'from source'), +(51, 'from source'); SET SQL_LOG_BIN=0; DELETE FROM issue_616.t WHERE id IN (22,32,42); SET SQL_LOG_BIN=1; diff --git a/t/pt-table-sync/basics.t b/t/pt-table-sync/basics.t index 896fa1d4..d77441d4 100644 --- a/t/pt-table-sync/basics.t +++ b/t/pt-table-sync/basics.t @@ -19,23 +19,23 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 24; } -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->create_dbs($source_dbh, [qw(test)]); -sub query_slave { - return $slave_dbh->selectall_arrayref(@_, {Slice => {}}); +sub query_replica { + return $replica_dbh->selectall_arrayref(@_, {Slice => {}}); } sub run { @@ -43,8 +43,8 @@ sub run { my $output = output( sub { pt_table_sync::main(qw(--print --execute), - "h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=$src", - "h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=$dst", + "h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=$src,s=1", + "h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=$dst,s=1", ($other ? split(" ", $other) : ()) ); }, @@ -60,82 +60,83 @@ sub run { sub run_cmd { my ($src, $dst, $other) = @_; - my $cmd = "$trunk/bin/pt-table-sync --print --execute h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=$src h=127.1,P=12346,D=test,t=$dst $other 2>&1"; + my $cmd = "$trunk/bin/pt-table-sync --print --execute h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=$src,s=1 h=127.1,P=12346,D=test,t=$dst,s=1 $other 2>&1"; chomp($output=`$cmd`); return $output; } # ############################################################################# -# Test basic master-slave syncing +# Test basic source-replica syncing # ############################################################################# -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); $output = run('test1', 'test2', ''); -like($output, qr/Can't make changes/, 'It dislikes changing a slave'); +like($output, qr/Can't make changes/, 'It dislikes changing a replica'); $output = run('test1', 'test2', '--no-bin-log'); is($output, "INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('1', 'en'); INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('2', 'ca');", 'No alg sync'); is_deeply( - query_slave('select * from test.test2'), + query_replica('select * from test.test2'), [ { a => 1, b => 'en' }, { a => 2, b => 'ca' } ], 'Synced OK with no alg' ); -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); $output = run('test1', 'test2', '--algorithms Stream --no-bin-log'); is($output, "INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('1', 'en'); INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('2', 'ca');", 'Basic Stream sync'); is_deeply( - query_slave('select * from test.test2'), + query_replica('select * from test.test2'), [ { a => 1, b => 'en' }, { a => 2, b => 'ca' } ], 'Synced OK with Stream' ); -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); $output = run('test1', 'test2', '--algorithms GroupBy --no-bin-log'); is($output, "INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('1', 'en'); INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('2', 'ca');", 'Basic GroupBy sync'); is_deeply( - query_slave('select * from test.test2'), + query_replica('select * from test.test2'), [ { a => 1, b => 'en' }, { a => 2, b => 'ca' } ], 'Synced OK with GroupBy' ); -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); $output = run('test1', 'test2', '--algorithms Chunk,GroupBy --no-bin-log'); is($output, "INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('1', 'en'); INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('2', 'ca');", 'Basic Chunk sync'); is_deeply( - query_slave('select * from test.test2'), + query_replica('select * from test.test2'), [ { a => 1, b => 'en' }, { a => 2, b => 'ca' } ], 'Synced OK with Chunk' ); -# Create a new user that is going to be replicated on slaves. -# After that, stop replication, delete the user from the master just to ensure that -# on the master we are using the sandbox user, and start relication again to run +# Create a new user that is going to be replicated on replicas. +# After that, stop replication, delete the user from the source just to ensure that +# on the source we are using the sandbox user, and start relication again to run # the tests -$sb->do_as_root("master", q/GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'slave_password'/); -$sb->do_as_root("master", q/set sql_log_bin=0/); -$sb->do_as_root("master", q/DROP USER 'slave_user'/); -$sb->do_as_root("master", q/set sql_log_bin=1/); +$sb->do_as_root("source", q/CREATE USER 'replica_user'@'%' IDENTIFIED BY 'replica_password'/); +$sb->do_as_root("source", q/GRANT REPLICATION SLAVE ON *.* TO 'replica_user'@'%'/); +$sb->do_as_root("source", q/set sql_log_bin=0/); +$sb->do_as_root("source", q/DROP USER 'replica_user'/); +$sb->do_as_root("source", q/set sql_log_bin=1/); -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); -$output = run('test1', 'test2', '--algorithms Chunk,GroupBy --no-bin-log --slave-user slave_user --slave-password slave_password'); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); +$output = run('test1', 'test2', '--algorithms Chunk,GroupBy --no-bin-log --replica-user replica_user --replica-password replica_password'); is($output, "INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('1', 'en'); INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('2', 'ca');", 'Basic Chunk sync'); is_deeply( - query_slave('select * from test.test2'), + query_replica('select * from test.test2'), [ { a => 1, b => 'en' }, { a => 2, b => 'ca' } ], - 'Synced OK with --slave-user' + 'Synced OK with --replica-user' ); -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); $output = run('test1', 'test2', '--algorithms Nibble --no-bin-log'); is($output, "INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('1', 'en'); INSERT INTO `test`.`test2`(`a`, `b`) VALUES ('2', 'ca');", 'Basic Nibble sync'); is_deeply( - query_slave('select * from test.test2'), + query_replica('select * from test.test2'), [ { a => 1, b => 'en' }, { a => 2, b => 'ca' } ], 'Synced OK with Nibble' ); @@ -143,7 +144,7 @@ is_deeply( # Save original PTDEBUG env because we modify it below. my $dbg = $ENV{PTDEBUG}; -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); $ENV{PTDEBUG} = 1; $output = run_cmd('test1', 'test2', '--algorithms Nibble --no-bin-log --chunk-size 1 --transaction --lock 1'); delete $ENV{PTDEBUG}; @@ -153,7 +154,7 @@ like( 'Nibble with transactions and locking' ); is_deeply( - query_slave('select * from test.test2'), + query_replica('select * from test.test2'), [ { a => 1, b => 'en' }, { a => 2, b => 'ca' } ], 'Synced OK with Nibble' ); @@ -190,13 +191,13 @@ $ENV{PTDEBUG} = $dbg || 0; # Fix bug 911996. # ########################################################################### -# pt-table-checksum waits for all checksums to replicate to all slaves, -# so no need to call $sb->wait_for_slaves() after this. +# pt-table-checksum waits for all checksums to replicate to all replicas, +# so no need to call $sb->wait_for_replicas() after this. `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --set-vars innodb_lock_wait_timeout=3 --chunk-size 50 --chunk-index idx_actor_last_name -t sakila.actor --quiet`; -$slave_dbh->do("update percona.checksums set this_crc='' where db='sakila' and tbl='actor' and chunk=3"); -$slave_dbh->do("update sakila.actor set last_name='' where actor_id=30"); -$sb->wait_for_slaves(); # wait for those ^ updates to replicate to slave2 (!2347) +$replica_dbh->do("update percona.checksums set this_crc='' where db='sakila' and tbl='actor' and chunk=3"); +$replica_dbh->do("update sakila.actor set last_name='' where actor_id=30"); +$sb->wait_for_replicas(); # wait for those ^ updates to replicate to replica2 (!2347) $output = output( sub { @@ -220,24 +221,24 @@ is( ); # Fix bug 927771. -$sb->load_file('master', 't/pt-table-sync/samples/bug_927771.sql'); -$slave_dbh->do("update test.t set c='z' where id>8"); +$sb->load_file('source', 't/pt-table-sync/samples/bug_927771.sql'); +$replica_dbh->do("update test.t set c='z' where id>8"); -# pt-table-checksum waits for all checksums to replicate to all slaves, -# so no need to call $sb->wait_for_slaves() after this. +# pt-table-checksum waits for all checksums to replicate to all replicas, +# so no need to call $sb->wait_for_replicas() after this. `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --max-load '' --set-vars innodb_lock_wait_timeout=3 --chunk-size 2 -t test.t --quiet`; $output = output( sub { pt_table_sync::main('h=127.1,P=12346,u=msandbox,p=msandbox', # qw(--print --execute --replicate percona.checksums), - qw(--print --execute --sync-to-master), + qw(--print --execute --sync-to-source), qw(--no-foreign-key-checks)) }, stderr => 1, ); -$sb->wait_for_slaves(); # wait for sync to replicate +$sb->wait_for_replicas(); # wait for sync to replicate like( $output, @@ -245,7 +246,7 @@ like( "--replicate with uc index (bug 927771)" ); -my $rows = $slave_dbh->selectall_arrayref("select id, c from test.t where id>8 order by id"); +my $rows = $replica_dbh->selectall_arrayref("select id, c from test.t where id>8 order by id"); is_deeply( $rows, @@ -253,13 +254,13 @@ is_deeply( [9, 'i'], [10, 'j'], ], - "Synced slaved (bug 927771)" + "Synced replicad (bug 927771)" ); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/bidirectional.t b/t/pt-table-sync/bidirectional.t index 03a5a79e..9b7e06b9 100644 --- a/t/pt-table-sync/bidirectional.t +++ b/t/pt-table-sync/bidirectional.t @@ -22,19 +22,19 @@ $Data::Dumper::Quotekeys = 0; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $c1_dbh = $sb->get_dbh_for('master'); +my $c1_dbh = $sb->get_dbh_for('source'); -diag(`$trunk/sandbox/start-sandbox master 2900 >/dev/null`); -my $r1_dbh = $sb->get_dbh_for('master3'); +diag(`$trunk/sandbox/start-sandbox source 2900 >/dev/null`); +my $r1_dbh = $sb->get_dbh_for('source3'); -diag(`$trunk/sandbox/start-sandbox master 2901 >/dev/null`); -my $r2_dbh = $sb->get_dbh_for('master4'); +diag(`$trunk/sandbox/start-sandbox source 2901 >/dev/null`); +my $r2_dbh = $sb->get_dbh_for('source4'); if ( !$c1_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; + plan skip_all => 'Cannot connect to sandbox source'; } elsif ( !$r1_dbh ) { - plan skip_all => 'Cannot connect to second sandbox master'; + plan skip_all => 'Cannot connect to second sandbox source'; } else { @@ -49,10 +49,10 @@ $sb->wipe_clean($c1_dbh); $sb->wipe_clean($r1_dbh); sub load_bidi_data { - $sb->load_file('master', 't/pt-table-sync/samples/bidirectional/table.sql'); - $sb->load_file('master3', 't/pt-table-sync/samples/bidirectional/table.sql'); - $sb->load_file('master', 't/pt-table-sync/samples/bidirectional/master-data.sql'); - $sb->load_file('master3', 't/pt-table-sync/samples/bidirectional/remote-1.sql'); + $sb->load_file('source', 't/pt-table-sync/samples/bidirectional/table.sql'); + $sb->load_file('source3', 't/pt-table-sync/samples/bidirectional/table.sql'); + $sb->load_file('source', 't/pt-table-sync/samples/bidirectional/master-data.sql'); + $sb->load_file('source3', 't/pt-table-sync/samples/bidirectional/remote-1.sql'); } my $r1_data_synced = [ @@ -323,14 +323,14 @@ is_deeply( # Test bidirectional sync with 3 servers. # ############################################################################# -# It's confusing but master4 = 2901, aka our 3rd master server. +# It's confusing but source4 = 2901, aka our 3rd source server. SKIP: { - skip 'Cannot connect to third sandbox master', 9 unless $r2_dbh; + skip 'Cannot connect to third sandbox source', 9 unless $r2_dbh; load_bidi_data(); - $sb->load_file('master4', 't/pt-table-sync/samples/bidirectional/table.sql'); - $sb->load_file('master4', 't/pt-table-sync/samples/bidirectional/remote-2.sql'); + $sb->load_file('source4', 't/pt-table-sync/samples/bidirectional/table.sql'); + $sb->load_file('source4', 't/pt-table-sync/samples/bidirectional/remote-2.sql'); $res = $r2_dbh->selectall_arrayref('select * from bidi.t order by id'); is_deeply( diff --git a/t/pt-table-sync/binlog_format.t b/t/pt-table-sync/binlog_format.t index 30ca9ff4..57a2e482 100644 --- a/t/pt-table-sync/binlog_format.t +++ b/t/pt-table-sync/binlog_format.t @@ -19,16 +19,16 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } -elsif ( VersionParser->new($master_dbh) < '5.1.5' ) { +elsif ( VersionParser->new($source_dbh) < '5.1.5' ) { plan skip_all => 'Requires MySQL 5.1.5 or newer'; } else { @@ -39,32 +39,32 @@ else { # Issue 95: Make mk-table-sync force statement-based binlog format on 5.1 # ############################################################################# -$sb->create_dbs($master_dbh, ['test']); -$master_dbh->do('create table test.t (i int, unique index (i))'); -$master_dbh->do('insert into test.t values (1),(2)'); -$sb->wait_for_slaves(); -$slave_dbh->do('insert into test.t values (3)'); # only on the slaves +$sb->create_dbs($source_dbh, ['test']); +$source_dbh->do('create table test.t (i int, unique index (i))'); +$source_dbh->do('insert into test.t values (1),(2)'); +$sb->wait_for_replicas(); +$replica_dbh->do('insert into test.t values (3)'); # only on the replicas is_deeply( - $master_dbh->selectall_arrayref('select * from test.t order by i'), + $source_dbh->selectall_arrayref('select * from test.t order by i'), [[1],[2]], - 'Data on master before sync' + 'Data on source before sync' ); -# Slaves have an extra row, something to sync. -my $rows = $slave_dbh->selectall_arrayref('select * from test.t order by i'); +# Replicas have an extra row, something to sync. +my $rows = $replica_dbh->selectall_arrayref('select * from test.t order by i'); is_deeply( $rows, [[1],[2],[3]], - 'Data on slave before sync' + 'Data on replica before sync' ) or print Dumper($rows); -$master_dbh->do("SET GLOBAL binlog_format='ROW'"); -$master_dbh->disconnect(); -$master_dbh = $sb->get_dbh_for('master'); +$source_dbh->do("SET GLOBAL binlog_format='ROW'"); +$source_dbh->disconnect(); +$source_dbh = $sb->get_dbh_for('source'); is_deeply( - $master_dbh->selectrow_arrayref('select @@binlog_format'), + $source_dbh->selectrow_arrayref('select @@binlog_format'), ['ROW'], 'Set global binlog_format = ROW' ); @@ -72,7 +72,7 @@ is_deeply( is( output( sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox", - qw(--sync-to-master -t test.t --print --execute)) }, + qw(--sync-to-source -t test.t --print --execute)) }, trf => \&remove_traces, ), "DELETE FROM `test`.`t` WHERE `i`='3' LIMIT 1; @@ -82,23 +82,23 @@ is( wait_until( sub { - my $rows = $slave_dbh->selectall_arrayref('select * from test.t'); + my $rows = $replica_dbh->selectall_arrayref('select * from test.t'); return $rows && @$rows == 2; } -) or die "DELETE did not replicate to slave"; +) or die "DELETE did not replicate to replica"; is_deeply( - $slave_dbh->selectall_arrayref('select * from test.t'), + $replica_dbh->selectall_arrayref('select * from test.t'), [[1],[2]], - 'DELETE replicated to slave' + 'DELETE replicated to replica' ); -$master_dbh->do("SET GLOBAL binlog_format='STATEMENT'"); -$master_dbh->disconnect(); -$master_dbh = $sb->get_dbh_for('master'); +$source_dbh->do("SET GLOBAL binlog_format='STATEMENT'"); +$source_dbh->disconnect(); +$source_dbh = $sb->get_dbh_for('source'); is_deeply( - $master_dbh->selectrow_arrayref('select @@binlog_format'), + $source_dbh->selectrow_arrayref('select @@binlog_format'), ['STATEMENT'], 'Set global binlog_format = STATEMENT' ); @@ -106,6 +106,6 @@ is_deeply( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/bugs.t b/t/pt-table-sync/bugs.t index cf5e2d10..9ce4e9db 100644 --- a/t/pt-table-sync/bugs.t +++ b/t/pt-table-sync/bugs.t @@ -19,34 +19,34 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 9; } my $sample = "t/pt-table-sync/samples"; -my $master_dsn = "h=127.1,P=12345,u=msandbox,p=msandbox"; -my $slave_dsn = "h=127.1,P=12346,u=msandbox,p=msandbox"; +my $source_dsn = "h=127.1,P=12345,u=msandbox,p=msandbox"; +my $replica_dsn = "h=127.1,P=12346,u=msandbox,p=msandbox"; # ############################################################################# # # ############################################################################# -$sb->load_file('master', "$sample/wrong-tbl-struct-bug-1003014.sql"); +$sb->load_file('source', "$sample/wrong-tbl-struct-bug-1003014.sql"); # Make a diff in each table. -$slave_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)"); -$slave_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)"); +$replica_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)"); +$replica_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)"); -$output = `$trunk/bin/pt-table-checksum $master_dsn --set-vars innodb_lock_wait_timeout=3 --max-load '' -d test --chunk-size 10 2>&1`; +$output = `$trunk/bin/pt-table-checksum $source_dsn --set-vars innodb_lock_wait_timeout=3 --max-load '' -d test --chunk-size 10 2>&1`; is( PerconaTest::count_checksum_results($output, 'diffs'), @@ -72,7 +72,7 @@ my $checksums = [ [qw( test zzz 14 )], ]; -my $rows = $master_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk"); +my $rows = $source_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk"); is_deeply( $rows, $checksums, @@ -81,12 +81,12 @@ is_deeply( my $exit_status; $output = output( - sub { $exit_status = pt_table_sync::main($slave_dsn, - qw(--replicate percona.checksums --sync-to-master --print --execute), + sub { $exit_status = pt_table_sync::main($replica_dsn, + qw(--replicate percona.checksums --sync-to-source --print --execute), "--tables", "test.aaa,test.zzz") }, stderr => 1, ); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); is( $exit_status, @@ -94,7 +94,7 @@ is( "Bug 1003014 (wrong tbl_struct): 0 exit" ) or diag($output); -$rows = $slave_dbh->selectall_arrayref("SELECT c FROM test.zzz WHERE id IN (44,45,46)"); +$rows = $replica_dbh->selectall_arrayref("SELECT c FROM test.zzz WHERE id IN (44,45,46)"); is_deeply( $rows, [ ['a'], ['a'], ['a'] ], @@ -102,17 +102,17 @@ is_deeply( ); # ######################################################################### -# Repeat the whole process without --sync-to-master so the second code path +# Repeat the whole process without --sync-to-source so the second code path # in sync_via_replication() is tested. # ######################################################################### -$sb->wipe_clean($master_dbh); -$sb->load_file('master', "$sample/wrong-tbl-struct-bug-1003014.sql"); +$sb->wipe_clean($source_dbh); +$sb->load_file('source', "$sample/wrong-tbl-struct-bug-1003014.sql"); -$slave_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)"); -$slave_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)"); +$replica_dbh->do("DELETE FROM test.aaa WHERE STOP_ARCHIVE IN (5,6,7)"); +$replica_dbh->do("UPDATE test.zzz SET c='x' WHERE id IN (44,45,46)"); -$output = `$trunk/bin/pt-table-checksum $master_dsn --set-vars innodb_lock_wait_timeout=3 --max-load '' -d test --chunk-size 10 2>&1`; +$output = `$trunk/bin/pt-table-checksum $source_dsn --set-vars innodb_lock_wait_timeout=3 --max-load '' -d test --chunk-size 10 2>&1`; is( PerconaTest::count_checksum_results($output, 'diffs'), @@ -120,7 +120,7 @@ is( "Bug 1003014 (wrong tbl_struct): 2 diffs (just replicate)" ) or print STDERR $output; -$rows = $master_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk"); +$rows = $source_dbh->selectall_arrayref("SELECT db, tbl, chunk FROM percona.checksums ORDER BY db, tbl, chunk"); is_deeply( $rows, $checksums, @@ -128,12 +128,12 @@ is_deeply( ); $output = output( - sub { $exit_status = pt_table_sync::main($master_dsn, + sub { $exit_status = pt_table_sync::main($source_dsn, qw(--replicate percona.checksums --print --execute), "--tables", "test.aaa,test.zzz") }, stderr => 1, ); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); is( $exit_status, @@ -141,7 +141,7 @@ is( "Bug 1003014 (wrong tbl_struct): 0 exit (just replicate)" ) or diag($output); -$rows = $slave_dbh->selectall_arrayref("SELECT c FROM test.zzz WHERE id IN (44,45,46)"); +$rows = $replica_dbh->selectall_arrayref("SELECT c FROM test.zzz WHERE id IN (44,45,46)"); is_deeply( $rows, [ ['a'], ['a'], ['a'] ], @@ -151,6 +151,6 @@ is_deeply( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/char_chunking.t b/t/pt-table-sync/char_chunking.t index 8b421ecb..a0f7bc64 100644 --- a/t/pt-table-sync/char_chunking.t +++ b/t/pt-table-sync/char_chunking.t @@ -17,35 +17,35 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 7; } my $output; -my @args = ('h=127.1,P=12346,u=msandbox,p=msandbox', qw(--sync-to-master -t test.ascii -v -v --print --chunk-size 30)); +my @args = ('h=127.1,P=12346,u=msandbox,p=msandbox', qw(--sync-to-source -t test.ascii -v -v --print --chunk-size 30)); -$sb->create_dbs($master_dbh, ['test']); -$sb->load_file('master', "t/lib/samples/char-chunking/ascii.sql", "test"); -$master_dbh->do('alter table test.ascii drop column `i`'); +$sb->create_dbs($source_dbh, ['test']); +$sb->load_file('source', "t/lib/samples/char-chunking/ascii.sql", "test"); +$source_dbh->do('alter table test.ascii drop column `i`'); wait_until( sub { my $row; - eval {$row = $slave_dbh->selectall_arrayref("select * from test.ascii");}; + eval {$row = $replica_dbh->selectall_arrayref("select * from test.ascii");}; return 1 if $row && @$row > 100; }, ); -$slave_dbh->do('delete from test.ascii where c like "Zesus%"'); +$replica_dbh->do('delete from test.ascii where c like "Zesus%"'); $output = output( sub { pt_table_sync::main(@args) }, @@ -85,6 +85,6 @@ like( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/check_privs.t b/t/pt-table-sync/check_privs.t index fdfd1e24..371c5bb7 100644 --- a/t/pt-table-sync/check_privs.t +++ b/t/pt-table-sync/check_privs.t @@ -18,21 +18,21 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); my $output; -my @args = ('h=127.1,P=12345,u=test_907,p=msandbox', 'P=12346,u=msandbox', qw(--print --no-check-slave -d issue_907)); +my @args = ('h=127.1,P=12345,u=test_907,p=msandbox,s=1', 'P=12346,u=msandbox,s=1', qw(--print --no-check-replica -d issue_907)); # ############################################################################# # Issue 907: Add --[no]check-privileges @@ -40,14 +40,14 @@ my @args = ('h=127.1,P=12345,u=test_907,p=msandbox', 'P=12346,u=msandbox', qw(-- #1) get the script to create the underprivileged user -$master_dbh->do('drop database if exists issue_907'); -$master_dbh->do('create database issue_907'); -$master_dbh->do('create table issue_907.t (i int)'); -PerconaTest::wait_for_table($slave_dbh, "issue_907.t"); -$slave_dbh->do('drop database if exists issue_907'); -$slave_dbh->do('create database issue_907'); -$slave_dbh->do('create table issue_907.t (i int)'); -$slave_dbh->do('insert into issue_907.t values (1)'); +$source_dbh->do('drop database if exists issue_907'); +$source_dbh->do('create database issue_907'); +$source_dbh->do('create table issue_907.t (i int)'); +PerconaTest::wait_for_table($replica_dbh, "issue_907.t"); +$replica_dbh->do('drop database if exists issue_907'); +$replica_dbh->do('create database issue_907'); +$replica_dbh->do('create table issue_907.t (i int)'); +$replica_dbh->do('insert into issue_907.t values (1)'); # On 5.1 user needs SUPER to set binlog_format, which mk-table-sync does. `/tmp/12345/use -uroot -e "CREATE USER 'test_907'\@'localhost' IDENTIFIED BY 'msandbox'"`; @@ -65,13 +65,13 @@ is( ); #3) clean up user -$master_dbh->do('DROP USER \'test_907\'@\'localhost\''); +$source_dbh->do('DROP USER \'test_907\'@\'localhost\''); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); done_testing; diff --git a/t/pt-table-sync/columns.t b/t/pt-table-sync/columns.t index 486d4740..627e8ca5 100644 --- a/t/pt-table-sync/columns.t +++ b/t/pt-table-sync/columns.t @@ -18,27 +18,27 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 6; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ############################################################################# # Issue 313: Add --ignore-columns (and add tests for --columns). # ############################################################################# -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); $output = `$trunk/bin/pt-table-sync --print h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=test3 t=test4`; $output = remove_traces($output); # This test changed because the row sql now does ORDER BY key_col (id here) @@ -75,7 +75,7 @@ EOF # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/diff_where.t b/t/pt-table-sync/diff_where.t index e1ba8b60..2922c79b 100644 --- a/t/pt-table-sync/diff_where.t +++ b/t/pt-table-sync/diff_where.t @@ -47,8 +47,8 @@ test_diff_where( cnt_diff => '-1', crc_diff => '1', lower_boundary => '7', - master_cnt => '3', - master_crc => '1ddd6c71', + source_cnt => '3', + source_crc => '1ddd6c71', table => 'test.mt1', this_cnt => '2', this_crc => '4a57d814', @@ -67,8 +67,8 @@ test_diff_where( crc_diff => '0', db => 'test', lower_boundary => undef, - master_cnt => '0', - master_crc => '0', + source_cnt => '0', + source_crc => '0', table => 'test.history', tbl => 'history', this_cnt => '49', diff --git a/t/pt-table-sync/enum_fields.t b/t/pt-table-sync/enum_fields.t index 05ab4dd0..90a9f0e6 100644 --- a/t/pt-table-sync/enum_fields.t +++ b/t/pt-table-sync/enum_fields.t @@ -18,27 +18,27 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 2; } -$sb->load_file('master', 't/pt-table-sync/samples/enum_fields.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/enum_fields.sql'); # ############################################################################# # Issue 804: mk-table-sync: can't nibble because index name isn't lower case? # ############################################################################# -$master_dbh->do('set sql_log_bin=0'); -$master_dbh->do(q/INSERT INTO enum_fields_db.rgb (name, hex_code) VALUES ('blue','0x0000FF')/); -$output = `$trunk/bin/pt-table-sync --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox -d enum_fields_db --print`; +$source_dbh->do('set sql_log_bin=0'); +$source_dbh->do(q/INSERT INTO enum_fields_db.rgb (name, hex_code) VALUES ('blue','0x0000FF')/); +$output = `$trunk/bin/pt-table-sync --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox -d enum_fields_db --print`; $output = remove_traces($output); chomp($output); is( @@ -50,7 +50,7 @@ is( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/filters.t b/t/pt-table-sync/filters.t index 611a684c..5928aa53 100644 --- a/t/pt-table-sync/filters.t +++ b/t/pt-table-sync/filters.t @@ -18,26 +18,26 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 18; } -my $master_dsn = $sb->dsn_for('master'); -my $slave1_dsn = $sb->dsn_for('slave1'); +my $source_dsn = $sb->dsn_for('source'); +my $replica1_dsn = $sb->dsn_for('replica1'); my $output; # See this SQL file because it has a number of simple dbs and tbls # that are used to checking schema object filters. -$sb->load_file('master', "t/lib/samples/SchemaIterator.sql"); +$sb->load_file('source', "t/lib/samples/SchemaIterator.sql"); sub test_filters { my (%args) = @_; @@ -50,7 +50,7 @@ sub test_filters { }, ); - my $tables_used = PerconaTest::tables_used($sb->genlog('master')); + my $tables_used = PerconaTest::tables_used($sb->genlog('source')); is_deeply( $tables_used, $args{res}, @@ -65,16 +65,16 @@ sub test_filters { # Not really a filter, but only the specified tables should be used. test_filters( name => "Sync d1.t1 to d1.t2", - cmds => ["$master_dsn,D=d1,t=t1", "t=t2"], + cmds => ["$source_dsn,D=d1,t=t1", "t=t2"], res => [qw(d1.t1 d1.t2)], ); -# Use slave1 like it's another master, ok becuase we're not actually -# syncing anything, so --no-check-slave is required else pt-table-sync -# won't run (because it doesn't like to sync directly to a slave). +# Use replica1 like it's another source, ok becuase we're not actually +# syncing anything, so --no-check-replica is required else pt-table-sync +# won't run (because it doesn't like to sync directly to a replica). test_filters( name => "-t d1.t1", - cmds => [$master_dsn, $slave1_dsn, qw(--no-check-slave), + cmds => [$source_dsn, $replica1_dsn, qw(--no-check-replica), qw(-t d1.t1)], res => [qw(d1.t1)], ); @@ -82,7 +82,7 @@ test_filters( # Like the previous test, but now any table called "t1". test_filters( name => "-t t1", - cmds => [$master_dsn, $slave1_dsn, qw(--no-check-slave), + cmds => [$source_dsn, $replica1_dsn, qw(--no-check-replica), qw(-t t1)], res => [qw(d1.t1 d2.t1)], ); @@ -90,7 +90,7 @@ test_filters( # Only the given db, all its tables: there's only 1 tbl in d2. test_filters( name => "--databases d2", - cmds => [$master_dsn, $slave1_dsn, qw(--no-check-slave), + cmds => [$source_dsn, $replica1_dsn, qw(--no-check-replica), qw(--databases d2)], res => [qw(d2.t1)], ); @@ -98,21 +98,21 @@ test_filters( # --database with --tables. test_filters( name => "--databases d1 --tables t2,t3", - cmds => [$master_dsn, $slave1_dsn, qw(--no-check-slave), + cmds => [$source_dsn, $replica1_dsn, qw(--no-check-replica), qw(--databases d1), "--tables", "t2,t3"], res => [qw(d1.t2 d1.t3)], ); # ############################################################################# -# Filters with --replicate and --sync-to-master. +# Filters with --replicate and --sync-to-source. # ############################################################################# # Checksum the filter tables. -$master_dbh->do("DROP DATABASE IF EXISTS percona"); -$sb->wait_for_slaves(); -diag(`$trunk/bin/pt-table-checksum $master_dsn -d d1,d2,d3 --chunk-size 100 --quiet --set-vars innodb_lock_wait_timeout=3 --max-load ''`); +$source_dbh->do("DROP DATABASE IF EXISTS percona"); +$sb->wait_for_replicas(); +diag(`$trunk/bin/pt-table-checksum $source_dsn -d d1,d2,d3 --chunk-size 100 --quiet --set-vars innodb_lock_wait_timeout=3 --max-load ''`); -my $rows = $master_dbh->selectall_arrayref("SELECT CONCAT(db, '.', tbl) FROM percona.checksums ORDER BY db, tbl"); +my $rows = $source_dbh->selectall_arrayref("SELECT CONCAT(db, '.', tbl) FROM percona.checksums ORDER BY db, tbl"); is_deeply( $rows, [ @@ -124,27 +124,27 @@ is_deeply( "Checksummed all tables" ) or diag(Dumper($rows)); -# Make all checksums on the slave different than the master +# Make all checksums on the replica different than the source # so that pt-table-sync would sync all the tables if there # were no filters. -$slave_dbh->do("UPDATE percona.checksums SET this_cnt=999 WHERE 1=1"); +$replica_dbh->do("UPDATE percona.checksums SET this_cnt=999 WHERE 1=1"); # Verify that that ^ is true. test_filters( - name => "All tables are different on the slave", - cmds => [$master_dsn, qw(--replicate percona.checksums)], + name => "All tables are different on the replica", + cmds => [$source_dsn, qw(--replicate percona.checksums)], res => [qw(d1.t1 d1.t2 d1.t3 d2.t1 percona.checksums)], ); -# Sync with --replicate, --sync-to-master, and some filters. -# --replicate and --sync-to-master have different code paths, +# Sync with --replicate, --sync-to-source, and some filters. +# --replicate and --sync-to-source have different code paths, # but the filter results should be the same. foreach my $args ( - [$master_dsn, qw(--replicate percona.checksums)], - [$slave1_dsn, qw(--replicate percona.checksums --sync-to-master)] + [$source_dsn, qw(--replicate percona.checksums)], + [$replica1_dsn, qw(--replicate percona.checksums --sync-to-source)] ) { - my $stm = $args->[-1] eq '--sync-to-master' ? ' --sync-to-master' : ''; + my $stm = $args->[-1] eq '--sync-to-source' ? ' --sync-to-source' : ''; test_filters( name => $stm . "--replicate --tables t1", @@ -172,18 +172,18 @@ foreach my $args ( # pt-table-sync --ignore-* options don't work with --replicate # https://bugs.launchpad.net/percona-toolkit/+bug/1002365 # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->load_file("master", "t/pt-table-sync/samples/simple-tbls.sql"); +$sb->wipe_clean($source_dbh); +$sb->load_file("source", "t/pt-table-sync/samples/simple-tbls.sql"); # Create a checksum diff in a table that we're going to ignore # when we sync. -$slave_dbh->do("INSERT INTO test.empty_it VALUES (null,11,11,'eleven')"); +$replica_dbh->do("INSERT INTO test.empty_it VALUES (null,11,11,'eleven')"); # Create the checksums. diag(`$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d test --quiet --quiet --set-vars innodb_lock_wait_timeout=3 --max-load ''`); # Make sure all the tables were checksummed. -$rows = $master_dbh->selectall_arrayref("SELECT DISTINCT db, tbl FROM percona.checksums ORDER BY db, tbl"); +$rows = $source_dbh->selectall_arrayref("SELECT DISTINCT db, tbl FROM percona.checksums ORDER BY db, tbl"); is_deeply( $rows, [ [qw(test empty_it) ], @@ -199,7 +199,7 @@ is_deeply( # Sync the checksummed tables, but ignore the table with the diff we created. $output = output( sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox", - qw(--print --sync-to-master --replicate percona.checksums), + qw(--print --sync-to-source --replicate percona.checksums), "--ignore-tables", "test.empty_it") }, stderr => 1, ); @@ -213,7 +213,7 @@ is( # Sync the checksummed tables, but ignore the database. $output = output( sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox", - qw(--print --sync-to-master --replicate percona.checksums), + qw(--print --sync-to-source --replicate percona.checksums), "--ignore-databases", "test") }, stderr => 1, ); @@ -224,10 +224,10 @@ is( "Database ignored, nothing to sync (bug 1002365)" ); -# The same should work for just --sync-to-master. +# The same should work for just --sync-to-source. $output = output( sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox", - qw(--print --sync-to-master), + qw(--print --sync-to-source), "--ignore-tables", "test.empty_it", "--ignore-databases", "percona") }, stderr => 1, @@ -236,12 +236,12 @@ $output = output( unlike( $output, qr/empty_it/, - "Table ignored, nothing to sync-to-master (bug 1002365)" + "Table ignored, nothing to sync-to-source (bug 1002365)" ); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/float_precision.t b/t/pt-table-sync/float_precision.t index e49a3e01..25d79734 100644 --- a/t/pt-table-sync/float_precision.t +++ b/t/pt-table-sync/float_precision.t @@ -19,32 +19,32 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } -my $master_dsn = $sb->dsn_for('master'); -my $slave1_dsn = $sb->dsn_for('slave1'); +my $source_dsn = $sb->dsn_for('source'); +my $replica1_dsn = $sb->dsn_for('replica1'); # ############################################################################# # Issue 410: mk-table-sync doesn't have --float-precision # ############################################################################# -$sb->create_dbs($master_dbh, ['test']); -$master_dbh->do('create table test.fl (id int not null primary key, f float(12,10), d double)'); -$master_dbh->do('insert into test.fl values (1, 1.0000012, 2.0000012)'); -$sb->wait_for_slaves(); -$slave_dbh->do('update test.fl set d = 2.0000013 where id = 1'); +$sb->create_dbs($source_dbh, ['test']); +$source_dbh->do('create table test.fl (id int not null primary key, f float(12,10), d double)'); +$source_dbh->do('insert into test.fl values (1, 1.0000012, 2.0000012)'); +$sb->wait_for_replicas(); +$replica_dbh->do('update test.fl set d = 2.0000013 where id = 1'); # The columns really are different at this point so we should # get a REPLACE without using --float-precision. -$output = `$trunk/bin/pt-table-sync --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=fl --print 2>&1`; +$output = `$trunk/bin/pt-table-sync --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=fl --print 2>&1`; $output = remove_traces($output); is( $output, @@ -56,7 +56,7 @@ is( # Now use --float-precision to roundoff the differing columns. # We have 2.0000012 # vs. 2.0000013, so if we round at 6 places, they should be the same. -$output = `$trunk/bin/pt-table-sync --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=fl --print --float-precision 6 2>&1`; +$output = `$trunk/bin/pt-table-sync --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=fl --print --float-precision 6 2>&1`; is( $output, '', @@ -68,19 +68,19 @@ is( # https://bugs.launchpad.net/percona-toolkit/+bug/1229861 # ############################################################################# -$sb->load_file('master', "t/pt-table-sync/samples/sync-float.sql"); -$slave_dbh->do("INSERT INTO sync_float_1229861.t (`c1`, `c2`, `c3`, `snrmin`, `snrmax`, `snravg`) VALUES (1,1,1,29.5,33.5,31.6)"); +$sb->load_file('source', "t/pt-table-sync/samples/sync-float.sql"); +$replica_dbh->do("INSERT INTO sync_float_1229861.t (`c1`, `c2`, `c3`, `snrmin`, `snrmax`, `snravg`) VALUES (1,1,1,29.5,33.5,31.6)"); $output = output(sub { pt_table_sync::main( - "$master_dsn,D=sync_float_1229861,t=t", - "$slave1_dsn", - qw(--no-check-slave --print --execute)) + "$source_dsn,D=sync_float_1229861,t=t", + "$replica1_dsn", + qw(--no-check-replica --print --execute)) }, stderr => 1, ); -my $rows = $slave_dbh->selectall_arrayref("SELECT * FROM sync_float_1229861.t"); +my $rows = $replica_dbh->selectall_arrayref("SELECT * FROM sync_float_1229861.t"); is_deeply( $rows, [], @@ -90,7 +90,7 @@ is_deeply( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); done_testing; diff --git a/t/pt-table-sync/force_index.t b/t/pt-table-sync/force_index.t index 44fe11ac..12513af4 100644 --- a/t/pt-table-sync/force_index.t +++ b/t/pt-table-sync/force_index.t @@ -18,40 +18,40 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 3; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ######################################################################## # Issue 8: Add --force-index parameter to mk-table-checksum and # mk-table-sync # ######################################################################## -$sb->load_file('master', 't/pt-table-sync/samples/issue_37.sql'); -$sb->use('master', '-e \'INSERT INTO test.issue_37 VALUES (5), (6), (7), (8), (9);\''); +$sb->load_file('source', 't/pt-table-sync/samples/issue_37.sql'); +$sb->use('source', '-e \'INSERT INTO test.issue_37 VALUES (5), (6), (7), (8), (9);\''); -$output = `PTDEBUG=1 $trunk/bin/pt-table-sync h=127.0.0.1,P=12345,u=msandbox,p=msandbox P=12346 -d test -t issue_37 --algorithms Chunk --chunk-size 3 --no-check-slave --no-check-triggers --print 2>&1 | grep 'src: '`; +$output = `PTDEBUG=1 $trunk/bin/pt-table-sync h=127.0.0.1,P=12345,u=msandbox,p=msandbox P=12346 -d test -t issue_37 --algorithms Chunk --chunk-size 3 --no-check-replica --no-check-triggers --print 2>&1 | grep 'src: '`; like($output, qr/FROM `test`\.`issue_37` FORCE INDEX \(`idx_a`\) WHERE/, 'Injects USE INDEX hint by default'); -$output = `PTDEBUG=1 $trunk/bin/pt-table-sync h=127.0.0.1,P=12345,u=msandbox,p=msandbox P=12346 -d test -t issue_37 --algorithms Chunk --chunk-size 3 --no-check-slave --no-check-triggers --no-index-hint --print 2>&1 | grep 'src: '`; +$output = `PTDEBUG=1 $trunk/bin/pt-table-sync h=127.0.0.1,P=12345,u=msandbox,p=msandbox P=12346 -d test -t issue_37 --algorithms Chunk --chunk-size 3 --no-check-replica --no-check-triggers --no-index-hint --print 2>&1 | grep 'src: '`; like($output, qr/FROM `test`\.`issue_37` WHERE/, 'No USE INDEX hint with --no-index-hint'); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/hex_blob.t b/t/pt-table-sync/hex_blob.t index 3342fdb0..84e2a921 100644 --- a/t/pt-table-sync/hex_blob.t +++ b/t/pt-table-sync/hex_blob.t @@ -17,10 +17,10 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); +my $dbh = $sb->get_dbh_for('source'); if ( !$dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; + plan skip_all => 'Cannot connect to sandbox source'; } else { plan tests => 3; @@ -30,7 +30,7 @@ my $output; my @args = (qw(-F /tmp/12345/my.sandbox.cnf --print), 'D=issue_641,t=lt', 'D=issue_641,t=rt'); -$sb->load_file('master', "t/lib/samples/issue_641.sql"); +$sb->load_file('source', "t/lib/samples/issue_641.sql"); # ############################################################################# # Issue 641: Make mk-table-sync use hex for binary/blob data diff --git a/t/pt-table-sync/instrumentaiton.t b/t/pt-table-sync/instrumentaiton.t index 93f2ddae..c432b9fb 100644 --- a/t/pt-table-sync/instrumentaiton.t +++ b/t/pt-table-sync/instrumentaiton.t @@ -17,21 +17,21 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 2; } my $output = ''; -my @args = (qw(--verbose --print --sync-to-master), 'h=127.1,P=12346,u=msandbox,p=msandbox'); +my @args = (qw(--verbose --print --sync-to-source), 'h=127.1,P=12346,u=msandbox,p=msandbox'); # ############################################################################# # Issue 377: Make mk-table-sync print start/end times @@ -51,7 +51,7 @@ like( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_1052.t b/t/pt-table-sync/issue_1052.t index 44aa206c..ad4c862d 100644 --- a/t/pt-table-sync/issue_1052.t +++ b/t/pt-table-sync/issue_1052.t @@ -17,21 +17,21 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 2; } my $output; -my @args = ('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', +my @args = ('--sync-to-source', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(-d issue_1052 --print)); # ############################################################################# @@ -39,12 +39,12 @@ my @args = ('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', # ############################################################################# # Re-using this table for this issue. It has 100 pk rows. -$sb->load_file('master', 't/pt-table-sync/samples/issue_1052.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/issue_1052.sql'); wait_until( sub { my $row; eval { - $row = $slave_dbh->selectrow_hashref("select * from issue_1052.t"); + $row = $replica_dbh->selectrow_hashref("select * from issue_1052.t"); }; return 1 if $row; }, @@ -65,6 +65,6 @@ is( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_1065.t b/t/pt-table-sync/issue_1065.t index 166e0495..e951842d 100644 --- a/t/pt-table-sync/issue_1065.t +++ b/t/pt-table-sync/issue_1065.t @@ -17,33 +17,33 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave1_dbh = $sb->get_dbh_for('slave1'); -my $slave2_dbh = $sb->get_dbh_for('slave2'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica1_dbh = $sb->get_dbh_for('replica1'); +my $replica2_dbh = $sb->get_dbh_for('replica2'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave1'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica1'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave2'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica2'; } else { plan tests => 2; } my $output; -my @args = ('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', +my @args = ('--sync-to-source', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(-t test.it1 --print --execute --no-check-triggers)); # ############################################################################# # Issue 1065: mk-table-sync --algorithm seems to be case-sensitive # ############################################################################# -$sb->load_file('master', "t/pt-table-sync/samples/simple-tbls.sql"); +$sb->load_file('source', "t/pt-table-sync/samples/simple-tbls.sql"); -$slave1_dbh->do("delete from test.it1 where id=1 limit 1"); +$replica1_dbh->do("delete from test.it1 where id=1 limit 1"); $output = output( sub { pt_table_sync::main(@args, qw(--algo chunk)) }, @@ -57,6 +57,6 @@ like( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_218.t b/t/pt-table-sync/issue_218.t index dd6b9132..b52df1a4 100644 --- a/t/pt-table-sync/issue_218.t +++ b/t/pt-table-sync/issue_218.t @@ -18,35 +18,35 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 2; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); # ############################################################################# # Issue 218: Two NULL column values don't compare properly w/ Stream/GroupBy # ############################################################################# -$sb->create_dbs($master_dbh, [qw(issue218)]); -$sb->use('master', '-e "CREATE TABLE issue218.t1 (i INT)"'); -$sb->use('master', '-e "INSERT INTO issue218.t1 VALUES (NULL)"'); -qx($trunk/bin/pt-table-sync --no-check-slave --print --database issue218 h=127.1,P=12345,u=msandbox,p=msandbox P=12346); +$sb->create_dbs($source_dbh, [qw(issue218)]); +$sb->use('source', '-e "CREATE TABLE issue218.t1 (i INT)"'); +$sb->use('source', '-e "INSERT INTO issue218.t1 VALUES (NULL)"'); +qx($trunk/bin/pt-table-sync --no-check-replica --print --database issue218 h=127.1,P=12345,u=msandbox,p=msandbox P=12346); ok(!$?, 'Issue 218: NULL values compare as equal'); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_22.t b/t/pt-table-sync/issue_22.t index b68ef8fe..422c3347 100644 --- a/t/pt-table-sync/issue_22.t +++ b/t/pt-table-sync/issue_22.t @@ -18,25 +18,25 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); +my $source_dbh = $sb->get_dbh_for('source'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } else { plan tests => 4; } -$sb->wipe_clean($master_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ############################################################################# # Issue 22: mk-table-sync fails with uninitialized value at line 2330 # ############################################################################# -$sb->use('master', "-D test < $trunk/t/pt-table-sync/samples/issue_22.sql"); -$sb->use('master', "-D test -e \"SET SQL_LOG_BIN=0; INSERT INTO test.messages VALUES (1,2,'author','2008-09-12 00:00:00','1','0','headers','msg');\""); -$sb->create_dbs($master_dbh, [qw(test2)]); -$sb->use('master', "-D test2 < $trunk/t/pt-table-sync/samples/issue_22.sql"); +$sb->use('source', "-D test < $trunk/t/pt-table-sync/samples/issue_22.sql"); +$sb->use('source', "-D test -e \"SET SQL_LOG_BIN=0; INSERT INTO test.messages VALUES (1,2,'author','2008-09-12 00:00:00','1','0','headers','msg');\""); +$sb->create_dbs($source_dbh, [qw(test2)]); +$sb->use('source', "-D test2 < $trunk/t/pt-table-sync/samples/issue_22.sql"); $output = 'foo'; # To make explicitly sure that the following command # returns blank because there are no rows and not just that @@ -44,7 +44,7 @@ $output = 'foo'; # To make explicitly sure that the following command $output = `/tmp/12345/use -D test2 -e 'SELECT * FROM messages'`; ok(!$output, 'test2.messages is empty before sync (issue 22)'); -$output = `$trunk/bin/pt-table-sync --no-check-slave --execute u=msandbox,p=msandbox,P=12345,h=127.1,D=test,t=messages u=msandbox,p=msandbox,P=12345,h=127.1,D=test2,t=messages 2>&1`; +$output = `$trunk/bin/pt-table-sync --no-check-replica --execute u=msandbox,p=msandbox,P=12345,h=127.1,D=test,t=messages u=msandbox,p=msandbox,P=12345,h=127.1,D=test2,t=messages 2>&1`; ok(!$output, 'Synced test.messages to test2.messages on same host (issue 22)'); $output = `/tmp/12345/use -D test -e 'SELECT * FROM messages'`; @@ -54,6 +54,6 @@ is($output, $output2, 'test2.messages matches test.messages (issue 22)'); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_262.t b/t/pt-table-sync/issue_262.t index a19e9646..aaf56a90 100644 --- a/t/pt-table-sync/issue_262.t +++ b/t/pt-table-sync/issue_262.t @@ -18,31 +18,31 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 2; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ############################################################################# # Issue 262 # ############################################################################# -$sb->create_dbs($master_dbh, ['foo']); -$sb->use('master', '-e "create table foo.t1 (i int)"'); -$sb->use('master', '-e "SET SQL_LOG_BIN=0; insert into foo.t1 values (1)"'); -$sb->use('slave1', '-e "truncate table foo.t1"'); -$output = `$trunk/bin/pt-table-sync --no-check-slave --print h=127.1,P=12345,u=msandbox,p=msandbox -d mysql,foo h=127.1,P=12346 2>&1`; +$sb->create_dbs($source_dbh, ['foo']); +$sb->use('source', '-e "create table foo.t1 (i int)"'); +$sb->use('source', '-e "SET SQL_LOG_BIN=0; insert into foo.t1 values (1)"'); +$sb->use('replica1', '-e "truncate table foo.t1"'); +$output = `$trunk/bin/pt-table-sync --no-check-replica --print h=127.1,P=12345,u=msandbox,p=msandbox -d mysql,foo h=127.1,P=12346 2>&1`; like( $output, qr/INSERT INTO `foo`\.`t1`\(`i`\) VALUES \('1'\)/, @@ -52,7 +52,7 @@ like( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_408.t b/t/pt-table-sync/issue_408.t index 0dff57e5..9fb79b05 100644 --- a/t/pt-table-sync/issue_408.t +++ b/t/pt-table-sync/issue_408.t @@ -18,26 +18,26 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); +my $source_dbh = $sb->get_dbh_for('source'); -diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`); -my $dbh2 = $sb->get_dbh_for('master1'); +diag(`$trunk/sandbox/start-sandbox source 12348 >/dev/null`); +my $dbh2 = $sb->get_dbh_for('source1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } elsif ( !$dbh2 ) { - plan skip_all => 'Cannot connect to second sandbox master'; + plan skip_all => 'Cannot connect to second sandbox source'; } else { plan tests => 2; } -$sb->wipe_clean($master_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # Need at least 1 table so the db will be used. -$master_dbh->do('create table test.foo (i int)'); +$source_dbh->do('create table test.foo (i int)'); # ############################################################################# # Issue 408: DBD::mysql::st execute failed: Unknown database 'd1' at @@ -54,7 +54,7 @@ like( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); diag(`/tmp/12348/stop >/dev/null`); diag(`rm -rf /tmp/12348 >/dev/null`); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); diff --git a/t/pt-table-sync/issue_560.t b/t/pt-table-sync/issue_560.t index 48b920b6..364dab00 100644 --- a/t/pt-table-sync/issue_560.t +++ b/t/pt-table-sync/issue_560.t @@ -18,14 +18,14 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 3; @@ -34,11 +34,11 @@ else { # ############################################################################# # Issue 560: mk-table-sync generates impossible WHERE # ############################################################################# -$sb->load_file("master", "t/pt-table-sync/samples/issue_560.sql"); +$sb->load_file("source", "t/pt-table-sync/samples/issue_560.sql"); -# Make slave differ. -$slave_dbh->do('UPDATE issue_560.buddy_list SET buddy_id=0 WHERE player_id IN (333,334)'); -$slave_dbh->do('UPDATE issue_560.buddy_list SET buddy_id=0 WHERE player_id=486'); +# Make replica differ. +$replica_dbh->do('UPDATE issue_560.buddy_list SET buddy_id=0 WHERE player_id IN (333,334)'); +$replica_dbh->do('UPDATE issue_560.buddy_list SET buddy_id=0 WHERE player_id=486'); $output = `$trunk/bin/pt-table-checksum --replicate issue_560.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_560 --chunk-size 50 --set-vars innodb_lock_wait_timeout=3`; @@ -49,7 +49,7 @@ is( ); $output = output( - sub { pt_table_sync::main('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(-d issue_560 --print -v -v --chunk-size 50 --replicate issue_560.checksum)) }, + sub { pt_table_sync::main('--sync-to-source', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(-d issue_560 --print -v -v --chunk-size 50 --replicate issue_560.checksum)) }, trf => \&remove_traces, ); $output =~ s/\d\d:\d\d:\d\d/00:00:00/g; @@ -65,7 +65,7 @@ ok( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_616.t b/t/pt-table-sync/issue_616.t index 0651b56f..fee68613 100644 --- a/t/pt-table-sync/issue_616.t +++ b/t/pt-table-sync/issue_616.t @@ -18,14 +18,14 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 3; @@ -35,42 +35,42 @@ else { # Issue 616: mk-table-sync inserts NULL values instead of correct values # ############################################################################# -$sb->load_file('master', "t/lib/samples/issue_616.sql"); +$sb->load_file('source', "t/lib/samples/issue_616.sql"); output( sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox", - qw(--sync-to-master --databases issue_616 --execute)); + qw(--sync-to-source --databases issue_616 --execute)); }, ); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); my $ok_r = [ - [ 1, 'from master' ], - [ 11, 'from master' ], - [ 21, 'from master' ], - [ 31, 'from master' ], - [ 41, 'from master' ], - [ 51, 'from master' ], + [ 1, 'from source' ], + [ 11, 'from source' ], + [ 21, 'from source' ], + [ 31, 'from source' ], + [ 41, 'from source' ], + [ 51, 'from source' ], ]; -my $r = $master_dbh->selectall_arrayref('SELECT * FROM issue_616.t ORDER BY id'); +my $r = $source_dbh->selectall_arrayref('SELECT * FROM issue_616.t ORDER BY id'); is_deeply( $r, $ok_r, - 'Issue 616 synced on master' + 'Issue 616 synced on source' ); -$r = $slave_dbh->selectall_arrayref('SELECT * FROM issue_616.t ORDER BY id'); +$r = $replica_dbh->selectall_arrayref('SELECT * FROM issue_616.t ORDER BY id'); is_deeply( $r, $ok_r, - 'Issue 616 synced on slave' + 'Issue 616 synced on replica' ); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_627.t b/t/pt-table-sync/issue_627.t index 411ba6eb..4a352845 100644 --- a/t/pt-table-sync/issue_627.t +++ b/t/pt-table-sync/issue_627.t @@ -18,22 +18,22 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 2; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ############################################################################# # Issue 627: Results for mk-table-sync --replicate may be incorrect @@ -44,15 +44,15 @@ sleep 1; # Make the table differ. # (10, '2009-09-03 14:18:00', 'k'), -> (10, '2009-09-03 14:18:00', 'z'), # (100, '2009-09-06 15:01:23', 'cv'); -> (100, '2009-09-06 15:01:23', 'zz'); -$slave_dbh->do('UPDATE issue_375.t SET foo="z" WHERE id=10'); -$slave_dbh->do('UPDATE issue_375.t SET foo="zz" WHERE id=100'); +$replica_dbh->do('UPDATE issue_375.t SET foo="z" WHERE id=10'); +$replica_dbh->do('UPDATE issue_375.t SET foo="zz" WHERE id=100'); # Checksum and replicate. diag(`$trunk/bin/pt-table-checksum --create-replicate-table --replicate issue_375.checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 -t t --set-vars innodb_lock_wait_timeout=3 > /dev/null`); # And now sync using the replicated checksum results/differences. $output = output( - sub { pt_table_sync::main('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(--replicate issue_375.checksum --print)) }, + sub { pt_table_sync::main('--sync-to-source', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(--replicate issue_375.checksum --print)) }, trf => \&remove_traces, ); is( @@ -69,7 +69,7 @@ REPLACE INTO `issue_375`.`t`(`id`, `updated_at`, `foo`) VALUES ('100', '2009-09- # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_631.t b/t/pt-table-sync/issue_631.t index a0beec98..318f13ac 100644 --- a/t/pt-table-sync/issue_631.t +++ b/t/pt-table-sync/issue_631.t @@ -18,17 +18,17 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); +my $source_dbh = $sb->get_dbh_for('source'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } else { plan tests => 3; } -$sb->wipe_clean($master_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ############################################################################# # Issue 631: mk-table-sync GroupBy and Stream fail @@ -66,6 +66,6 @@ ok( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_634.t b/t/pt-table-sync/issue_634.t index 1fdd00fd..fdf5ebf7 100644 --- a/t/pt-table-sync/issue_634.t +++ b/t/pt-table-sync/issue_634.t @@ -18,14 +18,14 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 4; @@ -34,16 +34,16 @@ else { # ############################################################################# # Issue 634: Cannot nibble table because MySQL chose no index # ############################################################################# -$sb->load_file('master', "t/pt-table-sync/samples/issue_634.sql"); -$slave_dbh->do('insert into issue_634.t values (1)'); +$sb->load_file('source', "t/pt-table-sync/samples/issue_634.sql"); +$replica_dbh->do('insert into issue_634.t values (1)'); $output = output( sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox", - qw(--sync-to-master -d issue_634 --print --execute --algorithms Nibble)) + qw(--sync-to-source -d issue_634 --print --execute --algorithms Nibble)) }, stderr => 1, ); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); like( $output, @@ -58,7 +58,7 @@ unlike( ); is_deeply( - $slave_dbh->selectall_arrayref('select * from issue_634.t'), + $replica_dbh->selectall_arrayref('select * from issue_634.t'), [], '1-row table was synced (issue 634)' ); @@ -66,6 +66,6 @@ is_deeply( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_644.t b/t/pt-table-sync/issue_644.t index a3cd23b2..82a4a11f 100644 --- a/t/pt-table-sync/issue_644.t +++ b/t/pt-table-sync/issue_644.t @@ -18,29 +18,29 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 3; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ############################################################################# # Issue 644: Another possible infinite loop with mk-table-sync Nibble # ############################################################################# diag(`/tmp/12345/use < $trunk/t/pt-table-sync/samples/issue_644.sql`); sleep 1; -$output = `$trunk/bin/pt-table-sync --algo Nibble --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox -d issue_644 --print --chunk-size 2 -v`; +$output = `$trunk/bin/pt-table-sync --algo Nibble --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox -d issue_644 --print --chunk-size 2 -v`; $output =~ s/\d\d:\d\d:\d\d/00:00:00/g; ok( no_diff( @@ -52,7 +52,7 @@ ok( ); # Thanks to issue 568, this table can be chunked on the char col. -$output = `$trunk/bin/pt-table-sync --algo Chunk --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox -d issue_644 --print --chunk-size 2 -v`; +$output = `$trunk/bin/pt-table-sync --algo Chunk --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox -d issue_644 --print --chunk-size 2 -v`; $output =~ s/\d\d:\d\d:\d\d/00:00:00/g; ok( no_diff( @@ -66,7 +66,7 @@ ok( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_804.t b/t/pt-table-sync/issue_804.t index d9dc3d8e..96a27b63 100644 --- a/t/pt-table-sync/issue_804.t +++ b/t/pt-table-sync/issue_804.t @@ -18,27 +18,27 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 2; } -$sb->load_file('master', 't/lib/samples/issue_804.sql'); +$sb->load_file('source', 't/lib/samples/issue_804.sql'); # ############################################################################# # Issue 804: mk-table-sync: can't nibble because index name isn't lower case? # ############################################################################# -$master_dbh->do('set sql_log_bin=0'); -$master_dbh->do('insert into issue_804.t values (999,999)'); -$output = `$trunk/bin/pt-table-sync --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox -d issue_804 --print --algorithms Nibble 2>&1`; +$source_dbh->do('set sql_log_bin=0'); +$source_dbh->do('insert into issue_804.t values (999,999)'); +$output = `$trunk/bin/pt-table-sync --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox -d issue_804 --print --algorithms Nibble 2>&1`; $output = remove_traces($output); is( $output, @@ -50,7 +50,7 @@ is( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_920.t b/t/pt-table-sync/issue_920.t index df0e8ed3..9edb072e 100644 --- a/t/pt-table-sync/issue_920.t +++ b/t/pt-table-sync/issue_920.t @@ -17,12 +17,12 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); +my $dbh = $sb->get_dbh_for('source'); plan skip_all => 'Pending solution: waiting for the PT-2338 fix'; if ( !$dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; + plan skip_all => 'Cannot connect to sandbox source'; } else { plan tests => 4; @@ -33,7 +33,7 @@ else { # conflict when using Chunk or Nibble. # ############################################################################# $sb->wipe_clean($dbh); -$sb->load_file('master', 't/pt-table-sync/samples/issue_920.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/issue_920.sql'); pt_table_sync::main(qw(--execute -F /tmp/12345/my.sandbox.cnf), 'D=issue_920,t=PK_UK_test', 'D=issue_920,t=PK_UK_test_2'); diff --git a/t/pt-table-sync/issue_96.t b/t/pt-table-sync/issue_96.t index 8786f8d0..0216069e 100644 --- a/t/pt-table-sync/issue_96.t +++ b/t/pt-table-sync/issue_96.t @@ -18,17 +18,17 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); +my $source_dbh = $sb->get_dbh_for('source'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } else { plan tests => 2; } -$sb->wipe_clean($master_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ############################################################################# # Issue 96: mk-table-sync: Nibbler infinite loop @@ -49,6 +49,6 @@ is( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/issue_965.t b/t/pt-table-sync/issue_965.t index e387e2fa..9427f72d 100644 --- a/t/pt-table-sync/issue_965.t +++ b/t/pt-table-sync/issue_965.t @@ -17,10 +17,10 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); +my $dbh = $sb->get_dbh_for('source'); if ( !$dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; + plan skip_all => 'Cannot connect to sandbox source'; } else { plan tests => 3; @@ -32,7 +32,7 @@ my $output; # Issue 965: mk-table-sync --trim can cause impossible WHERE, invalid SQL # ############################################################################# $sb->wipe_clean($dbh); -$sb->load_file('master', 't/pt-table-sync/samples/issue_965.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/issue_965.sql'); $output = output( sub { diff --git a/t/pt-table-sync/issue_996.t b/t/pt-table-sync/issue_996.t index de8ba6f4..6aa73b81 100644 --- a/t/pt-table-sync/issue_996.t +++ b/t/pt-table-sync/issue_996.t @@ -17,14 +17,14 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } elsif ( $sandbox_version ge '8.0' ) { plan skip_all => 'Test fails due to https://bugs.mysql.com/bug.php?id=115017'; @@ -34,7 +34,7 @@ else { } my $output; -my @args = ('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', +my @args = ('--sync-to-source', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(-d issue_375 --replicate issue_375.checksums --print)); my $pt_table_checksum = "$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox -d issue_375 --chunk-size 20 --chunk-size-limit 0 --set-vars innodb_lock_wait_timeout=3"; @@ -43,24 +43,24 @@ my $pt_table_checksum = "$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox # ############################################################################# # Re-using this table for this issue. It has 100 pk rows. -$sb->load_file('master', 't/pt-table-sync/samples/issue_375.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/issue_375.sql'); wait_until( sub { my $row; eval { - $row = $slave_dbh->selectrow_hashref("select * from issue_375.t where id=35"); + $row = $replica_dbh->selectrow_hashref("select * from issue_375.t where id=35"); }; return 1 if $row && $row->{foo} eq 'ai'; }, ); # Make the tables differ. These diff rows are all in chunk 1. -$slave_dbh->do("update issue_375.t set foo='foo' where id in (21, 25, 35)"); +$replica_dbh->do("update issue_375.t set foo='foo' where id in (21, 25, 35)"); wait_until( sub { my $row; eval { - $row = $slave_dbh->selectrow_hashref("select * from issue_375.t where id=35"); + $row = $replica_dbh->selectrow_hashref("select * from issue_375.t where id=35"); }; return 1 if $row && $row->{foo} eq 'foo'; }, @@ -107,6 +107,6 @@ diag(`rm -rf $file >/dev/null`); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/lock_and_rename.t b/t/pt-table-sync/lock_and_rename.t index 322964c6..8304c7da 100644 --- a/t/pt-table-sync/lock_and_rename.t +++ b/t/pt-table-sync/lock_and_rename.t @@ -18,17 +18,17 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( VersionParser->new($master_dbh) < '5.5' ) { +if ( VersionParser->new($source_dbh) < '5.5' ) { plan skip_all => "This functionality doesn't work correctly on MySQLs earlier than 5.5"; } -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 3; } @@ -36,8 +36,8 @@ elsif ( !$slave_dbh ) { # ############################################################################# # Issue 363: lock and rename. # ############################################################################# -$sb->create_dbs($master_dbh, [qw(test)]); -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->create_dbs($source_dbh, [qw(test)]); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); $output = `$trunk/bin/pt-table-sync --lock-and-rename h=127.1,P=12345 P=12346 2>&1`; like($output, qr/requires exactly two/, @@ -56,6 +56,6 @@ like($output, qr/COMMENT='test1'/, '--lock-and-rename worked'); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/lock_level.t b/t/pt-table-sync/lock_level.t index 8aa0eae7..74659f48 100644 --- a/t/pt-table-sync/lock_level.t +++ b/t/pt-table-sync/lock_level.t @@ -18,27 +18,27 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 2; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); # ############################################################################# # Issue 86: mk-table-sync: lock level 3 # ############################################################################# -$output = `$trunk/bin/pt-table-sync --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=t --print --lock 3 2>&1`; +$output = `$trunk/bin/pt-table-sync --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox,D=test,t=t --print --lock 3 2>&1`; unlike( $output, qr/Failed to lock server/, @@ -48,7 +48,7 @@ unlike( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/master_master.t b/t/pt-table-sync/master_master.t index 39001ef5..860a6c93 100644 --- a/t/pt-table-sync/master_master.t +++ b/t/pt-table-sync/master_master.t @@ -21,40 +21,40 @@ my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); plan tests => 4; # ############################################################################# -# Ensure that syncing master-master works OK +# Ensure that syncing source-source works OK # ############################################################################# # Start up 12348 <-> 12349 -diag('Starting master-master servers...'); -#diag(`$trunk/sandbox/start-sandbox master-master 12348 12349 >/dev/null`); -diag(`$trunk/sandbox/start-sandbox master-master 12348 12349`); -my $master1_dbh = $sb->get_dbh_for('master1'); -my $master2_dbh = $sb->get_dbh_for('master2'); +diag('Starting source-source servers...'); +#diag(`$trunk/sandbox/start-sandbox source-source 12348 12349 >/dev/null`); +diag(`$trunk/sandbox/start-sandbox source-source 12348 12349`); +my $source1_dbh = $sb->get_dbh_for('source1'); +my $source2_dbh = $sb->get_dbh_for('source2'); -# Load some tables and data (on both, since they're master-master). -$master1_dbh->do("CREATE DATABASE test"); -$sb->load_file("master1", "t/pt-table-sync/samples/before.sql"); -$sb->wait_for_slaves(); -$sb->wait_for_slaves( - master => 'master1', - slave => 'master2', +# Load some tables and data (on both, since they're source-source). +$source1_dbh->do("CREATE DATABASE test"); +$sb->load_file("source1", "t/pt-table-sync/samples/before.sql"); +$sb->wait_for_replicas(); +$sb->wait_for_replicas( + source => 'source1', + replica => 'source2', ); -# Make master2 different from master1. So master2 has the _correct_ data, -# and the sync below will make master1 have that data too. -$master2_dbh->do("set sql_log_bin=0"); -$master2_dbh->do("update test.test1 set b='mm' where a=1"); -$master2_dbh->do("set sql_log_bin=1"); +# Make source2 different from source1. So source2 has the _correct_ data, +# and the sync below will make source1 have that data too. +$source2_dbh->do("set sql_log_bin=0"); +$source2_dbh->do("update test.test1 set b='mm' where a=1"); +$source2_dbh->do("set sql_log_bin=1"); -# This will make master1's data match the changed, correcct data on master2 -# (that is _not_ a typo). The sync direction is therefore master2 -> master1 -# because, given the command below, the given host master1 and with -# --sync-to-master that makes master2 "the" master with the correct data. +# This will make source1's data match the changed, correcct data on source2 +# (that is _not_ a typo). The sync direction is therefore source2 -> source1 +# because, given the command below, the given host source1 and with +# --sync-to-source that makes source2 "the" source with the correct data. my $exit_status = 0; my $output = output( sub { $exit_status = pt_table_sync::main( - qw(--no-check-slave --sync-to-master --print --execute), + qw(--no-check-replica --sync-to-source --print --execute), "h=127.0.0.1,P=12348,u=msandbox,p=msandbox,D=test,t=test1") }, ); @@ -75,15 +75,15 @@ like( ); -PerconaTest::wait_for_table($master1_dbh, "test.test1", "a=1 and b='mm'"); -my $rows = $master1_dbh->selectall_arrayref("SELECT * FROM test.test1"); +PerconaTest::wait_for_table($source1_dbh, "test.test1", "a=1 and b='mm'"); +my $rows = $source1_dbh->selectall_arrayref("SELECT * FROM test.test1"); is_deeply( $rows, [ [1, 'mm'], [2, 'ca'] ], - "Diff row synced on master1" + "Diff row synced on source1" ); -diag('Stopping master-master servers...'); +diag('Stopping source-source servers...'); diag(`$trunk/sandbox/stop-sandbox 12348 12349 >/dev/null`); # ############################################################################# diff --git a/t/pt-table-sync/pt-1194.t b/t/pt-table-sync/pt-1194.t index 6e49b201..22044fe8 100644 --- a/t/pt-table-sync/pt-1194.t +++ b/t/pt-table-sync/pt-1194.t @@ -17,19 +17,19 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave1_dbh = $sb->get_dbh_for('slave1'); -my $slave2_dbh = $sb->get_dbh_for('slave2'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica1_dbh = $sb->get_dbh_for('replica1'); +my $replica2_dbh = $sb->get_dbh_for('replica2'); my $have_ncat = `which ncat 2>/dev/null`; -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave1'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica1'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave2'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica2'; } elsif (!$have_ncat) { plan skip_all => 'ncat, required for this test, is not installed or not in PATH'; @@ -38,8 +38,8 @@ else { plan tests => 3; } -$sb->load_file('master', "t/pt-table-sync/samples/pt-1205.sql"); -$sb->wait_for_slaves(); +$sb->load_file('source', "t/pt-table-sync/samples/pt-1205.sql"); +$sb->wait_for_replicas(); # Setting up tunnels my $pid1 = fork(); @@ -65,42 +65,42 @@ my $ms = new MasterSlave( DSNParser=>$dp, Quoter=>$q, ); -my $ss = $ms->get_slave_status($slave1_dbh); +my $ss = $ms->get_replica_status($replica1_dbh); -$slave1_dbh->do('STOP SLAVE'); -$slave1_dbh->do("CHANGE MASTER TO MASTER_PORT=3333, MASTER_LOG_POS=$ss->{exec_master_log_pos}"); -$slave1_dbh->do('START SLAVE'); +$replica1_dbh->do("STOP ${replica_name}"); +$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_PORT=3333, ${source_name}_LOG_POS=" . $ss->{"exec_${source_name}_log_pos"}); +$replica1_dbh->do("START ${replica_name}"); -my $output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=3334,u=msandbox,p=msandbox --database=test --table=t1 --sync-to-master --execute --verbose 2>&1`; +my $output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=3334,u=msandbox,p=msandbox --database=test --table=t1 --sync-to-source --execute --verbose 2>&1`; unlike( $output, - qr/The slave is connected to \d+ but the master's port is/, + qr/The replica is connected to \d+ but the source's port is/, 'No error for redirected replica' ) or diag($output); kill -1, getpgrp($pid1); kill -1, getpgrp($pid2); -$slave1_dbh->do('STOP SLAVE'); -$ss = $ms->get_slave_status($slave1_dbh); -$slave1_dbh->do("CHANGE MASTER TO MASTER_PORT=12347, MASTER_LOG_POS=$ss->{exec_master_log_pos}"); -$slave1_dbh->do('START SLAVE SQL_THREAD'); +$replica1_dbh->do("STOP ${replica_name}"); +$ss = $ms->get_replica_status($replica1_dbh); +$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_PORT=12347, ${source_name}_LOG_POS=" . $ss->{"exec_${source_name}_log_pos"}); +$replica1_dbh->do("START ${replica_name} SQL_THREAD"); -$output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=12346,u=msandbox,p=msandbox --database=test --table=t1 --sync-to-master --execute --verbose 2>&1`; +$output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=12346,u=msandbox,p=msandbox --database=test --table=t1 --sync-to-source --execute --verbose 2>&1`; like( $output, - qr/The server specified as a master has no connected slaves/, - 'Error printed for the wrong master' + qr/The server specified as a source has no connected replicas/, + 'Error printed for the wrong source' ) or diag($output); -$slave1_dbh->do('STOP SLAVE'); -$slave1_dbh->do("CHANGE MASTER TO MASTER_PORT=12345, MASTER_LOG_POS=$ss->{exec_master_log_pos}"); -$slave1_dbh->do('START SLAVE'); +$replica1_dbh->do("STOP ${replica_name}"); +$replica1_dbh->do("CHANGE ${source_change} TO ${source_name}_PORT=12345, ${source_name}_LOG_POS=" . $ss->{"exec_${source_name}_log_pos"}); +$replica1_dbh->do("START ${replica_name}"); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/pt-1205.t b/t/pt-table-sync/pt-1205.t index 0bd2b75a..db1da46d 100644 --- a/t/pt-table-sync/pt-1205.t +++ b/t/pt-table-sync/pt-1205.t @@ -17,34 +17,34 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave1_dbh = $sb->get_dbh_for('slave1'); -my $slave2_dbh = $sb->get_dbh_for('slave2'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica1_dbh = $sb->get_dbh_for('replica1'); +my $replica2_dbh = $sb->get_dbh_for('replica2'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave1'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica1'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave2'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica2'; } else { plan tests => 3; } -$sb->load_file('master', "t/pt-table-sync/samples/pt-1205.sql"); +$sb->load_file('source', "t/pt-table-sync/samples/pt-1205.sql"); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); -$slave1_dbh->do("DELETE FROM test.t1 LIMIT 3"); +$replica1_dbh->do("DELETE FROM test.t1 LIMIT 3"); # Save original PTDEBUG env because we modify it below. my $dbg = $ENV{PTDEBUG}; $ENV{PTDEBUG} = 1; -my $output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=t1,A=utf8 --sync-to-master --execute --verbose --function=MD5 2>&1`; +my $output = `$trunk/bin/pt-table-sync h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=t1,A=utf8 --sync-to-source --execute --verbose --function=MD5 2>&1`; unlike( $output, @@ -65,6 +65,6 @@ $ENV{PTDEBUG} = $dbg || 0; # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/pt-1256.t b/t/pt-table-sync/pt-1256.t index b65114c4..25817eba 100644 --- a/t/pt-table-sync/pt-1256.t +++ b/t/pt-table-sync/pt-1256.t @@ -23,18 +23,18 @@ require VersionParser; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave1_dbh = $sb->get_dbh_for('slave1'); -my $slave2_dbh = $sb->get_dbh_for('slave2'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica1_dbh = $sb->get_dbh_for('replica1'); +my $replica2_dbh = $sb->get_dbh_for('replica2'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave1'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica1'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave2'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica2'; } else { plan tests => 5; @@ -42,25 +42,25 @@ else { my ($output, $status); -my @args = ('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', +my @args = ('--sync-to-source', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(-t test.t1 --print --execute --charset utf8)); # use lib/samples dir since the main change is in DSNParser -$sb->load_file('master', "t/lib/samples/charset.sql"); +$sb->load_file('source', "t/lib/samples/charset.sql"); my $put = encode('UTF-8','абвгд'); my $want = 'абвгд'; my $row; -$master_dbh->do("SET NAMES 'utf8'"); -$slave1_dbh->do("SET NAMES 'utf8'"); -$slave1_dbh->do("SET NAMES 'utf8'"); +$source_dbh->do("SET NAMES 'utf8'"); +$replica1_dbh->do("SET NAMES 'utf8'"); +$replica1_dbh->do("SET NAMES 'utf8'"); -$master_dbh->do("INSERT INTO test.t1 VALUES (NULL, '$put')"); -$sb->wait_for_slaves(); +$source_dbh->do("INSERT INTO test.t1 VALUES (NULL, '$put')"); +$sb->wait_for_replicas(); -$slave1_dbh->do("DELETE FROM test.t1 WHERE id=1 LIMIT 1"); -$slave1_dbh->do("FLUSH TABLES"); +$replica1_dbh->do("DELETE FROM test.t1 WHERE id=1 LIMIT 1"); +$replica1_dbh->do("FLUSH TABLES"); # 1 @@ -75,12 +75,12 @@ like( ); SKIP: { - my $vp = VersionParser->new($master_dbh); + my $vp = VersionParser->new($source_dbh); if ($vp->cmp('8.0') > -1 && $vp->cmp('8.0.14') < 0 && $vp->flavor() !~ m/maria/i) { skip "Skipping in MySQL 8.0.4-rc - 8.0.13 since there is an error in the server itself", 3; } # 2 - $row = $slave1_dbh->selectrow_hashref("SELECT f2 FROM test.t1 WHERE id = 1"); + $row = $replica1_dbh->selectrow_hashref("SELECT f2 FROM test.t1 WHERE id = 1"); is( $row->{f2}, $want, @@ -93,7 +93,7 @@ SKIP: { like($output, qr/COMMENT='test1'/, '--lock-and-rename worked'); #4 - $row = $slave1_dbh->selectrow_hashref("SELECT f2 FROM test.t2 WHERE id = 1"); + $row = $replica1_dbh->selectrow_hashref("SELECT f2 FROM test.t2 WHERE id = 1"); is( $row->{f2}, $want, @@ -103,6 +103,6 @@ SKIP: { # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/pt-2016.t b/t/pt-table-sync/pt-2016.t index 49d4a1df..667688a8 100644 --- a/t/pt-table-sync/pt-2016.t +++ b/t/pt-table-sync/pt-2016.t @@ -22,18 +22,18 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave1_dbh = $sb->get_dbh_for('slave1'); -my $slave2_dbh = $sb->get_dbh_for('slave2'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica1_dbh = $sb->get_dbh_for('replica1'); +my $replica2_dbh = $sb->get_dbh_for('replica2'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave1'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica1'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave2'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica2'; } else { plan tests => 3; @@ -41,16 +41,16 @@ else { my ($output, $status); -my @args = ('h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=test2', '--sync-to-master', +my @args = ('h=127.0.0.1,P=12346,u=msandbox,p=msandbox,D=test,t=test2', '--sync-to-source', '--chunk-size=1', '--hex-blob', '--execute'); # use lib/samples dir since the main change is in DSNParser -$sb->load_file('master', "t/pt-table-sync/samples/pt-2016.sql"); +$sb->load_file('source', "t/pt-table-sync/samples/pt-2016.sql"); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); -$slave1_dbh->do("UPDATE test.test2 SET col3='bbb'"); -$slave1_dbh->do("FLUSH TABLES"); +$replica1_dbh->do("UPDATE test.test2 SET col3='bbb'"); +$replica1_dbh->do("FLUSH TABLES"); # 1 ($output, $status) = full_output( @@ -69,16 +69,16 @@ my $want = { col2 => 'aaa', col3 => 'aaa' }; -my $row = $slave1_dbh->selectrow_hashref("SELECT col1, col2, col3 FROM test.test2"); +my $row = $replica1_dbh->selectrow_hashref("SELECT col1, col2, col3 FROM test.test2"); is_deeply( $row, $want, - "PT-2016 table-sync CRC32 in key - Master was updated", + "PT-2016 table-sync CRC32 in key - Source was updated", ) or diag("Want '".($want||"")."', got '".($row->{col3}||"")."'"); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/pt-2309.t b/t/pt-table-sync/pt-2309.t index 0fe76bae..9c0d84c7 100644 --- a/t/pt-table-sync/pt-2309.t +++ b/t/pt-table-sync/pt-2309.t @@ -22,34 +22,34 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave1_dbh = $sb->get_dbh_for('slave1'); -my $slave2_dbh = $sb->get_dbh_for('slave2'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica1_dbh = $sb->get_dbh_for('replica1'); +my $replica2_dbh = $sb->get_dbh_for('replica2'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave1'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica1'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave2'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica2'; } else { plan tests => 7; } my ($output, $status); -my @args = ('h=127.0.0.1,P=12346,u=msandbox,p=msandbox', '--databases=pt_ts', '--sync-to-master', '--execute'); +my @args = ('h=127.0.0.1,P=12346,u=msandbox,p=msandbox', '--databases=pt_ts', '--sync-to-source', '--execute'); # use lib/samples dir since the main change is in DSNParser -$sb->load_file('master', "t/pt-table-sync/samples/pt-2309.sql"); +$sb->load_file('source', "t/pt-table-sync/samples/pt-2309.sql"); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); -$slave1_dbh->do("DELETE FROM pt_ts.test_table LIMIT 1000"); -$slave1_dbh->do("DELETE FROM pt_ts.test_table_char LIMIT 1000"); -$slave1_dbh->do("FLUSH TABLES"); +$replica1_dbh->do("DELETE FROM pt_ts.test_table LIMIT 1000"); +$replica1_dbh->do("DELETE FROM pt_ts.test_table_char LIMIT 1000"); +$replica1_dbh->do("FLUSH TABLES"); # 1 push(@args, ('--tables=test_table')); @@ -64,10 +64,10 @@ unlike( 'No "Cannot nibble table" error for binary data', ) or diag($output); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); -my $source_rows = $master_dbh->selectrow_arrayref("SELECT COUNT(*) FROM pt_ts.test_table"); -my $replica_rows = $slave1_dbh->selectrow_arrayref("SELECT COUNT(*) FROM pt_ts.test_table"); +my $source_rows = $source_dbh->selectrow_arrayref("SELECT COUNT(*) FROM pt_ts.test_table"); +my $replica_rows = $replica1_dbh->selectrow_arrayref("SELECT COUNT(*) FROM pt_ts.test_table"); is( $replica_rows->[0], @@ -94,10 +94,10 @@ unlike( 'No "Cannot nibble table" error for UUID in CHAR column', ) or diag($output); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); -$source_rows = $master_dbh->selectrow_arrayref("SELECT COUNT(*) FROM pt_ts.test_table_char"); -$replica_rows = $slave1_dbh->selectrow_arrayref("SELECT COUNT(*) FROM pt_ts.test_table_char"); +$source_rows = $source_dbh->selectrow_arrayref("SELECT COUNT(*) FROM pt_ts.test_table_char"); +$replica_rows = $replica1_dbh->selectrow_arrayref("SELECT COUNT(*) FROM pt_ts.test_table_char"); is( $replica_rows->[0], @@ -114,6 +114,6 @@ is( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/pt_221.t b/t/pt-table-sync/pt_221.t index ebcd0096..f7045351 100644 --- a/t/pt-table-sync/pt_221.t +++ b/t/pt-table-sync/pt_221.t @@ -18,32 +18,32 @@ require "$trunk/bin/pt-table-sync"; sub set_binlog_format { my ($sb, $format) = @_; - my $master_dbh = $sb->get_dbh_for('master'); - my $slave1_dbh = $sb->get_dbh_for('slave1'); - my $slave2_dbh = $sb->get_dbh_for('slave2'); + my $source_dbh = $sb->get_dbh_for('source'); + my $replica1_dbh = $sb->get_dbh_for('replica1'); + my $replica2_dbh = $sb->get_dbh_for('replica2'); - $slave2_dbh->do("STOP SLAVE"); - $slave1_dbh->do("STOP SLAVE"); + $replica2_dbh->do("STOP ${replica_name}"); + $replica1_dbh->do("STOP ${replica_name}"); - $slave2_dbh->do("SET GLOBAL binlog_format='$format'"); - $slave1_dbh->do("SET GLOBAL binlog_format='$format'"); - $master_dbh->do("SET GLOBAL binlog_format='$format'"); + $replica2_dbh->do("SET GLOBAL binlog_format='$format'"); + $replica1_dbh->do("SET GLOBAL binlog_format='$format'"); + $source_dbh->do("SET GLOBAL binlog_format='$format'"); - $slave2_dbh->do("START SLAVE"); - $slave1_dbh->do("START SLAVE"); + $replica2_dbh->do("START ${replica_name}"); + $replica1_dbh->do("START ${replica_name}"); } my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp, env => q/BINLOG_FORMAT="ROW"/); -my $master_dbh = $sb->get_dbh_for('master'); -my $master_dsn = $sb->dsn_for('master'); -my $slave_dsn = $sb->dsn_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $source_dsn = $sb->dsn_for('source'); +my $replica_dsn = $sb->dsn_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; -} elsif ($sb->has_engine('master', 'rocksdb') != 1) { +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; +} elsif ($sb->has_engine('source', 'rocksdb') != 1) { plan skip_all => 'This test needs RocksDB engine'; } else { plan tests => 4; @@ -51,12 +51,12 @@ if ( !$master_dbh ) { set_binlog_format($sb, 'ROW'); -$master_dbh->disconnect(); -$master_dbh = $sb->get_dbh_for('master'); +$source_dbh->disconnect(); +$source_dbh = $sb->get_dbh_for('source'); -$sb->load_file('master', 't/pt-table-sync/samples/pt_221.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/pt_221.sql'); -my @args = ('--sync-to-master', $slave_dsn, qw(-t test.t1 --print --execute)); +my @args = ('--sync-to-source', $replica_dsn, qw(-t test.t1 --print --execute)); my ($output, $exit) = full_output( sub { pt_table_sync::main(@args, qw()) }, @@ -66,18 +66,18 @@ my ($output, $exit) = full_output( isnt( $exit, 0, - "PT-221 fails if using --sync-to-master with RocksDB", + "PT-221 fails if using --sync-to-source with RocksDB", ); like( $output, - qr/Cannot sync using --sync-to-master with test.t1 due to the limitations of the RocksDB engine/, - "PT-221 Cannot use --sync-to-master with RockSDB", + qr/Cannot sync using --sync-to-source with test.t1 due to the limitations of the RocksDB engine/, + "PT-221 Cannot use --sync-to-source with RockSDB", ); -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); -@args = ('--replicate', 'test.checksums', $master_dsn, qw(-t test.t1 --print --execute)); +@args = ('--replicate', 'test.checksums', $source_dsn, qw(-t test.t1 --print --execute)); ($output, $exit) = full_output( sub { pt_table_sync::main(@args, qw()) }, @@ -95,7 +95,7 @@ set_binlog_format($sb, 'STATEMENT'); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); diff --git a/t/pt-table-sync/replicate.t b/t/pt-table-sync/replicate.t index b9fc075c..6ec95555 100644 --- a/t/pt-table-sync/replicate.t +++ b/t/pt-table-sync/replicate.t @@ -21,18 +21,18 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave1_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica1_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave1'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica1'; } -my $master_dsn = $sb->dsn_for('master'); -my $slave1_dsn = $sb->dsn_for('slave1'); +my $source_dsn = $sb->dsn_for('source'); +my $replica1_dsn = $sb->dsn_for('replica1'); my $output; my $sample = "t/pt-table-sync/samples"; @@ -47,16 +47,16 @@ my $sample = "t/pt-table-sync/samples"; # https://bugs.launchpad.net/percona-toolkit/+bug/918056 # ############################################################################# -# The slave has 49 extra rows on the low end, e.g. master has rows 50+ -# but slave has rows 1-49 and 50+. This tests syncing the lower oob chunk. -$sb->create_dbs($master_dbh, [qw(bug918056)]); -$sb->load_file('master', "$sample/bug-918056-master.sql", "bug918056"); -$sb->load_file('slave1', "$sample/bug-918056-slave.sql", "bug918056"); +# The replica has 49 extra rows on the low end, e.g. source has rows 50+ +# but replica has rows 1-49 and 50+. This tests syncing the lower oob chunk. +$sb->create_dbs($source_dbh, [qw(bug918056)]); +$sb->load_file('source', "$sample/bug-918056-master.sql", "bug918056"); +$sb->load_file('replica1', "$sample/bug-918056-slave.sql", "bug918056"); ok( no_diff( sub { - pt_table_sync::main($master_dsn, qw(--replicate percona.checksums), + pt_table_sync::main($source_dsn, qw(--replicate percona.checksums), qw(--print)) }, "$sample/bug-918056-print.txt", @@ -66,13 +66,13 @@ ok( ); # Test syncing the upper oob chunk. -$sb->load_file('master', "$sample/upper-oob-master.sql"); -$sb->load_file('slave1', "$sample/upper-oob-slave.sql"); +$sb->load_file('source', "$sample/upper-oob-master.sql"); +$sb->load_file('replica1', "$sample/upper-oob-slave.sql"); ok( no_diff( sub { - pt_table_sync::main($master_dsn, qw(--replicate percona.checksums), + pt_table_sync::main($source_dsn, qw(--replicate percona.checksums), qw(--print)) }, "$sample/upper-oob-print.txt", @@ -84,7 +84,7 @@ ok( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave1_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica1_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); done_testing; diff --git a/t/pt-table-sync/replicate_do_db.t b/t/pt-table-sync/replicate_do_db.t index 421410f4..1f3c58c4 100644 --- a/t/pt-table-sync/replicate_do_db.t +++ b/t/pt-table-sync/replicate_do_db.t @@ -17,18 +17,18 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave1_dbh = $sb->get_dbh_for('slave1'); -my $slave2_dbh = $sb->get_dbh_for('slave2'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica1_dbh = $sb->get_dbh_for('replica1'); +my $replica2_dbh = $sb->get_dbh_for('replica2'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave1_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave1'; +elsif ( !$replica1_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica1'; } -elsif ( !$slave2_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave2'; +elsif ( !$replica2_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica2'; } else { plan tests => 9; @@ -44,97 +44,97 @@ else { # Add two new test databases with a simple table. IMPORTANT: we do this before # reconfiguring the server, so this gets replicated! foreach my $db (qw(test1 test2)) { - $master_dbh->do("DROP DATABASE IF EXISTS $db"); - $master_dbh->do("CREATE DATABASE $db"); - $master_dbh->do("CREATE TABLE $db.foo (i INT NOT NULL PRIMARY KEY)"); - $master_dbh->do("INSERT INTO $db.foo VALUES (1),(2),(9)"); + $source_dbh->do("DROP DATABASE IF EXISTS $db"); + $source_dbh->do("CREATE DATABASE $db"); + $source_dbh->do("CREATE TABLE $db.foo (i INT NOT NULL PRIMARY KEY)"); + $source_dbh->do("INSERT INTO $db.foo VALUES (1),(2),(9)"); } -$sb->wait_for_slaves(); +$sb->wait_for_replicas(); -# Stop slave 12346, add replicate-do-db to its config, and restart it. -$slave1_dbh->disconnect; -diag('Restarting slave 12346 with replicate-do-db=test1'); +# Stop replica 12346, add replicate-do-db to its config, and restart it. +$replica1_dbh->disconnect; +diag('Restarting replica 12346 with replicate-do-db=test1'); diag(`/tmp/12346/stop >/dev/null`); diag(`echo "replicate-do-db = test1" >> /tmp/12346/my.sandbox.cnf`); diag(`/tmp/12346/start >/dev/null`); -$slave1_dbh = $sb->get_dbh_for('slave1'); -$slave2_dbh->do("stop slave"); -$slave2_dbh->do("start slave"); +$replica1_dbh = $sb->get_dbh_for('replica1'); +$replica2_dbh->do("stop ${replica_name}"); +$replica2_dbh->do("start ${replica_name}"); -my $r = $slave1_dbh->selectrow_hashref('show slave status'); +my $r = $replica1_dbh->selectrow_hashref("show ${replica_name} status"); is($r->{replicate_do_db}, 'test1', 'Server reconfigured'); # ############################################################################# # IMPORTANT: anything you want to replicate must now USE test1 first! -# IMPORTANT: $sb->wait_for_slaves won't work now! +# IMPORTANT: $sb->wait_for_replicas won't work now! # ############################################################################# -# Make master and slave differ. Because we USE test2, this DELETE on -# the master won't replicate to the slave in either case. -$master_dbh->do("USE test2"); -$master_dbh->do("DELETE FROM test1.foo WHERE i = 2"); -$master_dbh->do("DELETE FROM test2.foo WHERE i = 2"); -$master_dbh->do("COMMIT"); +# Make source and replica differ. Because we USE test2, this DELETE on +# the source won't replicate to the replica in either case. +$source_dbh->do("USE test2"); +$source_dbh->do("DELETE FROM test1.foo WHERE i = 2"); +$source_dbh->do("DELETE FROM test2.foo WHERE i = 2"); +$source_dbh->do("COMMIT"); -# NOTE: $sb->wait_for_slaves() won't work! Hence we do our own way... -$master_dbh->do('USE test1'); -$master_dbh->do('INSERT INTO test1.foo(i) VALUES(10)'); -PerconaTest::wait_for_table($slave2_dbh, "test1.foo", "i=10"); +# NOTE: $sb->wait_for_replicas() won't work! Hence we do our own way... +$source_dbh->do('USE test1'); +$source_dbh->do('INSERT INTO test1.foo(i) VALUES(10)'); +PerconaTest::wait_for_table($replica2_dbh, "test1.foo", "i=10"); -# Prove that the slave (12347, not 12346) still has i=2 in test2.foo, and the -# master doesn't. That is, both test1 and test2 are out-of-sync on the slave. -$r = $master_dbh->selectall_arrayref('select * from test1.foo where i=2'); -is_deeply( $r, [], 'master has no test1.foo.i=2'); -$r = $master_dbh->selectall_arrayref('select * from test2.foo where i=2'); -is_deeply( $r, [], 'master has no test2.foo.i=2'); -$r = $slave2_dbh->selectall_arrayref('select * from test1.foo where i=2'); -is_deeply( $r, [[2]], 'slave2 has test1.foo.i=2'); -$r = $slave2_dbh->selectall_arrayref('select * from test2.foo where i=2'), -is_deeply( $r, [[2]], 'slave2 has test2.foo.i=2') or diag(`/tmp/12346/use -e "show slave status\\G"; /tmp/12347/use -e "show slave status\\G"`); +# Prove that the replica (12347, not 12346) still has i=2 in test2.foo, and the +# source doesn't. That is, both test1 and test2 are out-of-sync on the replica. +$r = $source_dbh->selectall_arrayref('select * from test1.foo where i=2'); +is_deeply( $r, [], 'source has no test1.foo.i=2'); +$r = $source_dbh->selectall_arrayref('select * from test2.foo where i=2'); +is_deeply( $r, [], 'source has no test2.foo.i=2'); +$r = $replica2_dbh->selectall_arrayref('select * from test1.foo where i=2'); +is_deeply( $r, [[2]], 'replica2 has test1.foo.i=2'); +$r = $replica2_dbh->selectall_arrayref('select * from test2.foo where i=2'), +is_deeply( $r, [[2]], 'replica2 has test2.foo.i=2') or diag(`/tmp/12346/use -e "show ${replica_name} status\\G"; /tmp/12347/use -e "show ${replica_name} status\\G"`); # Now we sync, and if pt-table-sync USE's the db it's syncing, then test1 should # be in sync afterwards, and test2 shouldn't. -my $procs = $master_dbh->selectcol_arrayref('show processlist'); -diag('MySQL processes on master: ', join(', ', @$procs)); +my $procs = $source_dbh->selectcol_arrayref('show processlist'); +diag('MySQL processes on source: ', join(', ', @$procs)); my $output = output( sub { pt_table_sync::main("h=127.1,P=12346,u=msandbox,p=msandbox", - qw(--sync-to-master --execute --no-check-triggers), + qw(--sync-to-source --execute --no-check-triggers), "--databases", "test1,test2") }, stderr => 1, ); -# NOTE: $sb->wait_for_slaves() won't work! Hence we do our own way... -$master_dbh->do('USE test1'); -$master_dbh->do('INSERT INTO test1.foo(i) VALUES(11)'); -PerconaTest::wait_for_table($slave2_dbh, "test1.foo", "i=11"); +# NOTE: $sb->wait_for_replicas() won't work! Hence we do our own way... +$source_dbh->do('USE test1'); +$source_dbh->do('INSERT INTO test1.foo(i) VALUES(11)'); +PerconaTest::wait_for_table($replica2_dbh, "test1.foo", "i=11"); -$procs = $master_dbh->selectcol_arrayref('show processlist'); -diag('MySQL processes on master: ', join(', ', @$procs)); +$procs = $source_dbh->selectcol_arrayref('show processlist'); +diag('MySQL processes on source: ', join(', ', @$procs)); -$r = $slave2_dbh->selectall_arrayref('select * from test1.foo where i=2'); -is_deeply( $r, [], 'slave2 has NO test1.foo.i=2 after sync'); -$r = $slave2_dbh->selectall_arrayref('select * from test2.foo where i=2'), -is_deeply( $r, [[2]], 'slave2 has test2.foo.i=2 after sync') or diag(`/tmp/12346/use -e "show slave status\\G"; /tmp/12347/use -e "show slave status\\G"`); +$r = $replica2_dbh->selectall_arrayref('select * from test1.foo where i=2'); +is_deeply( $r, [], 'replica2 has NO test1.foo.i=2 after sync'); +$r = $replica2_dbh->selectall_arrayref('select * from test2.foo where i=2'), +is_deeply( $r, [[2]], 'replica2 has test2.foo.i=2 after sync') or diag(`/tmp/12346/use -e "show ${replica_name} status\\G"; /tmp/12347/use -e "show ${replica_name} status\\G"`); -$slave1_dbh->disconnect; +$replica1_dbh->disconnect; diag('Reconfiguring instance 12346 without replication filters'); diag(`grep -v replicate.do.db /tmp/12346/my.sandbox.cnf > /tmp/new.cnf`); diag(`mv /tmp/new.cnf /tmp/12346/my.sandbox.cnf`); diag(`/tmp/12346/stop >/dev/null`); diag(`/tmp/12346/start >/dev/null`); -$slave2_dbh->do("stop slave"); -$slave2_dbh->do("start slave"); +$replica2_dbh->do("stop ${replica_name}"); +$replica2_dbh->do("start ${replica_name}"); -$slave1_dbh = $sb->get_dbh_for('slave1'); -$r = $slave1_dbh->selectrow_hashref('show slave status'); +$replica1_dbh = $sb->get_dbh_for('replica1'); +$r = $replica1_dbh->selectrow_hashref("show ${replica_name} status"); is($r->{replicate_do_db}, '', 'Replication filter removed'); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/safety_checks.t b/t/pt-table-sync/safety_checks.t index 77554a3e..a4589d13 100644 --- a/t/pt-table-sync/safety_checks.t +++ b/t/pt-table-sync/safety_checks.t @@ -19,18 +19,18 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } -my $master_dsn = $sb->dsn_for('master'); -my $slave1_dsn = $sb->dsn_for('slave1'); +my $source_dsn = $sb->dsn_for('source'); +my $replica1_dsn = $sb->dsn_for('replica1'); # ############################################################################# # --[no]check-child-tables @@ -38,16 +38,16 @@ my $slave1_dsn = $sb->dsn_for('slave1'); # https://bugs.launchpad.net/percona-toolkit/+bug/1223458 # ############################################################################# -$sb->load_file('master', 't/pt-table-sync/samples/on_del_cas.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/on_del_cas.sql'); -$master_dbh->do("INSERT INTO on_del_cas.parent VALUES (1), (2)"); -$master_dbh->do("INSERT INTO on_del_cas.child1 VALUES (null, 1)"); -$master_dbh->do("INSERT INTO on_del_cas.child2 VALUES (null, 1)"); -$sb->wait_for_slaves(); +$source_dbh->do("INSERT INTO on_del_cas.parent VALUES (1), (2)"); +$source_dbh->do("INSERT INTO on_del_cas.child1 VALUES (null, 1)"); +$source_dbh->do("INSERT INTO on_del_cas.child2 VALUES (null, 1)"); +$sb->wait_for_replicas(); $output = output( sub { - pt_table_sync::main($slave1_dsn, qw(--sync-to-master), + pt_table_sync::main($replica1_dsn, qw(--sync-to-source), qw(--execute -d on_del_cas)) }, stderr => 1, @@ -59,7 +59,7 @@ like( "check-child-tables: error message" ); -my $rows = $slave_dbh->selectall_arrayref("select * from on_del_cas.child2"); +my $rows = $replica_dbh->selectall_arrayref("select * from on_del_cas.child2"); is_deeply( $rows, [ [1,1] ], @@ -68,7 +68,7 @@ is_deeply( $output = output( sub { - pt_table_sync::main($slave1_dsn, qw(--sync-to-master), + pt_table_sync::main($replica1_dsn, qw(--sync-to-source), qw(--print -d on_del_cas)) }, stderr => 1, @@ -83,6 +83,6 @@ unlike( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); done_testing; diff --git a/t/pt-table-sync/samples/bug-918056-master.sql b/t/pt-table-sync/samples/bug-918056-master.sql index f67a0ea5..c7c05021 100644 --- a/t/pt-table-sync/samples/bug-918056-master.sql +++ b/t/pt-table-sync/samples/bug-918056-master.sql @@ -48,8 +48,8 @@ CREATE TABLE `checksums` ( `upper_boundary` text, `this_crc` char(40) NOT NULL, `this_cnt` int(11) NOT NULL, - `master_crc` char(40) DEFAULT NULL, - `master_cnt` int(11) DEFAULT NULL, + `source_crc` char(40) DEFAULT NULL, + `source_cnt` int(11) DEFAULT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`db`,`tbl`,`chunk`), KEY `ts_db_tbl` (`ts`,`db`,`tbl`) diff --git a/t/pt-table-sync/samples/checksum_tbl.sql b/t/pt-table-sync/samples/checksum_tbl.sql index 16daac31..54f10477 100644 --- a/t/pt-table-sync/samples/checksum_tbl.sql +++ b/t/pt-table-sync/samples/checksum_tbl.sql @@ -9,8 +9,8 @@ CREATE TABLE checksum ( boundaries char(64) NOT NULL, this_crc char(40) NOT NULL, this_cnt int NOT NULL, - master_crc char(40) NULL, - master_cnt int NULL, + source_crc char(40) NULL, + source_cnt int NULL, ts timestamp NOT NULL, PRIMARY KEY (db, tbl, chunk) ); diff --git a/t/pt-table-sync/samples/pt_221.sql b/t/pt-table-sync/samples/pt_221.sql index 1f648455..13d83f0b 100644 --- a/t/pt-table-sync/samples/pt_221.sql +++ b/t/pt-table-sync/samples/pt_221.sql @@ -124,8 +124,8 @@ CREATE TABLE test.checksums ( upper_boundary TEXT NULL, this_crc CHAR(40) NOT NULL, this_cnt INT NOT NULL, - master_crc CHAR(40) NULL, - master_cnt INT NULL, + source_crc CHAR(40) NULL, + source_cnt INT NULL, ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (db, tbl, chunk), INDEX ts_db_tbl (ts, db, tbl) diff --git a/t/pt-table-sync/samples/upper-oob-master.sql b/t/pt-table-sync/samples/upper-oob-master.sql index 10feb36e..1b75e5f5 100644 --- a/t/pt-table-sync/samples/upper-oob-master.sql +++ b/t/pt-table-sync/samples/upper-oob-master.sql @@ -131,8 +131,8 @@ CREATE TABLE `checksums` ( `upper_boundary` text, `this_crc` char(40) NOT NULL, `this_cnt` int(11) NOT NULL, - `master_crc` char(40) DEFAULT NULL, - `master_cnt` int(11) DEFAULT NULL, + `source_crc` char(40) DEFAULT NULL, + `source_cnt` int(11) DEFAULT NULL, `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`db`,`tbl`,`chunk`), KEY `ts_db_tbl` (`ts`,`db`,`tbl`) diff --git a/t/pt-table-sync/specify_column_or_index.t b/t/pt-table-sync/specify_column_or_index.t index 70488713..23ad16db 100644 --- a/t/pt-table-sync/specify_column_or_index.t +++ b/t/pt-table-sync/specify_column_or_index.t @@ -18,28 +18,28 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 3; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); # ############################################################################# # Issue 376: Permit specifying an index for pt-table-sync # ############################################################################# diag(`/tmp/12345/use < $trunk/t/pt-table-sync/samples/issue_375.sql`); sleep 1; -$output = `$trunk/bin/pt-table-sync --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox -d issue_375 --print -v -v --chunk-size 50 --chunk-index updated_at`; +$output = `$trunk/bin/pt-table-sync --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox -d issue_375 --print -v -v --chunk-size 50 --chunk-index updated_at`; # We cannot rely on the exact time here, because pt-osc uses EXPLAIN to calculate rows range # and EXPLAIN does not guarantee accuracy of results. like( @@ -48,7 +48,7 @@ like( '--chunk-index', ); -$output = `$trunk/bin/pt-table-sync --sync-to-master h=127.1,P=12346,u=msandbox,p=msandbox -d issue_375 --print -v -v --chunk-size 50 --chunk-column updated_at`; +$output = `$trunk/bin/pt-table-sync --sync-to-source h=127.1,P=12346,u=msandbox,p=msandbox -d issue_375 --print -v -v --chunk-size 50 --chunk-column updated_at`; like( $output, qr/FROM `issue_375`.`t` FORCE INDEX \(`updated_at`\) WHERE \(`updated_at` > 0 AND `updated_at` < '2009-09-05 02:\d\d:\d\d'/, @@ -58,7 +58,7 @@ like( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/standard_options.t b/t/pt-table-sync/standard_options.t index 8786f78e..d1bbff12 100644 --- a/t/pt-table-sync/standard_options.t +++ b/t/pt-table-sync/standard_options.t @@ -45,7 +45,7 @@ EOF # Issue 391: Add --pid option to mk-table-sync # ############################################################################# `touch /tmp/mk-table-sync.pid`; -$output = `$trunk/bin/pt-table-sync h=127.1,P=12346,u=msandbox,p=msandbox --sync-to-master --print --no-check-triggers --pid /tmp/mk-table-sync.pid 2>&1`; +$output = `$trunk/bin/pt-table-sync h=127.1,P=12346,u=msandbox,p=msandbox --sync-to-source --print --no-check-triggers --pid /tmp/mk-table-sync.pid 2>&1`; like( $output, qr{PID file /tmp/mk-table-sync.pid exists}, diff --git a/t/pt-table-sync/sync_to_differnt_db.t b/t/pt-table-sync/sync_to_differnt_db.t index 55a9c1bb..f50b3ea2 100644 --- a/t/pt-table-sync/sync_to_differnt_db.t +++ b/t/pt-table-sync/sync_to_differnt_db.t @@ -18,24 +18,24 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); +my $source_dbh = $sb->get_dbh_for('source'); -diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`); -my $dbh2 = $sb->get_dbh_for('master1'); +diag(`$trunk/sandbox/start-sandbox source 12348 >/dev/null`); +my $dbh2 = $sb->get_dbh_for('source1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } elsif ( !$dbh2 ) { - plan skip_all => 'Cannot connect to second sandbox master'; + plan skip_all => 'Cannot connect to second sandbox source'; } else { plan tests => 3; } -$sb->wipe_clean($master_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); -$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); +$sb->wipe_clean($source_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); +$sb->load_file('source', 't/pt-table-sync/samples/before.sql'); # ############################################################################# # Issue 40: mk-table-sync feature: sync to different db @@ -45,7 +45,7 @@ $dbh2->do('DROP DATABASE IF EXISTS d2'); $dbh2->do('CREATE DATABASE d2'); $dbh2->do('CREATE TABLE d2.test2 (a INT NOT NULL, b char(2) NOT NULL, PRIMARY KEY (`a`,`b`) )'); -$output = `$trunk/bin/pt-table-sync --no-check-slave --execute h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=test1 h=127.1,P=12348,D=d2,t=test2 2>&1`; +$output = `$trunk/bin/pt-table-sync --no-check-replica --execute h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=test1 h=127.1,P=12348,D=d2,t=test2 2>&1`; is( $output, '', @@ -63,7 +63,7 @@ is( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/sync_using_channels.t b/t/pt-table-sync/sync_using_channels.t index 5c4a1d91..8ab8674c 100644 --- a/t/pt-table-sync/sync_using_channels.t +++ b/t/pt-table-sync/sync_using_channels.t @@ -17,43 +17,43 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } elsif ($sandbox_version lt '5.7') { plan skip_all => 'Only on MySQL 5.7+'; } else { plan tests => 2; } -my ($master1_dbh, $master1_dsn) = $sb->start_sandbox( - server => 'chan_master1', - type => 'master', +my ($source1_dbh, $source1_dsn) = $sb->start_sandbox( + server => 'chan_source1', + type => 'source', ); -my ($master2_dbh, $master2_dsn) = $sb->start_sandbox( - server => 'chan_master2', - type => 'master', +my ($source2_dbh, $source2_dsn) = $sb->start_sandbox( + server => 'chan_source2', + type => 'source', ); -my ($slave1_dbh, $slave1_dsn) = $sb->start_sandbox( - server => 'chan_slave1', - type => 'master', +my ($replica1_dbh, $replica1_dsn) = $sb->start_sandbox( + server => 'chan_replica1', + type => 'source', ); -my $slave1_port = $sb->port_for('chan_slave1'); +my $replica1_port = $sb->port_for('chan_replica1'); -$sb->load_file('chan_master1', "sandbox/gtid_on.sql", undef, no_wait => 1); -$sb->load_file('chan_master2', "sandbox/gtid_on.sql", undef, no_wait => 1); -$sb->load_file('chan_slave1', "sandbox/slave_channels.sql", undef, no_wait => 1); +$sb->load_file('chan_source1', "sandbox/gtid_on.sql", undef, no_wait => 1); +$sb->load_file('chan_source2', "sandbox/gtid_on.sql", undef, no_wait => 1); +$sb->load_file('chan_replica1', "sandbox/replica_channels.sql", undef, no_wait => 1); -my @args = qw(--execute --no-foreign-key-checks --verbose --databases=sakila --tables=actor --sync-to-master --channel=sourcechan1); +my @args = qw(--execute --no-foreign-key-checks --verbose --databases=sakila --tables=actor --sync-to-source --channel=sourcechan1); my $exit_status; my $output = output( - sub { $exit_status = pt_table_sync::main(@args, $slave1_dsn) }, + sub { $exit_status = pt_table_sync::main(@args, $replica1_dsn) }, stderr => 1, ); @@ -63,12 +63,12 @@ like ( 'Synced actor table' ); -$sb->stop_sandbox(qw(chan_master1 chan_master2 chan_slave1)); +$sb->stop_sandbox(qw(chan_source1 chan_source2 chan_replica1)); # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/traces.t b/t/pt-table-sync/traces.t index a3c8c3c7..15da5e0f 100644 --- a/t/pt-table-sync/traces.t +++ b/t/pt-table-sync/traces.t @@ -21,8 +21,8 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); my $mysqlbinlog = `which mysqlbinlog`; if ( $mysqlbinlog ) { @@ -32,11 +32,11 @@ elsif ( -x "$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqlbinlog" ) { $mysqlbinlog = "$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqlbinlog"; } -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } elsif ( !$mysqlbinlog ) { plan skip_all => 'Cannot find mysqlbinlog'; @@ -48,9 +48,9 @@ else { # We execute the test by changing a table so pt-table-sync will find something # to modify. Then we examine the binary log to find the SQL in it, and check # that. -$sb->load_file('master', "t/pt-table-sync/samples/issue_533.sql"); -my $pos = $master_dbh->selectrow_hashref('show master status'); -diag("Master position: $pos->{file} / $pos->{position}"); +$sb->load_file('source', "t/pt-table-sync/samples/issue_533.sql"); +my $pos = $source_dbh->selectrow_hashref("show ${source_status} status"); +diag("Source position: $pos->{file} / $pos->{position}"); my @args = ('h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=t1', 't=t2', '--execute'); output( @@ -74,6 +74,6 @@ like( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/triggers.t b/t/pt-table-sync/triggers.t index 8b0681e1..d7810682 100644 --- a/t/pt-table-sync/triggers.t +++ b/t/pt-table-sync/triggers.t @@ -18,44 +18,44 @@ require "$trunk/bin/pt-table-sync"; my $output; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } -elsif ( VersionParser->new($master_dbh) < '5.0.2' ) { +elsif ( VersionParser->new($source_dbh) < '5.0.2' ) { plan skip_all => 'Sever does not support triggers (< 5.0.2)'; } else { plan tests => 11; } -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); -$sb->create_dbs($master_dbh, [qw(test)]); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); +$sb->create_dbs($source_dbh, [qw(test)]); # ############################################################################# # Issue 37: mk-table-sync should warn about triggers # ############################################################################# -$sb->load_file('master', 't/pt-table-sync/samples/issue_37.sql'); -$sb->use('master', '-e "SET SQL_LOG_BIN=0; INSERT INTO test.issue_37 VALUES (1), (2);"'); +$sb->load_file('source', 't/pt-table-sync/samples/issue_37.sql'); +$sb->use('source', '-e "SET SQL_LOG_BIN=0; INSERT INTO test.issue_37 VALUES (1), (2);"'); `$trunk/bin/pt-table-checksum h=127.0.0.1,P=12345,u=msandbox,p=msandbox --replicate test.checksum -d test --set-vars innodb_lock_wait_timeout=3 2>&1 > /dev/null`; -$output = `$trunk/bin/pt-table-sync --no-check-slave --execute u=msandbox,p=msandbox,h=127.0.0.1,P=12345,D=test,t=issue_37 h=127.1,P=12346 2>&1`; +$output = `$trunk/bin/pt-table-sync --no-check-replica --execute u=msandbox,p=msandbox,h=127.0.0.1,P=12345,D=test,t=issue_37 h=127.1,P=12346 2>&1`; like($output, qr/Triggers are defined/, 'Die on trigger tbl write with one table (1/4, issue 37)' ); -$output = `$trunk/bin/pt-table-sync --replicate test.checksum --sync-to-master --execute h=127.1,P=12346,u=msandbox,p=msandbox -d test -t issue_37 2>&1`; +$output = `$trunk/bin/pt-table-sync --replicate test.checksum --sync-to-source --execute h=127.1,P=12346,u=msandbox,p=msandbox -d test -t issue_37 2>&1`; like($output, qr/Triggers are defined/, - 'Die on trigger tbl write with --replicate --sync-to-master (2/4, issue 37)' + 'Die on trigger tbl write with --replicate --sync-to-source (2/4, issue 37)' ); $output = `$trunk/bin/pt-table-sync --replicate test.checksum --execute h=127.1,P=12345,u=msandbox,p=msandbox -d test -t issue_37 2>&1`; @@ -78,7 +78,7 @@ ok( 'Table with trigger was not written' ); -$output = `$trunk/bin/pt-table-sync --no-check-slave --execute u=msandbox,p=msandbox,h=127.0.0.1,P=12345,D=test,t=issue_37 h=127.1,P=12346 --no-check-triggers 2>&1`; +$output = `$trunk/bin/pt-table-sync --no-check-replica --execute u=msandbox,p=msandbox,h=127.0.0.1,P=12345,D=test,t=issue_37 h=127.1,P=12346 --no-check-triggers 2>&1`; unlike( $output, qr/Triggers are defined/, @@ -96,11 +96,11 @@ like( # ############################################################################# diag('Loading file and waiting for replication'); -$sb->load_file('master', 't/pt-table-sync/samples/issue_367.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/issue_367.sql'); -# Make slave db1.t1 and db2.t1 differ from master. -$slave_dbh->do('INSERT INTO db1.t1 VALUES (9)'); -$slave_dbh->do('DELETE FROM db2.t1 WHERE i > 4'); +# Make replica db1.t1 and db2.t1 differ from source. +$replica_dbh->do('INSERT INTO db1.t1 VALUES (9)'); +$replica_dbh->do('DELETE FROM db2.t1 WHERE i > 4'); # Replicate checksum of db2.t1. $output = `$trunk/bin/pt-table-checksum h=127.1,P=12345,u=msandbox,p=msandbox --replicate db1.checksum --create-replicate-table --databases db1,db2 --set-vars innodb_lock_wait_timeout=3 2>&1`; @@ -110,7 +110,7 @@ like( 'Replicated checksums (issue 367)' ); -# Sync db2, which has no triggers, between master and slave using +# Sync db2, which has no triggers, between source and replica using # --replicate which has entries for both db1 and db2. db1 has a # trigger but since we also specify --databases db2, then db1 should # be ignored. @@ -121,8 +121,8 @@ unlike( "Doesn't warn about trigger on db1 (issue 367)" ); -$sb->wait_for_slaves(); -my $r = $slave_dbh->selectrow_array('SELECT * FROM db2.t1 WHERE i = 5'); +$sb->wait_for_replicas(); +my $r = $replica_dbh->selectrow_array('SELECT * FROM db2.t1 WHERE i = 5'); is( $r, '5', @@ -132,7 +132,7 @@ is( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); -$sb->wipe_clean($slave_dbh); +$sb->wipe_clean($source_dbh); +$sb->wipe_clean($replica_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/wait.t b/t/pt-table-sync/wait.t index 2d05ae2d..9147e485 100644 --- a/t/pt-table-sync/wait.t +++ b/t/pt-table-sync/wait.t @@ -17,35 +17,35 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 5; } my $output; -my @args = ('--sync-to-master', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(--print -v)); +my @args = ('--sync-to-source', 'h=127.1,P=12346,u=msandbox,p=msandbox', qw(--print -v)); -$sb->load_file('master', 't/pt-table-sync/samples/lag-slave.sql'); +$sb->load_file('source', 't/pt-table-sync/samples/lag-slave.sql'); wait_until( sub { my $row; eval { - $row = $slave_dbh->selectrow_hashref("select * from test.t2"); + $row = $replica_dbh->selectrow_hashref("select * from test.t2"); }; return 1 if $row && $row->{id}; }, ); -sub lag_slave { - my $dbh = $sb->get_dbh_for('master'); +sub lag_replica { + my $dbh = $sb->get_dbh_for('source'); for (1..10) { $dbh->do("update test.t1 set i=sleep(3) limit 1"); } @@ -56,7 +56,7 @@ sub lag_slave { my $pid = fork(); if ( !$pid ) { # child - lag_slave(); + lag_replica(); exit; } @@ -65,11 +65,11 @@ sleep(2); # parent PerconaTest::wait_until(sub { - $slave_dbh->selectrow_hashref("show slave status")->{seconds_behind_master} + $replica_dbh->selectrow_hashref("show ${replica_name} status")->{"seconds_behind_${source_name}"} }) or do { kill 15, $pid; waitpid ($pid, 0); - die "Slave did not lag"; + die "Replica did not lag"; }; my $start = time; @@ -90,16 +90,16 @@ cmp_ok( $t, '>', 1, - "Sync waited $t seconds for master" + "Sync waited $t seconds for source" ); # Repeat the test with --wait 0 to test that the sync happens without delay. PerconaTest::wait_until(sub { - $slave_dbh->selectrow_hashref("show slave status")->{seconds_behind_master} + $replica_dbh->selectrow_hashref("show ${replica_name} status")->{"seconds_behind_${source_name}"} }) or do { kill 15, $pid; waitpid ($pid, 0); - die "Slave did not lag"; + die "Replica did not lag"; }; $start = time; @@ -120,7 +120,7 @@ cmp_ok( $t, '<=', 1, - "Sync did not wait for master with --wait 0 ($t seconds)" + "Sync did not wait for source with --wait 0 ($t seconds)" ); # ############################################################################# @@ -128,6 +128,6 @@ cmp_ok( # ############################################################################# kill 15, $pid; waitpid ($pid, 0); -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-sync/zero_chunk.t b/t/pt-table-sync/zero_chunk.t index 1beb2418..85adbbc9 100644 --- a/t/pt-table-sync/zero_chunk.t +++ b/t/pt-table-sync/zero_chunk.t @@ -17,21 +17,21 @@ require "$trunk/bin/pt-table-sync"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $master_dbh = $sb->get_dbh_for('master'); -my $slave_dbh = $sb->get_dbh_for('slave1'); +my $source_dbh = $sb->get_dbh_for('source'); +my $replica_dbh = $sb->get_dbh_for('replica1'); -if ( !$master_dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; +if ( !$source_dbh ) { + plan skip_all => 'Cannot connect to sandbox source'; } -elsif ( !$slave_dbh ) { - plan skip_all => 'Cannot connect to sandbox slave'; +elsif ( !$replica_dbh ) { + plan skip_all => 'Cannot connect to sandbox replica'; } else { plan tests => 3; } my $output; -my @args = ('h=127.0.0.1,P=12346,u=msandbox,p=msandbox', qw(--sync-to-master -t sakila.actor -v -v --print --chunk-size 100)); +my @args = ('h=127.0.0.1,P=12346,u=msandbox,p=msandbox', qw(--sync-to-source -t sakila.actor -v -v --print --chunk-size 100)); $output = output( sub { pt_table_sync::main(@args) }, @@ -54,6 +54,6 @@ unlike( # ############################################################################# # Done. # ############################################################################# -$sb->wipe_clean($master_dbh); +$sb->wipe_clean($source_dbh); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); exit; diff --git a/t/pt-table-usage/explain_extended.t b/t/pt-table-usage/explain_extended.t index 6761b359..4761e9e8 100644 --- a/t/pt-table-usage/explain_extended.t +++ b/t/pt-table-usage/explain_extended.t @@ -17,10 +17,10 @@ require "$trunk/bin/pt-table-usage"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); +my $dbh = $sb->get_dbh_for('source'); if ( !$dbh ) { - plan skip_all => 'Cannot connect to sandbox master'; + plan skip_all => 'Cannot connect to sandbox source'; } else { plan tests => 4; diff --git a/t/pt-upgrade/compare_hosts.t b/t/pt-upgrade/compare_hosts.t index 0665711a..7f29ec52 100644 --- a/t/pt-upgrade/compare_hosts.t +++ b/t/pt-upgrade/compare_hosts.t @@ -19,7 +19,7 @@ use Sandbox; require "$trunk/bin/pt-upgrade"; # This runs immediately if the server is already running, else it starts it. -diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`); +diag(`$trunk/sandbox/start-sandbox source 12348 >/dev/null`); my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); diff --git a/t/pt-upgrade/compare_results.t b/t/pt-upgrade/compare_results.t index 4c64f06d..85b2d9e0 100644 --- a/t/pt-upgrade/compare_results.t +++ b/t/pt-upgrade/compare_results.t @@ -20,7 +20,7 @@ use Sandbox; require "$trunk/bin/pt-upgrade"; # This runs immediately if the server is already running, else it starts it. -diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`); +diag(`$trunk/sandbox/start-sandbox source 12348 >/dev/null`); my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); diff --git a/t/pt-upgrade/diff_rows.t b/t/pt-upgrade/diff_rows.t index 0396af39..5d13256b 100644 --- a/t/pt-upgrade/diff_rows.t +++ b/t/pt-upgrade/diff_rows.t @@ -21,10 +21,10 @@ require "$trunk/bin/pt-upgrade"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); +my $dbh = $sb->get_dbh_for('source'); if ( !$dbh ) { - plan skip_all => "Cannot connect to sandbox master"; + plan skip_all => "Cannot connect to sandbox source"; } sub test_diff { @@ -219,7 +219,7 @@ test_diff ( # pt-upgrade reports differences on NULL # ############################################################################# -$sb->load_file('master', "t/pt-upgrade/samples/007/tables.sql"); +$sb->load_file('source', "t/pt-upgrade/samples/007/tables.sql"); test_diff( name => 'Bug 1168434: no diff with NULL', diff --git a/t/pt-upgrade/diff_warnings.t b/t/pt-upgrade/diff_warnings.t index 55b58786..f0bf1e14 100644 --- a/t/pt-upgrade/diff_warnings.t +++ b/t/pt-upgrade/diff_warnings.t @@ -22,14 +22,14 @@ require "$trunk/bin/pt-upgrade"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh1 = $sb->get_dbh_for('master'); -my $dbh2 = $sb->get_dbh_for('master'); +my $dbh1 = $sb->get_dbh_for('source'); +my $dbh2 = $sb->get_dbh_for('source'); if ( !$dbh1 || !$dbh2 ) { - plan skip_all => "Cannot connect to sandbox master"; + plan skip_all => "Cannot connect to sandbox source"; } -$sb->load_file('master', "t/lib/samples/compare-warnings.sql"); +$sb->load_file('source', "t/lib/samples/compare-warnings.sql"); sub clear_warnings { $dbh1->do("SELECT /* clear warnings */ 1 FROM mysql.user"); diff --git a/t/pt-upgrade/run_time.t b/t/pt-upgrade/run_time.t index e65f2ebb..2ed48ae7 100644 --- a/t/pt-upgrade/run_time.t +++ b/t/pt-upgrade/run_time.t @@ -20,7 +20,7 @@ use Sandbox; require "$trunk/bin/pt-upgrade"; # This runs immediately if the server is already running, else it starts it. -diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`); +diag(`$trunk/sandbox/start-sandbox source 12348 >/dev/null`); my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); diff --git a/t/pt-upgrade/save_results.t b/t/pt-upgrade/save_results.t index 4feedba9..3cf22908 100644 --- a/t/pt-upgrade/save_results.t +++ b/t/pt-upgrade/save_results.t @@ -21,7 +21,7 @@ use Sandbox; require "$trunk/bin/pt-upgrade"; # This runs immediately if the server is already running, else it starts it. -diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`); +diag(`$trunk/sandbox/start-sandbox source 12348 >/dev/null`); my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); diff --git a/t/pt-variable-advisor/advice.t b/t/pt-variable-advisor/advice.t index 9caa4dd4..8d3a48a9 100644 --- a/t/pt-variable-advisor/advice.t +++ b/t/pt-variable-advisor/advice.t @@ -17,11 +17,11 @@ require "$trunk/bin/pt-variable-advisor"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); -my $dsn = $sb->dsn_for('master'); +my $dbh = $sb->get_dbh_for('source'); +my $dsn = $sb->dsn_for('source'); if ( !$dbh ) { - plan skip_all => "Cannot connect to sandbox master"; + plan skip_all => "Cannot connect to sandbox source"; } # ############################################################################# diff --git a/t/pt-variable-advisor/show_variables_online.t b/t/pt-variable-advisor/show_variables_online.t index 587dfa1f..8d465a81 100644 --- a/t/pt-variable-advisor/show_variables_online.t +++ b/t/pt-variable-advisor/show_variables_online.t @@ -17,10 +17,10 @@ require "$trunk/bin/pt-variable-advisor"; my $dp = new DSNParser(opts=>$dsn_opts); my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); -my $dbh = $sb->get_dbh_for('master'); +my $dbh = $sb->get_dbh_for('source'); if ( !$dbh ) { - plan skip_all => "Cannot connect to sandbox master"; + plan skip_all => "Cannot connect to sandbox source"; } else { plan tests => 3; diff --git a/t/pt-variable-advisor/show_variables_static.t b/t/pt-variable-advisor/show_variables_static.t index 28266795..e31669dc 100644 --- a/t/pt-variable-advisor/show_variables_static.t +++ b/t/pt-variable-advisor/show_variables_static.t @@ -73,7 +73,7 @@ my ($output) = full_output(sub { like( $output, - qr/\Qdual-master or ring replication configuration?\E$/sm, + qr/\Qdual-source or ring replication configuration?\E$/sm, "Sentences are delimited by . or ?" );