Avoid superfluous ZK exists calls
These cause a major (2x) slowdown in read calls since Zookeeper connections are expensive/slow. Instead, just try the thing and return None if there's no key there. Also wrap the children command in similar error handling since that did not exist and could likely cause some bugs at some point.
This commit is contained in:
parent
39e82ee426
commit
a080598781
|
@ -211,10 +211,10 @@ class ZKHandler(object):
|
|||
"""
|
||||
Read data from a key
|
||||
"""
|
||||
if self.exists(key):
|
||||
try:
|
||||
path = self.get_schema_path(key)
|
||||
data = self.zk_conn.get(path)[0].decode(self.encoding)
|
||||
else:
|
||||
except NoNodeError:
|
||||
data = None
|
||||
|
||||
return data
|
||||
|
@ -290,8 +290,13 @@ class ZKHandler(object):
|
|||
"""
|
||||
Lists all children of a key
|
||||
"""
|
||||
path = self.get_schema_path(key)
|
||||
return self.zk_conn.get_children(path)
|
||||
try:
|
||||
path = self.get_schema_path(key)
|
||||
children = self.zk_conn.get_children(path)
|
||||
except NoNodeError:
|
||||
children = None
|
||||
|
||||
return children
|
||||
|
||||
def rename(self, kkpairs):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue