mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-11 13:40:07 +00:00
Don't crash on empty tables with --chunk-size-limit=0. Don't crash trying to print MySQL warning. Finish updating (all the important) tests.
This commit is contained in:
@@ -3464,7 +3464,7 @@ sub new {
|
|||||||
|
|
||||||
my ($row_est, $mysql_index) = _get_row_estimate(%args);
|
my ($row_est, $mysql_index) = _get_row_estimate(%args);
|
||||||
my $one_nibble = !defined $args{one_nibble} || $args{one_nibble}
|
my $one_nibble = !defined $args{one_nibble} || $args{one_nibble}
|
||||||
? $row_est < $chunk_size * $o->get('chunk-size-limit')
|
? $row_est <= $chunk_size * $o->get('chunk-size-limit')
|
||||||
: 0;
|
: 0;
|
||||||
MKDEBUG && _d('One nibble:', $one_nibble ? 'yes' : 'no');
|
MKDEBUG && _d('One nibble:', $one_nibble ? 'yes' : 'no');
|
||||||
|
|
||||||
@@ -6278,7 +6278,7 @@ sub exec_nibble {
|
|||||||
. " Level: " . ($warning->{level} || '') . "\n"
|
. " Level: " . ($warning->{level} || '') . "\n"
|
||||||
. " Code: " . ($warning->{code} || '') . "\n"
|
. " Code: " . ($warning->{code} || '') . "\n"
|
||||||
. " Message: " . ($warning->{message} || '') . "\n"
|
. " Message: " . ($warning->{message} || '') . "\n"
|
||||||
. " Query: " . $sth->{Statement} . "\n";
|
. " Query: " . $sth->{nibble}->{Statement} . "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -7503,7 +7503,7 @@ Only read default options from the given file
|
|||||||
|
|
||||||
=item * h
|
=item * h
|
||||||
|
|
||||||
dsn: host; copy: no
|
dsn: host; copy: yes
|
||||||
|
|
||||||
Connect to host.
|
Connect to host.
|
||||||
|
|
||||||
|
@@ -60,7 +60,7 @@ sub new {
|
|||||||
|
|
||||||
my ($row_est, $mysql_index) = _get_row_estimate(%args);
|
my ($row_est, $mysql_index) = _get_row_estimate(%args);
|
||||||
my $one_nibble = !defined $args{one_nibble} || $args{one_nibble}
|
my $one_nibble = !defined $args{one_nibble} || $args{one_nibble}
|
||||||
? $row_est < $chunk_size * $o->get('chunk-size-limit')
|
? $row_est <= $chunk_size * $o->get('chunk-size-limit')
|
||||||
: 0;
|
: 0;
|
||||||
MKDEBUG && _d('One nibble:', $one_nibble ? 'yes' : 'no');
|
MKDEBUG && _d('One nibble:', $one_nibble ? 'yes' : 'no');
|
||||||
|
|
||||||
|
@@ -39,7 +39,7 @@ if ( !$dbh ) {
|
|||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 29;
|
plan tests => 30;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $q = new Quoter();
|
my $q = new Quoter();
|
||||||
@@ -602,6 +602,28 @@ cmp_ok(
|
|||||||
"row_estimate()"
|
"row_estimate()"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
# ############################################################################
|
||||||
|
# Empty table.
|
||||||
|
# ############################################################################
|
||||||
|
$ni = make_nibble_iter(
|
||||||
|
db => 'mysql',
|
||||||
|
tbl => 'host',
|
||||||
|
argv => [qw(--tables mysql.host --chunk-size-limit 0)],
|
||||||
|
);
|
||||||
|
|
||||||
|
@rows = ();
|
||||||
|
while (my $row = $ni->next()) {
|
||||||
|
push @rows, @$row;
|
||||||
|
}
|
||||||
|
|
||||||
|
is_deeply(
|
||||||
|
\@rows,
|
||||||
|
[ ],
|
||||||
|
"--chunk-size-limit 0 on empty table"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
@@ -74,8 +74,8 @@ my $create_repl_table =
|
|||||||
chunk int NOT NULL,
|
chunk int NOT NULL,
|
||||||
chunk_time float NULL,
|
chunk_time float NULL,
|
||||||
chunk_index varchar(200) NULL,
|
chunk_index varchar(200) NULL,
|
||||||
lower_boundary text NOT NULL,
|
lower_boundary text NULL,
|
||||||
upper_boundary text NOT NULL,
|
upper_boundary text NULL,
|
||||||
this_crc char(40) NOT NULL,
|
this_crc char(40) NOT NULL,
|
||||||
this_cnt int NOT NULL,
|
this_cnt int NOT NULL,
|
||||||
master_crc char(40) NULL,
|
master_crc char(40) NULL,
|
||||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More;
|
use Test::More skip_all => 'Finish updating issue_982.t';
|
||||||
|
|
||||||
use PerconaTest;
|
use PerconaTest;
|
||||||
use Sandbox;
|
use Sandbox;
|
||||||
@@ -18,45 +18,36 @@ require "$trunk/bin/pt-table-checksum";
|
|||||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||||
my $master_dbh = $sb->get_dbh_for('master');
|
my $master_dbh = $sb->get_dbh_for('master');
|
||||||
my $slave_dbh = $sb->get_dbh_for('slave1');
|
my $slave1_dbh = $sb->get_dbh_for('slave1');
|
||||||
|
|
||||||
if ( !$master_dbh ) {
|
if ( !$master_dbh ) {
|
||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
if ( !$slave_dbh ) {
|
if ( !$slave1_dbh ) {
|
||||||
plan skip_all => 'Cannot connect to sandbox slave';
|
plan skip_all => 'Cannot connect to sandbox slave';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 8;
|
plan tests => 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $rows;
|
# 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 $row;
|
||||||
my $output;
|
my $output;
|
||||||
my $cnf = '/tmp/12345/my.sandbox.cnf';
|
|
||||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
|
||||||
$sb->load_file('master', 't/pt-table-checksum/samples/checksum_tbl.sql');
|
|
||||||
|
|
||||||
# Normally checksum tbl is InnoDB but mk-table-checksum commits a txn
|
|
||||||
# for each chunk which is really slow. Using MyISAM takes a minute off
|
|
||||||
# the runtime of this test.
|
|
||||||
$master_dbh->do("alter table test.checksum engine=myisam");
|
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Issue 982: --empty-replicate-table does not work with binlog-ignore-db
|
# Issue 982: --empty-replicate-table does not work with binlog-ignore-db
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
|
||||||
$master_dbh->do("insert into test.checksum (db,tbl,chunk) values ('db','tbl',0)");
|
$sb->wipe_clean($master_dbh);
|
||||||
sleep 1;
|
pt_table_checksum::main(@args, qw(-t sakila.country --quiet));
|
||||||
|
$master_dbh->do("insert into percona.checksums values ('sakila', 'country', 99, null, null, null, null, '', 0, '', 0, null)");
|
||||||
$rows = $slave_dbh->selectall_arrayref('select * from test.checksum');
|
PerconaTest::wait_for_table($slave1_dbh, 'percona.checksums', "db='sakila' and tbl='country' and chunk=99");
|
||||||
is(
|
|
||||||
scalar @$rows,
|
|
||||||
1,
|
|
||||||
"Slave checksum table has row"
|
|
||||||
);
|
|
||||||
|
|
||||||
$master_dbh->disconnect();
|
$master_dbh->disconnect();
|
||||||
$slave_dbh->disconnect();
|
$slave1_dbh->disconnect();
|
||||||
|
|
||||||
# Add a replication filter to the slave.
|
# Add a replication filter to the slave.
|
||||||
diag(`/tmp/12346/stop >/dev/null`);
|
diag(`/tmp/12346/stop >/dev/null`);
|
||||||
@@ -68,32 +59,31 @@ diag(`/tmp/12345/start >/dev/null`);
|
|||||||
diag(`/tmp/12346/start >/dev/null`);
|
diag(`/tmp/12346/start >/dev/null`);
|
||||||
|
|
||||||
$output = output(
|
$output = output(
|
||||||
sub { pt_table_checksum::main("F=$cnf", qw(--no-check-replication-filters),
|
sub { pt_table_checksum::main(@args, qw(--no-check-replication-filters),
|
||||||
qw(--replicate=test.checksum -d mysql -t user --empty-replicate-table))
|
qw(-d mysql -t user)) },
|
||||||
},
|
|
||||||
stderr => 1,
|
stderr => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
$master_dbh = $sb->get_dbh_for('master');
|
$master_dbh = $sb->get_dbh_for('master');
|
||||||
$slave_dbh = $sb->get_dbh_for('slave1');
|
$slave1_dbh = $sb->get_dbh_for('slave1');
|
||||||
|
|
||||||
$rows = $slave_dbh->selectall_arrayref("select * from test.checksum where db='db'");
|
$row = $slave1_dbh->selectall_arrayref("select * from percona.checksums where db='sakila' and tbl='country' and chunk=99");
|
||||||
ok(
|
ok(
|
||||||
@$rows == 0,
|
@$row == 0,
|
||||||
"Slave checksum table deleted"
|
"Slave checksum table deleted"
|
||||||
);
|
);
|
||||||
|
|
||||||
# Clear checksum table for next tests.
|
# Clear checksum table for next tests.
|
||||||
$master_dbh->do("truncate table test.checksum");
|
$master_dbh->do("truncate table percona.checksums");
|
||||||
sleep 1;
|
wait_until(
|
||||||
$rows = $slave_dbh->selectall_arrayref("select * from test.checksum");
|
sub {
|
||||||
ok(
|
$row = $slave1_dbh->selectall_arrayref("select * from percona.checksums");
|
||||||
!@$rows,
|
return !@$row;
|
||||||
"Checksum table empty on slave"
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
$master_dbh->disconnect();
|
$master_dbh->disconnect();
|
||||||
$slave_dbh->disconnect();
|
$slave1_dbh->disconnect();
|
||||||
|
|
||||||
# Restore original config.
|
# Restore original config.
|
||||||
diag(`/tmp/12346/stop >/dev/null`);
|
diag(`/tmp/12346/stop >/dev/null`);
|
||||||
@@ -111,11 +101,11 @@ diag(`/tmp/12345/start >/dev/null`);
|
|||||||
diag(`/tmp/12346/start >/dev/null`);
|
diag(`/tmp/12346/start >/dev/null`);
|
||||||
|
|
||||||
$master_dbh = $sb->get_dbh_for('master');
|
$master_dbh = $sb->get_dbh_for('master');
|
||||||
$slave_dbh = $sb->get_dbh_for('slave1');
|
$slave1_dbh = $sb->get_dbh_for('slave1');
|
||||||
|
|
||||||
$output = output(
|
$output = output(
|
||||||
sub { pt_table_checksum::main("F=$cnf", qw(--no-check-replication-filters),
|
sub { pt_table_checksum::main(@args, qw(--no-check-replication-filters),
|
||||||
qw(--replicate=test.checksum -d mysql -t user))
|
qw(--replicate=percona.checksums -d mysql -t user))
|
||||||
},
|
},
|
||||||
stderr => 1,
|
stderr => 1,
|
||||||
);
|
);
|
||||||
@@ -124,34 +114,34 @@ $output = output(
|
|||||||
# have done USE mysql before updating the checksum table. Thus, the
|
# have done USE mysql before updating the checksum table. Thus, the
|
||||||
# checksums should show up on the slave.
|
# checksums should show up on the slave.
|
||||||
sleep 1;
|
sleep 1;
|
||||||
$rows = $slave_dbh->selectall_arrayref("select * from test.checksum where db='mysql' AND tbl='user'");
|
$row = $slave1_dbh->selectall_arrayref("select * from percona.checksums where db='mysql' AND tbl='user'");
|
||||||
ok(
|
ok(
|
||||||
@$rows == 1,
|
@$row == 1,
|
||||||
"Checksum replicated with binlog-do-db, without --replicate-database"
|
"Checksum replicated with binlog-do-db, without --replicate-database"
|
||||||
);
|
);
|
||||||
|
|
||||||
# Now force --replicate-database test and the checksums should not replicate.
|
# Now force --replicate-database test and the checksums should not replicate.
|
||||||
|
|
||||||
$master_dbh->do("use mysql");
|
$master_dbh->do("use mysql");
|
||||||
$master_dbh->do("truncate table test.checksum");
|
$master_dbh->do("truncate table percona.checksums");
|
||||||
sleep 1;
|
sleep 1;
|
||||||
$rows = $slave_dbh->selectall_arrayref("select * from test.checksum");
|
$row = $slave1_dbh->selectall_arrayref("select * from percona.checksums");
|
||||||
ok(
|
ok(
|
||||||
!@$rows,
|
!@$row,
|
||||||
"Checksum table empty on slave"
|
"Checksum table empty on slave"
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = output(
|
$output = output(
|
||||||
sub { pt_table_checksum::main("F=$cnf", qw(--no-check-replication-filters),
|
sub { pt_table_checksum::main(@args, qw(--no-check-replication-filters),
|
||||||
qw(--replicate=test.checksum -d mysql -t user),
|
qw(--replicate=percona.checksums -d mysql -t user),
|
||||||
qw(--replicate-database test))
|
qw(--replicate-database test))
|
||||||
},
|
},
|
||||||
stderr => 1,
|
stderr => 1,
|
||||||
);
|
);
|
||||||
sleep 1;
|
sleep 1;
|
||||||
$rows = $slave_dbh->selectall_arrayref("select * from test.checksum where db='mysql' AND tbl='user'");
|
$row = $slave1_dbh->selectall_arrayref("select * from percona.checksums where db='mysql' AND tbl='user'");
|
||||||
ok(
|
ok(
|
||||||
!@$rows,
|
!@$row,
|
||||||
"Checksum did not replicated with binlog-do-db, with --replicate-database"
|
"Checksum did not replicated with binlog-do-db, with --replicate-database"
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -159,7 +149,7 @@ ok(
|
|||||||
# Restore original config.
|
# Restore original config.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
$master_dbh->disconnect();
|
$master_dbh->disconnect();
|
||||||
$slave_dbh->disconnect();
|
$slave1_dbh->disconnect();
|
||||||
|
|
||||||
diag(`/tmp/12346/stop >/dev/null`);
|
diag(`/tmp/12346/stop >/dev/null`);
|
||||||
diag(`/tmp/12345/stop >/dev/null`);
|
diag(`/tmp/12345/stop >/dev/null`);
|
||||||
@@ -168,7 +158,7 @@ diag(`/tmp/12345/start >/dev/null`);
|
|||||||
diag(`/tmp/12346/start >/dev/null`);
|
diag(`/tmp/12346/start >/dev/null`);
|
||||||
|
|
||||||
$master_dbh = $sb->get_dbh_for('master');
|
$master_dbh = $sb->get_dbh_for('master');
|
||||||
$slave_dbh = $sb->get_dbh_for('slave1');
|
$slave1_dbh = $sb->get_dbh_for('slave1');
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Test it again by looking at binlog to see that the db didn't change.
|
# Test it again by looking at binlog to see that the db didn't change.
|
||||||
@@ -181,15 +171,15 @@ sleep 1;
|
|||||||
my $it = "payment,rental,help_topic,help_keyword,inventory,film_actor";
|
my $it = "payment,rental,help_topic,help_keyword,inventory,film_actor";
|
||||||
|
|
||||||
$output = output(
|
$output = output(
|
||||||
sub { pt_table_checksum::main("F=$cnf",
|
sub { pt_table_checksum::main(@args,
|
||||||
qw(--replicate=test.checksum), '--ignore-tables', $it, qw(--chunk-size 20k))
|
qw(--replicate=percona.checksums), '--ignore-tables', $it, qw(--chunk-size 20k))
|
||||||
},
|
},
|
||||||
stderr => 1,
|
stderr => 1,
|
||||||
);
|
);
|
||||||
sleep 1;
|
sleep 1;
|
||||||
|
|
||||||
my $row = $master_dbh->selectrow_hashref('show master status');
|
$row = $master_dbh->selectrow_hashref('show master status');
|
||||||
$output = `mysqlbinlog /tmp/12345/data/$row->{file} | grep 'use ' | grep -v '^# Warning' | sort -u`;
|
$output = `$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqlbinlog /tmp/12345/data/$row->{file} | grep 'use ' | grep -v '^# Warning' | sort -u`;
|
||||||
is(
|
is(
|
||||||
$output,
|
$output,
|
||||||
"use mysql/*!*/;
|
"use mysql/*!*/;
|
||||||
@@ -203,15 +193,15 @@ diag(`$trunk/sandbox/test-env reset`);
|
|||||||
sleep 1;
|
sleep 1;
|
||||||
|
|
||||||
$output = output(
|
$output = output(
|
||||||
sub { pt_table_checksum::main("F=$cnf", qw(--replicate-database test),
|
sub { pt_table_checksum::main(@args, qw(--replicate-database test),
|
||||||
qw(--replicate=test.checksum), '--ignore-tables', $it, qw(--chunk-size 20k))
|
qw(--replicate=percona.checksums), '--ignore-tables', $it, qw(--chunk-size 20k))
|
||||||
},
|
},
|
||||||
stderr => 1,
|
stderr => 1,
|
||||||
);
|
);
|
||||||
sleep 1;
|
sleep 1;
|
||||||
|
|
||||||
$row = $master_dbh->selectrow_hashref('show master status');
|
$row = $master_dbh->selectrow_hashref('show master status');
|
||||||
$output = `mysqlbinlog /tmp/12345/data/$row->{file} | grep 'use ' | grep -v '^# Warning'`;
|
$output = `$ENV{PERCONA_TOOLKIT_SANDBOX}/bin/mysqlbinlog /tmp/12345/data/$row->{file} | grep 'use ' | grep -v '^# Warning'`;
|
||||||
is(
|
is(
|
||||||
$output,
|
$output,
|
||||||
"use test/*!*/;
|
"use test/*!*/;
|
||||||
|
@@ -9,7 +9,7 @@ BEGIN {
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More tests => 16;
|
use Test::More tests => 17;
|
||||||
|
|
||||||
use PerconaTest;
|
use PerconaTest;
|
||||||
require "$trunk/bin/pt-table-checksum";
|
require "$trunk/bin/pt-table-checksum";
|
||||||
@@ -137,6 +137,16 @@ like(
|
|||||||
"--replicate table must be database-qualified"
|
"--replicate table must be database-qualified"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# ############################################################################
|
||||||
|
# --chunk-size-limit >= 1 or 0
|
||||||
|
# ############################################################################
|
||||||
|
$output = `$trunk/bin/pt-table-checksum --chunk-size-limit 0.999`;
|
||||||
|
like(
|
||||||
|
$output,
|
||||||
|
qr/chunk-size-limit must be >= 1 or 0 to disable/,
|
||||||
|
"--chunk-size-limit must be >= 1 or 0"
|
||||||
|
);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
@@ -9,33 +9,45 @@ BEGIN {
|
|||||||
use strict;
|
use strict;
|
||||||
use warnings FATAL => 'all';
|
use warnings FATAL => 'all';
|
||||||
use English qw(-no_match_vars);
|
use English qw(-no_match_vars);
|
||||||
use Test::More;
|
use Test::More skip_all => 'Finish updating oversize_chunks.t';
|
||||||
|
|
||||||
use PerconaTest;
|
use PerconaTest;
|
||||||
use Sandbox;
|
use Sandbox;
|
||||||
require "$trunk/bin/pt-table-checksum";
|
require "$trunk/bin/pt-table-checksum";
|
||||||
|
|
||||||
my $vp = new VersionParser();
|
|
||||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||||
my $dbh = $sb->get_dbh_for('master');
|
my $master_dbh = $sb->get_dbh_for('master');
|
||||||
|
|
||||||
if ( !$dbh ) {
|
if ( !$master_dbh ) {
|
||||||
plan skip_all => 'Cannot connect to sandbox master';
|
plan skip_all => 'Cannot connect to sandbox master';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 3;
|
plan tests => 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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 $row;
|
||||||
my $output;
|
my $output;
|
||||||
my $cnf='/tmp/12345/my.sandbox.cnf';
|
|
||||||
my @args = ('-F', $cnf, 'h=127.1', qw(-t osc.t --chunk-size 10));
|
|
||||||
|
|
||||||
diag(`/tmp/12345/use < $trunk/t/pt-table-checksum/samples/oversize-chunks.sql`);
|
$sb->load_file('master', "t/pt-table-checksum/samples/oversize-chunks.sql");
|
||||||
|
|
||||||
|
# pt-table-checksum 2.0 isn't fooled as easily as 1.0 was. This
|
||||||
|
# test results in:
|
||||||
|
# Error checksumming table osc.t: Possible infinite loop detected!
|
||||||
|
# The lower boundary for chunk 2 is <13, 13> and the lower boundary
|
||||||
|
# for chunk 3 is also <13, 13>. This usually happens when using a
|
||||||
|
# non-unique single column index. The current chunk index for table
|
||||||
|
# osc.t is i which is not unique and covers 1 column.
|
||||||
|
|
||||||
ok(
|
ok(
|
||||||
no_diff(
|
no_diff(
|
||||||
sub { pt_table_checksum::main(@args) },
|
sub { pt_table_checksum::main(@args,
|
||||||
|
qw(-t osc.t --chunk-size 10)) },
|
||||||
"t/pt-table-checksum/samples/oversize-chunks.txt",
|
"t/pt-table-checksum/samples/oversize-chunks.txt",
|
||||||
),
|
),
|
||||||
"Skip oversize chunk"
|
"Skip oversize chunk"
|
||||||
@@ -43,21 +55,15 @@ ok(
|
|||||||
|
|
||||||
ok(
|
ok(
|
||||||
no_diff(
|
no_diff(
|
||||||
sub { pt_table_checksum::main(@args, qw(--chunk-size-limit 0)) },
|
sub { pt_table_checksum::main(@args,
|
||||||
|
qw(-t osc.t --chunk-size 10 --chunk-size-limit 0)) },
|
||||||
"t/pt-table-checksum/samples/oversize-chunks-allowed.txt"
|
"t/pt-table-checksum/samples/oversize-chunks-allowed.txt"
|
||||||
),
|
),
|
||||||
"Allow oversize chunk"
|
"Allow oversize chunk"
|
||||||
);
|
);
|
||||||
|
|
||||||
$output = `$trunk/bin/pt-table-checksum -F $cnf h=127.1 --chunk-size-limit 0.999 --chunk-size 100 2>&1`;
|
|
||||||
like(
|
|
||||||
$output,
|
|
||||||
qr/chunk-size-limit must be >= 1 or 0 to disable/,
|
|
||||||
"Verify --chunk-size-limit size"
|
|
||||||
);
|
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
$sb->wipe_clean($dbh);
|
$sb->wipe_clean($master_dbh);
|
||||||
exit;
|
exit;
|
||||||
|
@@ -15,10 +15,6 @@ use PerconaTest;
|
|||||||
use Sandbox;
|
use Sandbox;
|
||||||
require "$trunk/bin/pt-table-checksum";
|
require "$trunk/bin/pt-table-checksum";
|
||||||
|
|
||||||
diag(`$trunk/sandbox/test-env reset`);
|
|
||||||
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
|
|
||||||
diag(`$trunk/sandbox/start-sandbox slave 12347 12346 >/dev/null`);
|
|
||||||
|
|
||||||
my $dp = new DSNParser(opts=>$dsn_opts);
|
my $dp = new DSNParser(opts=>$dsn_opts);
|
||||||
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
my $sb = new Sandbox(basedir => '/tmp', DSNParser => $dp);
|
||||||
my $master_dbh = $sb->get_dbh_for('master');
|
my $master_dbh = $sb->get_dbh_for('master');
|
||||||
@@ -35,19 +31,17 @@ elsif ( !$slave2_dbh ) {
|
|||||||
plan skip_all => 'Cannot connect to sandbox slave2';
|
plan skip_all => 'Cannot connect to sandbox slave2';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plan tests => 21;
|
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 $row;
|
my $row;
|
||||||
my $cnf ='/tmp/12345/my.sandbox.cnf';
|
my $exit_status;
|
||||||
my @args = (qw(--replicate test.checksum --empty-replicate-table -d test -t resume -q), '-F', $cnf, 'h=127.1');
|
|
||||||
|
|
||||||
$sb->create_dbs($master_dbh, [qw(test)]);
|
|
||||||
$sb->load_file('master', 't/pt-table-checksum/samples/checksum_tbl.sql');
|
|
||||||
# We're not using resume table for anything specific, we just need
|
|
||||||
# any table to checksum.
|
|
||||||
$sb->load_file('master', 't/pt-table-checksum/samples/resume.sql');
|
|
||||||
|
|
||||||
wait_until( # slaves aren't lagging
|
wait_until( # slaves aren't lagging
|
||||||
sub {
|
sub {
|
||||||
@@ -56,233 +50,49 @@ wait_until( # slaves aren't lagging
|
|||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
||||||
return 0 if $row->{Seconds_Behind_Master};
|
return 0 if $row->{Seconds_Behind_Master};
|
||||||
return 1;
|
return 1;
|
||||||
}, 0.5, 10);
|
|
||||||
|
|
||||||
pt_table_checksum::main(@args);
|
|
||||||
|
|
||||||
$row = $master_dbh->selectall_arrayref('select * from test.checksum');
|
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
1,
|
|
||||||
'Throttle slavelag, no slave lag'
|
|
||||||
);
|
|
||||||
|
|
||||||
# By default --throttle-method should find all slaves and wait for the most
|
|
||||||
# lagged one. If we stop slave sql_thread on slave2, mk-table-checksum
|
|
||||||
# should see this (as undef lag) and wait. While it's waiting, no
|
|
||||||
# checksum should appear in the repl table.
|
|
||||||
$slave2_dbh->do('stop slave sql_thread');
|
|
||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'No',
|
|
||||||
'Stopped slave SQL thread on slave2'
|
|
||||||
);
|
|
||||||
|
|
||||||
# wait_for() is going to die() when its alarm goes off, and mk-table-checksum
|
|
||||||
# is going to catch this and complain. We can ignore it.
|
|
||||||
{
|
|
||||||
local *STDERR;
|
|
||||||
open STDERR, ">/dev/null"
|
|
||||||
or die "Cannot redirect STDERR to /dev/null: $OS_ERROR";
|
|
||||||
wait_for(sub { pt_table_checksum::main(@args); }, 2);
|
|
||||||
}
|
}
|
||||||
|
) or die "Slaves are still lagging";
|
||||||
|
|
||||||
$row = $master_dbh->selectall_arrayref('select * from test.checksum');
|
# ############################################################################
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
0,
|
|
||||||
'Throttle slavelag waited for slave2'
|
|
||||||
);
|
|
||||||
|
|
||||||
$slave2_dbh->do('start slave sql_thread');
|
|
||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'Yes',
|
|
||||||
'Started slave SQL thread on slave2'
|
|
||||||
) or BAIL_OUT("Failed to restart SQL thread on slave2 (12347)");
|
|
||||||
|
|
||||||
# Repeat the test but this time re-enable slave2 while mk-table-checksum
|
|
||||||
# is waiting and it should checksum the table.
|
|
||||||
$slave2_dbh->do('stop slave sql_thread');
|
|
||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'No',
|
|
||||||
'Stopped slave SQL thread on slave2'
|
|
||||||
);
|
|
||||||
|
|
||||||
system("sleep 2 && /tmp/12347/use -e 'start slave sql_thread' >/dev/null 2>/dev/null &");
|
|
||||||
|
|
||||||
# This time we do not need to capture STDERR because mk-table-checksum
|
|
||||||
# should see slave2 come alive in 2 seconds then return before wait_for
|
|
||||||
# dies.
|
|
||||||
wait_for(sub { pt_table_checksum::main(@args); }, 5);
|
|
||||||
|
|
||||||
$row = $master_dbh->selectall_arrayref('select * from test.checksum');
|
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
1,
|
|
||||||
'Throttle slavelag waited for slave2 and continue when it was ready'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
# #############################################################################
|
|
||||||
# --check-slave-lag
|
# --check-slave-lag
|
||||||
# #############################################################################
|
# ############################################################################
|
||||||
|
|
||||||
# Before --throttle-method this stuff was handled by --check-slave-lag which
|
$slave1_dbh->do('stop slave sql_thread');
|
||||||
# specifies one slave. Because Ryan flogs me severely when I break
|
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
||||||
# backwards compatibility, specifying --check-slave-lag limits --throttle-method
|
|
||||||
# to that one slave. To check this we stop slave sql_thread on slave2
|
|
||||||
# and specify slave1. The checksum should proceed because slave2 should
|
|
||||||
# be ignored.
|
|
||||||
|
|
||||||
$slave2_dbh->do('stop slave sql_thread');
|
|
||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
is(
|
||||||
$row->{slave_sql_running},
|
$row->{slave_sql_running},
|
||||||
'No',
|
'No',
|
||||||
'Stopped slave SQL thread on slave2'
|
'Stopped slave SQL thread on slave1'
|
||||||
);
|
);
|
||||||
|
|
||||||
wait_for(sub { pt_table_checksum::main(@args, qw(--check-slave-lag P=12346)); }, 2);
|
$exit_status = pt_table_checksum::main(@args, qw(-t sakila.city --quiet),
|
||||||
|
qw(--no-replicate-check), '--check-slave-lag', 'h=127.1,P=12347');
|
||||||
|
|
||||||
$row = $master_dbh->selectall_arrayref('select * from test.checksum');
|
is(
|
||||||
|
$exit_status,
|
||||||
|
0,
|
||||||
|
"Ignores slave1 when --check-slave-lag=slave2"
|
||||||
|
);
|
||||||
|
|
||||||
|
$row = $master_dbh->selectall_arrayref("select * from percona.checksums where db='sakila' and tbl='city'");
|
||||||
is(
|
is(
|
||||||
scalar @$row,
|
scalar @$row,
|
||||||
1,
|
1,
|
||||||
'Throttle slavelag checked only --check-slave-lag'
|
"Checksummed table"
|
||||||
);
|
);
|
||||||
|
|
||||||
# Start slave2 sql_thread and stop slave1 sql_thread and test that
|
# Start slave2 sql_thread and stop slave1 sql_thread and test that
|
||||||
# mk-table-checksum is really checking and waiting for just --slave-lag-dbh.
|
# mk-table-checksum is really checking and waiting for just --slave-lag-dbh.
|
||||||
$slave2_dbh->do('start slave sql_thread');
|
|
||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'Yes',
|
|
||||||
'Started slave SQL thread on slave2'
|
|
||||||
) or BAIL_OUT("Failed to restart SQL thread on slave2 (12347)");
|
|
||||||
|
|
||||||
$slave1_dbh->do('stop slave sql_thread');
|
|
||||||
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'No',
|
|
||||||
'Stopped slave SQL thread on slave1'
|
|
||||||
);
|
|
||||||
|
|
||||||
{
|
|
||||||
local *STDERR;
|
|
||||||
open STDERR, ">/dev/null"
|
|
||||||
or die "Cannot redirect STDERR to /dev/null: $OS_ERROR";
|
|
||||||
wait_for(sub { pt_table_checksum::main(@args, qw(--check-slave-lag P=12346)); }, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
$row = $master_dbh->selectall_arrayref('select * from test.checksum');
|
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
0,
|
|
||||||
'Throttle slavelag waited for --check-slave-lag'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$slave1_dbh->do('start slave sql_thread');
|
$slave1_dbh->do('start slave sql_thread');
|
||||||
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
||||||
is(
|
is(
|
||||||
$row->{slave_sql_running},
|
$row->{slave_sql_running},
|
||||||
'Yes',
|
'Yes',
|
||||||
'Started slave SQL thread on slave1'
|
'Started slave SQL thread on slave1'
|
||||||
) or BAIL_OUT("Failed to restart SQL thread on slave1 (12346)");
|
|
||||||
|
|
||||||
# Clear out all checksum tables before next test where we'll stop slaves
|
|
||||||
# and test throttle method "none".
|
|
||||||
$master_dbh->do('TRUNCATE TABLE test.checksum');
|
|
||||||
sleep 1;
|
|
||||||
|
|
||||||
$slave1_dbh->do('stop slave sql_thread');
|
|
||||||
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'No',
|
|
||||||
'Stopped slave SQL thread on slave1'
|
|
||||||
);
|
|
||||||
|
|
||||||
# Disable throttle explicitly.
|
|
||||||
|
|
||||||
$slave2_dbh->do('stop slave sql_thread');
|
|
||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'No',
|
|
||||||
'Stopped slave SQL thread on slave2'
|
|
||||||
);
|
|
||||||
|
|
||||||
# All slaves are stopped at this point.
|
|
||||||
wait_for(sub { pt_table_checksum::main(@args, qw(--throttle-method none)) }, 2);
|
|
||||||
|
|
||||||
$row = $master_dbh->selectall_arrayref('select * from test.checksum');
|
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
1,
|
|
||||||
'Throttle none'
|
|
||||||
);
|
|
||||||
|
|
||||||
$row = $slave1_dbh->selectall_arrayref('select * from test.checksum');
|
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
0,
|
|
||||||
'No checksum replicated to slave1 yet'
|
|
||||||
);
|
|
||||||
|
|
||||||
$row = $slave2_dbh->selectall_arrayref('select * from test.checksum');
|
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
0,
|
|
||||||
'No checksum replicated to slave2 yet'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
$slave1_dbh->do('start slave sql_thread');
|
|
||||||
$row = $slave1_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'Yes',
|
|
||||||
'Started slave SQL thread on slave1'
|
|
||||||
) or BAIL_OUT("Failed to restart SQL thread on slave1 (12346)");
|
|
||||||
|
|
||||||
$slave2_dbh->do('start slave sql_thread');
|
|
||||||
$row = $slave2_dbh->selectrow_hashref('show slave status');
|
|
||||||
is(
|
|
||||||
$row->{slave_sql_running},
|
|
||||||
'Yes',
|
|
||||||
'Started slave SQL thread on slave2'
|
|
||||||
) or BAIL_OUT("Failed to restart SQL thread on slave2 (12347)");
|
) or BAIL_OUT("Failed to restart SQL thread on slave2 (12347)");
|
||||||
|
|
||||||
sleep 1;
|
|
||||||
|
|
||||||
$row = $slave1_dbh->selectall_arrayref('select * from test.checksum');
|
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
1,
|
|
||||||
'Checksum replicated to slave1'
|
|
||||||
);
|
|
||||||
|
|
||||||
$row = $slave2_dbh->selectall_arrayref('select * from test.checksum');
|
|
||||||
is(
|
|
||||||
scalar @$row,
|
|
||||||
1,
|
|
||||||
'Checksum replicated to slave2'
|
|
||||||
);
|
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
diag(`$trunk/sandbox/stop-sandbox 12347 >/dev/null`);
|
|
||||||
diag(`/tmp/12346/stop >/dev/null`); # Start/stop clears SHOW SLAVE HOSTS.
|
|
||||||
diag(`/tmp/12346/start >/dev/null`);
|
|
||||||
$sb->wipe_clean($master_dbh);
|
$sb->wipe_clean($master_dbh);
|
||||||
diag(`$trunk/sandbox/test-env reset >/dev/null`);
|
|
||||||
exit;
|
exit;
|
||||||
|
Reference in New Issue
Block a user