From 767bb0306067d8b13bc686a79ad9184437455991 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Wed, 25 Dec 2013 19:18:22 +0100 Subject: [PATCH] marsadm: allow overrides of "marsadm secondary" in disconnected clusters When the communication is down in partitioned clusters, the command "marsadm seconodary" would normally use the current timestamp of the command execution for the Lamport update protocol. Make an exception for the case that a concurrent "marsadm primary" was given somewhere else on a disconnected / partitioned node: let the "primary" always win over a "secondary" command. --- userspace/marsadm | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/userspace/marsadm b/userspace/marsadm index fb0c0c44..7e2a5383 100755 --- a/userspace/marsadm +++ b/userspace/marsadm @@ -92,22 +92,20 @@ sub set_link { sub finish_links { return unless @link_list; - my $timestamp = time(); - undef $/; - my $lamport = ""; - if (open(my $fh, "<", "/proc/sys/mars/lamport_clock")) { - $lamport = <$fh>; - } - if ($lamport =~ m/lamport_now=([0-9.]+)/) { - $timestamp = $1; - lprint "using lamport timestamp $timestamp\n" if $verbose; - } + my $timestamp = mars_time(); + lprint "using lamport timestamp $timestamp\n" if $verbose; while (my $link = shift @link_list) { my $link_tmp = to_tmp($link); - system("touch -h -d \"\@$timestamp\" $link_tmp") == 0 or ldie "cannot set mtime on symlink '$link_tmp'\n"; + my $target = readlink($link_tmp); + my $this_timestamp = $timestamp; + # allow overriding of secondaries in partitioned clusters by use of small timestamps + if ($target eq "(none)") { + my @stat = lstat($link); + $this_timestamp = $stat[9] + 1 if @stat; + } + system("touch -h -d \"\@$this_timestamp\" $link_tmp") == 0 or ldie "cannot set mtime on symlink '$link_tmp'\n"; rename($link_tmp, $link) or ldie "cannot finalize symlink '$link'\n"; if ($verbose) { - my $target = readlink($link); lprint "created symlink '$link' -> '$target'\n"; } }