[sheepdog] [PATCH stable-0.8 2/6] sheep: avoid dead loop when	zookeeper session is expired
    Hitoshi Mitake 
    mitake.hitoshi at lab.ntt.co.jp
       
    Tue Mar 18 07:30:55 CET 2014
    
    
  
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>
Signed-off-by: Liu Yuan <namei.unix at gmail.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 831e7e7..660ca0c 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_debug("Recreate seq node");
+			goto create_seq_node;
+		}
 		/* I got the lock */
 		if (!strncmp(lowest_seq_path, my_path, strlen(my_path))) {
 			sd_debug("I am master now. %s", lowest_seq_path);
-- 
1.8.1.2
    
    
More information about the sheepdog
mailing list