[sheepdog] [PATCH] zookeeper: show real session timeout in zk_init()

Liu Yuan namei.unix at gmail.com
Wed Feb 11 07:20:02 CET 2015


From: Liu Yuan <liuyuan at cmss.chinamobile.com>

ZK server has its own session timeout range, so client's timeout value passed
to server might be ignored and return the value it thinks proper.

>From the documentation, the server range is

[tickTime * 2, tickTime * 20]

e.g, if tickTime is 2s, then the range will be [4s, 40s]. If we pass 1s as
timeout to zk driver, we might be 4s returned.

This patch also change the zk server informatin printed as sd_info.

Signed-off-by: Liu Yuan <liuyuan at cmss.chinamobile.com>
---
 sheep/cluster/zookeeper.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
index 3248af2..b603d36 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -1360,7 +1360,7 @@ static void zk_unlock(uint64_t lock_id)
 static int zk_init(const char *option)
 {
 	char *hosts, *to, *p;
-	int ret, interval, retry = 0, max_retry;
+	int ret, interval, retry = 0, max_retry, timeo;
 
 	if (!option) {
 		sd_err("You must specify zookeeper servers.");
@@ -1376,8 +1376,8 @@ static int zk_init(const char *option)
 		p = strstr(hosts, "timeout");
 		*--p = '\0';
 	}
-	sd_debug("version %d.%d.%d, address %s, timeout %d", ZOO_MAJOR_VERSION,
-		 ZOO_MINOR_VERSION, ZOO_PATCH_VERSION, hosts, zk_timeout);
+	sd_info("version %d.%d.%d, address %s, timeout %d", ZOO_MAJOR_VERSION,
+		ZOO_MINOR_VERSION, ZOO_PATCH_VERSION, hosts, zk_timeout);
 	zhandle = zookeeper_init(hosts, zk_watcher, zk_timeout, NULL, NULL, 0);
 	if (!zhandle) {
 		sd_err("failed to initialize zk server %s", option);
@@ -1396,6 +1396,9 @@ static int zk_init(const char *option)
 		}
 	}
 
+	timeo = zoo_recv_timeout(zhandle);
+	sd_info("the negociated session timeout is %d", timeo);
+
 	uatomic_set_false(&stop);
 	uatomic_set_false(&is_master);
 	if (zk_queue_init() != ZOK)
-- 
1.9.1




More information about the sheepdog mailing list