mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-28 17:15:44 +00:00
Start rewritting pt-upgrade 2.2.
This commit is contained in:
8853
bin/pt-upgrade
8853
bin/pt-upgrade
File diff suppressed because it is too large
Load Diff
@@ -8,4 +8,3 @@ CREATE TABLE t (
|
||||
t tinyint
|
||||
);
|
||||
INSERT INTO t VALUES (1,'hi',1);
|
||||
|
||||
|
96
t/pt-upgrade/diff_rows.t
Normal file
96
t/pt-upgrade/diff_rows.t
Normal file
@@ -0,0 +1,96 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
BEGIN {
|
||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
$Data::Dumper::Indent = 1;
|
||||
$Data::Dumper::Sortkeys = 1;
|
||||
$Data::Dumper::Quotekeys = 0;
|
||||
|
||||
require "$trunk/bin/pt-upgrade";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $dbh = $sb->get_dbh_for('master');
|
||||
|
||||
if ( !$dbh ) {
|
||||
plan skip_all => "Cannot connect to sandbox master";
|
||||
}
|
||||
|
||||
sub test_diff {
|
||||
my (%args) = @_;
|
||||
|
||||
my $name = $args{name};
|
||||
my $query1 = $args{query1};
|
||||
my $query2 = $args{query2};
|
||||
my $expect = $args{expect};
|
||||
|
||||
my $sth1 = $dbh->prepare($query1);
|
||||
my $sth2 = $dbh->prepare($query2);
|
||||
|
||||
$sth1->execute();
|
||||
$sth2->execute();
|
||||
|
||||
my $diffs = pt_upgrade::diff_rows(
|
||||
sth1 => $sth1,
|
||||
sth2 => $sth2,
|
||||
);
|
||||
|
||||
$sth1->finish();
|
||||
$sth2->finish();
|
||||
|
||||
is_deeply(
|
||||
$diffs,
|
||||
$expect,
|
||||
$name,
|
||||
) or diag(Dumper($diffs));
|
||||
}
|
||||
|
||||
test_diff(
|
||||
name => 'No diff',
|
||||
query1 => 'select user from mysql.user order by user',
|
||||
query2 => 'select user from mysql.user order by user',
|
||||
expect => [],
|
||||
);
|
||||
|
||||
test_diff (
|
||||
name => '2 diffs (ORDER BY ASC vs. DESC)',
|
||||
query1 => "select user from mysql.user order by user ASC",
|
||||
query2 => "select user from mysql.user order by user DESC",
|
||||
expect => [
|
||||
{
|
||||
row_number => 1,
|
||||
sth1_rows => [qw(msandbox)],
|
||||
sth2_rows => [qw(root)],
|
||||
},
|
||||
{
|
||||
row_number => 2,
|
||||
sth1_rows => [qw(root)],
|
||||
sth2_rows => [qw(msandbox)],
|
||||
}
|
||||
],
|
||||
);
|
||||
|
||||
test_diff (
|
||||
name => "Stops when there's not 2 rows",
|
||||
query1 => "select user from mysql.user where user='msandbox' order by user",
|
||||
query2 => 'select user from mysql.user order by user',
|
||||
expect => [],
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($dbh);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
115
t/pt-upgrade/diff_warnings.t
Normal file
115
t/pt-upgrade/diff_warnings.t
Normal file
@@ -0,0 +1,115 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
BEGIN {
|
||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
use Data::Dumper;
|
||||
$Data::Dumper::Indent = 1;
|
||||
$Data::Dumper::Sortkeys = 1;
|
||||
$Data::Dumper::Quotekeys = 0;
|
||||
|
||||
use Sandbox;
|
||||
use PerconaTest;
|
||||
|
||||
require "$trunk/bin/pt-upgrade";
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $dbh1 = $sb->get_dbh_for('master');
|
||||
my $dbh2 = $sb->get_dbh_for('master');
|
||||
|
||||
if ( !$dbh1 || !$dbh2 ) {
|
||||
plan skip_all => "Cannot connect to sandbox master";
|
||||
}
|
||||
|
||||
$sb->load_file('master', "t/lib/samples/compare-warnings.sql");
|
||||
|
||||
sub clear_warnings {
|
||||
$dbh1->do("SELECT /* clear warnings */ 1 FROM mysql.user");
|
||||
$dbh2->do("SELECT /* clear warnings */ 1 FROM mysql.user");
|
||||
}
|
||||
|
||||
$dbh1->do("INSERT INTO test.t VALUES (2, '', 123456789)");
|
||||
$dbh2->do("INSERT INTO test.t VALUES (3, '', 123456789)");
|
||||
|
||||
my $w1 = pt_upgrade::get_warnings(dbh => $dbh1);
|
||||
my $w2 = pt_upgrade::get_warnings(dbh => $dbh2);
|
||||
|
||||
my $error_1264 = {
|
||||
code => '1264',
|
||||
level => 'Warning',
|
||||
message => "Out of range value for column 't' at row 1",
|
||||
};
|
||||
|
||||
is_deeply(
|
||||
$w1,
|
||||
{
|
||||
1264 => $error_1264,
|
||||
},
|
||||
"host1 warning"
|
||||
) or diag(Dumper($w1));
|
||||
|
||||
is_deeply(
|
||||
$w2,
|
||||
{
|
||||
1264 => $error_1264,
|
||||
},
|
||||
"... and host2 warning"
|
||||
) or diag(Dumper($w2));
|
||||
|
||||
my $diffs = pt_upgrade::diff_warnings(
|
||||
host1_warnings => $w1,
|
||||
host2_warnings => $w2,
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$diffs,
|
||||
[],
|
||||
'... but no diffs'
|
||||
) or diag(Dumper($diffs));
|
||||
|
||||
$diffs = pt_upgrade::diff_warnings(
|
||||
host1_warnings => {},
|
||||
host2_warnings => $w2,
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$diffs,
|
||||
[
|
||||
{
|
||||
host1 => undef,
|
||||
host2 => $error_1264,
|
||||
},
|
||||
],
|
||||
"host1 doesn't have the warning"
|
||||
) or diag(Dumper($diffs));
|
||||
|
||||
# #############################################################################
|
||||
# Ignore warnings
|
||||
# #############################################################################
|
||||
|
||||
$diffs = pt_upgrade::diff_warnings(
|
||||
ignore_warnings => { 1264 => 1 },
|
||||
host1_warnings => $w1,
|
||||
host2_warnings => $w2,
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$diffs,
|
||||
[],
|
||||
'Ignore a warning'
|
||||
) or diag(Dumper($diffs));
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
$sb->wipe_clean($dbh1);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
done_testing;
|
@@ -1,81 +0,0 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
BEGIN {
|
||||
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
|
||||
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
|
||||
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
|
||||
};
|
||||
|
||||
use strict;
|
||||
use warnings FATAL => 'all';
|
||||
use English qw(-no_match_vars);
|
||||
use Test::More;
|
||||
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
require "$trunk/bin/pt-upgrade";
|
||||
|
||||
# This runs immediately if the server is already running, else it starts it.
|
||||
diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`);
|
||||
|
||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||
my $dbh1 = $sb->get_dbh_for('master');
|
||||
my $dbh2 = $sb->get_dbh_for('master1');
|
||||
|
||||
if ( !$dbh1 ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
elsif ( !$dbh2 ) {
|
||||
plan skip_all => 'Cannot connect to second sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 5;
|
||||
}
|
||||
|
||||
$sb->load_file('master1', 't/pt-upgrade/samples/001/tables.sql');
|
||||
$sb->load_file('master', 't/pt-upgrade/samples/001/tables.sql');
|
||||
|
||||
# Issue 747: Make mk-upgrade rewrite non-SELECT
|
||||
|
||||
my $cmd = "$trunk/bin/pt-upgrade h=127.1,P=12345 P=12348 -u msandbox -p msandbox --compare results,warnings --zero-query-times --convert-to-select --fingerprints";
|
||||
|
||||
my $c1 = $dbh1->selectrow_arrayref('checksum table test.t')->[1];
|
||||
my $c2 = $dbh2->selectrow_arrayref('checksum table test.t')->[1];
|
||||
|
||||
is(
|
||||
$c1,
|
||||
$c2,
|
||||
'Table checksums identical'
|
||||
);
|
||||
|
||||
ok(
|
||||
no_diff(
|
||||
"$cmd $trunk/t/pt-upgrade/samples/001/non-selects.log",
|
||||
't/pt-upgrade/samples/001/non-selects-rewritten.txt'
|
||||
),
|
||||
'Rewrite non-SELECT'
|
||||
);
|
||||
|
||||
my $c1_after = $dbh1->selectrow_arrayref('checksum table test.t')->[1];
|
||||
my $c2_after = $dbh2->selectrow_arrayref('checksum table test.t')->[1];
|
||||
|
||||
is(
|
||||
$c1_after,
|
||||
$c1,
|
||||
'Table on host1 not changed'
|
||||
);
|
||||
|
||||
is(
|
||||
$c2_after,
|
||||
$c2,
|
||||
'Table on host2 not changed'
|
||||
);
|
||||
|
||||
# #############################################################################
|
||||
# Done.
|
||||
# #############################################################################
|
||||
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
|
||||
$sb->wipe_clean($dbh1);
|
||||
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
|
||||
exit;
|
Reference in New Issue
Block a user