diff --git a/bin/pt-archiver b/bin/pt-archiver index 548bcd39..89f234fc 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -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} ) { diff --git a/sandbox/start-sandbox b/sandbox/start-sandbox index eea8f943..06a75248 100755 --- a/sandbox/start-sandbox +++ b/sandbox/start-sandbox @@ -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 diff --git a/t/pt-archiver/bulk_insert.t b/t/pt-archiver/bulk_insert.t index 6bd093e5..ad95e36d 100644 --- a/t/pt-archiver/bulk_insert.t +++ b/t/pt-archiver/bulk_insert.t @@ -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. # ############################################################################# diff --git a/t/pt-archiver/bulk_regular_insert.t b/t/pt-archiver/bulk_regular_insert.t index 70babac4..b8315e1e 100644 --- a/t/pt-archiver/bulk_regular_insert.t +++ b/t/pt-archiver/bulk_regular_insert.t @@ -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; } diff --git a/t/pt-online-schema-change/alter_active_table.t b/t/pt-online-schema-change/alter_active_table.t index 645dea23..e5e316be 100644 --- a/t/pt-online-schema-change/alter_active_table.t +++ b/t/pt-online-schema-change/alter_active_table.t @@ -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(); diff --git a/t/pt-table-checksum/basics.t b/t/pt-table-checksum/basics.t index a8e7cd53..9fa2b17b 100644 --- a/t/pt-table-checksum/basics.t +++ b/t/pt-table-checksum/basics.t @@ -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, diff --git a/t/pt-table-checksum/chunk_size.t b/t/pt-table-checksum/chunk_size.t index d8250067..98d243f0 100644 --- a/t/pt-table-checksum/chunk_size.t +++ b/t/pt-table-checksum/chunk_size.t @@ -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"); diff --git a/t/pt-table-checksum/resume.t b/t/pt-table-checksum/resume.t index 07edcf09..02875469 100644 --- a/t/pt-table-checksum/resume.t +++ b/t/pt-table-checksum/resume.t @@ -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); }