Add (hardcoded) timeout to reserve_fileset

This commit is contained in:
Peter J. Holzer 2021-07-25 12:22:54 +02:00
parent 88f226757d
commit 7180c24cc3
1 changed files with 8 additions and 3 deletions

View File

@ -207,7 +207,9 @@ sub run {
sub backup2disk { sub backup2disk {
my ($self, $target) = @_; my ($self, $target) = @_;
$self->reserve_fileset($target); unless ($self->reserve_fileset($target)) {
return;
}
$self->log(3, "starting backup for target host " . $target->{host} . " dir " . $target->{dir}); $self->log(3, "starting backup for target host " . $target->{host} . " dir " . $target->{dir});
$self->{target} = $target; $self->{target} = $target;
@ -291,9 +293,10 @@ sub backup2disk {
sub reserve_fileset { sub reserve_fileset {
my ($self, $target) = @_; my ($self, $target) = @_;
for (;;) { my $start = time();
while (time() - $start < 3600) {
my $rows = $self->{dbh}->do(q{update filesets set pid=? where id = ? and pid is null}, {}, $$, $target->{id}); my $rows = $self->{dbh}->do(q{update filesets set pid=? where id = ? and pid is null}, {}, $$, $target->{id});
return if $rows == 1; return 1 if $rows == 1;
my $pid = $self->{dbh}->selectrow_array(q{select pid from filesets where id = ?}, {}, $target->{id}); my $pid = $self->{dbh}->selectrow_array(q{select pid from filesets where id = ?}, {}, $target->{id});
$self->log(3, "fileset $target->{id} appears to be in use by pid $pid"); $self->log(3, "fileset $target->{id} appears to be in use by pid $pid");
if (!kill(0, $pid) && $!{ESRCH}) { if (!kill(0, $pid) && $!{ESRCH}) {
@ -302,6 +305,8 @@ sub reserve_fileset {
} }
sleep 60; sleep 60;
} }
$self->log(2, "fileset $target->{id} appears to be still in use by pid $pid after grace perion - giving up");
return 0;
} }