From 522d7836e8300b5796a49c0a64c0d181c58cd3d2 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Tue, 17 Apr 2012 16:52:34 -0600 Subject: [PATCH] Move --sleep to just before SELECT instead of between each row after SELECT. --- bin/pt-archiver | 20 +++++++++---------- t/pt-archiver/basics.t | 44 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/bin/pt-archiver b/bin/pt-archiver index 7a5bd064..95a5f380 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -4178,6 +4178,16 @@ sub main { commit($o, 1) if $commit_each; $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'); trace('select', sub { my $select_start = time; @@ -4210,16 +4220,6 @@ sub main { $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 PTDEBUG && _d('Done fetching rows'); diff --git a/t/pt-archiver/basics.t b/t/pt-archiver/basics.t index 416d7410..8aa8a1ed 100644 --- a/t/pt-archiver/basics.t +++ b/t/pt-archiver/basics.t @@ -10,6 +10,7 @@ use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); use Test::More; +use Time::HiRes qw(time); use PerconaTest; use Sandbox; @@ -36,7 +37,7 @@ if ( ($rows || 0) != 4 ) { plan skip_all => 'Failed to load tables1-4.sql'; } else { - plan tests => 23; + plan tests => 25; } 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"`; 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. # #############################################################################