[sheepdog] [PATCH] zk: wait for session timeout if previous zk path exists at startup

Liu Yuan namei.unix at gmail.com
Thu May 30 04:46:33 CEST 2013


On 05/30/2013 10:06 AM, Kai Zhang wrote:
> Signed-off-by: Kai Zhang <kyle at zelin.io>
> ---
>  sheep/cluster/zookeeper.c |   13 ++++++++++---
>  1 files changed, 10 insertions(+), 3 deletions(-)
> 
> diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
> index 5f5e867..d144fa7 100644
> --- a/sheep/cluster/zookeeper.c
> +++ b/sheep/cluster/zookeeper.c
> @@ -491,7 +491,7 @@ static int add_join_event(void *msg, size_t msg_len)
>  static int zk_join(const struct sd_node *myself,
>  		   void *opaque, size_t opaque_len)
>  {
> -	int rc;
> +	int rc, sleep_ms;
>  	char path[MAX_NODE_STR_LEN];
>  
>  	this_node.node = *myself;
> @@ -499,8 +499,15 @@ static int zk_join(const struct sd_node *myself,
>  	snprintf(path, sizeof(path), MEMBER_ZNODE "/%s", node_to_str(myself));
>  	rc = zk_node_exists(path);
>  	if (rc == ZOK) {
> -		sd_eprintf("Previous zookeeper session exist, shoot myself.");
> -		exit(1);
> +		/* wait for previous session timeout */
> +		sleep_ms = zoo_recv_timeout(zhandle);
> +		usleep(sleep_ms * 1000);

Simply call zk_delete_node() on this node works better?

Thanks,
Yuan



More information about the sheepdog mailing list