Move --sleep to just before SELECT instead of between each row after SELECT.

This commit is contained in:
Daniel Nichter
2012-04-17 16:52:34 -06:00
parent c3724aedca
commit 522d7836e8
2 changed files with 53 additions and 11 deletions

View File

@@ -4178,6 +4178,16 @@ sub main {
commit($o, 1) if $commit_each; commit($o, 1) if $commit_each;
$get_sth = $get_next; $get_sth = $get_next;
# Sleep between fetching the next chunk of rows.
if( my $sleep_time = $o->get('sleep') ) {
$sleep_time = $last_select_time * $o->get('sleep-coef')
if $o->get('sleep-coef');
PTDEBUG && _d('Sleeping', $sleep_time);
trace('sleep', sub {
sleep($sleep_time);
});
}
PTDEBUG && _d('Fetching rows in next chunk'); PTDEBUG && _d('Fetching rows in next chunk');
trace('select', sub { trace('select', sub {
my $select_start = time; my $select_start = time;
@@ -4210,16 +4220,6 @@ sub main {
$lag = $ms->get_slave_lag($lag_dbh); $lag = $ms->get_slave_lag($lag_dbh);
} }
} }
# Sleep between rows.
if( my $sleep_time = $o->get('sleep') ) {
$sleep_time = $last_select_time * $o->get('sleep-coef')
if $o->get('sleep-coef');
PTDEBUG && _d('Sleeping', $sleep_time);
trace('sleep', sub {
sleep($sleep_time);
});
}
} # ROW } # ROW
PTDEBUG && _d('Done fetching rows'); PTDEBUG && _d('Done fetching rows');

View File

@@ -10,6 +10,7 @@ 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;
use Time::HiRes qw(time);
use PerconaTest; use PerconaTest;
use Sandbox; use Sandbox;
@@ -36,7 +37,7 @@ if ( ($rows || 0) != 4 ) {
plan skip_all => 'Failed to load tables1-4.sql'; plan skip_all => 'Failed to load tables1-4.sql';
} }
else { else {
plan tests => 23; plan tests => 25;
} }
my @args = qw(--dry-run --where 1=1); my @args = qw(--dry-run --where 1=1);
@@ -143,6 +144,47 @@ $output = output(sub {pt_archiver::main(@args, qw(--no-delete --purge --source),
$output = `/tmp/12345/use -N -e "select count(*) from test.table_1"`; $output = `/tmp/12345/use -N -e "select count(*) from test.table_1"`;
is($output + 0, 4, 'All 4 rows are still there'); is($output + 0, 4, 'All 4 rows are still there');
# #############################################################################
# --sleep
# #############################################################################
# This table, gt_n.t1, is nothing special; it just has 19 rows and a PK.
$sb->load_file('master', 't/pt-archiver/samples/gt_n.sql');
# https://bugs.launchpad.net/percona-toolkit/+bug/979092
# This shouldn't take more than 3 seconds because it only takes 2 SELECT
# with limit 10 to get all 19 rows. It should --sleep 1 between each fetch,
# not between each row, which is the bug.
my $t = time;
$output = output(
sub { pt_archiver::main(@args, '--source', "D=gt_n,t=t1,F=$cnf",
qw(--where 1=1 --purge --sleep 1 --no-check-charset --limit 10)) },
);
cmp_ok(
int(time - $t),
'<',
3,
"--sleep between SELECT (bug 979092)"
);
# Try again with --bulk-delete. The tool should work the same.
$sb->load_file('master', 't/pt-archiver/samples/gt_n.sql');
$t = time;
$output = output(
sub { pt_archiver::main(@args, '--source', "D=gt_n,t=t1,F=$cnf",
qw(--where 1=1 --purge --sleep 1 --no-check-charset --limit 10),
qw(--bulk-delete)) },
);
cmp_ok(
int(time - $t),
'<',
3,
"--sleep between SELECT --bulk-delete (bug 979092)"
);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################