[sheepdog] [PATCH v1 2/2] sheep: avoid dead loop when zookeeper session is expired

Liu Yuan namei.unix at gmail.com
Wed Feb 19 05:51:52 CET 2014


On Wed, Feb 19, 2014 at 09:51:23AM +0800, Robin Dong wrote:
> From: Robin Dong <sanbai at taobao.com>
> 
> When zookeeper session is expired, zk_get_least_seq() will return
> ZNONODE, but we have not check the return value of zk_get_least_seq()
> so the routine will fall in dead loop.
> 
> To avoid it, we add check for return value of zk_get_least_seq() and
> jump to recreate sequential-node if find out the ZNONODE event.
> 
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
>  sheep/cluster/zookeeper.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
> index 68d592d..5c21665 100644
> --- a/sheep/cluster/zookeeper.c
> +++ b/sheep/cluster/zookeeper.c
> @@ -1259,6 +1259,7 @@ static void zk_lock(uint64_t lock_id)
>  	 */
>  	snprintf(parent_node, MAX_NODE_STR_LEN, LOCK_ZNODE "/%"PRIu64,
>  		 cluster_lock->id);
> +create_seq_node:
>  	/* compete owner of lock is just like zk_compete_master() */
>  	while (true) {
>  		rc = zk_create_node(parent, node_to_str(&this_node.node),
> @@ -1283,9 +1284,13 @@ static void zk_lock(uint64_t lock_id)
>  
>  	/* create node ok now */
>  	while (true) {
> -		zk_get_least_seq(parent_node, lowest_seq_path, MAX_NODE_STR_LEN,
> -				 owner_name, &len);
> -
> +		rc = zk_get_least_seq(parent_node, lowest_seq_path,
> +				      MAX_NODE_STR_LEN, owner_name, &len);
> +		/* may be expired */
> +		if (rc == ZNONODE) {
> +			sd_info("Recreate seq node");

seems that you tend to use sd_info for debuging, but sd_info is information for
users.

Thanks
Yuan



More information about the sheepdog mailing list