mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-19 08:56:34 +00:00
Add Cxn::is_cluster_node(). Add /*!99997*/ to SELECT..INSERT if the master is a cluster ndoe.
This commit is contained in:
@@ -1436,14 +1436,15 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
dsn => $dsn,
|
dsn => $dsn,
|
||||||
dbh => $args{dbh},
|
dbh => $args{dbh},
|
||||||
dsn_name => $dp->as_string($dsn, [qw(h P S)]),
|
dsn_name => $dp->as_string($dsn, [qw(h P S)]),
|
||||||
hostname => '',
|
hostname => '',
|
||||||
set => $args{set},
|
set => $args{set},
|
||||||
dbh_set => 0,
|
dbh_set => 0,
|
||||||
OptionParser => $o,
|
is_cluster_node => undef,
|
||||||
DSNParser => $dp,
|
OptionParser => $o,
|
||||||
|
DSNParser => $dp,
|
||||||
};
|
};
|
||||||
|
|
||||||
return bless $self, $class;
|
return bless $self, $class;
|
||||||
@@ -1513,6 +1514,19 @@ sub name {
|
|||||||
return $self->{hostname} || $self->{dsn_name} || 'unknown host';
|
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 {
|
sub DESTROY {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
if ( $self->{dbh}
|
if ( $self->{dbh}
|
||||||
@@ -6499,6 +6513,7 @@ sub main {
|
|||||||
my $master_dbh = $master_cxn->dbh(); # just for brevity
|
my $master_dbh = $master_cxn->dbh(); # just for brevity
|
||||||
my $master_dsn = $master_cxn->dsn(); # just for brevity
|
my $master_dsn = $master_cxn->dsn(); # just for brevity
|
||||||
|
|
||||||
|
|
||||||
# ########################################################################
|
# ########################################################################
|
||||||
# If this is not a dry run (--explain was not specified), then we're
|
# 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
|
# going to checksum the tables, so do the necessary preparations and
|
||||||
@@ -6539,6 +6554,12 @@ sub main {
|
|||||||
);
|
);
|
||||||
PTDEBUG && _d(scalar @$slaves, 'slaves found');
|
PTDEBUG && _d(scalar @$slaves, 'slaves found');
|
||||||
|
|
||||||
|
if ( $master_cxn->is_cluster_node() && !@$slaves ) {
|
||||||
|
die $master_cxn->name() . " is a cluster node but no other nodes "
|
||||||
|
. "or regular replicas were found. Use --recursion-method=dsn "
|
||||||
|
. "to specify the other nodes in the cluster.\n";
|
||||||
|
}
|
||||||
|
|
||||||
if ( $o->get('check-slave-lag') ) {
|
if ( $o->get('check-slave-lag') ) {
|
||||||
PTDEBUG && _d('Will use --check-slave-lag to check for slave lag');
|
PTDEBUG && _d('Will use --check-slave-lag to check for slave lag');
|
||||||
my $cxn = $make_cxn->(
|
my $cxn = $make_cxn->(
|
||||||
@@ -6744,7 +6765,9 @@ sub main {
|
|||||||
my $checksum_dml = "REPLACE INTO $repl_table "
|
my $checksum_dml = "REPLACE INTO $repl_table "
|
||||||
. "(db, tbl, chunk, chunk_index,"
|
. "(db, tbl, chunk, chunk_index,"
|
||||||
. " lower_boundary, upper_boundary, this_cnt, this_crc) "
|
. " lower_boundary, upper_boundary, this_cnt, this_crc) "
|
||||||
. "SELECT ?, ?, ?, ?, ?, ?,";
|
. "SELECT "
|
||||||
|
. ($master_cxn->is_cluster_node() ? '/*!99997*/' : '')
|
||||||
|
. " ?, ?, ?, ?, ?, ?,";
|
||||||
my $past_cols = " COUNT(*), '0'";
|
my $past_cols = " COUNT(*), '0'";
|
||||||
|
|
||||||
# ########################################################################
|
# ########################################################################
|
||||||
|
30
lib/Cxn.pm
30
lib/Cxn.pm
@@ -98,14 +98,15 @@ sub new {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $self = {
|
my $self = {
|
||||||
dsn => $dsn,
|
dsn => $dsn,
|
||||||
dbh => $args{dbh},
|
dbh => $args{dbh},
|
||||||
dsn_name => $dp->as_string($dsn, [qw(h P S)]),
|
dsn_name => $dp->as_string($dsn, [qw(h P S)]),
|
||||||
hostname => '',
|
hostname => '',
|
||||||
set => $args{set},
|
set => $args{set},
|
||||||
dbh_set => 0,
|
dbh_set => 0,
|
||||||
OptionParser => $o,
|
is_cluster_node => undef,
|
||||||
DSNParser => $dp,
|
OptionParser => $o,
|
||||||
|
DSNParser => $dp,
|
||||||
};
|
};
|
||||||
|
|
||||||
return bless $self, $class;
|
return bless $self, $class;
|
||||||
@@ -193,6 +194,19 @@ sub name {
|
|||||||
return $self->{hostname} || $self->{dsn_name} || 'unknown host';
|
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 {
|
sub DESTROY {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
if ( $self->{dbh}
|
if ( $self->{dbh}
|
||||||
|
Reference in New Issue
Block a user