Decompose ReplicaLagLimiter into ReplicaLagWaiter and WeightedAvgRate. Don't use OptionParser in NibbleIterator; use chunk_size arg instead.

This commit is contained in:
Daniel Nichter
2011-09-21 11:19:49 -06:00
parent 31d6171355
commit f6fb8b44bd
7 changed files with 256 additions and 150 deletions

View File

@@ -77,10 +77,11 @@ sub make_nibble_iter {
1 while $si->next_schema_object();
my $ni = new NibbleIterator(
dbh => $dbh,
tbl => $schema->get_table($args{db}, $args{tbl}),
callbacks => $args{callbacks},
select => $args{select},
dbh => $dbh,
tbl => $schema->get_table($args{db}, $args{tbl}),
chunk_size => $o->get('chunk-size'),
callbacks => $args{callbacks},
select => $args{select},
%common_modules,
);

View File

@@ -9,9 +9,9 @@ BEGIN {
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 10;
use Test::More tests => 5;
use ReplicaLagLimiter;
use ReplicaLagWaiter;
use PerconaTest;
my $oktorun = 1;
@@ -35,75 +35,17 @@ sub sleep {
sleep $t;
}
my $rll = new ReplicaLagLimiter(
my $rll = new ReplicaLagWaiter(
oktorun => \&oktorun,
get_lag => \&get_lag,
sleep => \&sleep,
max_lag => 1,
initial_n => 1000,
initial_t => 1,
target_t => 1,
slaves => [
{ dsn=>{n=>'slave1'}, dbh=>1 },
{ dsn=>{n=>'slave2'}, dbh=>2 },
],
);
# ############################################################################
# Update master op, see if we get correct adjustment result.
# ############################################################################
# stay the same
for (1..5) {
$rll->update(1000, 1);
}
is(
$rll->update(1000, 1),
1000,
"Same rate, same n"
);
# slow down
for (1..5) {
$rll->update(1000, 2);
}
is(
$rll->update(1000, 2),
542,
"Decrease rate, decrease n"
);
for (1..15) {
$rll->update(1000, 2);
}
is(
$rll->update(1000, 2),
500,
"limit n=500 decreasing"
);
# speed up
for (1..5) {
$rll->update(1000, 1);
}
is(
$rll->update(1000, 1),
849,
"Increase rate, increase n"
);
for (1..20) {
$rll->update(1000, 1);
}
is(
$rll->update(1000, 1),
999,
"limit n=1000 increasing"
);
# ############################################################################
# Fake waiting for slaves.
# ############################################################################
@lag = (0, 0);
my $t = time;
$rll->wait();

85
t/lib/WeightedAvgRate.t Normal file
View File

@@ -0,0 +1,85 @@
#!/usr/bin/perl
BEGIN {
die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n"
unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH};
unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib";
};
use strict;
use warnings FATAL => 'all';
use English qw(-no_match_vars);
use Test::More tests => 6;
use WeightedAvgRate;
use PerconaTest;
my $rll = new WeightedAvgRate(
initial_n => 1000,
initial_t => 1,
target_t => 1,
);
# stay the same
for (1..5) {
$rll->update(1000, 1);
}
is(
$rll->update(1000, 1),
1000,
"Same rate, same n"
);
# slow down
for (1..5) {
$rll->update(1000, 2);
}
is(
$rll->update(1000, 2),
542,
"Decrease rate, decrease n"
);
for (1..15) {
$rll->update(1000, 2);
}
is(
$rll->update(1000, 2),
500,
"limit n=500 decreasing"
);
# speed up
for (1..5) {
$rll->update(1000, 1);
}
is(
$rll->update(1000, 1),
849,
"Increase rate, increase n"
);
for (1..20) {
$rll->update(1000, 1);
}
is(
$rll->update(1000, 1),
999,
"limit n=1000 increasing"
);
# #############################################################################
# Done.
# #############################################################################
my $output = '';
{
local *STDERR;
open STDERR, '>', \$output;
$rll->_d('Complete test coverage');
}
like(
$output,
qr/Complete test coverage/,
'_d() works'
);
exit;