Skip to content
Open
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
15 changes: 11 additions & 4 deletions lib/App/Switchman.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,15 @@ has termination_timeout => (
isa => sub {die "bad termination_timeout: $_[0]" if defined $_[0] && $_[0] !~ m{^\d+$}},
default => sub {10},
);
has session_timeout => (
is => 'ro',
isa => sub {die "bad session_timeout: $_[0]" if defined $_[0] && $_[0] !~ m{^\d+$}},
default => sub {10000},
);
has zkh => (
is => 'rw',
lazy => 1,
builder => sub {Net::ZooKeeper->new($_[0]->zkhosts)},
builder => sub {Net::ZooKeeper->new($_[0]->zkhosts, session_timeout => $_[0]->session_timeout)},
);
has zkhosts => (is => 'ro', required => 1);

Expand Down Expand Up @@ -142,7 +147,7 @@ sub BUILDARGS
}
die "$DEFAULT_CONFIG_PATH is absent and --config is missing, see $0 -h for help\n" unless $config_path;
my $config = _get_and_check_config($config_path);
for my $key (qw/data_read_len logfile loglevel prefix resources_wait_timeout termination_timeout zkhosts/) {
for my $key (qw/data_read_len logfile loglevel prefix resources_wait_timeout termination_timeout zkhosts session_timeout/) {
next unless exists $config->{$key};
$options{$key} = $config->{$key};
}
Expand Down Expand Up @@ -461,14 +466,16 @@ sub zk_connect
}
}
$self->log->debug("Trying to reconnect");
$self->zkh(Net::ZooKeeper->new($self->zkhosts));
$self->zkh(Net::ZooKeeper->new($self->zkhosts, session_timeout => $self->session_timeout));
}

if (!$self->zkh) {
$self->_error("Failed to connect to ZooKeeper");
}

$self->zkh->{data_read_len} = $self->data_read_len;

$self->log->debug("Connected with " . join(", ", map { "$_ " . ($self->zkh->{$_} // "undef") } qw(session_timeout watch_timeout)));
}


Expand Down Expand Up @@ -588,7 +595,7 @@ sub run

while (1) {
if ($self->lock_watch->{state}) {
$self->log->warn("It's not secure to proceed, lock watch received ".$self->lock_watch->{event});
$self->log->warn(sprintf "It's not secure to proceed, lock watch received: " . join(", ", map { "$_ " . ($self->lock_watch->{$_} // "undef") } qw(event state)));
$self->_stop_child($CHILD);
last;
}
Expand Down