pt-upgrade: Deal with LOCAL INFILE being disabled

This commit is contained in:
Brian Fraser
2012-07-11 18:36:43 -03:00
parent e9c9608c33
commit e0d97bbc98
4 changed files with 115 additions and 73 deletions

View File

@@ -10990,6 +10990,32 @@ sub main {
$host->{name} = $name || 'unknown host'; $host->{name} = $name || 'unknown host';
} }
# ########################################################################
# If we're comparing rows, check that LOAD DATA LOCAL INFILE works for,
# all hosts, or bail out early if it doesn't.
# ########################################################################
my $compare = $o->get('compare');
if ( $compare->{results}
&& lc($o->get('compare-results-method')) eq 'rows' )
{
foreach my $host ( @$hosts ) {
local $@;
my $sql = "LOAD DATA LOCAL INFILE '/dev/null' INTO TABLE "
. "`test`.`pt_not_there`";
eval { $host->{dbh}->do($sql); 1 } or do {
my $e = $@;
my $error_re = qr/\QDBD::mysql::db do failed: The used command is not allowed with this MySQL version [for Statement "LOAD DATA LOCAL INFILE/;
if ($e =~ $error_re) {
$_->{dbh}->disconnect() for @$hosts;
die("Cannot compare rows as LOAD DATA LOCAL INFILE "
. "is disabled for $host->{name}. See "
. "http://kb.percona.com/troubleshoot-load-data-infile"
);
}
};
}
}
# ######################################################################## # ########################################################################
# Make some common modules. # Make some common modules.
# ######################################################################## # ########################################################################
@@ -11023,7 +11049,6 @@ sub main {
# ######################################################################## # ########################################################################
# Make compare modules in order. # Make compare modules in order.
# ######################################################################## # ########################################################################
my $compare = $o->get('compare');
my @compare_modules; my @compare_modules;
if ( $compare->{results} ) { if ( $compare->{results} ) {
my $method = lc $o->get('compare-results-method'); my $method = lc $o->get('compare-results-method');

View File

@@ -125,7 +125,7 @@ sub test_disabled_load_data {
like($output, like($output,
qr!\Q--bulk-insert cannot work as LOAD DATA LOCAL INFILE is disabled. See http://kb.percona.com/troubleshoot-load-data-infile!, qr!\Q--bulk-insert cannot work as LOAD DATA LOCAL INFILE is disabled. See http://kb.percona.com/troubleshoot-load-data-infile!,
"" "--bulk-insert throws an error if LOCAL INFILE is disabled"
); );
} }

View File

@@ -33,6 +33,8 @@ else {
plan tests => 13; plan tests => 13;
} }
my $load_data_is_disabled = PerconaTest::load_data_is_disabled($dbh1);
my @host_args = ('h=127.1,P=12345', 'P=12348'); my @host_args = ('h=127.1,P=12345', 'P=12348');
my @op_args = (qw(-u msandbox -p msandbox), my @op_args = (qw(-u msandbox -p msandbox),
'--compare', 'results,warnings', '--compare', 'results,warnings',
@@ -64,23 +66,27 @@ ok(
'Report for multiple queries (checksum method)' 'Report for multiple queries (checksum method)'
); );
ok( SKIP: {
no_diff( skip "LOAD DATA LOCAL INFILE is disabled", 2 if $load_data_is_disabled;
sub { pt_upgrade::main(@args, "$trunk/$sample/001/select-one.log",
"--compare-results-method", "rows") },
"$sample/001/select-one-rows.txt"
),
'Report for a single query (rows method)'
);
ok( ok(
no_diff( no_diff(
sub { pt_upgrade::main(@args, "$trunk/$sample/001/select-everyone.log", sub { pt_upgrade::main(@args, "$trunk/$sample/001/select-one.log",
"--compare-results-method", "rows") }, "--compare-results-method", "rows") },
"$sample/001/select-everyone-rows.txt" "$sample/001/select-one-rows.txt"
), ),
'Report for multiple queries (rows method)' 'Report for a single query (rows method)'
); );
ok(
no_diff(
sub { pt_upgrade::main(@args, "$trunk/$sample/001/select-everyone.log",
"--compare-results-method", "rows") },
"$sample/001/select-everyone-rows.txt"
),
'Report for multiple queries (rows method)'
);
}
ok( ok(
no_diff( no_diff(
@@ -107,76 +113,84 @@ $sb->wipe_clean($dbh2);
# Issue 951: mk-upgrade "I need a db argument" error with # Issue 951: mk-upgrade "I need a db argument" error with
# compare-results-method=rows # compare-results-method=rows
# ############################################################################# # #############################################################################
$sb->load_file('master', "$sample/002/tables.sql"); SKIP: {
$sb->load_file('master1', "$sample/002/tables.sql"); skip "LOAD DATA LOCAL INFILE is disabled", 4 if $load_data_is_disabled;
$sb->load_file('master', "$sample/002/tables.sql");
$sb->load_file('master1', "$sample/002/tables.sql");
# Make a difference on one host so diff_rows() is called. # Make a difference on one host so diff_rows() is called.
$dbh1->do('insert into test.t values (5)'); $dbh1->do('insert into test.t values (5)');
ok( ok(
no_diff( no_diff(
sub { pt_upgrade::main(@op_args, "$log/002/no-db.log", sub { pt_upgrade::main(@op_args, "$log/002/no-db.log",
'h=127.1,P=12345,D=test', 'P=12348,D=test', 'h=127.1,P=12345,D=test', 'P=12348,D=test',
qw(--compare-results-method rows --temp-database test)) }, qw(--compare-results-method rows --temp-database test)) },
"$sample/002/report-01.txt", "$sample/002/report-01.txt",
), ),
'No db, compare results row, DSN D, --temp-database (issue 951)' 'No db, compare results row, DSN D, --temp-database (issue 951)'
); );
$sb->load_file('master', "$sample/002/tables.sql"); $sb->load_file('master', "$sample/002/tables.sql");
$sb->load_file('master1', "$sample/002/tables.sql"); $sb->load_file('master1', "$sample/002/tables.sql");
$dbh1->do('insert into test.t values (5)'); $dbh1->do('insert into test.t values (5)');
ok( ok(
no_diff( no_diff(
sub { pt_upgrade::main(@op_args, "$log/002/no-db.log", sub { pt_upgrade::main(@op_args, "$log/002/no-db.log",
'h=127.1,P=12345,D=test', 'P=12348,D=test', 'h=127.1,P=12345,D=test', 'P=12348,D=test',
qw(--compare-results-method rows --temp-database tmp_db)) }, qw(--compare-results-method rows --temp-database tmp_db)) },
"$sample/002/report-01.txt", "$sample/002/report-01.txt",
), ),
'No db, compare results row, DSN D' 'No db, compare results row, DSN D'
); );
is_deeply( is_deeply(
$dbh1->selectall_arrayref('show tables from `test`'), $dbh1->selectall_arrayref('show tables from `test`'),
[['t']], [['t']],
"Didn't create temp table in event's db" "Didn't create temp table in event's db"
); );
is_deeply( is_deeply(
$dbh1->selectall_arrayref('show tables from `tmp_db`'), $dbh1->selectall_arrayref('show tables from `tmp_db`'),
[['mk_upgrade_left']], [['mk_upgrade_left']],
"Createed temp table in --temp-database" "Createed temp table in --temp-database"
); );
$sb->wipe_clean($dbh1); $sb->wipe_clean($dbh1);
$sb->wipe_clean($dbh2); $sb->wipe_clean($dbh2);
}
# ############################################################################# # #############################################################################
# Bug 926598: DBD::mysql bug causes pt-upgrade to use wrong # Bug 926598: DBD::mysql bug causes pt-upgrade to use wrong
# precision (M) and scale (D) # precision (M) and scale (D)
# ############################################################################# # #############################################################################
$sb->load_file('master', "$sample/003/tables.sql"); SKIP: {
$sb->load_file('master1', "$sample/003/tables.sql"); skip "LOAD DATA LOCAL INFILE is disabled", 2 if $load_data_is_disabled;
# Make a difference on one host so diff_rows() is called. $sb->load_file('master', "$sample/003/tables.sql");
$dbh1->do('insert into test.t values (4, 1.00)'); $sb->load_file('master1', "$sample/003/tables.sql");
ok( # Make a difference on one host so diff_rows() is called.
no_diff( $dbh1->do('insert into test.t values (4, 1.00)');
sub { pt_upgrade::main(@args, "$log/003/double.log",
qw(--compare-results-method rows)) },
"$sample/003/report001.txt",
),
'M, D diff (bug 926598)',
);
my $row = $dbh1->selectrow_arrayref("show create table test.mk_upgrade_left"); ok(
like( no_diff(
$row->[1], sub { pt_upgrade::main(@args, "$log/003/double.log",
qr/[`"]SUM\(total\)[`"]\s+double\sDEFAULT/i, qw(--compare-results-method rows)) },
"No M,D in table def (bug 926598)" "$sample/003/report001.txt",
); ),
'M, D diff (bug 926598)',
);
my $row = $dbh1->selectrow_arrayref("show create table test.mk_upgrade_left");
like(
$row->[1],
qr/[`"]SUM\(total\)[`"]\s+double\sDEFAULT/i,
"No M,D in table def (bug 926598)"
);
}
# ############################################################################# # #############################################################################
# Done. # Done.

View File

@@ -29,6 +29,9 @@ if ( !$dbh1 ) {
elsif ( !$dbh2 ) { elsif ( !$dbh2 ) {
plan skip_all => 'Cannot connect to second sandbox master'; plan skip_all => 'Cannot connect to second sandbox master';
} }
elsif ( PerconaTest::load_data_is_disabled($dbh1) ) {
plan skip_all => 'LOAD DATA LOCAL INFILE is disabled';
}
else { else {
plan tests => 6; plan tests => 6;
} }