Allow initial values to be zero for ReplicaLagLimiter::new(). Return 1/0/death from ReplicaLagLimiter::wait().

This commit is contained in:
Daniel Nichter
2011-09-20 11:28:00 -06:00
parent be9337a202
commit 412e9e4e18
3 changed files with 36 additions and 9 deletions

View File

@@ -57,7 +57,7 @@ sub new {
my ( $class, %args ) = @_; my ( $class, %args ) = @_;
my @required_args = qw(spec slaves get_lag initial_n initial_t target_t); my @required_args = qw(spec slaves get_lag initial_n initial_t target_t);
foreach my $arg ( @required_args ) { foreach my $arg ( @required_args ) {
die "I need a $arg argument" unless $args{$arg}; die "I need a $arg argument" unless defined $args{$arg};
} }
my ($spec) = @args{@required_args}; my ($spec) = @args{@required_args};
@@ -146,7 +146,7 @@ sub update {
# Progress - <Progress> object to report waiting # Progress - <Progress> object to report waiting
# #
# Returns: # Returns:
# True if all slaves catch up before timeout, else die unless continue is true # 1 if all slaves catch up before timeout, else 0 if continue=yes, else die.
sub wait { sub wait {
my ( $self, %args ) = @_; my ( $self, %args ) = @_;
my @required_args = qw(); my @required_args = qw();
@@ -196,13 +196,19 @@ sub wait {
$slave = $slaves->[++$slave_no]; $slave = $slaves->[++$slave_no];
} }
} }
if ( $slave_no < @$slaves && $self->{continue} eq 'no' ) { if ( $slave_no < @$slaves ) {
die "Timeout waiting for replica " . $slaves->[$slave_no]->{dsn}->{n} if ( $self->{continue} eq 'no' ) {
. " to catch up\n"; die "Timeout waiting for replica " . $slaves->[$slave_no]->{dsn}->{n}
. " to catch up\n";
}
else {
MKDEBUG && _d('Some slave are not caught up');
return 0; # not ready
}
} }
MKDEBUG && _d('All slaves caught up'); MKDEBUG && _d('All slaves caught up');
return 1; return 1; # ready
} }
sub _d { sub _d {

View File

@@ -38,7 +38,7 @@ if ( !$dbh ) {
plan skip_all => 'Cannot connect to sandbox master'; plan skip_all => 'Cannot connect to sandbox master';
} }
else { else {
plan tests => 20; plan tests => 21;
} }
my $q = new Quoter(); my $q = new Quoter();
@@ -447,6 +447,27 @@ is_deeply(
"Change chunk size while nibbling" "Change chunk size while nibbling"
) or print STDERR Dumper(\@rows); ) or print STDERR Dumper(\@rows);
# ############################################################################
# Nibble one row at a time.
# ############################################################################
$ni = make_nibble_iter(
sql_file => "a-z.sql",
db => 'test',
tbl => 't',
argv => [qw(--databases test --chunk-size 1)],
);
@rows = ();
while (my $row = $ni->next()) {
push @rows, @$row;
}
is_deeply(
\@rows,
[ ('a'..'z') ],
"Nibble by 1 row"
);
# ############################################################################# # #############################################################################
# Done. # Done.
# ############################################################################# # #############################################################################

View File

@@ -197,8 +197,8 @@ $rll = new ReplicaLagLimiter(
@lag = (5, 0, 0); @lag = (5, 0, 0);
is( is(
$rll->wait(), $rll->wait(),
1, 0,
"wait() returns 1 despite timeout if continue=yes" "wait() returns 0 if timeout and continue=yes"
); );
# ############################################################################# # #############################################################################