[sheepdog] [PATCH v3] zookeeper: fix bug for default cluster id

Liu Yuan namei.unix at gmail.com
Wed Mar 4 08:14:37 CET 2015


On Wed, Mar 04, 2015 at 03:04:03PM +0800, Yu Yang wrote:
> From: Yu Yang <yuyang at cmss.chinamobile.com>
> 
> Append DEFAULT_BASE to hosts when cluster id is not set.
> 
> Signed-off-by: Yu Yang <yuyang at cmss.chinamobile.com>
> ---
>  sheep/cluster/zookeeper.c |    8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
> index 4f85043..a260363 100644
> --- a/sheep/cluster/zookeeper.c
> +++ b/sheep/cluster/zookeeper.c
> @@ -1466,7 +1466,13 @@ static int zk_init(const char *option)
>  
>  	sd_info("version %d.%d.%d, address %s, timeout %d", ZOO_MAJOR_VERSION,
>  		ZOO_MINOR_VERSION, ZOO_PATCH_VERSION, hosts, zk_timeout);
> -	if (zk_connect(hosts, zk_watcher, zk_timeout) < 0)
> +	if (!strchr(hosts, '/')) {
> +		char buf[MAX_NODE_STR_LEN];
> +		pstrcpy(buf, sizeof(buf), hosts);
> +		strcat(buf, DEFAULT_BASE);
> +		if (zk_connect(buf, zk_watcher, zk_timeout) < 0)
> +			return -1;
> +	} else if (zk_connect(hosts, zk_watcher, zk_timeout) < 0)
>  		return -1;

zk_prepare_root() process "hosts" and here we duplicately process it again.
I think you'd better:

1 change zk_prepare_root(const char *hosts) as zk_prepare_root(char *hosts)
2 get a proper hosts internally in zk_prepare_root()

Thanks,
Yuan



More information about the sheepdog mailing list