pt-osc added --null-to-not-null option

This commit is contained in:
frank-cizmich
2016-01-26 17:26:06 -03:00
parent 91dc29d00e
commit b40469d913
3 changed files with 80 additions and 14 deletions

View File

@@ -8029,14 +8029,24 @@ my $term_readkey = eval {
use sigtrap 'handler', \&sig_int, 'normal-signals';
my $exit_status = 0;
my $oktorun = 1;
my $dont_interrupt_now = 0;
my @drop_trigger_sqls;
my @triggers_not_dropped;
my $pxc_version = '0';
# Completely ignore these error codes.
my %ignore_code = (
# Error: 1592 SQLSTATE: HY000 (ER_BINLOG_UNSAFE_STATEMENT)
# Message: Statement may not be safe to log in statement format.
# Ignore this warning because we have purposely set statement-based
# replication.
1592 => 1,
# Error: 1062 SQLSTATE: 23000 ( ER_DUP_ENTRY )
# Message: Duplicate entry '%ld' for key '%s'
# MariaDB 5.5.28+ has this as a warning; See https://bugs.launchpad.net/percona-toolkit/+bug/1099836
1062 => 1,
);
$OUTPUT_AUTOFLUSH = 1;
@@ -8049,6 +8059,7 @@ sub main {
@drop_trigger_sqls = ();
@triggers_not_dropped = ();
$dont_interrupt_now = 0;
%ignore_code = (1592 => 1, 1062 => 1);
my %stats = (
INSERT => 0,
@@ -8062,6 +8073,10 @@ sub main {
$o->get_specs();
$o->get_opts();
if ( $o->get('null-to-not-null') ) {
$ignore_code{1048} = 1;
}
my $dp = $o->DSNParser();
$dp->prop('set-vars', $o->set_vars());
@@ -10749,18 +10764,6 @@ sub exec_nibble {
my $chunk = $nibble_iter->nibble_number();
my $chunk_index = $nibble_iter->nibble_index();
# Completely ignore these error codes.
my %ignore_code = (
# Error: 1592 SQLSTATE: HY000 (ER_BINLOG_UNSAFE_STATEMENT)
# Message: Statement may not be safe to log in statement format.
# Ignore this warning because we have purposely set statement-based
# replication.
1592 => 1,
# Error: 1062 SQLSTATE: 23000 ( ER_DUP_ENTRY )
# Message: Duplicate entry '%ld' for key '%s'
# MariaDB 5.5.28+ has this as a warning; See https://bugs.launchpad.net/percona-toolkit/+bug/1099836
1062 => 1,
);
# Warn once per-table for these error codes if the error message
# matches the pattern.
@@ -11614,6 +11617,13 @@ to 10 C<_> (underscore) to find a unique table name. If a table name is
specified, the tool does not prefix it with C<_>, so the table must not
exist.
=item --null-to-not-null
Allows MODIFYing a column that allows NULL values to one that doesn't allow
them. The rows which contain NULL values will be converted to the defined
default value. If no explicit DEFAULT value is given MySQL will assign a default
value based on datatype, e.g. 0 for number datatypes, '' for string datatypes.
=item --password
short form: -p; type: string

View File

@@ -38,6 +38,51 @@ my $output;
my $exit_status;
my $sample = "t/pt-online-schema-change/samples/";
# ############################################################################
# https://bugs.launchpad.net/percona-toolkit/+bug/1336734
# pt-online-schema-change 2.2.17 adds --null-to-not-null feature
# ############################################################################
$sb->load_file('master', "$sample/bug-1336734.sql");
($output, $exit_status) = full_output(
sub { pt_online_schema_change::main(@args,
"$master_dsn,D=test,t=lp1336734",
"--execute",
"--null-to-not-null",
# notice we are not using a DEFAULT value, to also
# test if the "default default" value for datatype
# is used
"--alter", "MODIFY COLUMN name VARCHAR(20) NOT NULL",
qw(--chunk-size 2 --print)) },
);
my $test_rows = $master_dbh->selectall_arrayref("SELECT id, name FROM test.lp1336734 ORDER BY id");
ok (!$exit_status,
"--null-to-not-null exit status = 0"
);
is_deeply(
$test_rows,
[
[
'1',
'curly'
],
[
'2',
'larry'
],
[
'3',
''
],
[
'4',
'moe'
]
],
"--null-to-not-null default value good"
);
# ############################################################################
# https://bugs.launchpad.net/percona-toolkit/+bug/994002
# pt-online-schema-change 2.1.1 doesn't choose the PRIMARY KEY

View File

@@ -0,0 +1,11 @@
drop database if exists test;
create database test;
use test;
CREATE TABLE lp1336734 (
id int primary key,
name varchar(20) DEFAULT NULL
);
INSERT INTO lp1336734 VALUES (1, "curly"), (2, "larry") , (3, NULL), (4, "moe");