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
=== modified file 'bin/pt-table-checksum'
--- bin/pt-table-checksum 2012-05-04 16:24:17 +0000
+++ bin/pt-table-checksum 2012-05-08 23:23:20 +0000
@@ -3951,7 +3951,11 @@
3951 PTDEBUG && _d($sql);3951 PTDEBUG && _d($sql);
3952 my $expl = $cxn->dbh()->selectrow_hashref($sql);3952 my $expl = $cxn->dbh()->selectrow_hashref($sql);
3953 PTDEBUG && _d(Dumper($expl));3953 PTDEBUG && _d(Dumper($expl));
3954 return ($expl->{rows} || 0), $expl->{key};3954 my $mysql_index = $expl->{key} || '';
3955 if ( $mysql_index ne 'PRIMARY' ) {
3956 $mysql_index = lc($mysql_index);
3957 }
3958 return ($expl->{rows} || 0), $mysql_index;
3955 }3959 }
3956 else {3960 else {
3957 PTDEBUG && _d('No WHERE clause, using table status for row estimate');3961 PTDEBUG && _d('No WHERE clause, using table status for row estimate');
39583962
=== modified file 'lib/NibbleIterator.pm'
--- lib/NibbleIterator.pm 2012-02-06 20:29:08 +0000
+++ lib/NibbleIterator.pm 2012-05-08 23:23:20 +0000
@@ -521,7 +521,15 @@
521 PTDEBUG && _d($sql);521 PTDEBUG && _d($sql);
522 my $expl = $cxn->dbh()->selectrow_hashref($sql);522 my $expl = $cxn->dbh()->selectrow_hashref($sql);
523 PTDEBUG && _d(Dumper($expl));523 PTDEBUG && _d(Dumper($expl));
524 return ($expl->{rows} || 0), $expl->{key};524 # MySQL's chosen index must be lowercase because TableParser::parse()
525 # lowercases all idents (search in that module for \L) except for
526 # the PRIMARY KEY which it leaves uppercase.
527 # https://bugs.launchpad.net/percona-toolkit/+bug/995274
528 my $mysql_index = $expl->{key} || '';
529 if ( $mysql_index ne 'PRIMARY' ) {
530 $mysql_index = lc($mysql_index);
531 }
532 return ($expl->{rows} || 0), $mysql_index;
525 }533 }
526 else {534 else {
527 PTDEBUG && _d('No WHERE clause, using table status for row estimate');535 PTDEBUG && _d('No WHERE clause, using table status for row estimate');
528536
=== modified file 't/lib/NibbleIterator.t'
--- t/lib/NibbleIterator.t 2012-03-06 13:56:08 +0000
+++ t/lib/NibbleIterator.t 2012-05-08 23:23:20 +0000
@@ -39,7 +39,7 @@
39 plan skip_all => 'Cannot connect to sandbox master';39 plan skip_all => 'Cannot connect to sandbox master';
40}40}
41else {41else {
42 plan tests => 46;42 plan tests => 48;
43}43}
4444
45my $q = new Quoter();45my $q = new Quoter();
@@ -86,7 +86,7 @@
8686
87 my $ni = new NibbleIterator(87 my $ni = new NibbleIterator(
88 Cxn => $cxn,88 Cxn => $cxn,
89 tbl => $schema->get_table($args{db}, $args{tbl}),89 tbl => $schema->get_table(lc($args{db}), lc($args{tbl})),
90 chunk_size => $o->get('chunk-size'),90 chunk_size => $o->get('chunk-size'),
91 chunk_index => $o->get('chunk-index'),91 chunk_index => $o->get('chunk-index'),
92 callbacks => $args{callbacks},92 callbacks => $args{callbacks},
@@ -796,6 +796,32 @@
796);796);
797797
798# #############################################################################798# #############################################################################
799# https://bugs.launchpad.net/percona-toolkit/+bug/995274
800# Index case-sensitivity.
801# #############################################################################
802$sb->load_file('master', "t/pt-table-checksum/samples/undef-arrayref-bug-995274.sql");
803PerconaTest::wait_for_table($dbh, "test.GroupMembers", "id=493076");
804
805eval {
806 $ni = make_nibble_iter(
807 db => 'test',
808 tbl => 'GroupMembers',
809 argv => [qw(--databases test --chunk-size 10 --where MemberId>1000)],
810 );
811};
812is(
813 $EVAL_ERROR,
814 '',
815 "Bug 995274: no error creating nibble iter"
816);
817
818is_deeply(
819 $ni->next(),
820 ['450876', '3','691360'],
821 "Bug 995274: nibble iter works"
822);
823
824# #############################################################################
799# Done.825# Done.
800# #############################################################################826# #############################################################################
801{827{
802828
=== added file 't/pt-table-checksum/bugs.t'
--- t/pt-table-checksum/bugs.t 1970-01-01 00:00:00 +0000
+++ t/pt-table-checksum/bugs.t 2012-05-08 23:23:20 +0000
@@ -0,0 +1,84 @@
1#!/usr/bin/env perl
2
3BEGIN {
4 die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
5 unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
6 unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
7};
8
9use strict;
10use warnings FATAL => 'all';
11use English qw(-no_match_vars);
12use Test::More;
13
14# Hostnames make testing less accurate. Tests need to see
15# that such-and-such happened on specific slave hosts, but
16# the sandbox servers are all on one host so all slaves have
17# the same hostname.
18$ENV{PERCONA_TOOLKIT_TEST_USE_DSN_NAMES} = 1;
19
20use Data::Dumper;
21use PerconaTest;
22use Sandbox;
23
24# Fix @INC because pt-table-checksum uses subclass OobNibbleIterator.
25shift @INC; # our unshift (above)
26shift @INC; # PerconaTest's unshift
27require "$trunk/bin/pt-table-checksum";
28
29my $dp = new DSNParser(opts=>$dsn_opts);
30my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
31my $master_dbh = $sb->get_dbh_for('master');
32my $slave_dbh = $sb->get_dbh_for('slave1');
33
34if ( !$master_dbh ) {
35 plan skip_all => 'Cannot connect to sandbox master';
36}
37elsif ( !$slave_dbh ) {
38 plan skip_all => 'Cannot connect to sandbox slave1';
39}
40else {
41 plan tests => 2;
42}
43
44# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
45# so we need to specify --lock-wait-timeout=3 else the tool will die.
46my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
47my @args = ($master_dsn, qw(--lock-wait-timeout 3));
48my $output;
49my $exit_status;
50my $sample = "t/pt-table-checksum/samples/";
51
52# ############################################################################
53# https://bugs.launchpad.net/percona-toolkit/+bug/995274
54# Can't use an undefined value as an ARRAY reference at pt-table-checksum
55# line 2206
56# ############################################################################
57$sb->load_file('master', "$sample/undef-arrayref-bug-995274.sql");
58PerconaTest::wait_for_table($slave_dbh, "test.GroupMembers", "id=493076");
59
60# Must chunk the table so an index is used.
61$output = output(
62 sub { $exit_status = pt_table_checksum::main(@args,
63 qw(-d test --chunk-size 10 --where MemberId>1000)) },
64 stderr => 1,
65);
66
67is(
68 $exit_status,
69 0,
70 "Bug 995274: zero exit status"
71);
72
73cmp_ok(
74 PerconaTest::count_checksum_results($output, 'rows'),
75 '>',
76 1,
77 "Bug 995274: checksummed rows"
78);
79
80# #############################################################################
81# Done.
82# #############################################################################
83$sb->wipe_clean($master_dbh);
84exit;
085
=== added file 't/pt-table-checksum/samples/undef-arrayref-bug-995274.sql'
--- t/pt-table-checksum/samples/undef-arrayref-bug-995274.sql 1970-01-01 00:00:00 +0000
+++ t/pt-table-checksum/samples/undef-arrayref-bug-995274.sql 2012-05-08 23:23:20 +0000
@@ -0,0 +1,18 @@
1DROP DATABASE IF EXISTS test;
2CREATE DATABASE test;
3USE test;
4CREATE TABLE `GroupMembers` (
5 `id` int(11) NOT NULL AUTO_INCREMENT,
6 `GroupId` int(11) NOT NULL DEFAULT '0',
7 `MemberId` int(11) NOT NULL DEFAULT '0',
8 PRIMARY KEY (`id`),
9 UNIQUE KEY `GroupMembers1` (`GroupId`,`MemberId`),
10 UNIQUE KEY `SHREDDER_GM1` (`MemberId`,`GroupId`)
11) ENGINE=InnoDB;
12
13/*!40000 ALTER TABLE `GroupMembers` DISABLE KEYS */;
14
15INSERT INTO `GroupMembers` VALUES
16(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);
17
18/*!40000 ALTER TABLE `GroupMembers` ENABLE KEYS */;

Subscribers

People subscribed via source and target branches