[sheepdog] [PATCH V2] sheep: initiative to send leave event to cluster when shutdown

Yunkai Zhang yunkai.me at gmail.com
Wed Jun 27 03:54:48 CEST 2012


From: Yunkai Zhang <qiushu.zyk at taobao.com>

V2:
- s/cluster_leave/leave_cluster/ in commit log
- s/leaved/left/ in patch's code
---------------------------------------------- >8

Sheep will stop itself after received collie shutdown CMD, but zookeeper
server can't detect this leaving action until session timeout(30 seconds
at this time), as a result we have to wait a few seconds before we can
restart sheep. This is very annoying.

Calling leave_cluster() before sheep exit can solve this problem.

Signed-off-by: Yunkai Zhang <qiushu.zyk at taobao.com>
---
 sheep/group.c |   11 ++++++++++-
 sheep/sheep.c |    1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/sheep/group.c b/sheep/group.c
index b448809..1dec931 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1171,8 +1171,17 @@ int create_cluster(int port, int64_t zone, int nr_vnodes,
 	return 0;
 }
 
-/* after this function is called, this node only works as a gateway */
+/* We will call this function for two reason:
+ * 1) make this node working as a gateway, or
+ * 2) the program is going to shutdown itself.
+ */
 int leave_cluster(void)
 {
+	static int left;
+
+	if (left)
+		return 0;
+
+	left = 1;
 	return sys->cdrv->leave();
 }
diff --git a/sheep/sheep.c b/sheep/sheep.c
index a2cd43e..956ad07 100644
--- a/sheep/sheep.c
+++ b/sheep/sheep.c
@@ -306,6 +306,7 @@ int main(int argc, char **argv)
 
 	vprintf(SDOG_INFO, "shutdown\n");
 
+	leave_cluster();
 	log_close();
 
 	return 0;
-- 
1.7.10.2




More information about the sheepdog mailing list