pt-archiver & tests: Deal with LOAD DATA LOCAL INFILE being disabled.

This occasionally shows up in some OSs, like Ubuntu 12.04 LTS.
This commit is contained in:
Brian Fraser
2012-07-11 17:31:03 -03:00
parent f38512c0d1
commit e9c9608c33
8 changed files with 72 additions and 5 deletions

View File

@@ -3945,6 +3945,22 @@ 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.
if ( $table->{a} ) {

View File

@@ -51,6 +51,9 @@ make_sandbox() {
if [ -n "$MULTIPLE_BUFFER_POOLS" ]; then
echo "innodb_buffer_pool_instances=$MULTIPLE_BUFFER_POOLS" >> /tmp/$port/my.sandbox.cnf
fi
if [ -n "$LOCAL_INFILE" ]; then
echo "local-infile=$LOCAL_INFILE" >> /tmp/$port/my.sandbox.cnf
fi
# If the sandbox is a slave, set it read_only.
if [ "$type" = "slave" ]; then

View File

@@ -22,8 +22,12 @@ 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 => 10;
plan tests => 11;
}
my $output;
@@ -34,6 +38,10 @@ my $cmd = "$trunk/bin/pt-archiver";
$sb->wipe_clean($dbh);
$sb->create_dbs($dbh, ['test']);
if ( PerconaTest::load_data_is_disabled($dbh) ) {
test_disabled_load_data($dbh, $sb);
}
else {
# Test --bulk-insert
$sb->load_file('master', 't/pt-archiver/samples/table5.sql');
$dbh->do('INSERT INTO `test`.`table_5_copy` SELECT * FROM `test`.`table_5`');
@@ -84,6 +92,43 @@ 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);
diag(`$trunk/sandbox/stop-sandbox 2900 >/dev/null 2>&1`);
$master3_dbh->disconnect() if $master3_dbh;
}
}
sub test_disabled_load_data {
my ($dbh, $sb) = @_;
$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!,
""
);
}
# #############################################################################
# Done.
# #############################################################################

View File

@@ -22,6 +22,9 @@ 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;
}

View File

@@ -159,7 +159,7 @@ diag('Loading sample dataset...');
$sb->load_file('master', "$sample/basic_no_fks.sql");
$master_dbh->do("USE pt_osc");
$master_dbh->do("TRUNCATE TABLE t");
$master_dbh->do("LOAD DATA LOCAL INFILE '$trunk/t/pt-online-schema-change/samples/basic_no_fks.data' INTO TABLE t");
$master_dbh->do("LOAD DATA INFILE '$trunk/t/pt-online-schema-change/samples/basic_no_fks.data' INTO TABLE t");
$master_dbh->do("ANALYZE TABLE t");
$sb->wait_for_slaves();

View File

@@ -363,7 +363,7 @@ is(
# Test --where.
# #############################################################################
$sb->load_file('master', 't/pt-table-checksum/samples/600cities.sql');
$master_dbh->do("LOAD DATA LOCAL INFILE '$trunk/t/pt-table-checksum/samples/600cities.data' INTO TABLE test.t");
$master_dbh->do("LOAD DATA INFILE '$trunk/t/pt-table-checksum/samples/600cities.data' INTO TABLE test.t");
$output = output(
sub { $exit_status = pt_table_checksum::main(@args,

View File

@@ -113,7 +113,7 @@ unlike(
# on replicas
# #############################################################################
$sb->load_file('master', 't/pt-table-checksum/samples/600cities.sql');
$master_dbh->do("LOAD DATA LOCAL INFILE '$trunk/t/pt-table-checksum/samples/600cities.data' INTO TABLE test.t");
$master_dbh->do("LOAD DATA INFILE '$trunk/t/pt-table-checksum/samples/600cities.data' INTO TABLE test.t");
$master_dbh->do("SET SQL_LOG_BIN=0");
$master_dbh->do("DELETE FROM test.t WHERE id > 100");
$master_dbh->do("SET SQL_LOG_BIN=1");

View File

@@ -43,7 +43,7 @@ my $output;
sub load_data_infile {
my ($file, $where) = @_;
$master_dbh->do('truncate table percona.checksums');
$master_dbh->do("LOAD DATA LOCAL INFILE '$trunk/t/pt-table-checksum/samples/checksum_results/$file' INTO TABLE percona.checksums");
$master_dbh->do("LOAD DATA INFILE '$trunk/t/pt-table-checksum/samples/checksum_results/$file' INTO TABLE percona.checksums");
if ( $where ) {
PerconaTest::wait_for_table($slave1_dbh, 'percona.checksums', $where);
}