mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-17 08:57:24 +00:00
Update create_replicate_table.t, filters.t, and float_precision.t. Remove unused before.sql.
This commit is contained in:
@@ -28,78 +28,99 @@ elsif ( !$slave_dbh ) {
|
|||||||
plan skip_all => 'Cannot connect to sandbox slave';
|
plan skip_all => 'Cannot connect to sandbox slave';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 5;
|
plan tests => 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||||
|
# so we need to specify --lock-wait-timeout=3 else the tool will die.
|
||||||
|
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
||||||
|
my @args = ($master_dsn, qw(--lock-wait-timeout 3));
|
||||||
|
|
||||||
my $output;
|
my $output;
|
||||||
my $cnf='/tmp/12345/my.sandbox.cnf';
|
my $row;
|
||||||
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
|
|
||||||
|
|
||||||
$sb->wipe_clean($master_dbh);
|
$sb->wipe_clean($master_dbh);
|
||||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
#$sb->create_dbs($master_dbh, [qw(test)]);
|
||||||
|
|
||||||
# #############################################################################
|
# Most other tests implicitly test that --create-replicate-table is on
|
||||||
# Issue 77: mk-table-checksum should be able to create the --replicate table
|
# by default because they use that functionality. So here we need to
|
||||||
# #############################################################################
|
# test that we can turn it off, that it doesn't blow up if the repl table
|
||||||
|
# already exists, etc.
|
||||||
|
|
||||||
is_deeply(
|
eval {
|
||||||
$master_dbh->selectall_arrayref('show tables from test'),
|
pt_table_checksum::main(@args, '--no-create-replicate-table');
|
||||||
[],
|
};
|
||||||
"Checksum table does not exist on master"
|
like(
|
||||||
|
$EVAL_ERROR,
|
||||||
|
qr/--replicate database percona does not exist/,
|
||||||
|
"--no-create-replicate-table dies if db doesn't exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
is_deeply(
|
$master_dbh->do('create database percona');
|
||||||
$slave_dbh->selectall_arrayref('show tables from test'),
|
$master_dbh->do('use percona');
|
||||||
[],
|
eval {
|
||||||
"Checksum table does not exist on slave"
|
pt_table_checksum::main(@args, '--no-create-replicate-table');
|
||||||
|
};
|
||||||
|
like(
|
||||||
|
$EVAL_ERROR,
|
||||||
|
qr/--replicate table `percona`.`checksums` does not exist/,
|
||||||
|
"--no-create-replicate-table dies if table doesn't exist"
|
||||||
);
|
);
|
||||||
|
|
||||||
# First check that, like a Klingon, it dies with honor.
|
my $create_repl_table =
|
||||||
$output = `$cmd --replicate test.checksum 2>&1`;
|
"CREATE TABLE `checksums` (
|
||||||
|
db char(64) NOT NULL,
|
||||||
|
tbl char(64) NOT NULL,
|
||||||
|
chunk int NOT NULL,
|
||||||
|
chunk_time float NULL,
|
||||||
|
chunk_index varchar(200) NULL,
|
||||||
|
lower_boundary text NOT NULL,
|
||||||
|
upper_boundary text NOT NULL,
|
||||||
|
this_crc char(40) NOT NULL,
|
||||||
|
this_cnt int NOT NULL,
|
||||||
|
master_crc char(40) NULL,
|
||||||
|
master_cnt int NULL,
|
||||||
|
ts timestamp NOT NULL,
|
||||||
|
PRIMARY KEY (db, tbl, chunk)
|
||||||
|
) ENGINE=InnoDB;";
|
||||||
|
|
||||||
|
$master_dbh->do($create_repl_table);
|
||||||
|
|
||||||
|
$output = output(
|
||||||
|
sub { pt_table_checksum::main(@args, '--no-create-replicate-table',
|
||||||
|
qw(-t sakila.country)) },
|
||||||
|
);
|
||||||
like(
|
like(
|
||||||
$output,
|
$output,
|
||||||
qr/replicate table .+ does not exist/,
|
qr/^\S+\s+0\s+0\s+109\s+1\s+0\s+\S+\s+sakila.country$/m,
|
||||||
'Dies with honor when replication table does not exist'
|
"Uses pre-created replicate table"
|
||||||
);
|
|
||||||
|
|
||||||
output(
|
|
||||||
sub { pt_table_checksum::main('-F', $cnf,
|
|
||||||
qw(--create-replicate-table --replicate test.checksum 127.1)) },
|
|
||||||
stderr => 0,
|
|
||||||
);
|
|
||||||
|
|
||||||
# In 5.0 "on" in "on update" is lowercase, in 5.1 it's uppercase.
|
|
||||||
my $create_tbl = lc("CREATE TABLE `checksum` (
|
|
||||||
`db` char(64) NOT NULL,
|
|
||||||
`tbl` char(64) NOT NULL,
|
|
||||||
`chunk` int(11) NOT NULL,
|
|
||||||
`boundaries` char(100) NOT NULL,
|
|
||||||
`this_crc` char(40) NOT NULL,
|
|
||||||
`this_cnt` int(11) NOT NULL,
|
|
||||||
`master_crc` char(40) default NULL,
|
|
||||||
`master_cnt` int(11) default NULL,
|
|
||||||
`ts` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
|
|
||||||
PRIMARY KEY (`db`,`tbl`,`chunk`)
|
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=latin1");
|
|
||||||
|
|
||||||
# In 5.0 there's 2 spaces, in 5.1 there 1.
|
|
||||||
if ( $vp->version_ge($master_dbh, '5.1.0') ) {
|
|
||||||
$create_tbl =~ s/primary key /primary key /;
|
|
||||||
}
|
|
||||||
|
|
||||||
is(
|
|
||||||
lc($master_dbh->selectrow_hashref('show create table test.checksum')->{'create table'}),
|
|
||||||
$create_tbl,
|
|
||||||
'Creates the replicate table'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
# Issue 1318: mk-tabke-checksum --create-replicate-table doesn't replicate
|
# Issue 1318: mk-tabke-checksum --create-replicate-table doesn't replicate
|
||||||
# ############################################################################
|
# ############################################################################
|
||||||
is(
|
|
||||||
lc($slave_dbh->selectrow_hashref('show create table test.checksum')->{'create table'}),
|
$sb->wipe_clean($master_dbh);
|
||||||
$create_tbl,
|
|
||||||
'Creates the replicate table replicates (issue 1318)'
|
# Wait until the slave no longer has the percona db.
|
||||||
|
PerconaTest::wait_until(
|
||||||
|
sub {
|
||||||
|
eval { $slave_dbh->do("use percona") };
|
||||||
|
return 1 if $EVAL_ERROR;
|
||||||
|
return 0;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
pt_table_checksum::main(@args, qw(-t sakila.country --quiet));
|
||||||
|
|
||||||
|
# Wait until the repl table replicates, or timeout.
|
||||||
|
PerconaTest::wait_for_table($slave_dbh, 'percona.checksums');
|
||||||
|
|
||||||
|
$row = $slave_dbh->selectrow_arrayref("show tables from percona");
|
||||||
|
is_deeply(
|
||||||
|
$row,
|
||||||
|
['checksums'],
|
||||||
|
'Auto-created replicate table replicates (issue 1318)'
|
||||||
);
|
);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
@@ -11,6 +11,7 @@ use warnings FATAL => 'all';
|
|||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
use PerconaTest;
|
use PerconaTest;
|
||||||
use Sandbox;
|
use Sandbox;
|
||||||
require "$trunk/bin/pt-table-checksum";
|
require "$trunk/bin/pt-table-checksum";
|
||||||
@@ -24,59 +25,85 @@ if ( !$dbh ) {
|
|||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 4;
|
plan tests => 7;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $output;
|
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||||
my $cnf='/tmp/12345/my.sandbox.cnf';
|
# so we need to specify --lock-wait-timeout=3 else the tool will die.
|
||||||
my @args = ('-F', $cnf, 'h=127.1');
|
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
||||||
|
my @args = ($master_dsn, qw(--lock-wait-timeout 3));
|
||||||
$sb->create_dbs($dbh, [qw(test)]);
|
|
||||||
$dbh->do('use test');
|
|
||||||
$dbh->do('create table t1 (i int) engine=myisam');
|
|
||||||
$dbh->do('create table t2 (i int) engine=innodb');
|
|
||||||
|
|
||||||
$output = output(
|
|
||||||
sub { pt_table_checksum::main(@args,
|
|
||||||
qw(--explain -d test --engines InnoDB)) },
|
|
||||||
);
|
|
||||||
|
|
||||||
is(
|
|
||||||
$output,
|
|
||||||
"test t2 CHECKSUM TABLE `test`.`t2`
|
|
||||||
",
|
|
||||||
'--engines'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$output = output(
|
# ############################################################################
|
||||||
sub { pt_table_checksum::main(@args,
|
# The schema object filters don't need to be tested extensively here
|
||||||
qw(--explain -d mysql --tables-regex user)) },
|
# because they should be tested extensively in SchemaIterator.t.
|
||||||
);
|
# ############################################################################
|
||||||
like(
|
|
||||||
$output,
|
sub test_filter {
|
||||||
qr/^mysql\s+user\s+/,
|
my ($filters, $tbls) = @_;
|
||||||
"--tables-regex"
|
|
||||||
|
my $output = output(
|
||||||
|
sub { pt_table_checksum::main(@args, '--explain', @$filters) },
|
||||||
|
);
|
||||||
|
my @got_tbls = $output =~ m/^-- (\S+)$/gm;
|
||||||
|
is_deeply(
|
||||||
|
\@got_tbls,
|
||||||
|
$tbls,
|
||||||
|
join(' ', @$filters),
|
||||||
|
) or print STDERR Dumper(\@got_tbls);
|
||||||
|
}
|
||||||
|
|
||||||
|
# sakila db has serval views where are (should be) automatically filtered out.
|
||||||
|
test_filter(
|
||||||
|
[qw(--databases sakila)],
|
||||||
|
[qw(
|
||||||
|
sakila.actor
|
||||||
|
sakila.address
|
||||||
|
sakila.category
|
||||||
|
sakila.city
|
||||||
|
sakila.country
|
||||||
|
sakila.customer
|
||||||
|
sakila.film
|
||||||
|
sakila.film_actor
|
||||||
|
sakila.film_category
|
||||||
|
sakila.film_text
|
||||||
|
sakila.inventory
|
||||||
|
sakila.language
|
||||||
|
sakila.payment
|
||||||
|
sakila.rental
|
||||||
|
sakila.staff
|
||||||
|
sakila.store
|
||||||
|
)],
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = output(
|
test_filter(
|
||||||
sub { pt_table_checksum::main(@args,
|
[qw(--tables actor)],
|
||||||
qw(--explain -d mysql --ignore-tables-regex user)) },
|
['sakila.actor'],
|
||||||
);
|
|
||||||
unlike(
|
|
||||||
$output,
|
|
||||||
qr/user/,
|
|
||||||
"--ignore-tables-regex"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = output(
|
test_filter(
|
||||||
sub { pt_table_checksum::main(@args,
|
[qw(--tables sakila.actor)],
|
||||||
qw(--explain -d mysql --ignore-databases-regex mysql)) },
|
['sakila.actor'],
|
||||||
);
|
);
|
||||||
is(
|
|
||||||
$output,
|
test_filter(
|
||||||
"",
|
['--tables', 'actor,film'],
|
||||||
"--ignore-databases-regex"
|
['sakila.actor', 'sakila.film'],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_filter(
|
||||||
|
['--tables', 'sakila.actor,mysql.user'],
|
||||||
|
['mysql.user', 'sakila.actor'],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_filter(
|
||||||
|
[qw(-d sakila --engines MyISAM)],
|
||||||
|
['sakila.film_text'],
|
||||||
|
);
|
||||||
|
|
||||||
|
test_filter(
|
||||||
|
[qw(-d sakila --engines myisam)],
|
||||||
|
['sakila.film_text'],
|
||||||
);
|
);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
@@ -23,24 +23,61 @@ if ( !$master_dbh ) {
|
|||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 5;
|
plan tests => 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
|
||||||
|
# so we need to specify --lock-wait-timeout=3 else the tool will die.
|
||||||
|
my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox';
|
||||||
|
my @args = ($master_dsn, qw(--lock-wait-timeout 3));
|
||||||
my $output;
|
my $output;
|
||||||
my $cnf='/tmp/12345/my.sandbox.cnf';
|
|
||||||
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
|
|
||||||
|
|
||||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
$sb->load_file('master', "t/pt-table-checksum/samples/float_precision.sql");
|
||||||
$sb->load_file('master', 't/pt-table-checksum/samples/before.sql');
|
|
||||||
|
|
||||||
# Ensure float-precision is effective
|
$output = output(
|
||||||
$output = `$cmd --function sha1 --algorithm BIT_XOR -d test -t fl_test --explain 127.0.0.1`;
|
sub { pt_table_checksum::main(@args, qw(-t float_precision.t --explain)) },
|
||||||
unlike($output, qr/ROUND\(`a`/, 'Column is not rounded');
|
);
|
||||||
like($output, qr/test/, 'Column is not rounded and I got output');
|
|
||||||
$output = `$cmd --function sha1 --float-precision 3 --algorithm BIT_XOR -d test -t fl_test --explain 127.0.0.1`;
|
like(
|
||||||
like($output, qr/ROUND\(`a`, 3/, 'Column a is rounded');
|
$output,
|
||||||
like($output, qr/ROUND\(`b`, 3/, 'Column b is rounded');
|
qr/^-- float_precision.t/m,
|
||||||
like($output, qr/ISNULL\(`b`\)/, 'Column b is not rounded inside ISNULL');
|
"Got output"
|
||||||
|
);
|
||||||
|
|
||||||
|
unlike(
|
||||||
|
$output,
|
||||||
|
qr/ROUND\(`a`/,
|
||||||
|
"No --float-precision, no rounding"
|
||||||
|
);
|
||||||
|
|
||||||
|
$output = output(
|
||||||
|
sub { pt_table_checksum::main(@args, qw(-t float_precision.t --explain),
|
||||||
|
qw(--float-precision 3)) },
|
||||||
|
);
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/^-- float_precision.t/m,
|
||||||
|
"Got output"
|
||||||
|
);
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/ROUND\(`a`, 3/,
|
||||||
|
'Column a is rounded'
|
||||||
|
);
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/ROUND\(`b`, 3/,
|
||||||
|
'Column b is rounded'
|
||||||
|
);
|
||||||
|
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/ISNULL\(`b`\)/,
|
||||||
|
'Column b is not rounded inside ISNULL'
|
||||||
|
);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
|
@@ -28,7 +28,6 @@ my $cnf='/tmp/12345/my.sandbox.cnf';
|
|||||||
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf -d test -t checksum_test 127.0.0.1";
|
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf -d test -t checksum_test 127.0.0.1";
|
||||||
|
|
||||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
$sb->create_dbs($master_dbh, [qw(test)]);
|
||||||
$sb->load_file('master', 't/pt-table-checksum/samples/before.sql');
|
|
||||||
|
|
||||||
eval { $master_dbh->do('DROP FUNCTION test.fnv_64'); };
|
eval { $master_dbh->do('DROP FUNCTION test.fnv_64'); };
|
||||||
eval { $master_dbh->do("CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'fnv_udf.so';"); };
|
eval { $master_dbh->do("CREATE FUNCTION fnv_64 RETURNS INTEGER SONAME 'fnv_udf.so';"); };
|
||||||
|
@@ -31,7 +31,6 @@ my $cnf='/tmp/12345/my.sandbox.cnf';
|
|||||||
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
|
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
|
||||||
|
|
||||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
$sb->create_dbs($master_dbh, [qw(test)]);
|
||||||
$sb->load_file('master', 't/pt-table-checksum/samples/before.sql');
|
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Issue 81: put some data that's too big into the boundaries table
|
# Issue 81: put some data that's too big into the boundaries table
|
||||||
|
File diff suppressed because one or more lines are too long
7
t/pt-table-checksum/samples/float_precision.sql
Normal file
7
t/pt-table-checksum/samples/float_precision.sql
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
DROP DATABASE IF EXISTS float_precision;
|
||||||
|
CREATE DATABASE float_precision;
|
||||||
|
USE float_precision;
|
||||||
|
CREATE TABLE t (
|
||||||
|
a float not null primary key,
|
||||||
|
b double
|
||||||
|
);
|
Reference in New Issue
Block a user