marsadm: safeguard race between split-brain log-deletes

This commit is contained in:
Thomas Schoebel-Theuer 2020-11-06 00:42:40 +01:00
parent 4797219f7e
commit dc1e778abb
1 changed files with 15 additions and 3 deletions

View File

@ -4789,6 +4789,19 @@ sub _get_deletable_logfiles {
my ($cmd, $res) = @_;
my $min = -1;
my $max = -1;
my %replay_links;
my $max_restarts = 3;
# Race prevention: get the replay links first, afterwards the logfiles
restart:
my @replay_paths = lamport_glob("$mars/resource-$res/replay-*") or ldie "cannot find any replay symlinks\n";
foreach my $path (@replay_paths) {
my $target = get_link($path, 1);
if (!$target) {
ldie "cannot get link '$path'\n" if $max_restarts-- < 0;
goto restart;
}
$replay_links{$path} = $target;
}
my @log_paths = lamport_glob("$mars/resource-$res/log-*") or ldie "cannot find any logfiles\n";
foreach my $path (@log_paths) {
$path =~ m/\/log-([0-9]+)-/;
@ -4796,9 +4809,8 @@ sub _get_deletable_logfiles {
$min = $nr if ($nr < $min || $min < 0);
$max = $nr if ($nr > $max || $max < 0);
}
my @paths = lamport_glob("$mars/resource-$res/replay-*") or ldie "cannot find any replay symlinks\n";
foreach my $path (@paths) {
my $target = get_link($path);
foreach my $path (@replay_paths) {
my $target = $replay_links{$path};
$target =~ m/^log-([0-9]+)/;
my $nr = $1;
$max = $nr if ($nr < $max || $max < 0);