Merge lp:~percona-toolkit-dev/percona-toolkit/undef-arrayref-bug-995274-2.0 into lp:percona-toolkit/2.0

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 227
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/undef-arrayref-bug-995274-2.0
Merge into: lp:percona-toolkit/2.0
Diff against target: 204 lines (+144/-4)
5 files modified
bin/pt-table-checksum (+5/-1)
lib/NibbleIterator.pm (+9/-1)
t/lib/NibbleIterator.t (+28/-2)
t/pt-table-checksum/bugs.t (+84/-0)
t/pt-table-checksum/samples/undef-arrayref-bug-995274.sql (+18/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/undef-arrayref-bug-995274-2.0
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+105146@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-table-checksum'
2--- bin/pt-table-checksum 2012-05-04 16:24:17 +0000
3+++ bin/pt-table-checksum 2012-05-08 23:23:20 +0000
4@@ -3951,7 +3951,11 @@
5 PTDEBUG && _d($sql);
6 my $expl = $cxn->dbh()->selectrow_hashref($sql);
7 PTDEBUG && _d(Dumper($expl));
8- return ($expl->{rows} || 0), $expl->{key};
9+ my $mysql_index = $expl->{key} || '';
10+ if ( $mysql_index ne 'PRIMARY' ) {
11+ $mysql_index = lc($mysql_index);
12+ }
13+ return ($expl->{rows} || 0), $mysql_index;
14 }
15 else {
16 PTDEBUG && _d('No WHERE clause, using table status for row estimate');
17
18=== modified file 'lib/NibbleIterator.pm'
19--- lib/NibbleIterator.pm 2012-02-06 20:29:08 +0000
20+++ lib/NibbleIterator.pm 2012-05-08 23:23:20 +0000
21@@ -521,7 +521,15 @@
22 PTDEBUG && _d($sql);
23 my $expl = $cxn->dbh()->selectrow_hashref($sql);
24 PTDEBUG && _d(Dumper($expl));
25- return ($expl->{rows} || 0), $expl->{key};
26+ # MySQL's chosen index must be lowercase because TableParser::parse()
27+ # lowercases all idents (search in that module for \L) except for
28+ # the PRIMARY KEY which it leaves uppercase.
29+ # https://bugs.launchpad.net/percona-toolkit/+bug/995274
30+ my $mysql_index = $expl->{key} || '';
31+ if ( $mysql_index ne 'PRIMARY' ) {
32+ $mysql_index = lc($mysql_index);
33+ }
34+ return ($expl->{rows} || 0), $mysql_index;
35 }
36 else {
37 PTDEBUG && _d('No WHERE clause, using table status for row estimate');
38
39=== modified file 't/lib/NibbleIterator.t'
40--- t/lib/NibbleIterator.t 2012-03-06 13:56:08 +0000
41+++ t/lib/NibbleIterator.t 2012-05-08 23:23:20 +0000
42@@ -39,7 +39,7 @@
43 plan skip_all => 'Cannot connect to sandbox master';
44 }
45 else {
46- plan tests => 46;
47+ plan tests => 48;
48 }
49
50 my $q = new Quoter();
51@@ -86,7 +86,7 @@
52
53 my $ni = new NibbleIterator(
54 Cxn => $cxn,
55- tbl => $schema->get_table($args{db}, $args{tbl}),
56+ tbl => $schema->get_table(lc($args{db}), lc($args{tbl})),
57 chunk_size => $o->get('chunk-size'),
58 chunk_index => $o->get('chunk-index'),
59 callbacks => $args{callbacks},
60@@ -796,6 +796,32 @@
61 );
62
63 # #############################################################################
64+# https://bugs.launchpad.net/percona-toolkit/+bug/995274
65+# Index case-sensitivity.
66+# #############################################################################
67+$sb->load_file('master', "t/pt-table-checksum/samples/undef-arrayref-bug-995274.sql");
68+PerconaTest::wait_for_table($dbh, "test.GroupMembers", "id=493076");
69+
70+eval {
71+ $ni = make_nibble_iter(
72+ db => 'test',
73+ tbl => 'GroupMembers',
74+ argv => [qw(--databases test --chunk-size 10 --where MemberId>1000)],
75+ );
76+};
77+is(
78+ $EVAL_ERROR,
79+ '',
80+ "Bug 995274: no error creating nibble iter"
81+);
82+
83+is_deeply(
84+ $ni->next(),
85+ ['450876', '3','691360'],
86+ "Bug 995274: nibble iter works"
87+);
88+
89+# #############################################################################
90 # Done.
91 # #############################################################################
92 {
93
94=== added file 't/pt-table-checksum/bugs.t'
95--- t/pt-table-checksum/bugs.t 1970-01-01 00:00:00 +0000
96+++ t/pt-table-checksum/bugs.t 2012-05-08 23:23:20 +0000
97@@ -0,0 +1,84 @@
98+#!/usr/bin/env perl
99+
100+BEGIN {
101+ die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
102+ unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
103+ unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
104+};
105+
106+use strict;
107+use warnings FATAL => 'all';
108+use English qw(-no_match_vars);
109+use Test::More;
110+
111+# Hostnames make testing less accurate. Tests need to see
112+# that such-and-such happened on specific slave hosts, but
113+# the sandbox servers are all on one host so all slaves have
114+# the same hostname.
115+$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
116+
117+use Data::Dumper;
118+use PerconaTest;
119+use Sandbox;
120+
121+# Fix @INC because pt-table-checksum uses subclass OobNibbleIterator.
122+shift @INC; # our unshift (above)
123+shift @INC; # PerconaTest's unshift
124+require "$trunk/bin/pt-table-checksum";
125+
126+my $dp = new DSNParser(opts=>$dsn_opts);
127+my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
128+my $master_dbh = $sb->get_dbh_for('master');
129+my $slave_dbh = $sb->get_dbh_for('slave1');
130+
131+if ( !$master_dbh ) {
132+ plan skip_all => 'Cannot connect to sandbox master';
133+}
134+elsif ( !$slave_dbh ) {
135+ plan skip_all => 'Cannot connect to sandbox slave1';
136+}
137+else {
138+ plan tests => 2;
139+}
140+
141+# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
142+# so we need to specify --lock-wait-timeout=3 else the tool will die.
143+my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
144+my @args = ($master_dsn, qw(--lock-wait-timeout 3));
145+my $output;
146+my $exit_status;
147+my $sample = "t/pt-table-checksum/samples/";
148+
149+# ############################################################################
150+# https://bugs.launchpad.net/percona-toolkit/+bug/995274
151+# Can't use an undefined value as an ARRAY reference at pt-table-checksum
152+# line 2206
153+# ############################################################################
154+$sb->load_file('master', "$sample/undef-arrayref-bug-995274.sql");
155+PerconaTest::wait_for_table($slave_dbh, "test.GroupMembers", "id=493076");
156+
157+# Must chunk the table so an index is used.
158+$output = output(
159+ sub { $exit_status = pt_table_checksum::main(@args,
160+ qw(-d test --chunk-size 10 --where MemberId>1000)) },
161+ stderr => 1,
162+);
163+
164+is(
165+ $exit_status,
166+ 0,
167+ "Bug 995274: zero exit status"
168+);
169+
170+cmp_ok(
171+ PerconaTest::count_checksum_results($output, 'rows'),
172+ '>',
173+ 1,
174+ "Bug 995274: checksummed rows"
175+);
176+
177+# #############################################################################
178+# Done.
179+# #############################################################################
180+$sb->wipe_clean($master_dbh);
181+exit;
182
183=== added file 't/pt-table-checksum/samples/undef-arrayref-bug-995274.sql'
184--- t/pt-table-checksum/samples/undef-arrayref-bug-995274.sql 1970-01-01 00:00:00 +0000
185+++ t/pt-table-checksum/samples/undef-arrayref-bug-995274.sql 2012-05-08 23:23:20 +0000
186@@ -0,0 +1,18 @@
187+DROP DATABASE IF EXISTS test;
188+CREATE DATABASE test;
189+USE test;
190+CREATE TABLE `GroupMembers` (
191+ `id` int(11) NOT NULL AUTO_INCREMENT,
192+ `GroupId` int(11) NOT NULL DEFAULT '0',
193+ `MemberId` int(11) NOT NULL DEFAULT '0',
194+ PRIMARY KEY (`id`),
195+ UNIQUE KEY `GroupMembers1` (`GroupId`,`MemberId`),
196+ UNIQUE KEY `SHREDDER_GM1` (`MemberId`,`GroupId`)
197+) ENGINE=InnoDB;
198+
199+/*!40000 ALTER TABLE `GroupMembers` DISABLE KEYS */;
200+
201+INSERT INTO `GroupMembers` VALUES
202+(450876,3,691360),(450881,3,691366),(450886,3,691372),(450893,3,691382),(450898,3,691388),(450903,3,691394),(450912,3,691408),(450921,3,691422),(450926,3,691428),(450931,3,691434),(450936,3,691440),(450945,3,691454),(450969,3,691496),(450989,3,691530),(450998,3,691544),(451022,3,691574),(451076,3,691636),(451081,3,691642),(451090,3,691656),(451095,3,691662),(451100,3,691668),(451115,3,691694),(451155,3,691756),(451171,3,691782),(451178,3,691792),(451183,3,691798),(451190,3,691808),(451245,3,691914),(451260,3,691940),(451267,3,691950),(451284,3,691976),(451290,3,691982),(451301,3,691992),(451323,3,692030),(451376,3,692128),(451395,3,692162),(451400,3,692168),(451433,3,692226),(451460,3,692276),(451471,3,692294),(451476,3,692300),(451487,3,692318),(451500,3,692340),(451517,3,692370),(451522,3,692376),(451527,3,692382),(451532,3,692388),(451537,3,692394),(451542,3,692400),(451549,3,692410),(451554,3,692416),(451563,3,692430),(451574,3,692448),(451587,3,692470),(451604,3,692500),(491255,3,751615),(491265,3,751629),(491279,3,751647),(491313,3,751689),(491318,3,751695),(491339,3,751725),(491344,3,751731),(491350,3,751737),(491367,3,751767),(491376,3,751781),(491381,3,751787),(491390,3,751801),(491399,3,751815),(491406,3,751825),(491415,3,751839),(491420,3,751845),(491425,3,751851),(491430,3,751857),(491447,3,751887),(491454,3,751897),(491463,3,751912),(491484,3,751950),(491563,3,752104),(491580,3,752134),(491595,3,752160),(491604,3,752174),(491615,3,752192),(491624,3,752206),(491631,3,752216),(491652,3,752254),(491657,3,752260),(491664,3,752270),(491675,3,752288),(491680,3,752294),(491685,3,752300),(491692,3,752310),(491697,3,752316),(491704,3,752326),(491715,3,752344),(491742,3,752394),(491757,3,752420),(491762,3,752426),(491769,3,752436),(491774,3,752442),(491779,3,752448),(491786,3,752458),(491799,3,752480),(491806,3,752490),(491813,3,752500),(491821,3,752510),(491833,3,752524),(491838,3,752530),(491843,3,752536),(491848,3,752542),(491853,3,752548),(491858,3,752554),(491865,3,752564),(491870,3,752570),(491875,3,752576),(491886,3,752594),(491891,3,752600),(491933,3,752642),(491938,3,752648),(491965,3,752686),(491976,3,752704),(491991,3,752726),(492004,3,752748),(492013,3,752762),(492018,3,752768),(492023,3,752774),(492030,3,752780),(492037,3,752786),(492062,3,752816),(492073,3,752834),(492078,3,752840),(492089,3,752858),(492094,3,752864),(492099,3,752870),(492128,3,752908),(492139,3,752922),(492158,3,752956),(492163,3,752962),(492184,3,753000),(492196,3,753010),(492224,3,753044),(492231,3,753054),(492236,3,753060),(492241,3,753066),(492246,3,753072),(492253,3,753082),(492258,3,753088),(492267,3,753102),(492272,3,753108),(492277,3,753114),(492282,3,753120),(492287,3,753126),(492292,3,753132),(492297,3,753138),(492302,3,753144),(492307,3,753150),(492312,3,753156),(492317,3,753162),(492326,3,753176),(492331,3,753182),(492338,3,753192),(492343,3,753198),(492348,3,753204),(492357,3,753218),(492364,3,753228),(492377,3,753250),(492384,3,753260),(492389,3,753266),(492394,3,753272),(492401,3,753282),(492458,3,753368),(492463,3,753374),(492469,3,753380),(492489,3,753414),(492496,3,753424),(492503,3,753434),(492510,3,753444),(492515,3,753450),(492528,3,753472),(492537,3,753486),(492577,3,753552),(492584,3,753562),(492591,3,753572),(492596,3,753578),(492605,3,753592),(492610,3,753598),(492615,3,753604),(492620,3,753610),(492625,3,753616),(492630,3,753622),(492636,3,753628),(492653,3,753654),(492664,3,753672),(492681,3,753702),(492686,3,753708),(492693,3,753718),(492700,3,753728),(492705,3,753734),(492716,3,753752),(492727,3,753770),(492736,3,753784),(492745,3,753798),(492754,3,753812),(492759,3,753818),(492764,3,753824),(492783,3,753846),(492817,3,753896),(492842,3,753942),(492847,3,753948),(492854,3,753958),(492863,3,753972),(492870,3,753982),(492895,3,754020),(492900,3,754026),(492907,3,754036),(492914,3,754046),(492919,3,754052),(492924,3,754058),(492929,3,754064),(492934,3,754070),(492943,3,754084),(492950,3,754094),(492957,3,754104),(492964,3,754114),(492969,3,754120),(492981,3,754138),(492996,3,754164),(493002,3,754170),(493007,3,754176),(493027,3,754202),(493035,3,754208),(493042,3,754218),(493053,3,754236),(493064,3,754254),(493071,3,754264),(493076,3,754270);
203+
204+/*!40000 ALTER TABLE `GroupMembers` ENABLE KEYS */;

Subscribers

People subscribed via source and target branches