Merge pull request #275 from percona/PT-209

PT-209 Check adding FKs to a RocksDB table
This commit is contained in:
Carlos Salguero
2017-11-27 14:06:28 -03:00
committed by GitHub
5 changed files with 114 additions and 1 deletions

View File

@@ -10037,6 +10037,9 @@ sub check_alter {
my $ok = 1;
$alter =~ s/^(.*?)\s+COMMENT\s+'(.*?[^\\]')+(.*)/$1$3/;
$alter =~ s/^(.*?)\s+COMMENT\s+"(.*?[^\\]")+(.*)/$1$3/;
my $unique_fields = get_unique_index_fields($alter);
if (scalar @$unique_fields && $o->get('check-unique-key-change')) {
@@ -10056,6 +10059,12 @@ sub check_alter {
die ($msg);
}
if ( ($tbl->{tbl_struct}->{engine} || '') =~ m/RocksDB/i ) {
if ($alter =~ m/FOREIGN KEY/i) {
my $msg = "FOREIGN KEYS are not supported by the RocksDB engine\n\n";
die ($msg);
}
}
# ########################################################################
# Check for DROP PRIMARY KEY.
# ########################################################################

View File

@@ -174,6 +174,13 @@ make_sandbox() {
/tmp/$port/use -e "start slave"
fi
if [ -x "$PERCONA_TOOLKIT_SANDBOX/bin/ps-admin" ]; then
# try to enable RocksDB. Only available on Percona Server 5.7.19+
if [ "$version" ">" "5.6" ]; then
$PERCONA_TOOLKIT_SANDBOX/bin/ps-admin --enable-rocksdb -u root -pmsandbox -h 127.1 -P $port
fi
fi
return 0
}

View File

@@ -1161,7 +1161,7 @@ SKIP: {
},
engine => 'InnoDB',
is_autoinc => { column2 => 0, column3 => 0, id => 0 },
is_col => { column2 => 1, column3 => 1, id => 1 },
is_col => { column2 => 1, id => 1 },
is_generated => { column3 => 1 },
is_nullable => { column2 => 1, column3 => 1 },
is_numeric => { column2 => 1, column3 => 1, id => 1 },

View File

@@ -0,0 +1,89 @@
#!/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 English qw(-no_match_vars);
use Test::More;
use Data::Dumper;
use PerconaTest;
use Sandbox;
use SqlModes;
use File::Temp qw/ tempdir /;
require "$trunk/bin/pt-online-schema-change";
my $dp = new DSNParser(opts=>$dsn_opts);
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
my $master_dbh = $sb->get_dbh_for('master');
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
if ( !$master_dbh ) {
plan skip_all => 'Cannot connect to sandbox master';
}
if ($sandbox_version lt '5.7') {
plan skip_all => "RocksDB is only available on Percona Server 5.7.19+";
}
my $rows = $master_dbh->selectall_arrayref('SHOW ENGINES', {Slice=>{}});
my $rocksdb_enabled;
for my $row (@$rows) {
if ($row->{engine} eq 'ROCKSDB') {
$rocksdb_enabled = 1;
last;
}
}
if (!$rocksdb_enabled) {
plan skip_all => "RocksDB engine is not available";
}
plan tests => 3;
# 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;
my $sample = "t/pt-online-schema-change/samples/";
$sb->load_file('master', "$sample/pt-209.sql");
($output, $exit_status) = full_output(
sub { pt_online_schema_change::main(@args, "$master_dsn,D=test,t=t1",
'--execute',
'--alter', "ADD CONSTRAINT fk_some_id FOREIGN KEY (some_id) REFERENCES some(id)`",
),
},
);
isnt(
$exit_status,
0,
"PT-209 Altering RocksDB table adding a foreign key exit status != 0",
);
like(
$output,
qr/FOREIGN KEYS are not supported by the RocksDB engine/s,
"PT-209 Message cannot add FKs to a RocksDB table",
);
$master_dbh->do("DROP DATABASE IF EXISTS test");
# #############################################################################
# Done.
# #############################################################################
$sb->wipe_clean($master_dbh);
ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
done_testing;

View File

@@ -0,0 +1,8 @@
CREATE SCHEMA IF NOT EXISTS test;
USE test;
DROP TABLE IF EXISTS t1;
CREATE TABLE `test`.`t1` (
`ID` int(11) NOT NULL,
`Column2` int(11) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=RocksDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;