[sheepdog] [PATCH v2 2/2] sheep/cluster: re-create znode of 'lock-id' if it isn't exists

Liu Yuan namei.unix at gmail.com
Fri Jan 17 09:20:38 CET 2014


On Fri, Jan 17, 2014 at 02:34:13PM +0800, Robin Dong wrote:
> From: Robin Dong <sanbai at taobao.com>
> 
> When a sheep daemon call zk_unlock(), it will remove the whole znode of 'lock-id' and
> make zoo_create() fail in zk_lock() which called by another sheep daemon.
> To avoid this, we should try to create a znode of 'lock-id' if zoo_create() fail.
> 
> Signed-off-by: Robin Dong <sanbai at taobao.com>
> ---
>  sheep/cluster/zookeeper.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/sheep/cluster/zookeeper.c b/sheep/cluster/zookeeper.c
> index 4ef3a9a..625443d 100644
> --- a/sheep/cluster/zookeeper.c
> +++ b/sheep/cluster/zookeeper.c
> @@ -1255,6 +1255,11 @@ static void zk_lock(uint64_t lock_id)
>  				flags, my_path, MAX_NODE_STR_LEN);
>  		if (rc == ZOK)
>  			break;
> +		if (rc == ZNONODE) {
> +			zoo_create(zhandle, parent, "", 0, &ZOO_OPEN_ACL_UNSAFE,
> +				   0, NULL, 0);
> +			continue;
> +		}

Why not use zk_create_node() which make sure retry for some condtions? And seems
that you use raw zoo_exists() too. Use	zk_node_exists().

Thanks
Yuan



More information about the sheepdog mailing list