mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-17 17:27:57 +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';
|
||||
}
|
||||
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 $cnf='/tmp/12345/my.sandbox.cnf';
|
||||
my $cmd = "$trunk/bin/pt-table-checksum -F $cnf 127.0.0.1";
|
||||
my $row;
|
||||
|
||||
$sb->wipe_clean($master_dbh);
|
||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
||||
#$sb->create_dbs($master_dbh, [qw(test)]);
|
||||
|
||||
# #############################################################################
|
||||
# Issue 77: mk-table-checksum should be able to create the --replicate table
|
||||
# #############################################################################
|
||||
# Most other tests implicitly test that --create-replicate-table is on
|
||||
# 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(
|
||||
$master_dbh->selectall_arrayref('show tables from test'),
|
||||
[],
|
||||
"Checksum table does not exist on master"
|
||||
eval {
|
||||
pt_table_checksum::main(@args, '--no-create-replicate-table');
|
||||
};
|
||||
like(
|
||||
$EVAL_ERROR,
|
||||
qr/--replicate database percona does not exist/,
|
||||
"--no-create-replicate-table dies if db doesn't exist"
|
||||
);
|
||||
|
||||
is_deeply(
|
||||
$slave_dbh->selectall_arrayref('show tables from test'),
|
||||
[],
|
||||
"Checksum table does not exist on slave"
|
||||
$master_dbh->do('create database percona');
|
||||
$master_dbh->do('use percona');
|
||||
eval {
|
||||
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.
|
||||
$output = `$cmd --replicate test.checksum 2>&1`;
|
||||
my $create_repl_table =
|
||||
"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(
|
||||
$output,
|
||||
qr/replicate table .+ does not exist/,
|
||||
'Dies with honor when replication table does not exist'
|
||||
);
|
||||
|
||||
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'
|
||||
qr/^\S+\s+0\s+0\s+109\s+1\s+0\s+\S+\s+sakila.country$/m,
|
||||
"Uses pre-created replicate table"
|
||||
);
|
||||
|
||||
# ############################################################################
|
||||
# Issue 1318: mk-tabke-checksum --create-replicate-table doesn't replicate
|
||||
# ############################################################################
|
||||
is(
|
||||
lc($slave_dbh->selectrow_hashref('show create table test.checksum')->{'create table'}),
|
||||
$create_tbl,
|
||||
'Creates the replicate table replicates (issue 1318)'
|
||||
|
||||
$sb->wipe_clean($master_dbh);
|
||||
|
||||
# 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 Test::More;
|
||||
|
||||
use Data::Dumper;
|
||||
use PerconaTest;
|
||||
use Sandbox;
|
||||
require "$trunk/bin/pt-table-checksum";
|
||||
@@ -24,59 +25,85 @@ if ( !$dbh ) {
|
||||
plan skip_all => 'Cannot connect to sandbox master';
|
||||
}
|
||||
else {
|
||||
plan tests => 4;
|
||||
plan tests => 7;
|
||||
}
|
||||
|
||||
my $output;
|
||||
my $cnf='/tmp/12345/my.sandbox.cnf';
|
||||
my @args = ('-F', $cnf, 'h=127.1');
|
||||
|
||||
$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'
|
||||
);
|
||||
# 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));
|
||||
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
qw(--explain -d mysql --tables-regex user)) },
|
||||
);
|
||||
like(
|
||||
$output,
|
||||
qr/^mysql\s+user\s+/,
|
||||
"--tables-regex"
|
||||
# ############################################################################
|
||||
# The schema object filters don't need to be tested extensively here
|
||||
# because they should be tested extensively in SchemaIterator.t.
|
||||
# ############################################################################
|
||||
|
||||
sub test_filter {
|
||||
my ($filters, $tbls) = @_;
|
||||
|
||||
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(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
qw(--explain -d mysql --ignore-tables-regex user)) },
|
||||
);
|
||||
unlike(
|
||||
$output,
|
||||
qr/user/,
|
||||
"--ignore-tables-regex"
|
||||
test_filter(
|
||||
[qw(--tables actor)],
|
||||
['sakila.actor'],
|
||||
);
|
||||
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args,
|
||||
qw(--explain -d mysql --ignore-databases-regex mysql)) },
|
||||
test_filter(
|
||||
[qw(--tables sakila.actor)],
|
||||
['sakila.actor'],
|
||||
);
|
||||
is(
|
||||
$output,
|
||||
"",
|
||||
"--ignore-databases-regex"
|
||||
|
||||
test_filter(
|
||||
['--tables', 'actor,film'],
|
||||
['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';
|
||||
}
|
||||
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 $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/before.sql');
|
||||
$sb->load_file('master', "t/pt-table-checksum/samples/float_precision.sql");
|
||||
|
||||
# Ensure float-precision is effective
|
||||
$output = `$cmd --function sha1 --algorithm BIT_XOR -d test -t fl_test --explain 127.0.0.1`;
|
||||
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($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');
|
||||
$output = output(
|
||||
sub { pt_table_checksum::main(@args, qw(-t float_precision.t --explain)) },
|
||||
);
|
||||
|
||||
like(
|
||||
$output,
|
||||
qr/^-- float_precision.t/m,
|
||||
"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.
|
||||
|
@@ -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";
|
||||
|
||||
$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("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";
|
||||
|
||||
$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
|
||||
|
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