Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make newly added pool nodes useful for services immediately #20

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/Perlbal/Pool.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use fields (
'nodefile.lastmod', # unix time nodefile was last modified
'nodefile.lastcheck', # unix time nodefile was last stated
'nodefile.checking', # boolean; if true AIO is stating the file for us
'waiting_services', # a hash of services waiting for this pool
);

sub new {
Expand All @@ -49,6 +50,7 @@ sub new {

$self->{nodefile} = undef;
$self->{balance_method} = BM_RANDOM;
$self->{waiting_services} = {};

return $self;
}
Expand Down Expand Up @@ -214,6 +216,18 @@ sub add {
$self->{node_used}->{"$ip:$port"} = 0;
push @{$self->{nodes}}, [ $ip, $port ];
$self->{node_count} = scalar(@{$self->{nodes}});

if ($self->{waiting_services}) {
foreach my $service (values %{$self->{waiting_services}}) {
next unless $service;
delete $self->{waiting_services}->{$service->{name}};
if ($service->{waiting_client_count} >0) {
Perlbal::log('info', "Pool $self->{name} was added much needed node. Now has " . $self->node_count . " nodes");
$service->spawn_backends;
last; # We only have enough for one.
}
}
}
}

sub remove {
Expand Down
8 changes: 8 additions & 0 deletions lib/Perlbal/Service.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,14 @@ sub spawn_backends {

# can't create more than this, assuming one pending connect per node
my $max_creatable = $pool ? ($self->{pool}->node_count - $self->{pending_connect_count}) : 1;

# If we cannot create any backends, register this service as waiting for nodes
if ($pool and $max_creatable <= 0 and $to_create > 0) {
$pool->{waiting_services}->{$self->{name}} = $self;
} else {
delete $pool->{waiting_services}->{$self->{name}};
}

$to_create = $max_creatable if $to_create > $max_creatable;

# cap number of attempted connects at once
Expand Down