Merge lp:~percona-toolkit-dev/percona-toolkit/fix-bailouts into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Approved by: Daniel Nichter
Approved revision: 381
Merged at revision: 382
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-bailouts
Merge into: lp:percona-toolkit/2.1
Diff against target: 313 lines (+64/-88)
6 files modified
bin/pt-table-sync (+2/-2)
bin/pt-table-usage (+26/-1)
bin/pt-upgrade (+11/-28)
lib/TableSyncNibble.pm (+2/-2)
t/lib/TableSyncGroupBy.t (+16/-4)
t/lib/TableSyncer.t (+7/-51)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-bailouts
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+121464@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve
382. By Daniel Nichter

Update modules.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/pt-table-sync'
2--- bin/pt-table-sync 2012-08-24 23:26:04 +0000
3+++ bin/pt-table-sync 2012-08-27 16:56:19 +0000
4@@ -5434,7 +5434,7 @@
5 if ( $row ) {
6 my $i = 0;
7 $ub = $s->{boundaries}->{'<='};
8- $ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
9+ $ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i++]})/eg;
10 }
11 else {
12 PTDEBUG && _d('No upper boundary');
13@@ -5466,7 +5466,7 @@
14 my $tmp = $self->{cached_row};
15 my $i = 0;
16 $lb = $s->{boundaries}->{'>'};
17- $lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
18+ $lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i++]})/eg;
19 $sql .= $args{where} ? " AND $lb" : " WHERE $lb";
20 }
21 $sql .= " ORDER BY " . join(',', map { $q->quote($_) } @{$self->{key_cols}})
22
23=== modified file 'bin/pt-table-usage'
24--- bin/pt-table-usage 2012-08-24 23:26:04 +0000
25+++ bin/pt-table-usage 2012-08-27 16:56:19 +0000
26@@ -6,7 +6,32 @@
27
28 use strict;
29 use warnings FATAL => 'all';
30-use constant PTDEBUG => $ENV{PTDEBUG} || 0;
31+
32+# This tool is "fat-packed": most of its dependent modules are embedded
33+# in this file. Setting %INC to this file for each module makes Perl aware
34+# of this so it will not try to load the module from @INC. See the tool's
35+# documentation for a full list of dependencies.
36+BEGIN {
37+ $INC{$_} = __FILE__ for map { (my $pkg = "$_.pm") =~ s!::!/!g; $pkg } (qw(
38+ DSNParser
39+ OptionParser
40+ SlowLogParser
41+ Transformers
42+ QueryRewriter
43+ QueryParser
44+ FileIterator
45+ SQLParser
46+ TableUsage
47+ Daemon
48+ Runtime
49+ Progress
50+ Pipeline
51+ Quoter
52+ TableParser
53+ MysqldumpParser
54+ SchemaQualifier
55+ ));
56+}
57
58 # ###########################################################################
59 # DSNParser package
60
61=== modified file 'bin/pt-upgrade'
62--- bin/pt-upgrade 2012-08-24 23:26:04 +0000
63+++ bin/pt-upgrade 2012-08-27 16:56:19 +0000
64@@ -5413,6 +5413,12 @@
65 }
66 PTDEBUG && _d("Base", $base, "chars:", @chars);
67
68+ die "Cannot chunk table $db_tbl using the character column "
69+ . "$chunk_col, most likely because all values start with the "
70+ . "same character. This table must be synced separately by "
71+ . "specifying a list of --algorithms without the Chunk algorithm"
72+ if $base == 1;
73+
74
75 $sql = "SELECT MAX(LENGTH($qchunk_col)) FROM $db_tbl "
76 . ($args{where} ? "WHERE $args{where} " : "")
77@@ -6982,9 +6988,10 @@
78 my $ms = $self->{MasterSlave};
79 my $tries = $args{wait_retry_args}->{tries} || 3;
80 my $wait;
81+ my $sleep = $args{wait_retry_args}->{wait} || 10;
82 $self->{Retry}->retry(
83 tries => $tries,
84- wait => sub { sleep $args{wait_retry_args}->{wait} || 10 },
85+ wait => sub { sleep($sleep) },
86 try => sub {
87 my ( %args ) = @_;
88
89@@ -7015,7 +7022,7 @@
90 . "the slave is running.";
91 }
92 if ( $tries - $args{tryno} ) {
93- $msg .= " Sleeping $wait seconds then retrying "
94+ $msg .= " Sleeping $sleep seconds then retrying "
95 . ($tries - $args{tryno}) . " more times.";
96 }
97 warn "$msg\n";
98@@ -7067,30 +7074,6 @@
99 return $result;
100 }
101
102-sub have_all_privs {
103- my ( $self, $dbh, $db, $tbl ) = @_;
104- my $db_tbl = $self->{Quoter}->quote($db, $tbl);
105- my $sql = "SHOW FULL COLUMNS FROM $db_tbl";
106- PTDEBUG && _d('Permissions check:', $sql);
107- my $cols = $dbh->selectall_arrayref($sql, {Slice => {}});
108- my ($hdr_name) = grep { m/privileges/i } keys %{$cols->[0]};
109- my $privs = $cols->[0]->{$hdr_name};
110- $sql = "DELETE FROM $db_tbl LIMIT 0"; # FULL COLUMNS doesn't show all privs
111- PTDEBUG && _d('Permissions check:', $sql);
112- eval { $dbh->do($sql); };
113- my $can_delete = $EVAL_ERROR ? 0 : 1;
114-
115- PTDEBUG && _d('User privs on', $db_tbl, ':', $privs,
116- ($can_delete ? 'delete' : ''));
117- if ( $privs =~ m/select/ && $privs =~ m/insert/ && $privs =~ m/update/
118- && $can_delete ) {
119- PTDEBUG && _d('User has all privs');
120- return 1;
121- }
122- PTDEBUG && _d('User does not have all privs');
123- return 0;
124-}
125-
126 sub _d {
127 my ($package, undef, $line) = caller 0;
128 @_ = map { (my $temp = $_) =~ s/\n/\n# /g; $temp; }
129@@ -7625,7 +7608,7 @@
130 if ( $row ) {
131 my $i = 0;
132 $ub = $s->{boundaries}->{'<='};
133- $ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
134+ $ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i++]})/eg;
135 }
136 else {
137 PTDEBUG && _d('No upper boundary');
138@@ -7657,7 +7640,7 @@
139 my $tmp = $self->{cached_row};
140 my $i = 0;
141 $lb = $s->{boundaries}->{'>'};
142- $lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
143+ $lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i++]})/eg;
144 $sql .= $args{where} ? " AND $lb" : " WHERE $lb";
145 }
146 $sql .= " ORDER BY " . join(',', map { $q->quote($_) } @{$self->{key_cols}})
147
148=== modified file 'lib/TableSyncNibble.pm'
149--- lib/TableSyncNibble.pm 2012-06-07 18:53:47 +0000
150+++ lib/TableSyncNibble.pm 2012-08-27 16:56:19 +0000
151@@ -286,7 +286,7 @@
152 # any lower boundary the table rows should be > the lower boundary.)
153 my $i = 0;
154 $ub = $s->{boundaries}->{'<='};
155- $ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
156+ $ub =~ s/\?/$q->quote_val($row->{$s->{scols}->[$i++]})/eg;
157 }
158 else {
159 # This usually happens at the end of the table, after we've nibbled
160@@ -331,7 +331,7 @@
161 my $tmp = $self->{cached_row};
162 my $i = 0;
163 $lb = $s->{boundaries}->{'>'};
164- $lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i]}, $self->{tbl_struct}->{is_numeric}->{$s->{scols}->[$i++]} || 0)/eg;
165+ $lb =~ s/\?/$q->quote_val($tmp->{$s->{scols}->[$i++]})/eg;
166 $sql .= $args{where} ? " AND $lb" : " WHERE $lb";
167 }
168 $sql .= " ORDER BY " . join(',', map { $q->quote($_) } @{$self->{key_cols}})
169
170=== modified file 't/lib/TableSyncGroupBy.t'
171--- t/lib/TableSyncGroupBy.t 2012-03-06 13:56:08 +0000
172+++ t/lib/TableSyncGroupBy.t 2012-08-27 16:56:19 +0000
173@@ -9,7 +9,8 @@
174 use strict;
175 use warnings FATAL => 'all';
176 use English qw(-no_match_vars);
177-use Test::More tests => 5;
178+use Test::More;
179+use Data::Dumper;
180
181 use TableSyncGroupBy;
182 use Quoter;
183@@ -19,7 +20,11 @@
184 use PerconaTest;
185
186 my $q = new Quoter();
187-my $tbl_struct = { is_col => {} }; # fake tbl_struct
188+my $tbl_struct = {
189+ type_for => { a => 'int', b => 'int', c => 'int' },
190+ col_posn => { a => 1, b => 2, c => 3 },
191+ is_col => { a => 1, b => 2, c => 3 },
192+};
193 my @rows;
194
195 throws_ok(
196@@ -40,6 +45,7 @@
197 replace => 0,
198 actions => [ sub { push @rows, $_[0] }, ],
199 queue => 0,
200+ tbl_struct => $tbl_struct,
201 );
202
203 $t->prepare_to_sync(
204@@ -93,7 +99,7 @@
205 { a => 4, b => 2, c => 3, __maatkit_count => 1 },
206 ),
207 syncer => $t,
208- tbl_struct => {},
209+ tbl_struct => $tbl_struct,
210 );
211
212 is_deeply(
213@@ -107,4 +113,10 @@
214 "DELETE FROM `test`.`foo` WHERE `a`='4' AND `b`='2' AND `c`='3' LIMIT 1",
215 ],
216 'rows from handler',
217-);
218+) or diag(Dumper(\@rows));
219+
220+# #############################################################################
221+# Done
222+# #############################################################################
223+done_testing;
224+exit;
225
226=== modified file 't/lib/TableSyncer.t'
227--- t/lib/TableSyncer.t 2012-08-14 23:08:06 +0000
228+++ t/lib/TableSyncer.t 2012-08-27 16:56:19 +0000
229@@ -49,9 +49,6 @@
230 elsif ( !$dst_dbh ) {
231 plan skip_all => 'Cannot connect to sandbox slave';
232 }
233-else {
234- plan tests => 61;
235-}
236
237 $sb->create_dbs($dbh, ['test']);
238 $sb->load_file('master', 't/lib/samples/before-TableSyncChunk.sql');
239@@ -636,52 +633,8 @@
240 # Test check_permissions().
241 # #############################################################################
242
243-SKIP: {
244- skip "Not tested on MySQL $sandbox_version", 5
245- unless $sandbox_version gt '4.0';
246-
247-# Re-using issue_96.t from above.
248-is(
249- $syncer->have_all_privs($src->{dbh}, 'issue_96', 't'),
250- 1,
251- 'Have all privs'
252-);
253-
254-diag(`/tmp/12345/use -u root -e "CREATE USER 'bob'\@'\%' IDENTIFIED BY 'bob'"`);
255-diag(`/tmp/12345/use -u root -e "GRANT select ON issue_96.t TO 'bob'\@'\%'"`);
256-my $bob_dbh = DBI->connect(
257- "DBI:mysql:;host=127.0.0.1;port=12345", 'bob', 'bob',
258- { PrintError => 0, RaiseError => 1 });
259-
260-is(
261- $syncer->have_all_privs($bob_dbh, 'issue_96', 't'),
262- 0,
263- "Don't have all privs, just select"
264-);
265-
266-diag(`/tmp/12345/use -u root -e "GRANT insert ON issue_96.t TO 'bob'\@'\%'"`);
267-is(
268- $syncer->have_all_privs($bob_dbh, 'issue_96', 't'),
269- 0,
270- "Don't have all privs, just select and insert"
271-);
272-
273-diag(`/tmp/12345/use -u root -e "GRANT update ON issue_96.t TO 'bob'\@'\%'"`);
274-is(
275- $syncer->have_all_privs($bob_dbh, 'issue_96', 't'),
276- 0,
277- "Don't have all privs, just select, insert and update"
278-);
279-
280-diag(`/tmp/12345/use -u root -e "GRANT delete ON issue_96.t TO 'bob'\@'\%'"`);
281-is(
282- $syncer->have_all_privs($bob_dbh, 'issue_96', 't'),
283- 1,
284- "Bob got his privs"
285-);
286-
287-diag(`/tmp/12345/use -u root -e "DROP USER 'bob'"`);
288-}
289+# have_all_privs() removed due to
290+# https://bugs.launchpad.net/percona-toolkit/+bug/1036747
291
292 # ###########################################################################
293 # Test that the calback gives us the src and dst sql.
294@@ -930,6 +883,7 @@
295 );
296
297 diag(`$trunk/sandbox/stop-sandbox 12348 >/dev/null &`);
298+ $dbh3->disconnect();
299 }
300
301 # #############################################################################
302@@ -1066,7 +1020,9 @@
303 qr/Complete test coverage/,
304 '_d() works'
305 );
306-$sb->wipe_clean($src_dbh);
307-$sb->wipe_clean($dst_dbh);
308+$src_dbh->disconnect() if $src_dbh;
309+$dst_dbh->disconnect() if $dst_dbh;
310+$sb->wipe_clean($dbh);
311 ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
312+done_testing;
313 exit;

Subscribers

People subscribed via source and target branches