Kill cxn only if using a db in Sandbox::wipe_clean(). Fix pt-duplicate-key-checker/basics.t for 5.0. Make pt-table-sync/lock_and_rename.t more stable.

This commit is contained in:
Daniel Nichter
2012-06-04 18:46:35 -07:00
parent 3a717b645c
commit 1b11b7d7d9
4 changed files with 24 additions and 18 deletions

View File

@@ -34,8 +34,8 @@ use English qw(-no_match_vars);
use Time::HiRes qw(sleep); use Time::HiRes qw(sleep);
use Data::Dumper; use Data::Dumper;
$Data::Dumper::Indent = 1; $Data::Dumper::Indent = 1;
$Data::Dumper::Quotekeys = 0;
$Data::Dumper::Sortkeys = 1; $Data::Dumper::Sortkeys = 1;
$Data::Dumper::Quotekeys = 0;
use constant PTDEBUG => $ENV{PTDEBUG} || 0; use constant PTDEBUG => $ENV{PTDEBUG} || 0;
my $trunk = $ENV{PERCONA_TOOLKIT_BRANCH}; my $trunk = $ENV{PERCONA_TOOLKIT_BRANCH};
@@ -164,11 +164,17 @@ sub wipe_clean {
# the DROP commands will just hang forever. # the DROP commands will just hang forever.
my @cxns = @{$dbh->selectall_arrayref('SHOW FULL PROCESSLIST', {Slice => {}})}; my @cxns = @{$dbh->selectall_arrayref('SHOW FULL PROCESSLIST', {Slice => {}})};
foreach my $cxn ( @cxns ) { foreach my $cxn ( @cxns ) {
if ( if ((
(($cxn->{user}||'') eq 'msandbox' && ($cxn->{command}||'') eq 'Sleep') (($cxn->{user}||'') eq 'msandbox' && ($cxn->{command}||'') eq 'Sleep')
|| (($cxn->{User}||'') eq 'msandbox' && ($cxn->{Command}||'') eq 'Sleep') || (($cxn->{User}||'') eq 'msandbox' && ($cxn->{Command}||'') eq 'Sleep')
) && $cxn->{db}
) { ) {
eval { $dbh->do("KILL $cxn->{id}"); }; my $id = $cxn->{id} ? $cxn->{id} : $cxn->{Id};
my $sql = "KILL $id /* db: $cxn->{db} */";
Test::More::diag($sql);
eval { $dbh->do($sql); };
Test::More::diag("Error executing $sql in Sandbox::wipe_clean(): "
. $EVAL_ERROR) if $EVAL_ERROR;
} }
} }
foreach my $db ( @{$dbh->selectcol_arrayref('SHOW DATABASES')} ) { foreach my $db ( @{$dbh->selectcol_arrayref('SHOW DATABASES')} ) {

View File

@@ -102,6 +102,7 @@ ok(
no_diff( no_diff(
sub { pt_duplicate_key_checker::main(@args, qw(-d test)) }, sub { pt_duplicate_key_checker::main(@args, qw(-d test)) },
"$sample/bug-894140.txt", "$sample/bug-894140.txt",
sed => [ "-e 's/ */ /g'" ],
), ),
"Bug 894140" "Bug 894140"
); );

View File

@@ -1,29 +1,29 @@
# ######################################################################## # ########################################################################
# test.bug_894140 # test.bug_894140
# ######################################################################## # ########################################################################
# row_id is a duplicate of PRIMARY # row_id is a duplicate of PRIMARY
# Key definitions: # Key definitions:
# UNIQUE KEY `row_id` (`row_id`), # UNIQUE KEY `row_id` (`row_id`),
# PRIMARY KEY (`row_id`), # PRIMARY KEY (`row_id`),
# Column types: # Column types:
# `row_id` bigint(20) not null auto_increment # `row_id` bigint(20) not null auto_increment
# To remove this duplicate index, execute: # To remove this duplicate index, execute:
ALTER TABLE `test`.`bug_894140` DROP INDEX `row_id`; ALTER TABLE `test`.`bug_894140` DROP INDEX `row_id`;
# player_id_2 is a duplicate of player_id # player_id_2 is a duplicate of player_id
# Key definitions: # Key definitions:
# KEY `player_id_2` (`player_id`) # KEY `player_id_2` (`player_id`)
# UNIQUE KEY `player_id` (`player_id`), # UNIQUE KEY `player_id` (`player_id`),
# Column types: # Column types:
# `player_id` bigint(20) default null # `player_id` bigint(20) default null
# To remove this duplicate index, execute: # To remove this duplicate index, execute:
ALTER TABLE `test`.`bug_894140` DROP INDEX `player_id_2`; ALTER TABLE `test`.`bug_894140` DROP INDEX `player_id_2`;
# ######################################################################## # ########################################################################
# Summary of indexes # Summary of indexes
# ######################################################################## # ########################################################################
# Size Duplicate Indexes 17 # Size Duplicate Indexes 17
# Total Duplicate Indexes 2 # Total Duplicate Indexes 2
# Total Indexes 4 # Total Indexes 4

View File

@@ -33,20 +33,20 @@ else {
} }
$sb->wipe_clean($master_dbh); $sb->wipe_clean($master_dbh);
$sb->wipe_clean($slave_dbh);
$sb->create_dbs($master_dbh, [qw(test)]); $sb->create_dbs($master_dbh, [qw(test)]);
# ############################################################################# # #############################################################################
# Issue 363: lock and rename. # Issue 363: lock and rename.
# ############################################################################# # #############################################################################
$sb->load_file('master', 't/pt-table-sync/samples/before.sql'); $sb->load_file('master', 't/pt-table-sync/samples/before.sql');
PerconaTest::wait_for_table($slave_dbh, "test.test2");
$output = `$trunk/bin/pt-table-sync --lock-and-rename h=127.1,P=12345 P=12346 2>&1`; $output = `$trunk/bin/pt-table-sync --lock-and-rename h=127.1,P=12345 P=12346 2>&1`;
like($output, qr/requires exactly two/, like($output, qr/requires exactly two/,
'--lock-and-rename error when DSNs do not specify table'); '--lock-and-rename error when DSNs do not specify table');
# It's hard to tell exactly which table is which, and the tables are going to be # It's hard to tell exactly which table is which, and the tables are going
# "swapped", so we'll put a marker in each table to test the swapping. # to be "swapped", so we'll put a marker in each table to test the swapping.
`/tmp/12345/use -e "alter table test.test1 comment='test1'"`; `/tmp/12345/use -e "alter table test.test1 comment='test1'"`;
$output = `$trunk/bin/pt-table-sync --execute --lock-and-rename h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=test1 t=test2 2>&1`; $output = `$trunk/bin/pt-table-sync --execute --lock-and-rename h=127.1,P=12345,u=msandbox,p=msandbox,D=test,t=test1 t=test2 2>&1`;
@@ -59,6 +59,5 @@ like($output, qr/COMMENT='test1'/, '--lock-and-rename worked');
# Done. # Done.
# ############################################################################# # #############################################################################
$sb->wipe_clean($master_dbh); $sb->wipe_clean($master_dbh);
$sb->wipe_clean($slave_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
exit; exit;