mirror of
https://github.com/percona/percona-toolkit.git
synced 2026-02-02 02:01:22 +08:00
Implement Hosts section for each type of use-case.
This commit is contained in:
143
bin/pt-upgrade
143
bin/pt-upgrade
@@ -8388,11 +8388,28 @@ sub main {
|
||||
|
||||
$o->usage_or_errors();
|
||||
|
||||
# ########################################################################
|
||||
# Get results dir and DSN strings from whatever we just parsed.
|
||||
# ########################################################################
|
||||
my $results_dir;
|
||||
my $host1_dsn_string;
|
||||
my $host2_dsn_string;
|
||||
if ( $o->get('save-results')) {
|
||||
$results_dir = $o->get('save-results');
|
||||
$host1_dsn_string = shift @dsns;
|
||||
}
|
||||
elsif ( @dirs ) {
|
||||
$results_dir = shift @dirs;
|
||||
$host2_dsn_string = shift @dsns;
|
||||
}
|
||||
else {
|
||||
$host1_dsn_string = shift @dsns;
|
||||
$host2_dsn_string = shift @dsns;
|
||||
}
|
||||
|
||||
# ########################################################################
|
||||
# Connect to the hosts.
|
||||
# ########################################################################
|
||||
my $host1_dsn_string = shift @dsns;
|
||||
my $host2_dsn_string = shift @dsns;
|
||||
my $host1;
|
||||
my $host2;
|
||||
|
||||
@@ -8486,14 +8503,21 @@ sub main {
|
||||
);
|
||||
if ( $report->{logs} ) {
|
||||
report_logs(
|
||||
logs => \@logs,
|
||||
logs => \@logs,
|
||||
results_dir => $results_dir,
|
||||
);
|
||||
}
|
||||
|
||||
# ########################################################################
|
||||
# Execute and compare the queries.
|
||||
# ########################################################################
|
||||
my $results_dir = shift @dirs;
|
||||
if ( $report->{hosts} ) {
|
||||
report_hosts(
|
||||
host1 => $host1,
|
||||
host2 => $host2,
|
||||
results_dir => $results_dir,
|
||||
);
|
||||
}
|
||||
|
||||
my %optional_args = (
|
||||
dry_run => $o->get('dry-run'),
|
||||
@@ -8504,15 +8528,7 @@ sub main {
|
||||
read_timeout => $o->get('read-timeout'),
|
||||
);
|
||||
|
||||
|
||||
if ( $host1 && $host2 ) {
|
||||
if ( $report->{hosts} ) {
|
||||
report_hosts(
|
||||
host1 => $host1,
|
||||
host2 => $host2,
|
||||
);
|
||||
}
|
||||
|
||||
compare_host_to_host(
|
||||
logs => \@logs,
|
||||
parser => $parser,
|
||||
@@ -8835,7 +8851,8 @@ sub save_results {
|
||||
# host1
|
||||
# host2
|
||||
# )) or die;
|
||||
my $file = $args{file};
|
||||
my $logs = $args{logs};
|
||||
my $parser = $args{parser};
|
||||
my $host = $args{host};
|
||||
my $results_dir = $args{results_dir};
|
||||
my $upgrade_table = $args{upgrade_table};
|
||||
@@ -8848,26 +8865,6 @@ sub save_results {
|
||||
my $ignore_warnings = $args{ignore_warnings};
|
||||
my $read_only = $args{read_only};
|
||||
my $read_timeout = $args{read_timeout};
|
||||
|
||||
# Print the host and where we're saving the results.
|
||||
my $v = VersionParser->new($host->dbh);
|
||||
my $hostname = get_hostname($host->dbh);
|
||||
|
||||
printf "Log file: %s
|
||||
|
||||
host1:
|
||||
|
||||
DSN: %s
|
||||
hostname: %s
|
||||
MySQL: %s
|
||||
|
||||
Results directory: $results_dir
|
||||
",
|
||||
$file,
|
||||
($host->{dsn_name} || '?'),
|
||||
$hostname,
|
||||
($v->flavor . ' ' . $v->version),
|
||||
$results_dir;
|
||||
|
||||
# Get set up to execute queries and save the results.
|
||||
my $clear_warnings_sql = "SELECT * FROM $upgrade_table LIMIT 1 "
|
||||
@@ -8882,11 +8879,11 @@ Results directory: $results_dir
|
||||
my $qr = QueryRewriter->new(); # fingerprint
|
||||
|
||||
my $file_iter = FileIterator->new();
|
||||
my $files = $file_iter->get_file_itr($file);
|
||||
my $files = $file_iter->get_file_itr(@$logs);
|
||||
|
||||
my $query_iter = QueryIterator->new(
|
||||
file_iter => $files,
|
||||
parser => SlowLogParser->new(),
|
||||
parser => $parser,
|
||||
fingerprint => sub { return $qr->fingerprint(@_) },
|
||||
oktorun => sub { return $oktorun },
|
||||
stats => $stats,
|
||||
@@ -9251,12 +9248,18 @@ sub identical_rows {
|
||||
|
||||
sub report_logs {
|
||||
my (%args) = @_;
|
||||
my $logs = $args{logs};
|
||||
my $logs = $args{logs};
|
||||
my $results_dir = $args{results_dir};
|
||||
|
||||
print_header('Logs', '-');
|
||||
|
||||
foreach my $log ( @$logs ) {
|
||||
printf "\nFile: %s\nSize: %s\n", $log, (-s $log || '?');
|
||||
if ( @$logs ) {
|
||||
foreach my $log ( @$logs ) {
|
||||
printf "\nFile: %s\nSize: %s\n", $log, (-s $log || '?');
|
||||
}
|
||||
}
|
||||
elsif ( $results_dir ) {
|
||||
printf "\nResults directory: $results_dir\n";
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -9264,18 +9267,20 @@ sub report_logs {
|
||||
|
||||
sub report_hosts {
|
||||
my (%args) = @_;
|
||||
my $host1 = $args{host1};
|
||||
my $host2 = $args{host2};
|
||||
my $host1 = $args{host1};
|
||||
my $host2 = $args{host2};
|
||||
my $results_dir = $args{results_dir};
|
||||
|
||||
# Print which hosts we're comparing.
|
||||
my $v1 = VersionParser->new($host1->dbh);
|
||||
my $v2 = VersionParser->new($host2->dbh);
|
||||
my $hostname1 = get_hostname($host1->dbh);
|
||||
my $hostname2 = get_hostname($host2->dbh);
|
||||
my $v1 = $host1 ? VersionParser->new($host1->dbh) : undef;
|
||||
my $v2 = $host2 ? VersionParser->new($host2->dbh) : undef;
|
||||
my $hostname1 = $host1 ? get_hostname($host1->dbh) : undef;
|
||||
my $hostname2 = $host2 ? get_hostname($host2->dbh) : undef;
|
||||
|
||||
print_header('Hosts', '-');
|
||||
|
||||
printf "
|
||||
if ( $host1 && $host2 ) {
|
||||
printf "
|
||||
host1:
|
||||
|
||||
DSN: %s
|
||||
@@ -9288,12 +9293,48 @@ host2:
|
||||
hostname: %s
|
||||
MySQL: %s
|
||||
",
|
||||
($host1->{dsn_name} || '?'),
|
||||
$hostname1,
|
||||
($v1->flavor . ' ' . $v1->version),
|
||||
($host2->{dsn_name} || '?'),
|
||||
$hostname2,
|
||||
($v2->flavor . ' ' . $v2->version);
|
||||
($host1->{dsn_name} || '?'),
|
||||
$hostname1,
|
||||
($v1->flavor . ' ' . $v1->version),
|
||||
($host2->{dsn_name} || '?'),
|
||||
$hostname2,
|
||||
($v2->flavor . ' ' . $v2->version);
|
||||
}
|
||||
elsif ( $host1 && $results_dir ) {
|
||||
printf "
|
||||
host1:
|
||||
|
||||
DSN: %s
|
||||
hostname: %s
|
||||
MySQL: %s
|
||||
|
||||
Saving results in %s
|
||||
",
|
||||
($host1->{dsn_name} || '?'),
|
||||
$hostname1,
|
||||
($v1->flavor . ' ' . $v1->version),
|
||||
$results_dir;
|
||||
}
|
||||
elsif ( $results_dir && $host2 ) {
|
||||
printf "
|
||||
host1:
|
||||
|
||||
Reading results from %s
|
||||
|
||||
host2:
|
||||
|
||||
DSN: %s
|
||||
hostname: %s
|
||||
MySQL: %s
|
||||
",
|
||||
$results_dir,
|
||||
($host2->{dsn_name} || '?'),
|
||||
$hostname2,
|
||||
($v2->flavor . ' ' . $v2->version);
|
||||
}
|
||||
else {
|
||||
print "\nUnknown hosts.\n";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -97,17 +97,20 @@ while ( my $sampleno = readdir $dh ) {
|
||||
stderr => 1,
|
||||
);
|
||||
|
||||
my $file
|
||||
= -f "$samples_dir/$sampleno/${basename}_results.txt" ? "${basename}_results.txt"
|
||||
: -f "$samples_dir/$sampleno/${basename}.txt" ? "${basename}.txt"
|
||||
: undef;
|
||||
if ( $file ) {
|
||||
if ( -f "$samples_dir/$sampleno/${basename}_results.txt" ) {
|
||||
ok(
|
||||
no_diff(
|
||||
$output,
|
||||
"$sample/$sampleno/$file",
|
||||
"$sample/$sampleno/${basename}_results.txt",
|
||||
cmd_output => 1,
|
||||
($sed ? (sed => [ $sed ]) : ()),
|
||||
sed => [
|
||||
q{'s/Results directory: .*/Results directory: .../'},
|
||||
q{'s/Reading results from .*/Reading results from .../'},
|
||||
q{'s/Saving results in .*/Saving results in .../'},
|
||||
q{'s/ hostname: .*/ hostname: .../'},
|
||||
q{'s/ MySQL: .*/ MySQL: .../'},
|
||||
($sed ? $sed : ()),
|
||||
],
|
||||
),
|
||||
"$sampleno: $basename.txt"
|
||||
) or diag("\n\n---- DIFF ----\n\n", $test_diff,
|
||||
|
||||
@@ -1,4 +1,24 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Logs
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
Results directory: ...
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Hosts
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
host1:
|
||||
|
||||
Reading results from ...
|
||||
|
||||
host2:
|
||||
|
||||
DSN: h=127.1,P=12348
|
||||
hostname: ...
|
||||
MySQL: ...
|
||||
|
||||
########################################################################
|
||||
# Stats
|
||||
########################################################################
|
||||
|
||||
32
t/pt-upgrade/samples/001/select_results.txt
Normal file
32
t/pt-upgrade/samples/001/select_results.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Logs
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
Results directory: ...
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Hosts
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
host1:
|
||||
|
||||
Reading results from ...
|
||||
|
||||
host2:
|
||||
|
||||
DSN: h=127.1,P=12348
|
||||
hostname: ...
|
||||
MySQL: ...
|
||||
|
||||
########################################################################
|
||||
# Stats
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 1
|
||||
queries_read 1
|
||||
queries_with_diffs 0
|
||||
queries_with_errors 0
|
||||
57
t/pt-upgrade/samples/002/select_missing_rows_results.txt
Normal file
57
t/pt-upgrade/samples/002/select_missing_rows_results.txt
Normal file
@@ -0,0 +1,57 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Logs
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
Results directory: ...
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Hosts
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
host1:
|
||||
|
||||
Reading results from ...
|
||||
|
||||
host2:
|
||||
|
||||
DSN: h=127.1,P=12348
|
||||
hostname: ...
|
||||
MySQL: ...
|
||||
|
||||
########################################################################
|
||||
# Query class 483E7FA163F8DA7B
|
||||
########################################################################
|
||||
|
||||
Reporting class because it has diffs, but hasn't been reported yet.
|
||||
|
||||
Total queries 1
|
||||
Unique queries 1
|
||||
Discarded queries 0
|
||||
|
||||
select * from test.t order by id
|
||||
|
||||
##
|
||||
## Row diffs: 1
|
||||
##
|
||||
|
||||
-- 1.
|
||||
|
||||
@ first 3 of 5 missing rows
|
||||
> 7,g,2013-01-01 00:00:07
|
||||
> 8,h,2013-01-01 00:00:08
|
||||
> 9,i,2013-01-01 00:00:09
|
||||
|
||||
select * from test.t order by id
|
||||
|
||||
########################################################################
|
||||
# Stats
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
queries_with_diffs 1
|
||||
queries_with_errors 0
|
||||
60
t/pt-upgrade/samples/003/insert_truncate_warning_results.txt
Normal file
60
t/pt-upgrade/samples/003/insert_truncate_warning_results.txt
Normal file
@@ -0,0 +1,60 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Logs
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
Results directory: ...
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Hosts
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
host1:
|
||||
|
||||
Reading results from ...
|
||||
|
||||
host2:
|
||||
|
||||
DSN: h=127.1,P=12348
|
||||
hostname: ...
|
||||
MySQL: ...
|
||||
|
||||
########################################################################
|
||||
# Query class AAD020567F8398EE
|
||||
########################################################################
|
||||
|
||||
Reporting class because it has diffs, but hasn't been reported yet.
|
||||
|
||||
Total queries 1
|
||||
Unique queries 1
|
||||
Discarded queries 0
|
||||
|
||||
insert into t (id, username) values(?+)
|
||||
|
||||
##
|
||||
## Warning diffs: 1
|
||||
##
|
||||
|
||||
-- 1.
|
||||
|
||||
Code: 1265
|
||||
Level: Warning
|
||||
Message: Data truncated for column 'username' at row 1
|
||||
|
||||
vs.
|
||||
|
||||
No warning 1265
|
||||
|
||||
INSERT INTO t (id, username) VALUES (NULL, 'long_username')
|
||||
|
||||
########################################################################
|
||||
# Stats
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
queries_with_diffs 1
|
||||
queries_with_errors 0
|
||||
56
t/pt-upgrade/samples/005/error_on_both_hosts_results.txt
Normal file
56
t/pt-upgrade/samples/005/error_on_both_hosts_results.txt
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Logs
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
Results directory: ...
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Hosts
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
host1:
|
||||
|
||||
Reading results from ...
|
||||
|
||||
host2:
|
||||
|
||||
DSN: h=127.1,P=12348
|
||||
hostname: ...
|
||||
MySQL: ...
|
||||
|
||||
########################################################################
|
||||
# Query class 0F88A9418F511C18
|
||||
########################################################################
|
||||
|
||||
Reporting class because it has SQL errors, but hasn't been reported yet.
|
||||
|
||||
Total queries 1
|
||||
Unique queries 1
|
||||
Discarded queries 0
|
||||
|
||||
select nonexistent_col from test.t
|
||||
|
||||
##
|
||||
## SQL errors: 1
|
||||
##
|
||||
|
||||
-- 1.
|
||||
|
||||
On both hosts:
|
||||
|
||||
DBD::mysql::st execute failed: Unknown column 'nonexistent_col' in 'field list' [for Statement "select nonexistent_col from test.t"]
|
||||
|
||||
select nonexistent_col from test.t
|
||||
|
||||
########################################################################
|
||||
# Stats
|
||||
########################################################################
|
||||
|
||||
failed_queries 1
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
queries_with_diffs 0
|
||||
queries_with_errors 0
|
||||
58
t/pt-upgrade/samples/005/error_on_host1_results.txt
Normal file
58
t/pt-upgrade/samples/005/error_on_host1_results.txt
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Logs
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
Results directory: ...
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Hosts
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
host1:
|
||||
|
||||
Reading results from ...
|
||||
|
||||
host2:
|
||||
|
||||
DSN: h=127.1,P=12348
|
||||
hostname: ...
|
||||
MySQL: ...
|
||||
|
||||
########################################################################
|
||||
# Query class 883A4BC43021922E
|
||||
########################################################################
|
||||
|
||||
Reporting class because it has diffs, but hasn't been reported yet.
|
||||
|
||||
Total queries 1
|
||||
Unique queries 1
|
||||
Discarded queries 0
|
||||
|
||||
select host?_col from test.t
|
||||
|
||||
##
|
||||
## Query errors diffs: 1
|
||||
##
|
||||
|
||||
-- 1.
|
||||
|
||||
DBD::mysql::st execute failed: Unknown column 'host2_col' in 'field list' [for Statement "select host2_col from test.t"]
|
||||
|
||||
vs.
|
||||
|
||||
No error
|
||||
|
||||
select host2_col from test.t
|
||||
|
||||
########################################################################
|
||||
# Stats
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
queries_with_diffs 0
|
||||
queries_with_errors 1
|
||||
58
t/pt-upgrade/samples/005/error_on_host2_results.txt
Normal file
58
t/pt-upgrade/samples/005/error_on_host2_results.txt
Normal file
@@ -0,0 +1,58 @@
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Logs
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
Results directory: ...
|
||||
|
||||
#-----------------------------------------------------------------------
|
||||
# Hosts
|
||||
#-----------------------------------------------------------------------
|
||||
|
||||
host1:
|
||||
|
||||
Reading results from ...
|
||||
|
||||
host2:
|
||||
|
||||
DSN: h=127.1,P=12348
|
||||
hostname: ...
|
||||
MySQL: ...
|
||||
|
||||
########################################################################
|
||||
# Query class 883A4BC43021922E
|
||||
########################################################################
|
||||
|
||||
Reporting class because it has diffs, but hasn't been reported yet.
|
||||
|
||||
Total queries 1
|
||||
Unique queries 1
|
||||
Discarded queries 0
|
||||
|
||||
select host?_col from test.t
|
||||
|
||||
##
|
||||
## Query errors diffs: 1
|
||||
##
|
||||
|
||||
-- 1.
|
||||
|
||||
No error
|
||||
|
||||
vs.
|
||||
|
||||
DBD::mysql::st execute failed: Unknown column 'host1_col' in 'field list' [for Statement "select host1_col from test.t"]
|
||||
|
||||
select host1_col from test.t
|
||||
|
||||
########################################################################
|
||||
# Stats
|
||||
########################################################################
|
||||
|
||||
failed_queries 0
|
||||
not_select 0
|
||||
queries_filtered 0
|
||||
queries_no_diffs 0
|
||||
queries_read 1
|
||||
queries_with_diffs 0
|
||||
queries_with_errors 1
|
||||
Reference in New Issue
Block a user