Remove LOAD DATA check from pt-archiver and pt-upgrade. Make test-env check if LOAD DATA works and PerconaTest export . Rewrite how pt-archiver/t/bulk_insert.t conditionalizes on LOAD DATA working.

This commit is contained in:
Daniel Nichter
2012-07-31 15:37:02 -06:00
parent 702d475eda
commit 570b26de20
8 changed files with 46 additions and 127 deletions

View File

@@ -3955,24 +3955,8 @@ sub main {
$dp->get_cxn_params($table), { AutoCommit => $ac });
PTDEBUG && _d('Inspecting table on', $dp->as_string($table));
if ( $o->get('bulk-insert') ) {
local $@;
my $sql = "LOAD DATA LOCAL INFILE '/dev/null' INTO TABLE "
. "`test`.`pt_not_there`";
eval { $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();
die("--bulk-insert cannot work as LOAD DATA LOCAL INFILE "
. "is disabled. See http://kb.percona.com/troubleshoot-load-data-infile"
);
}
};
}
# Set options that can enable removing data on the master and archiving it
# on the slaves.
# Set options that can enable removing data on the master
# and archiving it on the slaves.
if ( $table->{a} ) {
$dbh->do("USE $table->{a}");
}

View File

@@ -10371,32 +10371,6 @@ sub main {
$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.
# ########################################################################
@@ -10430,6 +10404,7 @@ sub main {
# ########################################################################
# Make compare modules in order.
# ########################################################################
my $compare = $o->get('compare');
my @compare_modules;
if ( $compare->{results} ) {
my $method = lc $o->get('compare-results-method');

View File

@@ -68,6 +68,7 @@ our @EXPORT = qw(
$trunk
$dsn_opts
$sandbox_version
$can_load_data
);
our $trunk = $ENV{PERCONA_TOOLKIT_BRANCH};
@@ -78,6 +79,8 @@ eval {
$sandbox_version = $v if $v;
};
our $can_load_data = can_load_data();
our $dsn_opts = [
{
key => 'A',
@@ -777,17 +780,9 @@ sub tables_used {
return [ sort keys %tables ];
}
sub load_data_is_disabled {
my ($dbh) = @_;
my $sql = "LOAD DATA LOCAL INFILE '/dev/null' INTO TABLE "
. "`t`.`pt_not_there`";
local $@;
if (!eval { $dbh->do($sql); 1 } ) {
my $e = $@;
return 1 if $e =~ qr/\QDBD::mysql::db do failed: The used command is not allowed with this MySQL version [for Statement "LOAD DATA LOCAL INFILE/;
}
return;
sub can_load_data {
my $output = `/tmp/12345/use -e "SELECT * FROM percona_test.load_data" 2>/dev/null`;
return ($output || '') =~ /42/;
}
1;

View File

@@ -234,6 +234,23 @@ set_mysql_version() {
fi
}
check_load_data() {
# LOAD DATA is disabled or broken on some boxes. PerconaTest exports
# $can_load_data which is true if percona_test.load_data has the 42 row,
# signaling that LOAD DATA LOCAL INFILE worked.
/tmp/12345/use -e "CREATE TABLE IF NOT EXISTS percona_test.load_data (i int)"
echo 42 > /tmp/load_data_test.$$
/tmp/12345/use -e "LOAD DATA LOCAL INFILE '/tmp/load_data_test.$$' INTO TABLE percona_test.load_data"
sleep 0.1
rm /tmp/load_data_test.$$
/tmp/12345/use -e "SELECT * FROM percona_test.load_data" | grep 42 >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "LOAD DATA LOCAL INFILE is enabled"
else
echo "LOAD DATA LOCAL INFILE is disabled"
fi
}
# ###########################################################################
# Sanity check the cmd line options.
# ###########################################################################
@@ -290,6 +307,7 @@ case $opt in
echo "OK"
fi
../util/checksum-test-dataset
check_load_data
ping=$(/tmp/12345/use -ss -e "SELECT MD5(RAND())")
/tmp/12345/use -e "create table percona_test.sentinel(id int primary key, ping varchar(64) not null default '')"
/tmp/12345/use -e "insert into percona_test.sentinel(id, ping) values(1, '$ping')";

View File

@@ -22,12 +22,8 @@ my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
elsif ( PerconaTest::load_data_is_disabled($dbh) ) {
diag("LOAD DATA LOCAL INFILE is disabled, only going to test the error message");
plan tests => 2;
}
else {
plan tests => 11;
elsif ( !$can_load_data ) {
plan skip_all => 'LOAD DATA LOCAL INFILE is disabled';
}
my $output;
@@ -35,11 +31,6 @@ my $rows;
my $cnf = "/tmp/12345/my.sandbox.cnf";
my $cmd = "$trunk/bin/pt-archiver";
if ( PerconaTest::load_data_is_disabled($dbh) ) {
test_disabled_load_data($dbh, $sb, 'master', $cnf);
}
else {
$sb->wipe_clean($dbh);
$sb->create_dbs($dbh, ['test']);
@@ -67,7 +58,6 @@ $output = `/tmp/12345/use -N -e "checksum table test.table_5_dest, test.table_5_
my ( $chks ) = $output =~ m/dest\s+(\d+)/;
like($output, qr/copy\s+$chks/, 'copy checksum');
# ############################################################################
# Issue 1260: mk-archiver --bulk-insert data loss
# ############################################################################
@@ -93,48 +83,10 @@ is_deeply(
"--bulk-insert archived 7 rows (issue 1260)"
);
# Test that the tool bails out early if LOAD DATA LOCAL INFILE is disabled
{
if ( -d "/tmp/2900" ) {
diag(`$trunk/sandbox/stop-sandbox 2900 >/dev/null 2>&1`);
}
local $ENV{LOCAL_INFILE} = 0;
diag(`$trunk/sandbox/start-sandbox master 2900 >/dev/null 2>&1`);
my $master3_dbh = $sb->get_dbh_for('master3');
test_disabled_load_data($master3_dbh, $sb, 'master3', "/tmp/2900/my.sandbox.cnf");
diag(`$trunk/sandbox/stop-sandbox 2900 >/dev/null 2>&1`);
$master3_dbh->disconnect() if $master3_dbh;
}
}
sub test_disabled_load_data {
my ($dbh, $sb, $master, $cnf) = @_;
$sb->wipe_clean($dbh);
$sb->create_dbs($dbh, ['test']);
$sb->load_file($master, 't/pt-archiver/samples/table5.sql');
$dbh->do('INSERT INTO `test`.`table_5_copy` SELECT * FROM `test`.`table_5`');
my ($output, undef) = full_output(
sub { pt_archiver::main(qw(--no-ascend --limit 50 --bulk-insert),
qw(--bulk-delete --where 1=1 --statistics),
'--source', "D=test,t=table_5,F=$cnf",
'--dest', "t=table_5_dest") },
);
like($output,
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"
);
}
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;
exit;

View File

@@ -22,11 +22,8 @@ my $dbh = $sb->get_dbh_for('master');
if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
elsif ( PerconaTest::load_data_is_disabled($dbh) ) {
plan skip_all => 'Cannot use --bulk-insert with LOAD DATA LOCAL INFILE disabled';
}
else {
plan tests => 5;
elsif ( !$can_load_data ) {
plan skip_all => 'LOAD DATA LOCAL INFILE is disabled';
}
my $output;
@@ -98,4 +95,5 @@ is_deeply(
# #############################################################################
$sb->wipe_clean($dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;
exit;

View File

@@ -29,11 +29,6 @@ if ( !$dbh1 ) {
elsif ( !$dbh2 ) {
plan skip_all => 'Cannot connect to second sandbox master';
}
else {
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 @op_args = (qw(-u msandbox -p msandbox),
@@ -67,7 +62,7 @@ ok(
);
SKIP: {
skip "LOAD DATA LOCAL INFILE is disabled", 2 if $load_data_is_disabled;
skip "LOAD DATA LOCAL INFILE is disabled", 2 unless $can_load_data;
ok(
no_diff(
@@ -114,7 +109,8 @@ $sb->wipe_clean($dbh2);
# compare-results-method=rows
# #############################################################################
SKIP: {
skip "LOAD DATA LOCAL INFILE is disabled", 4 if $load_data_is_disabled;
skip "LOAD DATA LOCAL INFILE is disabled", 4 unless $can_load_data;
$sb->load_file('master', "$sample/002/tables.sql");
$sb->load_file('master1', "$sample/002/tables.sql");
@@ -159,7 +155,6 @@ SKIP: {
$sb->wipe_clean($dbh1);
$sb->wipe_clean($dbh2);
}
# #############################################################################
@@ -167,7 +162,7 @@ SKIP: {
# precision (M) and scale (D)
# #############################################################################
SKIP: {
skip "LOAD DATA LOCAL INFILE is disabled", 2 if $load_data_is_disabled;
skip "LOAD DATA LOCAL INFILE is disabled", 2 unless $can_load_data;
$sb->load_file('master', "$sample/003/tables.sql");
$sb->load_file('master1', "$sample/003/tables.sql");
@@ -199,4 +194,5 @@ diag(`rm /tmp/left-outfile.txt /tmp/right-outfile.txt 2>/dev/null`);
diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null`);
$sb->wipe_clean($dbh1);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;
exit;

View File

@@ -15,6 +15,13 @@ use PerconaTest;
use Sandbox;
require "$trunk/bin/pt-upgrade";
# This test calls pt-upgrade with --compare-results-method rows
# which use LOAD DATA LOCAL INFILE. If LOAD DATA is disabled,
# then this this test can't run.
if ( !$can_load_data ) {
plan skip_all => 'LOAD DATA LOCAL INFILE is disabled';
}
# This runs immediately if the server is already running, else it starts it.
diag(`$trunk/sandbox/start-sandbox master 12348 >/dev/null`);
@@ -31,13 +38,6 @@ elsif ( !$dbh2 ) {
diag(`$trunk/sandbox/stop-sandbox master 12348 >/dev/null`);
plan skip_all => 'Cannot connect to second sandbox master';
}
elsif ( PerconaTest::load_data_is_disabled($dbh1) ) {
diag(`$trunk/sandbox/stop-sandbox master 12348 >/dev/null`);
plan skip_all => 'LOAD DATA LOCAL INFILE is disabled';
}
else {
plan tests => 6;
}
$sb->load_file('master', 't/pt-upgrade/samples/001/tables.sql');
$sb->load_file('master1', 't/pt-upgrade/samples/001/tables.sql');
@@ -102,4 +102,5 @@ ok(
$sb->wipe_clean($dbh1);
diag(`$trunk/sandbox/stop-sandbox master 12348 >/dev/null`);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;
exit;