mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-17 17:27:57 +00:00
Handle MySQL instance ID for MySQL 5.0.
This commit is contained in:
@@ -307,10 +307,31 @@ sub _generate_identifier {
|
|||||||
my $dbh = $instance->{dbh};
|
my $dbh = $instance->{dbh};
|
||||||
my $dsn = $instance->{dsn};
|
my $dsn = $instance->{dsn};
|
||||||
|
|
||||||
my $sql = q{SELECT CONCAT(@@hostname, @@port)};
|
# MySQL 5.1+ has @@hostname and @@port
|
||||||
|
# MySQL 5.0 has @@hostname but port only in SHOW VARS
|
||||||
|
# MySQL 4.x has nothing, so we use the dsn
|
||||||
|
my $sql = q{SELECT CONCAT(@@hostname, @@port)};
|
||||||
|
PTDEBUG && _d($sql);
|
||||||
my ($name) = eval { $dbh->selectrow_array($sql) };
|
my ($name) = eval { $dbh->selectrow_array($sql) };
|
||||||
if ( $EVAL_ERROR ) { # assume that it's MySQL 4.x
|
if ( $EVAL_ERROR ) {
|
||||||
$name = ($dsn->{h} || 'localhost') . ($dsn->{P} || 3306);
|
# MySQL 4.x or 5.0
|
||||||
|
PTDEBUG && _d($EVAL_ERROR);
|
||||||
|
$sql = q{SELECT @@hostname};
|
||||||
|
PTDEBUG && _d($sql);
|
||||||
|
($name) = eval { $dbh->selectrow_array($sql) };
|
||||||
|
if ( $EVAL_ERROR ) {
|
||||||
|
# MySQL 4.x
|
||||||
|
PTDEBUG && _d($EVAL_ERROR);
|
||||||
|
$name = ($dsn->{h} || 'localhost') . ($dsn->{P} || 3306);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
# MySQL 5.0
|
||||||
|
$sql = q{SHOW VARIABLES LIKE 'port'};
|
||||||
|
PTDEBUG && _d($sql);
|
||||||
|
my (undef, $port) = eval { $dbh->selectrow_array($sql) };
|
||||||
|
PTDEBUG && _d('port:', $port);
|
||||||
|
$name .= $port || '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
my $id = md5_hex($name);
|
my $id = md5_hex($name);
|
||||||
|
|
||||||
|
@@ -35,11 +35,10 @@ if ( $master_dbh ) {
|
|||||||
(undef, $mysql_distro)
|
(undef, $mysql_distro)
|
||||||
= $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version_comment'");
|
= $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version_comment'");
|
||||||
|
|
||||||
my $sql = q{SELECT CONCAT(@@hostname, @@port)};
|
(undef, $master_id) = Pingback::_generate_identifier(
|
||||||
my ($name) = $master_dbh->selectrow_array($sql);
|
{ dbh => $master_dbh, dsn => { h => '127.1', P => 12345 }});
|
||||||
$master_id = md5_hex($name);
|
(undef, $slave1_id) = Pingback::_generate_identifier(
|
||||||
|
{ dbh => $slave1_dbh, dsn => { h => '127.1', P => 12346 }});
|
||||||
(undef, $slave1_id) = Pingback::_generate_identifier( { dbh => $slave1_dbh } );
|
|
||||||
|
|
||||||
$master_inst = {
|
$master_inst = {
|
||||||
id => $master_id,
|
id => $master_id,
|
||||||
@@ -283,12 +282,28 @@ is(
|
|||||||
|
|
||||||
SKIP: {
|
SKIP: {
|
||||||
skip 'Cannot connect to sandbox master', 2 unless $master_dbh;
|
skip 'Cannot connect to sandbox master', 2 unless $master_dbh;
|
||||||
skip 'Requires MySQL 5.0.38 or newer', unless $sandbox_version ge '5.0.38';
|
|
||||||
|
|
||||||
|
my $expect_master_id;
|
||||||
|
if ( $sandbox_version ge '5.1' ) {
|
||||||
|
my $sql = q{SELECT CONCAT(@@hostname, @@port)};
|
||||||
|
my ($name) = $master_dbh->selectrow_array($sql);
|
||||||
|
$expect_master_id = md5_hex($name);
|
||||||
|
}
|
||||||
|
elsif ( $sandbox_version eq '5.0' ) {
|
||||||
|
my $sql = q{SELECT @@hostname};
|
||||||
|
my ($hostname) = $master_dbh->selectrow_array($sql);
|
||||||
|
$sql = q{SHOW VARIABLES LIKE 'port'};
|
||||||
|
my (undef, $port) = $master_dbh->selectrow_array($sql);
|
||||||
|
$expect_master_id = md5_hex($hostname . $port);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$expect_master_id = md5_hex("localhost", 12345);
|
||||||
|
}
|
||||||
|
|
||||||
is(
|
is(
|
||||||
Pingback::_generate_identifier( { dbh => $master_dbh, dsn => undef } ),
|
|
||||||
$master_id,
|
$master_id,
|
||||||
"_generate_identifier() works with a dbh"
|
$expect_master_id,
|
||||||
|
"_generate_identifier() for MySQL $sandbox_version"
|
||||||
);
|
);
|
||||||
|
|
||||||
# The time limit file already exists (see previous tests), but this is
|
# The time limit file already exists (see previous tests), but this is
|
||||||
|
Reference in New Issue
Block a user