From 15ffa974eb01fac4f6e22ffb0d62d0d1411fc1c0 Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Sun, 22 Nov 2020 18:58:00 -0300 Subject: [PATCH] PT-1528 [WIP] Proposed solution --- bin/pt-online-schema-change | 3 +- t/pt-online-schema-change/pt-1528.t | 105 ++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 t/pt-online-schema-change/pt-1528.t diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index f198a468..fd7af631 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -8387,6 +8387,7 @@ package pt_online_schema_change; use strict; use warnings FATAL => 'all'; +use utf8; use English qw(-no_match_vars); use Percona::Toolkit; @@ -8474,7 +8475,7 @@ sub main { @drop_trigger_sqls = (); @triggers_not_dropped = (); $dont_interrupt_now = 0; - %ignore_code = (1592 => 1, 1062 => 1); + %ignore_code = (1592 => 1, 1062 => 1, 1300 => 1); my %stats = ( INSERT => 0, diff --git a/t/pt-online-schema-change/pt-1528.t b/t/pt-online-schema-change/pt-1528.t new file mode 100644 index 00000000..d9c9fc36 --- /dev/null +++ b/t/pt-online-schema-change/pt-1528.t @@ -0,0 +1,105 @@ +#!/usr/bin/env perl + +BEGIN { + die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" + unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; + unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; +}; + +use strict; +use warnings FATAL => 'all'; +use threads; +use threads::shared; +use Thread::Semaphore; + +use English qw(-no_match_vars); +use Test::More; + +use Data::Dumper; +use PerconaTest; +use Sandbox; +use SqlModes; +use File::Temp qw/ tempdir /; + +if ($sandbox_version lt '5.7') { + plan skip_all => 'This test needs MySQL 5.7+'; +} else { + plan tests => 5; +} + +require "$trunk/bin/pt-online-schema-change"; + +my $dp = new DSNParser(opts=>$dsn_opts); +my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp); + +my $dbh = $sb->get_dbh_for('master'); +my $dsn = $sb->dsn_for("master"); + +# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic +# so we need to specify --set-vars innodb_lock_wait_timeout=3 else the +# tool will die. +my @args = (qw(--set-vars innodb_lock_wait_timeout=3)); +my $output; +my $exit_status; + +$sb->load_file('master', "t/pt-online-schema-change/samples/pt-1574.sql"); + +# TODO WRITE A PROPER TEST +# It should: +# 1. import the data from the jira ticket +# 2. run pt-osc with --no-drop-old table +# 3. compare old and new table. they should have the same info +# +die('incomplete test'); + +# ($output, $exit_status) = full_output( +# sub { pt_online_schema_change::main(@args, "$dsn,D=test,t=t1", +# '--execute', "--chunk-index", "idx_id", "--chunk-size", "1", +# "--nocheck-plan", '--alter', "engine=innodb", +# ), +# }, +# stderr => 1, +# ); +# +# my $sql_mode = $dbh->selectcol_arrayref('SELECT @@sql_mode'); +# +# isnt( +# $exit_status, +# 0, +# "PT-1574, PT-1590 There is no unique index exit status", +# ); +# +# like( +# $output, +# qr/at least one UNIQUE and NOT NULLABLE index/s, +# "PT-1574, PT-1590 Message you need an unique index.", +# ); +# +# ($output, $exit_status) = full_output( +# sub { pt_online_schema_change::main(@args, "$dsn,D=test,t=t2", +# '--execute', "--chunk-index", "idx_id", "--chunk-size", "1", +# "--nocheck-plan", '--alter', "engine=innodb", +# ), +# }, +# stderr => 1, +# ); +# diag($output); +# +# is( +# $exit_status, +# 0, +# "PT-1574, PT-1590 Exit status 0 with null fields, got $exit_status", +# ); +# +# like( +# $output, +# qr/Successfully altered `test`.`t2`/s, +# "PT-1574, PT-1590 Successfully altered `test`.`t2`", +# ); + +# ############################################################################# +# Done. +# ############################################################################# +$sb->wipe_clean($dbh); +ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); +done_testing;