mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-19 17:04:00 +00:00
Have ResultWriter.pm save the current db.
This commit is contained in:
@@ -5287,12 +5287,6 @@ has 'default_database' => (
|
|||||||
required => 0,
|
required => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'current_database' => (
|
|
||||||
is => 'rw',
|
|
||||||
isa => 'Maybe[Str]',
|
|
||||||
required => 0,
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
has 'stats' => (
|
has 'stats' => (
|
||||||
is => 'ro',
|
is => 'ro',
|
||||||
@@ -5319,7 +5313,7 @@ sub exec_event {
|
|||||||
|
|
||||||
eval {
|
eval {
|
||||||
my $db = $event->{db} || $event->{Schema} || $self->default_database;
|
my $db = $event->{db} || $event->{Schema} || $self->default_database;
|
||||||
if ( !$host->{current_db} || $host->{current_db} ne $db ) {
|
if ( $db && (!$host->{current_db} || $host->{current_db} ne $db) ) {
|
||||||
PTDEBUG && _d('New current db:', $db);
|
PTDEBUG && _d('New current db:', $db);
|
||||||
$host->dbh->do("USE `$db`");
|
$host->dbh->do("USE `$db`");
|
||||||
$host->{current_db} = $db;
|
$host->{current_db} = $db;
|
||||||
@@ -5926,6 +5920,18 @@ has 'pretty' => (
|
|||||||
default => 0,
|
default => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
has 'default_database' => (
|
||||||
|
is => 'rw',
|
||||||
|
isa => 'Maybe[Str]',
|
||||||
|
required => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
has 'current_database' => (
|
||||||
|
is => 'rw',
|
||||||
|
isa => 'Maybe[Str]',
|
||||||
|
required => 0,
|
||||||
|
);
|
||||||
|
|
||||||
has '_query_fh' => (
|
has '_query_fh' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'Maybe[FileHandle]',
|
isa => 'Maybe[FileHandle]',
|
||||||
@@ -5976,9 +5982,17 @@ sub BUILDARGS {
|
|||||||
sub save {
|
sub save {
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
my $host = $args{host};
|
||||||
my $event = $args{event};
|
my $event = $args{event};
|
||||||
my $results = $args{results};
|
my $results = $args{results};
|
||||||
|
|
||||||
|
my $current_db = $self->current_database;
|
||||||
|
my $db = $event->{db} || $event->{Schema} || $self->default_database;
|
||||||
|
if ( $db && (!$current_db || $current_db ne $db) ) {
|
||||||
|
PTDEBUG && _d('New current db:', $db);
|
||||||
|
print { $self->_query_fh } "use `$db`;\n";
|
||||||
|
$self->current_database($db);
|
||||||
|
}
|
||||||
print { $self->_query_fh } $event->{arg}, "\n##\n";
|
print { $self->_query_fh } $event->{arg}, "\n##\n";
|
||||||
|
|
||||||
if ( my $error = $results->{error} ) {
|
if ( my $error = $results->{error} ) {
|
||||||
@@ -6385,8 +6399,8 @@ sub main {
|
|||||||
}
|
}
|
||||||
elsif ( $results_dir && $host2 ) {
|
elsif ( $results_dir && $host2 ) {
|
||||||
compare_results_to_host(
|
compare_results_to_host(
|
||||||
host => $host2,
|
|
||||||
results_dir => $results_dir,
|
results_dir => $results_dir,
|
||||||
|
host => $host2,
|
||||||
upgrade_table => $o->get('upgrade-table'),
|
upgrade_table => $o->get('upgrade-table'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -6539,9 +6553,6 @@ sub check_table {
|
|||||||
|
|
||||||
PTDEBUG && _d('Table', $db, $tbl, 'exists');
|
PTDEBUG && _d('Table', $db, $tbl, 'exists');
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
# No more privs check:
|
|
||||||
# https://bugs.launchpad.net/percona-toolkit/+bug/1036747
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub compare_host_to_host {
|
sub compare_host_to_host {
|
||||||
@@ -6741,6 +6752,7 @@ sub save_results {
|
|||||||
host => $host,
|
host => $host,
|
||||||
);
|
);
|
||||||
$results->save(
|
$results->save(
|
||||||
|
host => $host,
|
||||||
event => $event,
|
event => $event,
|
||||||
results => $host_results,
|
results => $host_results,
|
||||||
);
|
);
|
||||||
|
@@ -36,12 +36,6 @@ has 'default_database' => (
|
|||||||
required => 0,
|
required => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
has 'current_database' => (
|
|
||||||
is => 'rw',
|
|
||||||
isa => 'Maybe[Str]',
|
|
||||||
required => 0,
|
|
||||||
);
|
|
||||||
|
|
||||||
##
|
##
|
||||||
# Private
|
# Private
|
||||||
##
|
##
|
||||||
@@ -71,7 +65,7 @@ sub exec_event {
|
|||||||
|
|
||||||
eval {
|
eval {
|
||||||
my $db = $event->{db} || $event->{Schema} || $self->default_database;
|
my $db = $event->{db} || $event->{Schema} || $self->default_database;
|
||||||
if ( !$host->{current_db} || $host->{current_db} ne $db ) {
|
if ( $db && (!$host->{current_db} || $host->{current_db} ne $db) ) {
|
||||||
PTDEBUG && _d('New current db:', $db);
|
PTDEBUG && _d('New current db:', $db);
|
||||||
$host->dbh->do("USE `$db`");
|
$host->dbh->do("USE `$db`");
|
||||||
$host->{current_db} = $db;
|
$host->{current_db} = $db;
|
||||||
|
@@ -42,6 +42,18 @@ has 'pretty' => (
|
|||||||
default => 0,
|
default => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
has 'default_database' => (
|
||||||
|
is => 'rw',
|
||||||
|
isa => 'Maybe[Str]',
|
||||||
|
required => 0,
|
||||||
|
);
|
||||||
|
|
||||||
|
has 'current_database' => (
|
||||||
|
is => 'rw',
|
||||||
|
isa => 'Maybe[Str]',
|
||||||
|
required => 0,
|
||||||
|
);
|
||||||
|
|
||||||
has '_query_fh' => (
|
has '_query_fh' => (
|
||||||
is => 'rw',
|
is => 'rw',
|
||||||
isa => 'Maybe[FileHandle]',
|
isa => 'Maybe[FileHandle]',
|
||||||
@@ -92,10 +104,18 @@ sub BUILDARGS {
|
|||||||
sub save {
|
sub save {
|
||||||
my ($self, %args) = @_;
|
my ($self, %args) = @_;
|
||||||
|
|
||||||
|
my $host = $args{host};
|
||||||
my $event = $args{event};
|
my $event = $args{event};
|
||||||
my $results = $args{results};
|
my $results = $args{results};
|
||||||
|
|
||||||
# Save the query.
|
# Save the query.
|
||||||
|
my $current_db = $self->current_database;
|
||||||
|
my $db = $event->{db} || $event->{Schema} || $self->default_database;
|
||||||
|
if ( $db && (!$current_db || $current_db ne $db) ) {
|
||||||
|
PTDEBUG && _d('New current db:', $db);
|
||||||
|
print { $self->_query_fh } "use `$db`;\n";
|
||||||
|
$self->current_database($db);
|
||||||
|
}
|
||||||
print { $self->_query_fh } $event->{arg}, "\n##\n";
|
print { $self->_query_fh } $event->{arg}, "\n##\n";
|
||||||
|
|
||||||
if ( my $error = $results->{error} ) {
|
if ( my $error = $results->{error} ) {
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
|
use `test`;
|
||||||
select * from test.t order by id
|
select * from test.t order by id
|
||||||
##
|
##
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
|
use `test`;
|
||||||
select * from test.t order by id
|
select * from test.t order by id
|
||||||
##
|
##
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
|
use `test`;
|
||||||
INSERT INTO t (id, username) VALUES (NULL, 'long_username')
|
INSERT INTO t (id, username) VALUES (NULL, 'long_username')
|
||||||
##
|
##
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
|
use `test`;
|
||||||
select nonexistent_col from test.t
|
select nonexistent_col from test.t
|
||||||
##
|
##
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
|
use `test`;
|
||||||
select host2_col from test.t
|
select host2_col from test.t
|
||||||
##
|
##
|
||||||
|
@@ -1,2 +1,3 @@
|
|||||||
|
use `test`;
|
||||||
select host1_col from test.t
|
select host1_col from test.t
|
||||||
##
|
##
|
||||||
|
Reference in New Issue
Block a user