[sheepdog] [PATCH 13/13] zookeeper: add an option to control heartbeat timeout

Liu Yuan namei.unix at gmail.com
Tue Dec 18 06:38:02 CET 2012


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

the new interface will be:
 sheep -c zookeeper:host:ip,host:ip,hostip,timeout=XXX
or
 sheep -c zookeeper:host:ip,host:ip,hostip # use default timeout

- change the default value as 10s

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

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index feb5ec8..b8c81dd 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -21,7 +21,7 @@
 #include "util.h"
 #include "rbtree.h"
 
-#define SESSION_TIMEOUT 30000		/* millisecond */
+#define SESSION_TIMEOUT 10000		/* millisecond */
 #define MEMBER_CREATE_TIMEOUT SESSION_TIMEOUT
 #define MEMBER_CREATE_INTERVAL 10	/* millisecond */
 
@@ -668,25 +668,30 @@ static void zk_event_handler(int listen_fd, int events, void *data)
 
 static int zk_init(const char *option)
 {
-	int ret;
+	char *hosts, *to, *p;
+	int ret, timeout = SESSION_TIMEOUT;
 
 	if (!option) {
-		eprintf("specify comma separated host:port pairs, "
-			"each corresponding to a zk server.\n");
-		eprintf("e.g. sheep /store -c zookeeper:127.0.0.1:"
-			"3000,127.0.0.1:3001,127.0.0.1:3002\n");
+		eprintf("You must specify zookeeper servers.\n");
 		return -1;
 	}
 
-	zhandle = zookeeper_init(option, zk_watcher, SESSION_TIMEOUT, NULL, NULL,
-				 0);
+	hosts = strtok((char *)option, "=");
+	if ((to = strtok(NULL, "="))) {
+		if (sscanf(to, "%u", &timeout) != 1) {
+			eprintf("Invalid paramter for timeout\n");
+			return -1;
+		}
+		p = strstr(hosts, "timeout");
+		*--p = '\0';
+	}
+	dprintf("version %d.%d.%d, address %s, timeout %d\n", ZOO_MAJOR_VERSION,
+		ZOO_MINOR_VERSION, ZOO_PATCH_VERSION, hosts, timeout);
+	zhandle = zookeeper_init(hosts, zk_watcher, timeout, NULL, NULL, 0);
 	if (!zhandle) {
 		eprintf("failed to connect to zk server %s\n", option);
 		return -1;
 	}
-	dprintf("request session timeout:%dms, "
-		"negotiated session timeout:%dms\n",
-		SESSION_TIMEOUT, zoo_recv_timeout(zhandle));
 
 	zk_queue_init();
 
-- 
1.7.9.5




More information about the sheepdog mailing list