Merge branch '3.0' into PT-144

This commit is contained in:
Carlos Salguero
2017-05-24 11:37:46 -03:00
13 changed files with 330 additions and 60 deletions

View File

@@ -52,7 +52,7 @@ my $want = [
key_len => 2,
ref => 'const',
rows => 1,
Extra => $sandbox_version gt '5.6' ? undef : '',
Extra => $sandbox_version eq '5.6' ? undef : '',
},
];
if ( $sandbox_version gt '5.6' ) {

View File

@@ -115,6 +115,25 @@ like(
"..but an unknown charset fails"
);
local $SIG{__WARN__} = undef;
$sb->load_file('master', 't/pt-archiver/samples/table2.sql');
`rm -f archive.test.table_2`;
$output = output(
sub { pt_archiver::main(qw(--where 1=1 --output-format=csv), "--source", "D=test,t=table_2,F=$cnf", "--file", 'archive.%D.%t') },
);
$output = `cat archive.test.table_2`;
is($output, <<EOF
1, 2, 3, "4"
2, "\\N", 3, "4"
3, 2, 3, "\\\t"
4, 2, 3, "\\\n"
5, 2, 3, "Zapp \\"Brannigan"
EOF
, '--output-format=csv');
`rm -f archive.test.table_2`;
# #############################################################################
# Done.
# #############################################################################

68
t/pt-archiver/pt-143.t Normal file
View File

@@ -0,0 +1,68 @@
#!/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-archiver";
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';
}
else {
plan tests => 3;
}
my $output;
# #############################################################################
# Issue 1152: mk-archiver columns option resulting in null archived table data
# #############################################################################
$sb->load_file('master', 't/pt-archiver/samples/pt-143.sql');
my $original_rows = $dbh->selectall_arrayref('select * from test.stats_r');
my $exit_status;
$output = output(
sub { $exit_status = pt_archiver::main(
'--source', 'h=127.1,P=12345,D=test,t=stats_r,u=msandbox,p=msandbox',
'--dest', 'D=test,t=stats_s',
qw(--where 1=1 --purge))
},
);
is (
$exit_status,
0,
"PT-143 exit status OK",
);
my $archived_rows = $dbh->selectall_arrayref('select * from test.stats_s');
is_deeply(
$original_rows,
$archived_rows,
"PT-143 Archived rows match original rows"
);
$dbh->do('DROP DATABASE test');
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit;

View File

@@ -0,0 +1,33 @@
DROP SCHEMA IF EXISTS test;
CREATE SCHEMA test;
CREATE TABLE test.`stats_r` (
`id` int(10) unsigned NOT NULL,
`end` datetime NOT NULL,
`start` datetime NOT NULL,
`sum_value` float DEFAULT NULL,
`user_id` varchar(100) NOT NULL DEFAULT '',
`interval` int(10) unsigned NOT NULL DEFAULT '0',
`mean` float DEFAULT NULL,
`max` float DEFAULT NULL,
`min` float DEFAULT NULL,
PRIMARY KEY (`id`,`start`,`end`,`user_id`(13),`interval`),
KEY `cid_start_end` (`user_id`(13),`start`,`end`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
CREATE TABLE test.stats_s LIKE test.stats_r;
INSERT INTO `test`.`stats_r`
(`id`,`end`,`start`,`sum_value`,`user_id`,`interval`,`mean`,`max`,`min`)
VALUES
(1,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(2,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(3,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(4,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(5,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(6,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(7,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(8,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(9,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1),
(10,now() + INTERVAL 1 hour, NOW(), 1,1,1,1,1,1);

View File

@@ -0,0 +1,19 @@
CREATE SCHEMA IF NOT EXISTS test;
use test;
drop table if exists table_2;
create table table_2(
a int not null primary key,
b int,
c int not null,
d varchar(50),
key(b)
) engine=innodb;
insert into table_2 values
(1, 2, 3, 4),
(2, null, 3, 4),
(3, 2, 3, "\t"),
(4, 2, 3, "\n"),
(5, 2, 3, "Zapp \"Brannigan");

View File

@@ -445,6 +445,31 @@ $output = output(
# clear databases with their foreign keys
$sb->load_file('master', "$sample/bug-1315130_cleanup.sql");
# #############################################################################
# Issue 1315130
# Failed to detect child tables in other schema, and falsely identified
# child tables in own schema
# #############################################################################
$sb->load_file('master', "$sample/bug-1315130_cleanup.sql");
$sb->load_file('master', "$sample/bug-1315130.sql");
$output = output(
sub { pt_online_schema_change::main(@args, "$master_dsn,D=bug_1315130_a,t=parent_table",
'--dry-run',
'--alter', "add column c varchar(16)",
'--alter-foreign-keys-method', 'auto', '--only-same-schema-fks'),
},
);
like(
$output,
qr/Child tables:\s*`bug_1315130_a`\.`child_table_in_same_schema` \(approx\. 1 rows\)[^`]*?Will/s,
"Ignore child tables in other schemas.",
);
# clear databases with their foreign keys
$sb->load_file('master', "$sample/bug-1315130_cleanup.sql");
# #############################################################################
# Issue 1340728

View File

@@ -105,7 +105,7 @@ ok(
$row = $master_dbh->selectrow_arrayref("select count(*) from percona.checksums");
my $max_rows = $sandbox_version < '5.7' ? 75 : 100;
my $max_rows = $sandbox_version < '5.7' ? 90 : 100;
ok(
$row->[0] >= 75 && $row->[0] <= $max_rows,
'Between 75 and 90 chunks on master'