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

Yunkai Zhang yunkai.me at gmail.com
Tue Jun 26 17:28:43 CEST 2012


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

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 cluster_leave() 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..0e681fa 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 leaved;
+
+	if (leaved)
+		return 0;
+
+	leaved = 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