Merge lp:~percona-toolkit-dev/percona-toolkit/fix-1041372-pt-osc-long-table-names into lp:percona-toolkit/2.1

Proposed by Brian Fraser
Status: Merged
Approved by: Daniel Nichter
Approved revision: 384
Merged at revision: 389
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-1041372-pt-osc-long-table-names
Merge into: lp:percona-toolkit/2.1
Diff against target: 113 lines (+59/-3)
2 files modified
bin/pt-online-schema-change (+25/-3)
t/pt-online-schema-change/bugs.t (+34/-0)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-1041372-pt-osc-long-table-names
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+122157@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-online-schema-change'
2--- bin/pt-online-schema-change 2012-08-29 20:23:41 +0000
3+++ bin/pt-online-schema-change 2012-08-30 21:41:19 +0000
4@@ -7479,7 +7479,6 @@
5 eval {
6 $new_tbl = create_new_table(
7 orig_tbl => $orig_tbl,
8- suffix => '_new',
9 Cxn => $cxn,
10 Quoter => $q,
11 OptionParser => $o,
12@@ -8196,7 +8195,7 @@
13
14 my $tries = $args{tries} || 10; # don't try forever
15 my $prefix = $args{prefix} || '_';
16- my $suffix = $args{suffix} || '_new';
17+ my $suffix = '_new';
18 my $table_name = $orig_tbl->{tbl} . $suffix;
19
20 print "Creating new table...\n";
21@@ -8204,6 +8203,14 @@
22 my @old_tables;
23 while ( $tryno++ < $tries ) {
24 $table_name = $prefix . $table_name;
25+
26+ if ( length($table_name) > 64 ) {
27+ my $truncated_table_name = substr($table_name, 0, 60) . $suffix;
28+ PTDEBUG && _d($table_name, 'is over 64 characters long, truncating to',
29+ $truncated_table_name);
30+ $table_name = $truncated_table_name;
31+ }
32+
33 my $quoted = $q->quote($orig_tbl->{db}, $table_name);
34
35 # Generate SQL to create the new table. We do not use CREATE TABLE LIKE
36@@ -8282,9 +8289,17 @@
37 }
38 elsif ( $o->get('execute') ) {
39 print "Swapping tables...\n";
40-
41+
42 while ( $tries-- ) {
43 $table_name = $prefix . $table_name;
44+
45+ if ( length($table_name) > 64 ) {
46+ my $truncated_table_name = substr($table_name, 0, 64);
47+ PTDEBUG && _d($table_name, 'is over 64 characters long, truncating to',
48+ $truncated_table_name);
49+ $table_name = $truncated_table_name;
50+ }
51+
52 my $sql = "RENAME TABLE $orig_tbl->{name} "
53 . "TO " . $q->quote($orig_tbl->{db}, $table_name)
54 . ", $new_tbl->{name} TO $orig_tbl->{name}";
55@@ -8623,6 +8638,13 @@
56 my $prefix = 'pt_osc_' . $orig_tbl->{db} . '_' . $orig_tbl->{tbl};
57 $prefix =~ s/\W/_/g;
58
59+ if ( length($prefix) > 60 ) {
60+ my $truncated_prefix = substr($prefix, 0, 60);
61+ PTDEBUG && _d('Trigger prefix', $prefix, 'is over 60 characters long,',
62+ 'truncating to', $truncated_prefix);
63+ $prefix = $truncated_prefix;
64+ }
65+
66 # To be safe, the delete trigger must specify all the columns of the
67 # primary key/unique index. We use null-safe equals, because unique
68 # unique indexes can be nullable.
69
70=== modified file 't/pt-online-schema-change/bugs.t'
71--- t/pt-online-schema-change/bugs.t 2012-07-31 16:33:30 +0000
72+++ t/pt-online-schema-change/bugs.t 2012-08-30 21:41:19 +0000
73@@ -159,6 +159,40 @@
74 );
75 }
76
77+# ############################################################################
78+# Bug 1041372: ptc-osc and long table names
79+# https://bugs.launchpad.net/percona-toolkit/+bug/1041372
80+# ############################################################################
81+my $orig_tbl = 'very_very_very_very_very_very_very_very_very_long_table_name';
82+
83+$master_dbh->do(q{DROP DATABASE IF EXISTS `bug_1041372`});
84+$master_dbh->do(q{CREATE DATABASE `bug_1041372`});
85+
86+for my $i ( 0..4 ) {
87+ my $tbl = $orig_tbl . ("a" x $i);
88+ $master_dbh->do(qq{create table `bug_1041372`.$tbl (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY )});
89+ $master_dbh->do(qq{insert into `bug_1041372`.$tbl values (1), (2), (3), (4), (5)});
90+
91+ ($output) = full_output(sub { pt_online_schema_change::main(@args,
92+ '--alter', "ADD COLUMN ptosc INT",
93+ '--execute', "$master_dsn,D=bug_1041372,t=$tbl")});
94+
95+ like(
96+ $output,
97+ qr/\QSuccessfully altered `bug_1041372`.`$tbl`/,
98+ "pt-osc works on long table names (length " . length($tbl) . ")"
99+ );
100+}
101+
102+my $triggers = $master_dbh->selectall_arrayref(qq{SHOW TRIGGERS FROM `bug_1041372`});
103+is_deeply(
104+ $triggers,
105+ [],
106+ "No triggers left for long table names"
107+) or diag(Dumper($triggers));
108+
109+$master_dbh->do(q{DROP DATABASE IF EXISTS `bug_1041372`});
110+
111 # #############################################################################
112 # Done.
113 # #############################################################################

Subscribers

People subscribed via source and target branches