mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-02 02:34:19 +00:00
PT-2156 Fix tests for lib (#606)
* PT-2156 - Fix tests for lib
- Fixed tests broken for lib/TableParser.pm after fix for PT-1059
- Updated tests for lib/TableParser.pm that are broken due to SHOW CREATE TABLE output format change in 8.0
- Updated modules for all tools that use lib/TableParser.pm
* Revert "Fixed pt-archiver tests"
This reverts commit a3ab87b12e
.
This commit wa needed, because removed code in sandbox/slave_channels.sql broked the test. Proper fix would be to do not remove channel names rather than chaging the test. So revertig it.
* PT-2156 - Fix tests for lib
- Updated test t/lib/TableChecksum.t so it reflects changes, introduced in the fix for PT-2016
- Updated test t/lib/RowChecksum.t so it reflects changes added to in the fix for PT-2138: UTF8 support
- Uncommented SQL in sandbox/slave_channels.sql that made t/lib/MasterSlave.t to fail
- Added check for undef into t/pt-archiver/archive_using_channels.t
- Updated lib/Cxn.pm so it uses $dbh->{Active} after issue with the ping() call, reported at https://github.com/perl5-dbi/DBD-mysql/issues/306
* PT-2156 - Fix tests for lib
- Impoved the fix for PT-2016, so it does not files with keys with USING keyword
- Added brackets to expression in lib/TableNibbler.pm, so it does not crap query wit many indexes with OR keyword
- Adjusted test t/lib/TableNibbler.t, so it reflects above chages
- Modified lib/Cxn.pm, so it has workaround for https://github.com/perl5-dbi/DBD-mysql/issues/306 , introduced in DBD::mysql 4.0.50
- Updated tests: added debugging code and cleanups
- Updated modules for tools
This commit is contained in:
50
lib/Cxn.pm
50
lib/Cxn.pm
@@ -123,7 +123,8 @@ sub connect {
|
||||
my $dp = $self->{DSNParser};
|
||||
|
||||
my $dbh = $self->{dbh};
|
||||
if ( !$dbh || !$dbh->ping() ) {
|
||||
# We cannot use $dbh->ping() here due to https://github.com/perl5-dbi/DBD-mysql/issues/306
|
||||
if ( !$dbh || ( $dbh && $self->{dbh_set} && !$self->_ping($dbh) ) ) {
|
||||
# Ask for password once.
|
||||
if ( $self->{ask_pass} && !$self->{asked_for_pass} && !defined $dsn->{p} ) {
|
||||
$dsn->{p} = OptionParser::prompt_noecho("Enter MySQL password: ");
|
||||
@@ -153,18 +154,6 @@ sub connect {
|
||||
sub set_dbh {
|
||||
my ($self, $dbh) = @_;
|
||||
|
||||
# If we already have a dbh, and that dbh is the same as this dbh,
|
||||
# and the dbh has already been set, then do not re-set the same
|
||||
# dbh. dbh_set is required so that if this obj was created with
|
||||
# a dbh, we set that dbh when connect() is called because whoever
|
||||
# created the dbh probably didn't set what we set here. For example,
|
||||
# MasterSlave makes dbhs when finding slaves, but it doesn't set
|
||||
# anything.
|
||||
if ( $self->{dbh} && $self->{dbh} == $dbh && $self->{dbh_set} ) {
|
||||
PTDEBUG && _d($dbh, 'Already set dbh');
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
PTDEBUG && _d($dbh, 'Setting dbh');
|
||||
|
||||
# Set stuff for this dbh (i.e. initialize it).
|
||||
@@ -172,10 +161,26 @@ sub set_dbh {
|
||||
|
||||
# Update the cxn's name. Until we connect, the DSN parts
|
||||
# h and P are used. Once connected, use @@hostname.
|
||||
my $sql = 'SELECT @@server_id /*!50038 , @@hostname*/';
|
||||
my $sql = 'SELECT @@server_id /*!50038 , @@hostname*/, CONNECTION_ID() as connection_id';
|
||||
PTDEBUG && _d($dbh, $sql);
|
||||
my ($server_id, $hostname) = $dbh->selectrow_array($sql);
|
||||
my ($server_id, $hostname, $connection_id) = $dbh->selectrow_array($sql);
|
||||
PTDEBUG && _d($dbh, 'hostname:', $hostname, $server_id);
|
||||
|
||||
# If we already have a dbh, and that dbh is the same as this dbh,
|
||||
# and the dbh has already been set, then do not re-set the same
|
||||
# dbh. dbh_set is required so that if this obj was created with
|
||||
# a dbh, we set that dbh when connect() is called because whoever
|
||||
# created the dbh probably didn't set what we set here. For example,
|
||||
# MasterSlave makes dbhs when finding slaves, but it doesn't set
|
||||
# anything.
|
||||
# Due to https://github.com/perl5-dbi/DBD-mysql/issues/306 we assigning
|
||||
# connection_id to $self->{dbh_set} and compare it with current connection_id.
|
||||
# This is required to set variable values again after disconnect.
|
||||
if ( $self->{dbh} && $self->{dbh} == $dbh && $self->{dbh_set} && $self->{dbh_set} == $connection_id) {
|
||||
PTDEBUG && _d($dbh, 'Already set dbh');
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
if ( $hostname ) {
|
||||
$self->{hostname} = $hostname;
|
||||
}
|
||||
@@ -191,7 +196,7 @@ sub set_dbh {
|
||||
}
|
||||
|
||||
$self->{dbh} = $dbh;
|
||||
$self->{dbh_set} = 1;
|
||||
$self->{dbh_set} = $connection_id;
|
||||
return $dbh;
|
||||
}
|
||||
|
||||
@@ -343,6 +348,19 @@ sub DESTROY {
|
||||
return;
|
||||
}
|
||||
|
||||
# We have to create a wrapper around $dbh->ping() here due to
|
||||
# https://github.com/perl5-dbi/DBD-mysql/issues/306
|
||||
sub _ping() {
|
||||
my ( $self, $dbh ) = @_;
|
||||
if (!$dbh->ping()) {
|
||||
return 0;
|
||||
}
|
||||
my $sql = 'SELECT CONNECTION_ID() as connection_id';
|
||||
PTDEBUG && _d($dbh, $sql);
|
||||
my ($connection_id) = $dbh->selectrow_array($sql);
|
||||
return $self->{dbh_set} == $connection_id;
|
||||
}
|
||||
|
||||
sub _d {
|
||||
my ($package, undef, $line) = caller 0;
|
||||
@_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
|
||||
|
Reference in New Issue
Block a user