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

Robin Dong robin.k.dong at gmail.com
Thu Jan 16 09:11:04 CET 2014


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..14f5988 100644
--- a/sheep/cluster/zookeeper.c
+++ b/sheep/cluster/zookeeper.c
@@ -1256,6 +1256,11 @@ static void zk_lock(uint64_t lock_id)
 		if (rc == ZOK)
 			break;
 		sd_err("failed to create path:%s, %s", my_path, zerror(rc));
+		if (rc == ZNONODE) {
+			zoo_create(zhandle, parent, "", 0, &ZOO_OPEN_ACL_UNSAFE,
+				   0, NULL, 0);
+			continue;
+		}
 		zk_wait();
 	}
 	sd_debug("create path %s success", my_path);
-- 
1.7.12.4




More information about the sheepdog mailing list