From 9ae940cd7661abb95375f9ddd01efc8c224fd84f Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 11 Jul 2012 17:29:04 -0300 Subject: [PATCH 1/8] PerconaTest: Add load_data_is_disabled and correct full_output load_data_is_disabled checks if LOAD DATA LOCAL INFILE is disabled; it'll be used in the future by a couple of tests. full_output was changed to use two different filehandles for STDOUT and STDERR; THis is because otherwise, code closing STDOUT (like the --quiet option in pt-osc) would also accidentally close STDERR. --- lib/PerconaTest.pm | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/PerconaTest.pm b/lib/PerconaTest.pm index 08fbd0f2..8221de9b 100644 --- a/lib/PerconaTest.pm +++ b/lib/PerconaTest.pm @@ -717,12 +717,17 @@ sub full_output { my ( $code, %args ) = @_; die "I need a code argument" unless $code; - my (undef, $file) = tempfile(); - open *output_fh, '>', $file - or die "Cannot open file $file: $OS_ERROR"; - local *STDOUT = *output_fh; + local (*STDOUT, *STDERR); + require IO::File; - *STDERR = *STDOUT; + my (undef, $file) = tempfile(); + open *STDOUT, '>', $file + or die "Cannot open file $file: $OS_ERROR"; + *STDOUT->autoflush(1); + + open *STDERR, '>', $file + or die "Cannot open file $file: $OS_ERROR"; + *STDERR->autoflush(1); my $status; if (my $pid = fork) { @@ -745,7 +750,7 @@ sub full_output { else { exit $code->(); } - close *output_fh; + close $_ or die "Cannot close $_: $OS_ERROR" for qw(STDOUT STDERR); my $output = do { local $/; open my $fh, "<", $file or die $!; <$fh> }; return ($output, $status); @@ -772,6 +777,19 @@ 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; +} + 1; } # ########################################################################### From f38512c0d1a12e6ce62066b342223dca1c255105 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 11 Jul 2012 17:30:37 -0300 Subject: [PATCH 2/8] t/pt-online-schema-change/sanity_checks.t: use full_output() --- t/pt-online-schema-change/sanity_checks.t | 29 ++++++++++++++++++----- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/t/pt-online-schema-change/sanity_checks.t b/t/pt-online-schema-change/sanity_checks.t index 4b40c4c8..a2cdc9fb 100644 --- a/t/pt-online-schema-change/sanity_checks.t +++ b/t/pt-online-schema-change/sanity_checks.t @@ -46,16 +46,22 @@ my $rows; # ############################################################################# # Of course, the orig database and table must exist. -throws_ok( +($output, undef) = full_output( sub { pt_online_schema_change::main(@args, "$dsn,D=nonexistent_db,t=t", qw(--dry-run)) }, +); + +like( $output, qr/Unknown database/, "Original database must exist" ); -throws_ok( +($output, undef) = full_output( sub { pt_online_schema_change::main(@args, "$dsn,D=mysql,t=nonexistent_tbl", qw(--dry-run)) }, +); + +like( $output, qr/`mysql`.`nonexistent_tbl` does not exist/, "Original table must exist" ); @@ -66,9 +72,12 @@ $slave_dbh->do("USE pt_osc"); # The orig table cannot have any triggers. $master_dbh->do("CREATE TRIGGER pt_osc.pt_osc_test AFTER DELETE ON pt_osc.t FOR EACH ROW DELETE FROM pt_osc.t WHERE 0"); -throws_ok( +($output, undef) = full_output( sub { pt_online_schema_change::main(@args, "$dsn,D=pt_osc,t=t", qw(--dry-run)) }, +); + +like( $output, qr/`pt_osc`.`t` has triggers/, "Original table cannot have triggers" ); @@ -77,9 +86,12 @@ $master_dbh->do('DROP TRIGGER pt_osc.pt_osc_test'); # The orig table must have a pk or unique index so the delete trigger is safe. $master_dbh->do("ALTER TABLE pt_osc.t DROP COLUMN id"); $master_dbh->do("ALTER TABLE pt_osc.t DROP INDEX c"); -throws_ok( +($output, undef) = full_output( sub { pt_online_schema_change::main(@args, "$dsn,D=pt_osc,t=t", qw(--dry-run)) }, +); + +like( $output, qr/`pt_osc`.`t` does not have a PRIMARY KEY or a unique index/, "Original table must have a PK or unique index" ); @@ -97,9 +109,14 @@ for my $i ( 1..10 ) { $master_dbh->do("create table $table (id int)"); } -throws_ok( +my $x; +($output, $x) = full_output( sub { pt_online_schema_change::main(@args, - "$dsn,D=pt_osc,t=t", qw(--quiet --dry-run)) }, + "$dsn,D=pt_osc,t=t", qw(--quiet --dry-run)); }, +); + +like( + $output, qr/Failed to find a unique new table name/, "Doesn't try forever to find a new table name" ); From e9c9608c335a211a8dde8604e7d64afb4e0b7509 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 11 Jul 2012 17:31:03 -0300 Subject: [PATCH 3/8] pt-archiver & tests: Deal with LOAD DATA LOCAL INFILE being disabled. This occasionally shows up in some OSs, like Ubuntu 12.04 LTS. --- bin/pt-archiver | 16 +++++++ sandbox/start-sandbox | 3 ++ t/pt-archiver/bulk_insert.t | 47 ++++++++++++++++++- t/pt-archiver/bulk_regular_insert.t | 3 ++ .../alter_active_table.t | 2 +- t/pt-table-checksum/basics.t | 2 +- t/pt-table-checksum/chunk_size.t | 2 +- t/pt-table-checksum/resume.t | 2 +- 8 files changed, 72 insertions(+), 5 deletions(-) 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); } From e0d97bbc98746a11d8b95fc19d374b663af00ff5 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 11 Jul 2012 18:36:43 -0300 Subject: [PATCH 4/8] pt-upgrade: Deal with LOCAL INFILE being disabled --- bin/pt-upgrade | 27 ++++++- t/pt-archiver/bulk_insert.t | 2 +- t/pt-upgrade/basics.t | 156 ++++++++++++++++++++---------------- t/pt-upgrade/warnings.t | 3 + 4 files changed, 115 insertions(+), 73 deletions(-) diff --git a/bin/pt-upgrade b/bin/pt-upgrade index b1cb2986..00070224 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -10990,6 +10990,32 @@ 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. # ######################################################################## @@ -11023,7 +11049,6 @@ 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'); diff --git a/t/pt-archiver/bulk_insert.t b/t/pt-archiver/bulk_insert.t index ad95e36d..8ad8380a 100644 --- a/t/pt-archiver/bulk_insert.t +++ b/t/pt-archiver/bulk_insert.t @@ -125,7 +125,7 @@ sub test_disabled_load_data { 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" ); } diff --git a/t/pt-upgrade/basics.t b/t/pt-upgrade/basics.t index 064f7b81..702be9a4 100644 --- a/t/pt-upgrade/basics.t +++ b/t/pt-upgrade/basics.t @@ -33,6 +33,8 @@ 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), '--compare', 'results,warnings', @@ -64,23 +66,27 @@ ok( 'Report for multiple queries (checksum method)' ); -ok( - no_diff( - 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)' -); +SKIP: { + skip "LOAD DATA LOCAL INFILE is disabled", 2 if $load_data_is_disabled; + + ok( + no_diff( + 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( - 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( + 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( no_diff( @@ -107,76 +113,84 @@ $sb->wipe_clean($dbh2); # Issue 951: mk-upgrade "I need a db argument" error with # compare-results-method=rows # ############################################################################# -$sb->load_file('master', "$sample/002/tables.sql"); -$sb->load_file('master1', "$sample/002/tables.sql"); +SKIP: { + 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. -$dbh1->do('insert into test.t values (5)'); + # Make a difference on one host so diff_rows() is called. + $dbh1->do('insert into test.t values (5)'); -ok( - no_diff( - sub { pt_upgrade::main(@op_args, "$log/002/no-db.log", - 'h=127.1,P=12345,D=test', 'P=12348,D=test', - qw(--compare-results-method rows --temp-database test)) }, - "$sample/002/report-01.txt", - ), - 'No db, compare results row, DSN D, --temp-database (issue 951)' -); + ok( + no_diff( + sub { pt_upgrade::main(@op_args, "$log/002/no-db.log", + 'h=127.1,P=12345,D=test', 'P=12348,D=test', + qw(--compare-results-method rows --temp-database test)) }, + "$sample/002/report-01.txt", + ), + 'No db, compare results row, DSN D, --temp-database (issue 951)' + ); -$sb->load_file('master', "$sample/002/tables.sql"); -$sb->load_file('master1', "$sample/002/tables.sql"); -$dbh1->do('insert into test.t values (5)'); + $sb->load_file('master', "$sample/002/tables.sql"); + $sb->load_file('master1', "$sample/002/tables.sql"); + $dbh1->do('insert into test.t values (5)'); -ok( - no_diff( - sub { pt_upgrade::main(@op_args, "$log/002/no-db.log", - 'h=127.1,P=12345,D=test', 'P=12348,D=test', - qw(--compare-results-method rows --temp-database tmp_db)) }, - "$sample/002/report-01.txt", - ), - 'No db, compare results row, DSN D' -); + ok( + no_diff( + sub { pt_upgrade::main(@op_args, "$log/002/no-db.log", + 'h=127.1,P=12345,D=test', 'P=12348,D=test', + qw(--compare-results-method rows --temp-database tmp_db)) }, + "$sample/002/report-01.txt", + ), + 'No db, compare results row, DSN D' + ); -is_deeply( - $dbh1->selectall_arrayref('show tables from `test`'), - [['t']], - "Didn't create temp table in event's db" -); + is_deeply( + $dbh1->selectall_arrayref('show tables from `test`'), + [['t']], + "Didn't create temp table in event's db" + ); -is_deeply( - $dbh1->selectall_arrayref('show tables from `tmp_db`'), - [['mk_upgrade_left']], - "Createed temp table in --temp-database" -); + is_deeply( + $dbh1->selectall_arrayref('show tables from `tmp_db`'), + [['mk_upgrade_left']], + "Createed temp table in --temp-database" + ); + + $sb->wipe_clean($dbh1); + $sb->wipe_clean($dbh2); -$sb->wipe_clean($dbh1); -$sb->wipe_clean($dbh2); +} # ############################################################################# # Bug 926598: DBD::mysql bug causes pt-upgrade to use wrong # precision (M) and scale (D) # ############################################################################# -$sb->load_file('master', "$sample/003/tables.sql"); -$sb->load_file('master1', "$sample/003/tables.sql"); +SKIP: { + skip "LOAD DATA LOCAL INFILE is disabled", 2 if $load_data_is_disabled; -# Make a difference on one host so diff_rows() is called. -$dbh1->do('insert into test.t values (4, 1.00)'); + $sb->load_file('master', "$sample/003/tables.sql"); + $sb->load_file('master1', "$sample/003/tables.sql"); -ok( - no_diff( - sub { pt_upgrade::main(@args, "$log/003/double.log", - qw(--compare-results-method rows)) }, - "$sample/003/report001.txt", - ), - 'M, D diff (bug 926598)', -); + # Make a difference on one host so diff_rows() is called. + $dbh1->do('insert into test.t values (4, 1.00)'); -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)" -); + ok( + no_diff( + 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"); + like( + $row->[1], + qr/[`"]SUM\(total\)[`"]\s+double\sDEFAULT/i, + "No M,D in table def (bug 926598)" + ); +} # ############################################################################# # Done. diff --git a/t/pt-upgrade/warnings.t b/t/pt-upgrade/warnings.t index a89454f5..fce82d2b 100644 --- a/t/pt-upgrade/warnings.t +++ b/t/pt-upgrade/warnings.t @@ -29,6 +29,9 @@ if ( !$dbh1 ) { elsif ( !$dbh2 ) { 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 { plan tests => 6; } From d43ad54b387739142fe2d56b7d00b4ce294a8e59 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 11 Jul 2012 20:27:02 -0300 Subject: [PATCH 5/8] Missing skips for the LOCAL INFILE issue --- t/lib/CompareResults.t | 11 +++++++++-- t/pt-upgrade/warnings.t | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/t/lib/CompareResults.t b/t/lib/CompareResults.t index fc760979..f15c18c6 100644 --- a/t/lib/CompareResults.t +++ b/t/lib/CompareResults.t @@ -303,8 +303,10 @@ is_deeply( # ############################################################################# # Test the rows method. # ############################################################################# - my $tmpdir = '/tmp/mk-upgrade-res'; +SKIP: { + skip "LOAD DATA LOCAL INFILE is disabled, can't test method => rows", 30 + if PerconaTest::load_data_is_disabled($dbh1); diag(`rm -rf $tmpdir 2>/dev/null; mkdir $tmpdir`); $sb->load_file('master', "t/lib/samples/compare-results.sql"); @@ -680,7 +682,7 @@ is( $report, 'rows: report, left with more rows' ); - +} # ############################################################################# # Try to compare without having done the actions. # ############################################################################# @@ -725,6 +727,9 @@ is_deeply( 'No differences after bad compare()' ); +SKIP: { + skip "LOAD DATA LOCAL INFILE is disabled, can't test method => rows", 2 + if PerconaTest::load_data_is_disabled($dbh1); $cr = new CompareResults( method => 'rows', 'base-dir' => $tmpdir, @@ -754,6 +759,8 @@ is_deeply( 'No differences after bad compare()' ); +} + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-upgrade/warnings.t b/t/pt-upgrade/warnings.t index fce82d2b..01d086b8 100644 --- a/t/pt-upgrade/warnings.t +++ b/t/pt-upgrade/warnings.t @@ -24,12 +24,15 @@ my $dbh1 = $sb->get_dbh_for('master'); my $dbh2 = $sb->get_dbh_for('master1'); if ( !$dbh1 ) { + diag(`$trunk/sandbox/stop-sandbox master 12348 >/dev/null`); plan skip_all => 'Cannot connect to sandbox master'; } 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 { From f9f8c4a675827c986da80176c8f9c92a96985e7e Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Wed, 11 Jul 2012 20:33:35 -0300 Subject: [PATCH 6/8] Increase the timeout for t/pt-table-checksum/throttle.t to avoid white smoke --- t/pt-table-checksum/throttle.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/pt-table-checksum/throttle.t b/t/pt-table-checksum/throttle.t index 0b938412..879d89a3 100644 --- a/t/pt-table-checksum/throttle.t +++ b/t/pt-table-checksum/throttle.t @@ -69,7 +69,7 @@ wait_until(sub { # wait for it to stop "lagging". ($output) = PerconaTest::full_output( sub { pt_table_checksum::main(@args, qw(-t sakila.city)) }, - wait_for => 3, + wait_for => 10, ); like( From 0277f19f6d682ca5cb9195608e3ec5c5f7cd51f7 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Thu, 12 Jul 2012 14:14:47 -0300 Subject: [PATCH 7/8] t/pt-archiver/bulk_insert.t: Don't assume that the db is already there --- t/pt-archiver/bulk_insert.t | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/t/pt-archiver/bulk_insert.t b/t/pt-archiver/bulk_insert.t index 8ad8380a..8db5cf07 100644 --- a/t/pt-archiver/bulk_insert.t +++ b/t/pt-archiver/bulk_insert.t @@ -35,13 +35,14 @@ my $rows; my $cnf = "/tmp/12345/my.sandbox.cnf"; 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 { + +$sb->wipe_clean($dbh); +$sb->create_dbs($dbh, ['test']); + # 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`'); @@ -113,6 +114,8 @@ is_deeply( sub test_disabled_load_data { my ($dbh, $sb) = @_; + $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`'); From 4266e926924f9244683398706d4e008810063480 Mon Sep 17 00:00:00 2001 From: Brian Fraser Date: Thu, 12 Jul 2012 16:25:39 -0300 Subject: [PATCH 8/8] Silence tput and stty warnings in ReadKeyMini --- bin/pt-diskstats | 39 ++++++++++++++------------------------- lib/ReadKeyMini.pm | 21 +++++++++++---------- 2 files changed, 25 insertions(+), 35 deletions(-) diff --git a/bin/pt-diskstats b/bin/pt-diskstats index 876cf37d..e25634cb 100755 --- a/bin/pt-diskstats +++ b/bin/pt-diskstats @@ -1389,25 +1389,20 @@ sub _d { # ########################################################################### # ########################################################################### -# ReadKeyMini +# ReadKeyMini package +# This package is a copy without comments from the original. The original +# with comments and its test file can be found in the Bazaar repository at, +# lib/ReadKeyMini.pm +# t/lib/ReadKeyMini.t +# See https://launchpad.net/percona-toolkit for more information. # ########################################################################### +{ + BEGIN { package ReadKeyMini; -# Here be magic. We lie to %INC and say that someone already pulled us from -# the filesystem. Which might be true, if this is inside a .pm file, but -# might not be, if we are part of the big file. The spurious BEGINs are mostly -# unnecesary, but if we aren't inside a .pm and something uses us, import or -# EXPORT_OK might not yet be defined. Though that probably won't help. -# Costs us nothing though, so worth trying. Putting this on top of the file -# would solve the issue. BEGIN { $INC{"ReadKeyMini.pm"} ||= 1 } -# Package: ReadKeyMini -# ReadKeyMini is a wrapper around Term::ReadKey. If that's available, -# we use ReadMode and GetTerminalSize from there. Otherwise, we use homebrewn -# definitions. - use warnings; use strict; use English qw(-no_match_vars); @@ -1434,14 +1429,14 @@ my %modes = ( 'ultra-raw' => 5, ); -# This primarily comes from the Perl Cookbook, recipe 15.8 { + my $fd_stdin = fileno(STDIN); my $flags; unless ( $PerconaTest::DONT_RESTORE_STDIN ) { $flags = fcntl(STDIN, F_GETFL, 0) - or die "can't fcntl F_GETFL: $!"; + or warn "can't fcntl F_GETFL: $!"; } my $term = POSIX::Termios->new(); $term->getattr($fd_stdin); @@ -1475,7 +1470,7 @@ my %modes = ( $term->setattr( $fd_stdin, TCSANOW ); unless ( $PerconaTest::DONT_RESTORE_STDIN ) { fcntl(STDIN, F_SETFL, $flags) - or die "can't fcntl F_SETFL: $!"; + or warn "can't fcntl F_SETFL: $!"; } } @@ -1489,9 +1484,6 @@ sub readkey { sysread(STDIN, $key, 1); my $timeout = 0.1; if ( $key eq "\033" ) { - # Ugly and broken hack, but good enough for the two minutes it took to write. - # Namely, Ctrl escapes, the F-NUM keys, and other stuff you can send from the keyboard - # take more than one "character" to represent, and would be wrong to break into pieces. { my $x = ''; STDIN->blocking(0); @@ -1505,15 +1497,11 @@ sub readkey { return $key; } -# As per perlfaq8: BEGIN { eval { no warnings; local $^W; require 'sys/ioctl.ph' }; if ( !defined &TIOCGWINSZ ) { *TIOCGWINSZ = sub () { - # Very few systems actually have ioctl.ph, thus it comes to this. - # These seem to be good enough, for now. See: - # http://stackoverflow.com/a/4286840/536499 $^O eq 'linux' ? 0x005413 : $^O eq 'solaris' ? 0x005468 : 0x40087468; @@ -1536,11 +1524,11 @@ sub _GetTerminalSize { } } - if ( $rows = `tput lines` ) { + if ( $rows = `tput lines 2>/dev/null` ) { chomp($rows); chomp($cols = `tput cols`); } - elsif ( my $stty = `stty -a` ) { + elsif ( my $stty = `stty -a 2>/dev/null` ) { ($rows, $cols) = $stty =~ /([0-9]+) rows; ([0-9]+) columns;/; } else { @@ -1555,6 +1543,7 @@ sub _GetTerminalSize { } 1; +} # ########################################################################### # End ReadKeyMini package # ########################################################################### diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index 0ef12ce3..c2634b9d 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -15,8 +15,14 @@ # this program; if not, write to the Free Software Foundation, Inc., 59 Temple # Place, Suite 330, Boston, MA 02111-1307 USA. # ########################################################################### -# ReadKeyMini +# ReadKeyMini package # ########################################################################### + +# Package: ReadKeyMini +# ReadKeyMini is a wrapper around Term::ReadKey. If that's available, +# we use ReadMode and GetTerminalSize from there. Otherwise, we use homebrewn +# definitions. + BEGIN { package ReadKeyMini; @@ -29,11 +35,6 @@ package ReadKeyMini; # would solve the issue. BEGIN { $INC{"ReadKeyMini.pm"} ||= 1 } -# Package: ReadKeyMini -# ReadKeyMini is a wrapper around Term::ReadKey. If that's available, -# we use ReadMode and GetTerminalSize from there. Otherwise, we use homebrewn -# definitions. - use warnings; use strict; use English qw(-no_match_vars); @@ -72,7 +73,7 @@ my %modes = ( my $flags; unless ( $PerconaTest::DONT_RESTORE_STDIN ) { $flags = fcntl(STDIN, F_GETFL, 0) - or die "can't fcntl F_GETFL: $!"; + or warn "can't fcntl F_GETFL: $!"; } my $term = POSIX::Termios->new(); $term->getattr($fd_stdin); @@ -106,7 +107,7 @@ my %modes = ( $term->setattr( $fd_stdin, TCSANOW ); unless ( $PerconaTest::DONT_RESTORE_STDIN ) { fcntl(STDIN, F_SETFL, $flags) - or die "can't fcntl F_SETFL: $!"; + or warn "can't fcntl F_SETFL: $!"; } } @@ -167,11 +168,11 @@ sub _GetTerminalSize { } } - if ( $rows = `tput lines` ) { + if ( $rows = `tput lines 2>/dev/null` ) { chomp($rows); chomp($cols = `tput cols`); } - elsif ( my $stty = `stty -a` ) { + elsif ( my $stty = `stty -a 2>/dev/null` ) { ($rows, $cols) = $stty =~ /([0-9]+) rows; ([0-9]+) columns;/; } else {