mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-02 02:34:19 +00:00
Moved the PXC-dealing parts of Cxn.pm into Percona::XtraDB::Cluster
This commit is contained in:
@@ -1568,19 +1568,6 @@ sub name {
|
||||
return $self->{hostname} || $self->{dsn_name} || 'unknown host';
|
||||
}
|
||||
|
||||
sub is_cluster_node {
|
||||
my ($self) = @_;
|
||||
return $self->{is_cluster_node} if defined $self->{is_cluster_node};
|
||||
|
||||
my $sql = "SHOW VARIABLES LIKE 'wsrep_on'";
|
||||
PTDEBUG && _d($sql);
|
||||
my $row = $self->{dbh}->selectrow_arrayref($sql);
|
||||
PTDEBUG && _d(defined $row ? @$row : 'undef');
|
||||
$self->{is_cluster_node} = $row && $row->[0] ? 1 : 0;
|
||||
|
||||
return $self->{is_cluster_node};
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
if ( $self->{dbh}
|
||||
|
13
bin/pt-kill
13
bin/pt-kill
@@ -4832,19 +4832,6 @@ sub name {
|
||||
return $self->{hostname} || $self->{dsn_name} || 'unknown host';
|
||||
}
|
||||
|
||||
sub is_cluster_node {
|
||||
my ($self) = @_;
|
||||
return $self->{is_cluster_node} if defined $self->{is_cluster_node};
|
||||
|
||||
my $sql = "SHOW VARIABLES LIKE 'wsrep_on'";
|
||||
PTDEBUG && _d($sql);
|
||||
my $row = $self->{dbh}->selectrow_arrayref($sql);
|
||||
PTDEBUG && _d(defined $row ? @$row : 'undef');
|
||||
$self->{is_cluster_node} = $row && $row->[0] ? 1 : 0;
|
||||
|
||||
return $self->{is_cluster_node};
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
if ( $self->{dbh}
|
||||
|
@@ -3462,19 +3462,6 @@ sub name {
|
||||
return $self->{hostname} || $self->{dsn_name} || 'unknown host';
|
||||
}
|
||||
|
||||
sub is_cluster_node {
|
||||
my ($self) = @_;
|
||||
return $self->{is_cluster_node} if defined $self->{is_cluster_node};
|
||||
|
||||
my $sql = "SHOW VARIABLES LIKE 'wsrep_on'";
|
||||
PTDEBUG && _d($sql);
|
||||
my $row = $self->{dbh}->selectrow_arrayref($sql);
|
||||
PTDEBUG && _d(defined $row ? @$row : 'undef');
|
||||
$self->{is_cluster_node} = $row && $row->[0] ? 1 : 0;
|
||||
|
||||
return $self->{is_cluster_node};
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
if ( $self->{dbh}
|
||||
|
@@ -21,6 +21,7 @@ BEGIN {
|
||||
OptionParser
|
||||
Mo
|
||||
Cxn
|
||||
Percona::XtraDB::Cluster
|
||||
Quoter
|
||||
VersionParser
|
||||
TableParser
|
||||
@@ -3322,84 +3323,6 @@ sub name {
|
||||
return $self->{hostname} || $self->{dsn_name} || 'unknown host';
|
||||
}
|
||||
|
||||
sub is_cluster_node {
|
||||
my ($self) = @_;
|
||||
return $self->{is_cluster_node} if defined $self->{is_cluster_node};
|
||||
|
||||
my $sql = "SHOW VARIABLES LIKE 'wsrep_on'";
|
||||
PTDEBUG && _d($sql);
|
||||
my $row = $self->{dbh}->selectrow_arrayref($sql);
|
||||
PTDEBUG && _d(defined $row ? @$row : 'undef');
|
||||
$self->{is_cluster_node} = $row && $row->[1]
|
||||
? ($row->[1] eq 'ON' || $row->[1] eq '1')
|
||||
: 0;
|
||||
|
||||
return $self->{is_cluster_node};
|
||||
}
|
||||
|
||||
sub same_cluster {
|
||||
my ($self, $cxn) = @_;
|
||||
return unless $self->is_cluster_node() && $cxn->is_cluster_node();
|
||||
return if $self->is_master_of($cxn) || $cxn->is_master_of($self);
|
||||
|
||||
my $sql = q{SHOW VARIABLES LIKE 'wsrep_cluster_name'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $row) = $self->dbh->selectrow_array($sql);
|
||||
my (undef, $cxn_row) = $cxn->dbh->selectrow_array($sql);
|
||||
|
||||
return unless $row eq $cxn_row;
|
||||
|
||||
$sql = q{SHOW VARIABLES LIKE 'wsrep_cluster_address'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $addr) = $self->dbh->selectrow_array($sql);
|
||||
my (undef, $cxn_addr) = $cxn->dbh->selectrow_array($sql);
|
||||
|
||||
return if $addr eq 'gcomm://' && $cxn_addr eq 'gcomm://';
|
||||
|
||||
if ( $addr eq 'gcomm://' ) {
|
||||
$addr = $self->_find_full_gcomm_addr($self->dbh);
|
||||
}
|
||||
elsif ( $cxn_addr eq 'gcomm://' ) {
|
||||
$cxn_addr = $self->_find_full_gcomm_addr($cxn->dbh);
|
||||
}
|
||||
|
||||
return 1 if $addr eq $cxn_addr;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub is_master_of {
|
||||
my ($self, $cxn) = @_;
|
||||
|
||||
my $cxn_dbh = $cxn->dbh;
|
||||
local $cxn_dbh->{FetchHashKeyName} = 'NAME_lc';
|
||||
my $sql = q{SHOW SLAVE STATUS};
|
||||
PTDEBUG && _d($sql);
|
||||
my $slave_status = $cxn_dbh->selectrow_hashref($sql);
|
||||
return unless ref($slave_status) eq 'HASH';
|
||||
|
||||
my $port = $self->dsn->{P};
|
||||
return unless $slave_status->{master_port} eq $port;
|
||||
return 1 if $self->dsn->{h} eq $slave_status->{master_host};
|
||||
|
||||
my $host = scalar gethostbyname($self->dsn->{h});
|
||||
my $master_host = scalar gethostbyname($slave_status->{master_host});
|
||||
return 1 if $master_host eq $host;
|
||||
return;
|
||||
}
|
||||
|
||||
sub _find_full_gcomm_addr {
|
||||
my ($self, $dbh) = @_;
|
||||
|
||||
my $sql = q{SHOW VARIABLES LIKE 'wsrep_provider_options'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $provider_opts) = $dbh->selectrow_array($sql);
|
||||
my ($prov_addr) = $provider_opts =~ m{\Qgmcast.listen_addr\E\s*=\s*tcp://([^:]+:[0-9]+)\s*;};
|
||||
my $full_gcomm = "gcomm://$prov_addr";
|
||||
PTDEBUG && _d("gcomm address: ", $full_gcomm);
|
||||
return $full_gcomm;
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
if ( $self->{dbh}
|
||||
@@ -3425,6 +3348,104 @@ sub _d {
|
||||
# End Cxn package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# Percona::XtraDB::Cluster package
|
||||
# This package is a copy without comments from the original. The original
|
||||
# with comments and its test file can be found in the Bazaar repository at,
|
||||
# lib/Percona/XtraDB/Cluster.pm
|
||||
# t/lib/Percona/XtraDB/Cluster.t
|
||||
# See https://launchpad.net/percona-toolkit for more information.
|
||||
# ###########################################################################
|
||||
{
|
||||
|
||||
package Percona::XtraDB::Cluster;
|
||||
use Mo;
|
||||
use constant PTDEBUG => $ENV{PTDEBUG} || 0;
|
||||
|
||||
sub is_cluster_node {
|
||||
my ($self, $cxn) = @_;
|
||||
return $self->{is_cluster_node}->{$cxn} if defined $self->{is_cluster_node}->{$cxn};
|
||||
|
||||
my $sql = "SHOW VARIABLES LIKE 'wsrep_on'";
|
||||
PTDEBUG && _d($sql);
|
||||
my $row = $cxn->dbh->selectrow_arrayref($sql);
|
||||
PTDEBUG && _d(defined $row ? @$row : 'undef');
|
||||
$self->{is_cluster_node}->{$cxn} = $row && $row->[1]
|
||||
? ($row->[1] eq 'ON' || $row->[1] eq '1')
|
||||
: 0;
|
||||
|
||||
return $self->{is_cluster_node}->{$cxn};
|
||||
}
|
||||
|
||||
sub same_cluster {
|
||||
my ($self, $cxn1, $cxn2) = @_;
|
||||
return unless $self->is_cluster_node($cxn1) && $self->is_cluster_node($cxn2);
|
||||
return if $self->is_master_of($cxn1, $cxn2) || $self->is_master_of($cxn2, $cxn1);
|
||||
|
||||
my $sql = q{SHOW VARIABLES LIKE 'wsrep_cluster_name'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $row) = $cxn1->dbh->selectrow_array($sql);
|
||||
my (undef, $cxn2_row) = $cxn2->dbh->selectrow_array($sql);
|
||||
|
||||
return unless $row eq $cxn2_row;
|
||||
|
||||
$sql = q{SHOW VARIABLES LIKE 'wsrep_cluster_address'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $addr) = $cxn1->dbh->selectrow_array($sql);
|
||||
my (undef, $cxn2_addr) = $cxn2->dbh->selectrow_array($sql);
|
||||
|
||||
return if $addr eq 'gcomm://' && $cxn2_addr eq 'gcomm://';
|
||||
|
||||
if ( $addr eq 'gcomm://' ) {
|
||||
$addr = $self->_find_full_gcomm_addr($cxn1->dbh);
|
||||
}
|
||||
elsif ( $cxn2_addr eq 'gcomm://' ) {
|
||||
$cxn2_addr = $self->_find_full_gcomm_addr($cxn2->dbh);
|
||||
}
|
||||
|
||||
return 1 if lc($addr) eq lc($cxn2_addr);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub is_master_of {
|
||||
my ($self, $cxn1, $cxn2) = @_;
|
||||
|
||||
my $cxn2_dbh = $cxn2->dbh;
|
||||
my $sql = q{SHOW SLAVE STATUS};
|
||||
PTDEBUG && _d($sql);
|
||||
local $cxn2_dbh->{FetchHashKeyName} = 'NAME_lc';
|
||||
my $slave_status = $cxn2_dbh->selectrow_hashref($sql);
|
||||
return unless ref($slave_status) eq 'HASH';
|
||||
|
||||
my $port = $cxn1->dsn->{P};
|
||||
return unless $slave_status->{master_port} eq $port;
|
||||
return 1 if $cxn1->dsn->{h} eq $slave_status->{master_host};
|
||||
|
||||
my $host = scalar gethostbyname($cxn1->dsn->{h});
|
||||
my $master_host = scalar gethostbyname($slave_status->{master_host});
|
||||
return 1 if $master_host eq $host;
|
||||
return;
|
||||
}
|
||||
|
||||
sub _find_full_gcomm_addr {
|
||||
my ($self, $dbh) = @_;
|
||||
|
||||
my $sql = q{SHOW VARIABLES LIKE 'wsrep_provider_options'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $provider_opts) = $dbh->selectrow_array($sql);
|
||||
my ($prov_addr) = $provider_opts =~ m{\Qgmcast.listen_addr\E\s*=\s*tcp://([^:]+:[0-9]+)\s*;}i;
|
||||
my $full_gcomm = "gcomm://$prov_addr";
|
||||
PTDEBUG && _d("gcomm address: ", $full_gcomm);
|
||||
return $full_gcomm;
|
||||
}
|
||||
|
||||
1;
|
||||
}
|
||||
# ###########################################################################
|
||||
# End Percona::XtraDB::Cluster package
|
||||
# ###########################################################################
|
||||
|
||||
# ###########################################################################
|
||||
# Quoter package
|
||||
# This package is a copy without comments from the original. The original
|
||||
@@ -8618,6 +8639,9 @@ sub main {
|
||||
$have_time = sub { return 1; };
|
||||
}
|
||||
|
||||
# PXC helper class
|
||||
my $cluster = Percona::XtraDB::Cluster->new();
|
||||
|
||||
# ########################################################################
|
||||
# If this is not a dry run (--explain was not specified), then we're
|
||||
# going to checksum the tables, so do the necessary preparations and
|
||||
@@ -8659,7 +8683,7 @@ sub main {
|
||||
);
|
||||
PTDEBUG && _d(scalar @$slaves, 'slaves found');
|
||||
|
||||
if ( $master_cxn->is_cluster_node() ) {
|
||||
if ( $cluster->is_cluster_node($master_cxn) ) {
|
||||
if ( !@$slaves ) {
|
||||
die $master_cxn->name() . " is a cluster node but no other nodes "
|
||||
. "or regular replicas were found. Use --recursion-method=dsn "
|
||||
@@ -8668,8 +8692,8 @@ sub main {
|
||||
else {
|
||||
my $err = '';
|
||||
for my $slave (@$slaves) {
|
||||
if ( $slave->is_cluster_node()
|
||||
&& !$slave->same_cluster($master_cxn) ) {
|
||||
if ( $cluster->is_cluster_node($slave)
|
||||
&& !$cluster->same_cluster($slave, $master_cxn) ) {
|
||||
$err .= $slave->name() . " is a cluster node, but doesn't "
|
||||
. "belong to the same cluster as " . $master_cxn->name()
|
||||
. ". This is not currently supported; You can try "
|
||||
@@ -8683,7 +8707,7 @@ sub main {
|
||||
elsif ( @$slaves ) {
|
||||
my $err = '';
|
||||
for my $slave (@$slaves) {
|
||||
if ( $slave->is_cluster_node() ) {
|
||||
if ( $cluster->is_cluster_node($slave) ) {
|
||||
$err .= $slave->name() . " is a cluster node, but "
|
||||
. $master_cxn->name() . " is not. This is not currently "
|
||||
. "supported; You can try to specify "
|
||||
@@ -8713,8 +8737,8 @@ sub main {
|
||||
# to appear should be sufficient.
|
||||
@$slave_lag_cxns = grep {
|
||||
my $slave_cxn = $_;
|
||||
if ( $slave_cxn->is_cluster_node()
|
||||
&& $master_cxn->same_cluster($slave_cxn) ) {
|
||||
if ( $cluster->is_cluster_node($slave_cxn)
|
||||
&& $cluster->same_cluster($master_cxn, $slave_cxn) ) {
|
||||
warn "Not checking replica lag on " . $slave_cxn->name()
|
||||
. " because it is a cluster node.\n";
|
||||
0;
|
||||
@@ -8929,7 +8953,7 @@ sub main {
|
||||
. "(db, tbl, chunk, chunk_index,"
|
||||
. " lower_boundary, upper_boundary, this_cnt, this_crc) "
|
||||
. "SELECT"
|
||||
. ($master_cxn->is_cluster_node() ? ' /*!99997*/' : '')
|
||||
. ($cluster->is_cluster_node($master_cxn) ? ' /*!99997*/' : '')
|
||||
. " ?, ?, ?, ?, ?, ?,";
|
||||
my $past_cols = " COUNT(*), '0'";
|
||||
|
||||
|
102
lib/Cxn.pm
102
lib/Cxn.pm
@@ -46,15 +46,6 @@ use constant {
|
||||
PERCONA_TOOLKIT_TEST_USE_DSN_NAMES => $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} || 0,
|
||||
};
|
||||
|
||||
use Data::Dumper ();
|
||||
sub Dumper {
|
||||
local $Data::Dumper::Indent = 1;
|
||||
local $Data::Dumper::Sortkeys = 1;
|
||||
local $Data::Dumper::Quotekeys = 0;
|
||||
|
||||
Data::Dumper::Dumper(@_);
|
||||
}
|
||||
|
||||
# Sub: new
|
||||
#
|
||||
# Required Arguments:
|
||||
@@ -205,99 +196,6 @@ sub name {
|
||||
return $self->{hostname} || $self->{dsn_name} || 'unknown host';
|
||||
}
|
||||
|
||||
sub is_cluster_node {
|
||||
my ($self) = @_;
|
||||
return $self->{is_cluster_node} if defined $self->{is_cluster_node};
|
||||
|
||||
my $sql = "SHOW VARIABLES LIKE 'wsrep_on'";
|
||||
PTDEBUG && _d($sql);
|
||||
my $row = $self->{dbh}->selectrow_arrayref($sql);
|
||||
PTDEBUG && _d(defined $row ? @$row : 'undef');
|
||||
$self->{is_cluster_node} = $row && $row->[1]
|
||||
? ($row->[1] eq 'ON' || $row->[1] eq '1')
|
||||
: 0;
|
||||
|
||||
return $self->{is_cluster_node};
|
||||
}
|
||||
|
||||
sub same_cluster {
|
||||
my ($self, $cxn) = @_;
|
||||
return unless $self->is_cluster_node() && $cxn->is_cluster_node();
|
||||
return if $self->is_master_of($cxn) || $cxn->is_master_of($self);
|
||||
|
||||
my $sql = q{SHOW VARIABLES LIKE 'wsrep_cluster_name'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $row) = $self->dbh->selectrow_array($sql);
|
||||
my (undef, $cxn_row) = $cxn->dbh->selectrow_array($sql);
|
||||
|
||||
return unless $row eq $cxn_row;
|
||||
|
||||
# Now it becomes tricky. Ostensibly clusters shouldn't have the
|
||||
# same name, but tell that to the world.
|
||||
$sql = q{SHOW VARIABLES LIKE 'wsrep_cluster_address'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $addr) = $self->dbh->selectrow_array($sql);
|
||||
my (undef, $cxn_addr) = $cxn->dbh->selectrow_array($sql);
|
||||
|
||||
# If they both have gcomm://, then they are both the first
|
||||
# node of a cluster, so they can't be in the same one.
|
||||
return if $addr eq 'gcomm://' && $cxn_addr eq 'gcomm://';
|
||||
|
||||
if ( $addr eq 'gcomm://' ) {
|
||||
$addr = $self->_find_full_gcomm_addr($self->dbh);
|
||||
}
|
||||
elsif ( $cxn_addr eq 'gcomm://' ) {
|
||||
$cxn_addr = $self->_find_full_gcomm_addr($cxn->dbh);
|
||||
}
|
||||
|
||||
# Meanwhile, if they have the same address, then
|
||||
# they are definitely part of the same cluster
|
||||
return 1 if $addr eq $cxn_addr;
|
||||
|
||||
# However, this still leaves us with the issue that
|
||||
# the cluster addresses could look like this:
|
||||
# node1 -> node2, node2 -> node1,
|
||||
# or
|
||||
# node1 -> node2 addr,
|
||||
# node2 -> node3 addr,
|
||||
# node3 -> node1 addr,
|
||||
# TODO No clue what to do here
|
||||
return 1;
|
||||
}
|
||||
|
||||
sub is_master_of {
|
||||
my ($self, $cxn) = @_;
|
||||
|
||||
my $cxn_dbh = $cxn->dbh;
|
||||
local $cxn_dbh->{FetchHashKeyName} = 'NAME_lc';
|
||||
my $sql = q{SHOW SLAVE STATUS};
|
||||
PTDEBUG && _d($sql);
|
||||
my $slave_status = $cxn_dbh->selectrow_hashref($sql);
|
||||
return unless ref($slave_status) eq 'HASH';
|
||||
|
||||
my $port = $self->dsn->{P};
|
||||
return unless $slave_status->{master_port} eq $port;
|
||||
return 1 if $self->dsn->{h} eq $slave_status->{master_host};
|
||||
|
||||
# They might be the same but in different format
|
||||
my $host = scalar gethostbyname($self->dsn->{h});
|
||||
my $master_host = scalar gethostbyname($slave_status->{master_host});
|
||||
return 1 if $master_host eq $host;
|
||||
return;
|
||||
}
|
||||
|
||||
sub _find_full_gcomm_addr {
|
||||
my ($self, $dbh) = @_;
|
||||
|
||||
my $sql = q{SHOW VARIABLES LIKE 'wsrep_provider_options'};
|
||||
PTDEBUG && _d($sql);
|
||||
my (undef, $provider_opts) = $dbh->selectrow_array($sql);
|
||||
my ($prov_addr) = $provider_opts =~ m{\Qgmcast.listen_addr\E\s*=\s*tcp://([^:]+:[0-9]+)\s*;};
|
||||
my $full_gcomm = "gcomm://$prov_addr";
|
||||
PTDEBUG && _d("gcomm address: ", $full_gcomm);
|
||||
return $full_gcomm;
|
||||
}
|
||||
|
||||
sub DESTROY {
|
||||
my ($self) = @_;
|
||||
if ( $self->{dbh}
|
||||
|
143
t/lib/Cxn.t
143
t/lib/Cxn.t
@@ -248,149 +248,6 @@ is_deeply(
|
||||
"Default cxn inherits default connection options"
|
||||
);
|
||||
|
||||
@ARGV = ();
|
||||
$o->get_opts();
|
||||
|
||||
diag("Starting master1");
|
||||
$sb->start_sandbox("master", "master1");
|
||||
|
||||
$cxn = make_cxn( dsn_string => $sb->dsn_for("master1") );
|
||||
$cxn->connect();
|
||||
ok(
|
||||
!$cxn->is_cluster_node(),
|
||||
"is_cluster_node works correctly for non-nodes"
|
||||
);
|
||||
|
||||
my $db_flavor = VersionParser->new($master_dbh)->flavor();
|
||||
SKIP: {
|
||||
skip "PXC-only test", 17
|
||||
unless $db_flavor =~ /XtraDB Cluster/;
|
||||
|
||||
diag("Starting a 1-node PXC");
|
||||
my ($node) = $sb->start_cluster(cluster_size => 1);
|
||||
|
||||
my $cxn1 = make_cxn( dsn_string => $sb->dsn_for($node) );
|
||||
$cxn1->connect();
|
||||
ok(
|
||||
$cxn1->is_cluster_node(),
|
||||
"is_cluster_node works correctly for cluster nodes"
|
||||
);
|
||||
|
||||
ok(
|
||||
!$cxn->is_master_of($cxn1),
|
||||
"->is_master_of works correctly for a server unrelated to a cluster"
|
||||
);
|
||||
|
||||
diag("Setting node as a slave of master1");
|
||||
$sb->set_as_slave($node, "master1");
|
||||
ok(
|
||||
$cxn->is_master_of($cxn1),
|
||||
"->is_master_of works correctly for master -> cluster"
|
||||
);
|
||||
ok(
|
||||
!$cxn1->is_master_of($cxn),
|
||||
"...and the inverse returns the expected result"
|
||||
);
|
||||
ok(
|
||||
!$cxn->same_cluster($cxn1),
|
||||
"->same_cluster works for master -> cluster"
|
||||
);
|
||||
diag("Restarting the cluster");
|
||||
diag($sb->stop_sandbox($node));
|
||||
($node) = $sb->start_cluster(cluster_size => 1);
|
||||
$cxn1 = make_cxn( dsn_string => $sb->dsn_for($node) );
|
||||
$cxn1->connect();
|
||||
|
||||
diag("Setting master1 as a slave of the node");
|
||||
$sb->set_as_slave("master1", $node);
|
||||
ok(
|
||||
$cxn1->is_master_of($cxn),
|
||||
"->is_master_of works correctly for cluster -> master"
|
||||
);
|
||||
ok(
|
||||
!$cxn->is_master_of($cxn1),
|
||||
"...and the inverse returns the expected result"
|
||||
);
|
||||
|
||||
ok(
|
||||
!$cxn1->same_cluster($cxn),
|
||||
"->same_cluster works for cluster -> master"
|
||||
);
|
||||
|
||||
diag("Starting a 2-node PXC");
|
||||
my ($node2, $node3) = $sb->start_cluster(cluster_size => 2);
|
||||
|
||||
my $cxn2 = make_cxn( dsn_string => $sb->dsn_for($node2) );
|
||||
$cxn2->connect();
|
||||
my $cxn3 = make_cxn( dsn_string => $sb->dsn_for($node3) );
|
||||
$cxn3->connect();
|
||||
ok(
|
||||
$cxn2->is_cluster_node(),
|
||||
"is_cluster_node correctly finds that this node is part of a cluster"
|
||||
);
|
||||
|
||||
ok(
|
||||
!$cxn1->same_cluster($cxn2),
|
||||
"and same_cluster correctly finds that they don't belong to the same cluster, even when they have the same cluster name"
|
||||
);
|
||||
|
||||
ok(
|
||||
$cxn2->same_cluster($cxn3),
|
||||
"...but does find that they are in the same cluster, even if one is node1"
|
||||
);
|
||||
|
||||
TODO: {
|
||||
local $::TODO = "Should detected that (cluster1.node1) (cluster2.node2) come from different clusters, but doesn't";
|
||||
ok(
|
||||
!$cxn1->same_cluster($cxn3),
|
||||
"...same_cluster works correctly when they have the same cluster names"
|
||||
);
|
||||
}
|
||||
|
||||
diag("Making the second cluster a slave of the first");
|
||||
$sb->set_as_slave($node2, $node);
|
||||
ok($cxn1->is_master_of($cxn2), "is_master_of works");
|
||||
|
||||
ok(
|
||||
!$cxn1->same_cluster($cxn2),
|
||||
"...same_cluster works correctly when they are cluster1.node1.master -> cluster2.node1.slave"
|
||||
);
|
||||
|
||||
diag($sb->stop_sandbox($node2, $node3));
|
||||
diag("Starting a 3-node cluster");
|
||||
my $node4;
|
||||
($node2, $node3, $node4)
|
||||
= $sb->start_cluster(
|
||||
cluster_size => 3,
|
||||
cluster_name => "pt_cxn_test",
|
||||
);
|
||||
$cxn2 = make_cxn( dsn_string => $sb->dsn_for($node2) );
|
||||
$cxn2->connect();
|
||||
$cxn3 = make_cxn( dsn_string => $sb->dsn_for($node3) );
|
||||
$cxn3->connect();
|
||||
my $cxn4 = make_cxn( dsn_string => $sb->dsn_for($node4) );
|
||||
$cxn4->connect();
|
||||
|
||||
ok(
|
||||
!$cxn1->same_cluster($cxn2),
|
||||
"...same_cluster works correctly when they have different cluster names & the are both gcomm"
|
||||
);
|
||||
|
||||
ok(
|
||||
!$cxn1->same_cluster($cxn3),
|
||||
"same_cluster detects that (cluster1.node1) (cluster2.node2) come from different clusters if they have different cluster_names"
|
||||
);
|
||||
|
||||
ok(
|
||||
$cxn2->same_cluster($cxn3),
|
||||
"sanity check: but still finds that nodes in the same cluster belong together"
|
||||
);
|
||||
|
||||
diag($sb->stop_sandbox($node, $node2, $node3, $node4));
|
||||
}
|
||||
|
||||
diag($sb->stop_sandbox("master1"));
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
|
@@ -21,12 +21,10 @@ $ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
use VersionParser;
|
||||
|
||||
# Fix @INC because pt-table-checksum uses subclass OobNibbleIterator.
|
||||
shift @INC; # our unshift (above)
|
||||
shift @INC; # PerconaTest's unshift
|
||||
require "$trunk/bin/pt-table-checksum";
|
||||
# Do this after requiring ptc, since it uses Mo
|
||||
require VersionParser;
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
|
Reference in New Issue
Block a user