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
1=== modified file 'bin/pt-deadlock-logger'
2--- bin/pt-deadlock-logger 2012-10-22 18:17:08 +0000
3+++ bin/pt-deadlock-logger 2012-10-22 21:33:21 +0000
4@@ -4072,7 +4072,7 @@
5 $hash->{wait_hold} = $what eq 'WAITING FOR THIS LOCK TO BE GRANTED' ? 'w' : 'h';
6 @{$hash}{ qw(lock_type idx db tbl txn_id lock_mode) }
7 = $body
8- =~ 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;
9+ =~ 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;
10 if ( $hash->{txn_id} ) {
11 my ( $high, $low ) = $hash->{txn_id} =~ m/^(\d+) (\d+)$/;
12 $hash->{txn_id} = $high ? ( $low + ($high << 32) ) : $low;
13
14=== modified file 't/pt-deadlock-logger/basics.t'
15--- t/pt-deadlock-logger/basics.t 2012-06-03 19:14:30 +0000
16+++ t/pt-deadlock-logger/basics.t 2012-10-22 21:33:21 +0000
17@@ -23,9 +23,6 @@
18 if ( !$dbh1 || !$dbh2 ) {
19 plan skip_all => 'Cannot connect to sandbox master';
20 }
21-else {
22- plan tests => 10;
23-}
24
25 my $output;
26 my $cnf = "/tmp/12345/my.sandbox.cnf";
27@@ -44,46 +41,50 @@
28 $dbh1->{InactiveDestroy} = 1;
29 $dbh2->{InactiveDestroy} = 1;
30
31-# Fork off two children to deadlock against each other.
32-my %children;
33-foreach my $child ( 0..1 ) {
34- my $pid = fork();
35- if ( defined($pid) && $pid == 0 ) { # I am a child
36- eval {
37- my $dbh = ($dbh1, $dbh2)[$child];
38- my @stmts = (
39- "set transaction isolation level serializable",
40- "begin",
41- "select * from test.dl where a = $child",
42- "update test.dl set a = $child where a <> $child",
43- );
44- foreach my $stmt (@stmts[0..2]) {
45- $dbh->do($stmt);
46- }
47- sleep(1 + $child);
48- $dbh->do($stmts[-1]);
49- };
50- if ( $EVAL_ERROR ) {
51- if ( $EVAL_ERROR !~ m/Deadlock found/ ) {
52- die $EVAL_ERROR;
53- }
54- }
55- exit(0);
56- }
57- elsif ( !defined($pid) ) {
58- die("Unable to fork for clearing deadlocks!\n");
59- }
60-
61- # I already exited if I'm a child, so I'm the parent.
62- $children{$child} = $pid;
63-}
64-
65-# Wait for the children to exit.
66-foreach my $child ( keys %children ) {
67- my $pid = waitpid($children{$child}, 0);
68-}
69-$dbh1->commit;
70-$dbh2->commit;
71+sub make_deadlock {
72+ # Fork off two children to deadlock against each other.
73+ my %children;
74+ foreach my $child ( 0..1 ) {
75+ my $pid = fork();
76+ if ( defined($pid) && $pid == 0 ) { # I am a child
77+ eval {
78+ my $dbh = ($dbh1, $dbh2)[$child];
79+ my @stmts = (
80+ "set transaction isolation level serializable",
81+ "begin",
82+ "select * from test.dl where a = $child",
83+ "update test.dl set a = $child where a <> $child",
84+ );
85+ foreach my $stmt (@stmts[0..2]) {
86+ $dbh->do($stmt);
87+ }
88+ sleep(1 + $child);
89+ $dbh->do($stmts[-1]);
90+ };
91+ if ( $EVAL_ERROR ) {
92+ if ( $EVAL_ERROR !~ m/Deadlock found/ ) {
93+ die $EVAL_ERROR;
94+ }
95+ }
96+ exit(0);
97+ }
98+ elsif ( !defined($pid) ) {
99+ die("Unable to fork for clearing deadlocks!\n");
100+ }
101+
102+ # I already exited if I'm a child, so I'm the parent.
103+ $children{$child} = $pid;
104+ }
105+
106+ # Wait for the children to exit.
107+ foreach my $child ( keys %children ) {
108+ my $pid = waitpid($children{$child}, 0);
109+ }
110+ $dbh1->commit;
111+ $dbh2->commit;
112+}
113+
114+make_deadlock();
115
116 # Test that there is a deadlock
117 $output = $dbh1->selectrow_hashref('show /*!40101 engine*/ innodb status')->{status};
118@@ -163,10 +164,40 @@
119 );
120
121 # #############################################################################
122+# Bug 1043528: pt-deadlock-logger can't parse db/tbl/index on partitioned tables
123+# #############################################################################
124+SKIP: {
125+ skip "Deadlock with partitions test requires MySQL 5.1 and newer", 1
126+ unless $sandbox_version ge '5.1';
127+
128+ $dbh1->do('rollback');
129+ $dbh2->do('rollback');
130+ $output = 'foo';
131+ $dbh1->do('TRUNCATE TABLE test.deadlocks');
132+
133+ $sb->load_file('master', "t/pt-deadlock-logger/samples/dead-lock-with-partitions.sql");
134+
135+ make_deadlock();
136+
137+ $output = output(
138+ sub { pt_deadlock_logger::main("F=/tmp/12345/my.sandbox.cnf",
139+ qw(--print) );
140+ }
141+ );
142+
143+ like(
144+ $output,
145+ qr/test dl PRIMARY RECORD/,
146+ "Deadlock with partitions (bug 1043528)"
147+ );
148+}
149+
150+# #############################################################################
151 # Done.
152 # #############################################################################
153 $dbh1->commit;
154 $dbh2->commit;
155 $sb->wipe_clean($dbh1);
156 ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
157+done_testing;
158 exit;
159
160=== added file 't/pt-deadlock-logger/samples/dead-lock-with-partitions.sql'
161--- t/pt-deadlock-logger/samples/dead-lock-with-partitions.sql 1970-01-01 00:00:00 +0000
162+++ t/pt-deadlock-logger/samples/dead-lock-with-partitions.sql 2012-10-22 21:33:21 +0000
163@@ -0,0 +1,19 @@
164+drop database if exists test;
165+create database test;
166+use test;
167+
168+CREATE TABLE dl (
169+ id INT NOT NULL,
170+ store_id INT NOT NULL,
171+ a INT NOT NULL,
172+ primary key (id, store_id),
173+ unique key (store_id)
174+) ENGINE=InnoDB
175+
176+PARTITION BY RANGE (store_id) (
177+ PARTITION p0 VALUES LESS THAN (6),
178+ PARTITION p1 VALUES LESS THAN (11)
179+);
180+
181+insert into test.dl values
182+ (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