[sheepdog] [PATCH 5/8] zookeeper: allow only one to continue for concurrent setup

Liu Yuan namei.unix at gmail.com
Sun Dec 23 16:26:29 CET 2012


From: Liu Yuan <tailai.ly at taobao.com>

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/cluster/zookeeper.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index de775e2..fe4093d 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -354,12 +354,9 @@ static bool is_master(void)
 	struct zk_node *zk;
 
 	if (!nr_sd_nodes) {
-		if (zk_member_empty()) {
-			if (zk_master_create() == ZOK)
-				return true;
-			else
-				return false;
-		} else
+		if (zk_member_empty())
+			return true;
+		else
 			return false;
 	}
 
@@ -461,6 +458,10 @@ static int zk_join(const struct sd_node *myself,
 		exit(1);
 	}
 
+	/* For concurrent nodes setup, we allow only one to continue */
+	while (zk_member_empty() && zk_master_create() != ZOK)
+		;/* wait */
+
 	return add_event(EVENT_JOIN_REQUEST, &this_node, opaque, opaque_len);
 }
 
-- 
1.7.9.5




More information about the sheepdog mailing list