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

Liu Yuan namei.unix at gmail.com
Sun Jan 19 15:24:11 CET 2014


On Sun, Jan 19, 2014 at 10:03:54PM +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.

You have done more than commit log suggested so please update commit log and
subject to reflect what your patch actually solve.

> 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 fd6dcaf..784bba3 100644
> --- a/sheep/cluster/zookeeper.c
> +++ b/sheep/cluster/zookeeper.c
> @@ -1240,6 +1240,7 @@ static void zk_lock(uint64_t lock_id)
>  	int rc, len = MAX_NODE_STR_LEN;
>  	char *my_path;
>  	char parent[MAX_NODE_STR_LEN];
> +	char parent_node[MAX_NODE_STR_LEN];
>  	char lowest_seq_path[MAX_NODE_STR_LEN];
>  	char owner_name[MAX_NODE_STR_LEN];
>  	struct cluster_lock *cluster_lock;
> @@ -1251,21 +1252,25 @@ static void zk_lock(uint64_t lock_id)
>  	/* compete owner of lock is just like zk_compete_master() */
>  	snprintf(parent, MAX_NODE_STR_LEN, LOCK_ZNODE "/%"PRIu64"/",
>  		 cluster_lock->id);
> +	snprintf(parent_node, MAX_NODE_STR_LEN, LOCK_ZNODE "/%"PRIu64,
> +		 cluster_lock->id);

now we both have parent and parent node, you need clearify why so.

>  	while (true) {
>  		rc = zk_create_node(parent, "", 0, &ZOO_OPEN_ACL_UNSAFE,
>  				     flags, my_path, MAX_NODE_STR_LEN);
>  		if (rc == ZOK)
>  			break;
> +		if (rc == ZNONODE) {
> +			zk_init_node(parent_node);

please include some comment about why you don't need to check return value of
zk_init_node

Thanks
Yuan



More information about the sheepdog mailing list