Merged fix-1041372-pt-osc-long-table-names

This commit is contained in:
Brian Fraser
2012-08-31 13:01:14 -03:00
2 changed files with 59 additions and 3 deletions

View File

@@ -7479,7 +7479,6 @@ sub main {
eval {
$new_tbl = create_new_table(
orig_tbl => $orig_tbl,
suffix => '_new',
Cxn => $cxn,
Quoter => $q,
OptionParser => $o,
@@ -8196,7 +8195,7 @@ sub create_new_table{
my $tries = $args{tries} || 10; # don't try forever
my $prefix = $args{prefix} || '_';
my $suffix = $args{suffix} || '_new';
my $suffix = '_new';
my $table_name = $orig_tbl->{tbl} . $suffix;
print "Creating new table...\n";
@@ -8204,6 +8203,14 @@ sub create_new_table{
my @old_tables;
while ( $tryno++ < $tries ) {
$table_name = $prefix . $table_name;
if ( length($table_name) > 64 ) {
my $truncated_table_name = substr($table_name, 0, 60) . $suffix;
PTDEBUG && _d($table_name, 'is over 64 characters long, truncating to',
$truncated_table_name);
$table_name = $truncated_table_name;
}
my $quoted = $q->quote($orig_tbl->{db}, $table_name);
# Generate SQL to create the new table. We do not use CREATE TABLE LIKE
@@ -8285,6 +8292,14 @@ sub swap_tables {
while ( $tries-- ) {
$table_name = $prefix . $table_name;
if ( length($table_name) > 64 ) {
my $truncated_table_name = substr($table_name, 0, 64);
PTDEBUG && _d($table_name, 'is over 64 characters long, truncating to',
$truncated_table_name);
$table_name = $truncated_table_name;
}
my $sql = "RENAME TABLE $orig_tbl->{name} "
. "TO " . $q->quote($orig_tbl->{db}, $table_name)
. ", $new_tbl->{name} TO $orig_tbl->{name}";
@@ -8623,6 +8638,13 @@ sub create_triggers {
my $prefix = 'pt_osc_' . $orig_tbl->{db} . '_' . $orig_tbl->{tbl};
$prefix =~ s/\W/_/g;
if ( length($prefix) > 60 ) {
my $truncated_prefix = substr($prefix, 0, 60);
PTDEBUG && _d('Trigger prefix', $prefix, 'is over 60 characters long,',
'truncating to', $truncated_prefix);
$prefix = $truncated_prefix;
}
# To be safe, the delete trigger must specify all the columns of the
# primary key/unique index. We use null-safe equals, because unique
# unique indexes can be nullable.

View File

@@ -159,6 +159,40 @@ like $output,
);
}
# ############################################################################
# Bug 1041372: ptc-osc and long table names
# https://bugs.launchpad.net/percona-toolkit/+bug/1041372
# ############################################################################
my $orig_tbl = 'very_very_very_very_very_very_very_very_very_long_table_name';
$master_dbh->do(q{DROP DATABASE IF EXISTS `bug_1041372`});
$master_dbh->do(q{CREATE DATABASE `bug_1041372`});
for my $i ( 0..4 ) {
my $tbl = $orig_tbl . ("a" x $i);
$master_dbh->do(qq{create table `bug_1041372`.$tbl (a INT NOT NULL AUTO_INCREMENT PRIMARY KEY )});
$master_dbh->do(qq{insert into `bug_1041372`.$tbl values (1), (2), (3), (4), (5)});
($output) = full_output(sub { pt_online_schema_change::main(@args,
'--alter', "ADD COLUMN ptosc INT",
'--execute', "$master_dsn,D=bug_1041372,t=$tbl")});
like(
$output,
qr/\QSuccessfully altered `bug_1041372`.`$tbl`/,
"pt-osc works on long table names (length " . length($tbl) . ")"
);
}
my $triggers = $master_dbh->selectall_arrayref(qq{SHOW TRIGGERS FROM `bug_1041372`});
is_deeply(
$triggers,
[],
"No triggers left for long table names"
) or diag(Dumper($triggers));
$master_dbh->do(q{DROP DATABASE IF EXISTS `bug_1041372`});
# #############################################################################
# Done.
# #############################################################################