merged pt-table-checksum-refuses-to-run-on-PXC-if-server_id-is-the-same-on-all-nodes-1217466

This commit is contained in:
Frank Cizmich
2014-11-06 19:38:59 -02:00
10 changed files with 319 additions and 72 deletions

View File

@@ -226,6 +226,19 @@ sub name {
return $self->{hostname} || $self->{dsn_name} || 'unknown host';
}
# This is used to help remove_duplicate_cxns detect cluster nodes
# (which often have unreliable server_id's)
sub is_cluster_node {
my ($self, $cxn) = @_;
my $sql = "SHOW VARIABLES LIKE 'wsrep\_on'";
PTDEBUG && _d($cxn->name, $sql);
my $row = $cxn->dbh->selectrow_arrayref($sql);
PTDEBUG && _d(Dumper($row));
return $row && $row->[1] && ($row->[1] eq 'ON' || $row->[1] eq '1') ? 1 : 0;
}
# There's two reasons why there might be dupes:
# If the "master" is a cluster node, then a DSN table might have been
# used, and it may have all nodes' DSNs so the user can run the tool
@@ -233,7 +246,7 @@ sub name {
# on the command line.
# On the other hand, maybe find_cluster_nodes worked, in which case
# we definitely have a dupe for the master cxn, but we may also have a
# dupe for every other node if this was unsed in conjunction with a
# dupe for every other node if this was used in conjunction with a
# DSN table.
# So try to detect and remove those.
sub remove_duplicate_cxns {
@@ -245,7 +258,11 @@ sub remove_duplicate_cxns {
for my $cxn ( @cxns ) {
my $dbh = $cxn->dbh();
my $sql = q{SELECT @@server_id};
# Very often cluster nodes are configured with matching server_id's
# So in that case we'll use its incoming address as its unique identifier
# Note: this relies on "seen_ids" being populated using the same strategy
my $sql = $self->is_cluster_node($cxn) ? q{SELECT @@wsrep_node_incoming_address} : q{SELECT @@server_id};
PTDEBUG && _d($sql);
my ($id) = $dbh->selectrow_array($sql);
PTDEBUG && _d('Server ID for ', $cxn->name, ': ', $id);

View File

@@ -132,8 +132,29 @@ sub find_cluster_nodes {
sub remove_duplicate_cxns {
my ($self, %args) = @_;
my @cxns = @{$args{cxns}};
my $seen_ids = $args{seen_ids};
return Cxn->remove_duplicate_cxns(%args);
my $seen_ids = $args{seen_ids} || {};
PTDEBUG && _d("Removing duplicates nodes from ", join(" ", map { $_->name } @cxns));
my @trimmed_cxns;
for my $cxn ( @cxns ) {
my $dbh = $cxn->dbh();
# Very often cluster nodes are configured with matching server_id's
# So in that case we'll use its incoming address as its unique identifier
# Note: This relies on "seen_ids" being populated using the same strategy
my $sql = $self->is_cluster_node($cxn) ? q{SELECT @@wsrep_node_incoming_address} : q{SELECT @@server_id};
PTDEBUG && _d($sql);
my ($id) = $dbh->selectrow_array($sql);
PTDEBUG && _d('Server ID for ', $cxn->name, ': ', $id);
if ( ! $seen_ids->{$id}++ ) {
push @trimmed_cxns, $cxn
}
else {
PTDEBUG && _d("Removing ", $cxn->name,
", ID ", $id, ", because we've already seen it");
}
}
return \@trimmed_cxns;
}
sub same_cluster {