marsadm: make logrotate more rubust against missing logfiles

This should not happen at all.

During several millions of operations hour, it occurs however when
hardware is defective. Try self-healing as far as possible.
This commit is contained in:
Thomas Schoebel-Theuer 2017-01-16 14:21:03 +01:00
parent d726df70f3
commit 812011aa07

View File

@ -1934,9 +1934,17 @@ sub delete_res {
sub logrotate_res {
my ($cmd, $res) = @_;
check_primary(@_) unless $force;
my @paths = glob("$mars/resource-$res/log-*-$host") or ldie "cannot find any logfiles\n";
@paths = sort(@paths);
my $last = pop(@paths);
my @paths = glob("$mars/resource-$res/log-*-$host");
my $last;
if (@paths) {
@paths = sort(@paths);
$last = pop(@paths);
} else {
lwarn "no logfile exists on '$host' for resource '$res'\n";
my $replay = get_link("$mars/resource-$res/replay-$host");
$replay =~ m:^(log-[0-9]+-[^,]+),: or ldie "badly formed replaylink '$replay'\n";
$last = $1;
}
if (-z $last) {
lprint "an empty logfile '$last' already exists, nothing to do.\n" if $verbose;
return;