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

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Thu Feb 12 09:36:56 CET 2015


At Wed, 11 Feb 2015 14:20:02 +0800,
Liu Yuan wrote:
> 
> 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(-)

Cc-ing Ruoyu. If he cannot allocate time for review, I'll do it later.

Thanks,
Hitoshi

> 
> 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
> 
> -- 
> sheepdog mailing list
> sheepdog at lists.wpkg.org
> https://lists.wpkg.org/mailman/listinfo/sheepdog



More information about the sheepdog mailing list