Merge back changes to r32.

This commit is contained in:
Daniel Nichter
2011-07-14 11:10:58 -06:00
13 changed files with 86 additions and 146 deletions

View File

@@ -34,7 +34,7 @@ use English qw(-no_match_vars);
use constant MKDEBUG => $ENV{MKDEBUG} || 0;
use Test::More;
use Time::HiRes qw(usleep);
use Time::HiRes qw(sleep);
use POSIX qw(signal_h);
use Data::Dumper;
$Data::Dumper::Indent = 1;
@@ -219,15 +219,14 @@ sub parse_file {
# Wait until code returns true.
sub wait_until {
my ( $code, $t, $max_t ) = @_;
my $slept = 0;
my $sleep_int = $t || .5;
$t ||= .5;
$max_t ||= 5;
$t *= 1_000_000;
$max_t ||= 10;
my $slept = 0;
while ( $slept <= $max_t ) {
return if $code->();
usleep($t);
$slept += $sleep_int;
sleep $t;
$slept += $t;
}
return;
}
@@ -255,6 +254,24 @@ sub wait_for {
return 0;
}
sub wait_for_table {
my ($dbh, $tbl, $where) = @_;
my $sql = "SELECT 1 FROM $tbl" . ($where ? " WHERE $where LIMIT 1" : "");
return wait_until(
sub {
my $r;
eval { $r = $dbh->selectrow_arrayref($sql); };
return 0 if $EVAL_ERROR;
if ( $where ) {
return 0 unless $r && @$r;
}
return 1;
},
0.25,
15,
);
}
sub _read {
my ( $fh ) = @_;
return <$fh>;

View File

@@ -42,4 +42,6 @@ cd $PERCONA_TOOLKIT_BRANCH/sandbox
/tmp/$PORT/use < sakila-db/sakila-schema.sql
/tmp/$PORT/use < sakila-db/sakila-data.sql
$PERCONA_TOOLKIT_BRANCH/sandbox/test-env reset
exit 0

File diff suppressed because one or more lines are too long

View File

@@ -42,6 +42,7 @@ my $cmd = "$trunk/bin/pt-archiver";
# Issue 758: Make mk-archiver wait for a slave
# #############################################################################
$sb->load_file('master', 't/pt-archiver/samples/issue_758.sql');
PerconaTest::wait_for_table($dbh2, "issue_758.t");
is_deeply(
$dbh->selectall_arrayref('select * from issue_758.t'),
@@ -81,7 +82,7 @@ is_deeply(
# After this sleep the slave should have executed the INSERT SELECT,
# which returns 0, and the 2 purge/delete statments from above.
sleep 1;
sleep 3;
is_deeply(
$dbh->selectall_arrayref('select * from issue_758.t'),
[[0]],

View File

@@ -36,6 +36,7 @@ my $cmd = "perl -I $trunk/t/pt-archiver/samples $trunk/bin/pt-archiver";
# Bulk delete with limit that results in 2 chunks.
# ###########################################################################
$sb->load_file('master', "t/pt-archiver/samples/delete_more.sql");
PerconaTest::wait_for_table($dbh, '`db`.`main_table-123`');
$dbh->do('use dm');
is_deeply(
@@ -121,7 +122,8 @@ SKIP: {
# Run it again without DSN b so changes should be made on slave.
$sb->load_file('master', "t/pt-archiver/samples/delete_more.sql");
sleep 1;
PerconaTest::wait_for_table($slave_dbh, "`dm`.`main_table-123`", 'id=5');
PerconaTest::wait_for_table($slave_dbh, "`dm`.`other_table-123`", 'id=r6');
is_deeply(
$slave_dbh->selectall_arrayref('select * from `main_table-123` order by id'),

View File

@@ -35,6 +35,7 @@ my $cmd = "$trunk/bin/pt-archiver";
# Test the custom plugin gt_n.
# ###########################################################################
$sb->load_file('master', 't/pt-archiver/samples/gt_n.sql');
PerconaTest::wait_for_table($dbh, 'gt_n.t1', 'status="ok"');
my $sql = 'select status, count(*) from gt_n.t1 group by status';
is_deeply(
$dbh->selectall_arrayref($sql),

View File

@@ -33,8 +33,9 @@ my $cnf = "/tmp/12345/my.sandbox.cnf";
# #############################################################################
# Issue 1152: mk-archiver columns option resulting in null archived table data
# #############################################################################
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
PerconaTest::wait_for_table($dbh, 'issue_1225.t');
$dbh->do('set names "utf8"');
my $original_rows = $dbh->selectall_arrayref('select * from issue_1225.t where i in (1, 2)');
is_deeply(

View File

@@ -36,6 +36,8 @@ my $file = "/tmp/mk-archiver-file.txt";
# archive to file
# #############################################################################
$sb->load_file('master', 't/pt-archiver/samples/issue_1225.sql');
PerconaTest::wait_for_table($dbh, 'issue_1225.t');
$dbh->do('set names "utf8"');
my $original_rows = $dbh->selectall_arrayref('select * from issue_1225.t where i in (1, 2)');
is_deeply(

View File

@@ -85,6 +85,7 @@ SKIP: {
# This test will achive rows from dbh:test.table_1 to dbh2:test.table_2.
$sb->load_file('master', 't/pt-archiver/samples/tables1-4.sql');
PerconaTest::wait_for_table($dbh2, 'test.table_2');
# Change passwords so defaults files won't work.
$dbh->do('SET PASSWORD FOR msandbox = PASSWORD("foo")');
@@ -92,7 +93,7 @@ SKIP: {
$dbh2->do('TRUNCATE TABLE test.table_2');
$output = `MKDEBUG=1 $trunk/bin/pt-archiver --where 1=1 --source h=127.1,P=12345,D=test,t=table_1,u=msandbox,p=foo --dest P=12346,t=table_2 --statistics 2>&1`;
$output = `$trunk/bin/pt-archiver --where 1=1 --source h=127.1,P=12345,D=test,t=table_1,u=msandbox,p=foo --dest P=12346,t=table_2 2>&1`;
my $r = $dbh2->selectall_arrayref('SELECT * FROM test.table_2');
is(
scalar @$r,
@@ -112,7 +113,6 @@ SKIP: {
. 'status" and restart with "test-env restart". The error was: '
. $EVAL_ERROR);
}
};
# #############################################################################

View File

@@ -32,42 +32,42 @@ SKIP: {
# There's no hung queries so we'll just make sure it outputs anything,
# its debug stuff in this case.
`$cmd --print --interval 1s --run-time 2 --pid /tmp/mk-kill.pid --log /tmp/mk-kill.log --daemonize`;
$output = `ps -eaf | grep 'mk-kill \-F'`;
`$cmd --print --interval 1s --run-time 2 --pid /tmp/pt-kill.pid --log /tmp/pt-kill.log --daemonize`;
$output = `ps -eaf | grep 'pt-kill \-F'`;
like(
$output,
qr/mk-kill -F /,
qr/pt-kill -F /,
'It lives daemonized'
);
ok(
-f '/tmp/mk-kill.pid',
-f '/tmp/pt-kill.pid',
'PID file created'
);
ok(
-f '/tmp/mk-kill.log',
-f '/tmp/pt-kill.log',
'Log file created'
);
sleep 2;
ok(
!-f '/tmp/mk-kill.pid',
!-f '/tmp/pt-kill.pid',
'PID file removed'
);
diag(`rm -rf /tmp/mk-kill.log`);
diag(`rm -rf /tmp/pt-kill.log`);
}
# #########################################################################
# Issue 391: Add --pid option to all scripts
# #########################################################################
`touch /tmp/mk-script.pid`;
$output = `$cmd $trunk/t/lib/samples/pl/recset006.txt --match-state Locked --print --pid /tmp/mk-script.pid 2>&1`;
`touch /tmp/pt-script.pid`;
$output = `$cmd $trunk/t/lib/samples/pl/recset006.txt --match-state Locked --print --pid /tmp/pt-script.pid 2>&1`;
like(
$output,
qr{PID file /tmp/mk-script.pid already exists},
qr{PID file /tmp/pt-script.pid already exists},
'Dies if PID file already exists (--pid without --daemonize) (issue 391)'
);
`rm -rf /tmp/mk-script.pid`;
`rm -rf /tmp/pt-script.pid`;
# #############################################################################
# Done.

View File

@@ -90,7 +90,7 @@ ok(
'--report-format', 'query_report,profile',
"$trunk/t/lib/samples/slowlogs/slow007.txt") },
"t/pt-query-digest/samples/slow007_explain_3.txt",
trf => "sed 's/at [a-zA-Z\/\-]\\+ line [0-9]\\+/at line ?/'",
trf => "sed 's/at .* line [0-9]*/at line ?/'",
),
'Analysis for slow007 with --explain, failed',
);

View File

@@ -52,18 +52,20 @@ $master_dbh->do('create table t (i int, unique index (i))');
$master_dbh->do('insert into t values (1),(2)');
$slave_dbh->do('insert into t values (3)');
PerconaTest::wait_for_table($slave_dbh, 'test.t', 'i=1');
is_deeply(
$master_dbh->selectall_arrayref('select * from test.t'),
$master_dbh->selectall_arrayref('select * from test.t order by i'),
[[1],[2]],
'Data on master before sync'
);
use Data::Dumper;
my $rows = $slave_dbh->selectall_arrayref('select * from test.t order by i');
is_deeply(
$slave_dbh->selectall_arrayref('select * from test.t'),
$rows,
[[1],[2],[3]],
'Data on slave before sync'
);
) or print Dumper($rows);
$master_dbh->do('SET GLOBAL binlog_format="ROW"');
$master_dbh->disconnect();

View File

@@ -51,12 +51,12 @@ output(
my $binlog = $master_dbh->selectrow_arrayref('show master logs');
$output = `$mysqlbinlog /tmp/12345/data/$binlog->[0] | grep maatkit`;
$output = `$mysqlbinlog /tmp/12345/data/$binlog->[0] | grep 'percona-toolkit'`;
$output =~ s/pid:\d+/pid:0/ if $output;
$output =~ s/host:\S+?\*/host:-*/ if $output;
is(
$output,
"DELETE FROM `onlythisdb`.`t` WHERE `i`='5' LIMIT 1 /*maatkit src_db:onlythisdb src_tbl:t src_dsn:P=12345,h=127.0.0.1,p=...,u=msandbox dst_db:onlythisdb dst_tbl:t dst_dsn:P=12346,h=127.0.0.1,p=...,u=msandbox lock:1 transaction:0 changing_src:1 replicate:0 bidirectional:0 pid:0 user:$ENV{USER} host:-*/
"DELETE FROM `onlythisdb`.`t` WHERE `i`='5' LIMIT 1 /*percona-toolkit src_db:onlythisdb src_tbl:t src_dsn:P=12345,h=127.0.0.1,p=...,u=msandbox dst_db:onlythisdb dst_tbl:t dst_dsn:P=12346,h=127.0.0.1,p=...,u=msandbox lock:1 transaction:0 changing_src:1 replicate:0 bidirectional:0 pid:0 user:$ENV{USER} host:-*/
",
"Trace message appended to change SQL"
);