marsadm: fetch newest symlinks at join-resource

This commit is contained in:
Thomas Schoebel-Theuer 2017-06-08 14:03:23 +02:00
parent 12e41def3f
commit 4c74c8e985

View File

@ -171,6 +171,7 @@ sub rsync_cmd {
lprint "DRY_RUN: would execute the following command:\n$rsync_cmd\n"; lprint "DRY_RUN: would execute the following command:\n$rsync_cmd\n";
$rsync_cmd .= " --dry-run"; $rsync_cmd .= " --dry-run";
} }
finish_links();
# Repeat the action because some symlinks might be updated (or even vanish) # Repeat the action because some symlinks might be updated (or even vanish)
# when the peer is actively running. There seems to exist no rsync option # when the peer is actively running. There seems to exist no rsync option
# for ignoring all of these errors. # for ignoring all of these errors.
@ -1794,27 +1795,34 @@ sub create_res {
ldie "could not create resource '$res'\n" unless -d $resdir; ldie "could not create resource '$res'\n" unless -d $resdir;
set_link($size, "$resdir/size"); set_link($size, "$resdir/size");
} else { # join } else { # join
if (-d $resdir) { # For safety, try to get the very newest infos.
$primary = _get_designated_primary($res, 1); # Reason: newer kernel modules will fetch non-member resource infos less frequently.
# For safety, try to get the very newest infos # Therefore we shift some responsibility for non-member -> member transitions to userspace.
my @peers = map { m:^$mars/ips/ip-(.+):; $1 } glob("$mars/ips/ip-*");
$primary = _get_designated_primary($res, 1);
my $max_retry = 5;
for (;;) {
if ($primary && $primary ne "(none)") { if ($primary && $primary ne "(none)") {
rsync_cmd("--max-size=1 --update $primary:$mars/resource-$res/ $mars/resource-$res/", 1); # for safety, fetch newest infos from last known primary
rsync_cmd($primary, "--max-size=1 --update $primary:$mars/resource-$res/ $mars/resource-$res/", $res, 1);
last;
}
if (!@peers || $max_retry < 0) {
lwarn "cannot get a relevant primary";
last;
} }
}
if (!-d $resdir || !_get_designated_primary($res, 1)) {
# We are desperate. Try to fetch the directory from anywhere. # We are desperate. Try to fetch the directory from anywhere.
my @peers = glob("$mars/ips/ip-*"); my $peer = shift @peers;
my $max_rsync = 3; next if $peer eq $host;
foreach my $peer (map { m:^$mars/ips/ip-(.+):; $1 } @peers) { next if $peer eq $real_host;
next if $peer eq $host; rsync_cmd($peer, "--max-size=1 --update $peer:$mars/resource-$res $mars/", 1);
next if $peer eq $real_host; $primary = _get_designated_primary($res, 1);
rsync_cmd($peer, "--max-size=1 --update $peer:$mars/resource-$res/ $mars/resource-$res/", 1); $max_retry--;
if (_get_designated_primary($res, 1)) { } # retry loop
last if $max_rsync-- <= 0; ldie "resource '$res' does not exist\n" unless -d $resdir;
} ldie "resource '$res' has no designated primary\n" unless $primary && $primary ne "(none)";
} finish_links();
ldie "resource '$res' does not exist\n" unless -d $resdir; wait_cluster($cmd, $res);
}
my $res_size = get_link("$mars/resource-$res/size", 1); my $res_size = get_link("$mars/resource-$res/size", 1);
if ($size < $res_size) { if ($size < $res_size) {
lwarn "size of new device is only $size, but should be $res_size\n"; lwarn "size of new device is only $size, but should be $res_size\n";