Merge lp:~percona-toolkit-dev/percona-toolkit/pdl-partitions-bug-1043528 into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 427
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/pdl-partitions-bug-1043528
Merge into: lp:percona-toolkit/2.1
Diff against target: 182 lines (+94/-44)
3 files modified
bin/pt-deadlock-logger (+1/-1)
t/pt-deadlock-logger/basics.t (+74/-43)
t/pt-deadlock-logger/samples/dead-lock-with-partitions.sql (+19/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/pdl-partitions-bug-1043528
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+130908@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-deadlock-logger'
--- bin/pt-deadlock-logger 2012-10-22 18:17:08 +0000
+++ bin/pt-deadlock-logger 2012-10-22 21:33:21 +0000
@@ -4072,7 +4072,7 @@
4072 $hash->{wait_hold} = $what eq 'WAITING FOR THIS LOCK TO BE GRANTED' ? 'w' : 'h';4072 $hash->{wait_hold} = $what eq 'WAITING FOR THIS LOCK TO BE GRANTED' ? 'w' : 'h';
4073 @{$hash}{ qw(lock_type idx db tbl txn_id lock_mode) }4073 @{$hash}{ qw(lock_type idx db tbl txn_id lock_mode) }
4074 = $body4074 = $body
4075 =~ m{^(RECORD|TABLE) LOCKS? (?:space id \d+ page no \d+ n bits \d+ index `?$n`? of )?table `$n(?:/|`\.`)$n` trx id $t lock.mode (\S+)}m;4075 =~ m{^(RECORD|TABLE) LOCKS? (?:space id \d+ page no \d+ n bits \d+ index `?$n`? of )?table `$n(?:/|`\.`)$n`.*?trx id $t lock.mode (\S+)}m;
4076 if ( $hash->{txn_id} ) {4076 if ( $hash->{txn_id} ) {
4077 my ( $high, $low ) = $hash->{txn_id} =~ m/^(\d+) (\d+)$/;4077 my ( $high, $low ) = $hash->{txn_id} =~ m/^(\d+) (\d+)$/;
4078 $hash->{txn_id} = $high ? ( $low + ($high << 32) ) : $low;4078 $hash->{txn_id} = $high ? ( $low + ($high << 32) ) : $low;
40794079
=== modified file 't/pt-deadlock-logger/basics.t'
--- t/pt-deadlock-logger/basics.t 2012-06-03 19:14:30 +0000
+++ t/pt-deadlock-logger/basics.t 2012-10-22 21:33:21 +0000
@@ -23,9 +23,6 @@
23if ( !$dbh1 || !$dbh2 ) {23if ( !$dbh1 || !$dbh2 ) {
24 plan skip_all => 'Cannot connect to sandbox master';24 plan skip_all => 'Cannot connect to sandbox master';
25}25}
26else {
27 plan tests => 10;
28}
2926
30my $output;27my $output;
31my $cnf = "/tmp/12345/my.sandbox.cnf";28my $cnf = "/tmp/12345/my.sandbox.cnf";
@@ -44,46 +41,50 @@
44$dbh1->{InactiveDestroy} = 1;41$dbh1->{InactiveDestroy} = 1;
45$dbh2->{InactiveDestroy} = 1;42$dbh2->{InactiveDestroy} = 1;
4643
47# Fork off two children to deadlock against each other.44sub make_deadlock {
48my %children;45 # Fork off two children to deadlock against each other.
49foreach my $child ( 0..1 ) {46 my %children;
50 my $pid = fork();47 foreach my $child ( 0..1 ) {
51 if ( defined($pid) && $pid == 0 ) { # I am a child48 my $pid = fork();
52 eval {49 if ( defined($pid) && $pid == 0 ) { # I am a child
53 my $dbh = ($dbh1, $dbh2)[$child];50 eval {
54 my @stmts = (51 my $dbh = ($dbh1, $dbh2)[$child];
55 "set transaction isolation level serializable",52 my @stmts = (
56 "begin",53 "set transaction isolation level serializable",
57 "select * from test.dl where a = $child",54 "begin",
58 "update test.dl set a = $child where a <> $child",55 "select * from test.dl where a = $child",
59 );56 "update test.dl set a = $child where a <> $child",
60 foreach my $stmt (@stmts[0..2]) {57 );
61 $dbh->do($stmt);58 foreach my $stmt (@stmts[0..2]) {
62 }59 $dbh->do($stmt);
63 sleep(1 + $child);60 }
64 $dbh->do($stmts[-1]);61 sleep(1 + $child);
65 };62 $dbh->do($stmts[-1]);
66 if ( $EVAL_ERROR ) {63 };
67 if ( $EVAL_ERROR !~ m/Deadlock found/ ) {64 if ( $EVAL_ERROR ) {
68 die $EVAL_ERROR;65 if ( $EVAL_ERROR !~ m/Deadlock found/ ) {
69 }66 die $EVAL_ERROR;
70 }67 }
71 exit(0);68 }
72 }69 exit(0);
73 elsif ( !defined($pid) ) {70 }
74 die("Unable to fork for clearing deadlocks!\n");71 elsif ( !defined($pid) ) {
75 }72 die("Unable to fork for clearing deadlocks!\n");
7673 }
77 # I already exited if I'm a child, so I'm the parent.74
78 $children{$child} = $pid;75 # I already exited if I'm a child, so I'm the parent.
79}76 $children{$child} = $pid;
8077 }
81# Wait for the children to exit.78
82foreach my $child ( keys %children ) {79 # Wait for the children to exit.
83 my $pid = waitpid($children{$child}, 0);80 foreach my $child ( keys %children ) {
84}81 my $pid = waitpid($children{$child}, 0);
85$dbh1->commit;82 }
86$dbh2->commit;83 $dbh1->commit;
84 $dbh2->commit;
85}
86
87make_deadlock();
8788
88# Test that there is a deadlock89# Test that there is a deadlock
89$output = $dbh1->selectrow_hashref('show /*!40101 engine*/ innodb status')->{status};90$output = $dbh1->selectrow_hashref('show /*!40101 engine*/ innodb status')->{status};
@@ -163,10 +164,40 @@
163);164);
164165
165# #############################################################################166# #############################################################################
167# Bug 1043528: pt-deadlock-logger can't parse db/tbl/index on partitioned tables
168# #############################################################################
169SKIP: {
170 skip "Deadlock with partitions test requires MySQL 5.1 and newer", 1
171 unless $sandbox_version ge '5.1';
172
173 $dbh1->do('rollback');
174 $dbh2->do('rollback');
175 $output = 'foo';
176 $dbh1->do('TRUNCATE TABLE test.deadlocks');
177
178 $sb->load_file('master', "t/pt-deadlock-logger/samples/dead-lock-with-partitions.sql");
179
180 make_deadlock();
181
182 $output = output(
183 sub { pt_deadlock_logger::main("F=/tmp/12345/my.sandbox.cnf",
184 qw(--print) );
185 }
186 );
187
188 like(
189 $output,
190 qr/test dl PRIMARY RECORD/,
191 "Deadlock with partitions (bug 1043528)"
192 );
193}
194
195# #############################################################################
166# Done.196# Done.
167# #############################################################################197# #############################################################################
168$dbh1->commit;198$dbh1->commit;
169$dbh2->commit;199$dbh2->commit;
170$sb->wipe_clean($dbh1);200$sb->wipe_clean($dbh1);
171ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");201ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
202done_testing;
172exit;203exit;
173204
=== added file 't/pt-deadlock-logger/samples/dead-lock-with-partitions.sql'
--- t/pt-deadlock-logger/samples/dead-lock-with-partitions.sql 1970-01-01 00:00:00 +0000
+++ t/pt-deadlock-logger/samples/dead-lock-with-partitions.sql 2012-10-22 21:33:21 +0000
@@ -0,0 +1,19 @@
1drop database if exists test;
2create database test;
3use test;
4
5CREATE TABLE dl (
6 id INT NOT NULL,
7 store_id INT NOT NULL,
8 a INT NOT NULL,
9 primary key (id, store_id),
10 unique key (store_id)
11) ENGINE=InnoDB
12
13PARTITION BY RANGE (store_id) (
14 PARTITION p0 VALUES LESS THAN (6),
15 PARTITION p1 VALUES LESS THAN (11)
16);
17
18insert into test.dl values
19 (1, 1, 0), (2, 2, 0), (3, 3, 0), (4, 4, 1), (5, 5, 1), (6, 6, 1);

Subscribers

People subscribed via source and target branches