pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mme...@apache.org
Subject [incubator-pulsar] branch master updated: Only exit from watch-znode if we managed to communicate with zk (#2127)
Date Tue, 10 Jul 2018 17:01:09 GMT
This is an automated email from the ASF dual-hosted git repository.

mmerli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pulsar.git


The following commit(s) were added to refs/heads/master by this push:
     new 914de19  Only exit from watch-znode if we managed to communicate with zk (#2127)
914de19 is described below

commit 914de19f8d3a1f11d547cde934519f08fa3d6d4c
Author: Ivan Kelly <ivank@apache.org>
AuthorDate: Tue Jul 10 18:01:07 2018 +0100

    Only exit from watch-znode if we managed to communicate with zk (#2127)
    
    The integration tests sometimes fail because the watch-znode script
    which is used to set the order of service startup throws an exception
    and exits without waiting for initialization to happen.
    
    This patch changes the watch-znode script to only ever exit if
    communication with zk has been successful.
---
 docker/pulsar/scripts/watch-znode.py | 40 +++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 16 deletions(-)

diff --git a/docker/pulsar/scripts/watch-znode.py b/docker/pulsar/scripts/watch-znode.py
index 5075353..6e8d55d 100755
--- a/docker/pulsar/scripts/watch-znode.py
+++ b/docker/pulsar/scripts/watch-znode.py
@@ -20,6 +20,7 @@
 
 import sys, getopt, time, logging
 from kazoo.client import KazooClient
+from kazoo.exceptions import NodeExistsError
 from kazoo.retry import KazooRetry
 
 logging.getLogger('kazoo.client').addHandler(logging.StreamHandler())
@@ -80,19 +81,26 @@ if (not watch and not create and not exists):
     usage()
     sys.exit(5)
 
-zk = KazooClient(hosts=zookeeper, timeout=1, connection_retry=KazooRetry(max_tries=-1))
-zk.start()
-
-if create:
-    zk.create(znode)
-elif watch:
-    while not zk.exists(znode):
-        print "Waiting for %s" % znode
-        time.sleep(1)
-elif exists:
-    if zk.exists(znode):
-        sys.exit(0)
-    else:
-        sys.exit(-1)
-
-zk.stop()
+while True:
+    zk = KazooClient(hosts=zookeeper, timeout=1, connection_retry=KazooRetry(max_tries=-1))
+    try:
+        zk.start()
+        if create:
+            try:
+                zk.create(znode)
+            except NodeExistsError:
+                pass
+            sys.exit(0)
+        elif watch:
+            while not zk.exists(znode):
+                print "Waiting for %s" % znode
+                time.sleep(1)
+            sys.exit(0)
+        elif exists:
+            if zk.exists(znode):
+                sys.exit(0)
+            else:
+                sys.exit(-1)
+    finally:
+        zk.stop()
+        zk.close()


Mime
View raw message