def info_completion(result): try: content, stat = result.get() except self.DISCONNECT_EXCEPTIONS: self._once(KazooState.CONNECTED, do_info) return except ke.NoNodeException: future = self._members.pop(member, Future()) future.set_result(Membership.error()) return except ke.KazooException as e: log.warning('Unexpected Kazoo result in info: (%s)%s' % (type(e), e)) future = self._members.pop(member, Future()) future.set_result(Membership.error()) return self._members[member].set_result(content)
def _update_children(self, children): """ Given a new child list [znode strings], return a tuple of sets of Memberships: left: the children that left the set new: the children that joined the set """ cached_children = set(self._members) current_children = set( Membership(self.znode_to_id(znode)) for znode in filter(self.znode_owned, children)) new = current_children - cached_children left = cached_children - current_children for child in left: future = self._members.pop(child, Future()) future.set_result(Membership.error()) for child in new: self._members[child] = Future() return left, new
def info_completion(_, rc, content, stat): if rc in self._zk.COMPLETION_RETRY: do_info() return if rc == zookeeper.NONODE: future = self._members.pop(member, Future()) future.set_result(Membership.error()) return elif rc != zookeeper.OK: return self._members[member].set_result(content)
def adelete_completion(_, rc): if rc in self._zk.COMPLETION_RETRY: do_cancel() return # The rationale here is two situations: # - rc == zookeeper.OK ==> we successfully deleted the znode and the membership is dead. # - rc == zookeeper.NONODE ==> the membership is dead, though we may not have actually # been the ones to cancel, or the node never existed in the first place. it's possible # we owned the membership but it got severed due to session expiration. if rc == zookeeper.OK or rc == zookeeper.NONODE: future = self._members.pop(member.id, Future()) future.set_result(Membership.error()) capture.set(True) else: capture.set(False)
def adelete_completion(result): try: success = result.get() except self.DISCONNECT_EXCEPTIONS: self._once(KazooState.CONNECTED, do_cancel) return except ke.NoNodeError: success = True except ke.KazooException as e: log.warning('Unexpected Kazoo result in cancel: (%s)%s' % (type(e), e)) success = False future = self._members.pop(member.id, Future()) future.set_result(Membership.error()) capture.set(success)
def acreate_completion(_, rc, path): if rc in self._zk.COMPLETION_RETRY: do_join() return if rc == zookeeper.OK: created_id = self.znode_to_id(path) membership = Membership(created_id) with self._member_lock: result_future = self._members.get(membership, Future()) result_future.set_result(blob) self._members[membership] = result_future if expire_callback: self._zk.aexists(path, exists_watch, exists_completion) else: membership = Membership.error() membership_promise.set(membership)
def info(self, member, callback=None): if member == Membership.error(): raise self.InvalidMemberError('Cannot get info on error member!') capture = Capture(callback) def do_info(): self._zk.get_async(path).rawlink(info_completion) with self._member_lock: member_future = self._members.setdefault(member, Future()) member_future.add_done_callback( lambda future: capture.set(future.result())) dispatch = False with self._member_lock: if not member_future.done() and not member_future.running(): try: dispatch = member_future.set_running_or_notify_cancel() except: pass def info_completion(result): try: content, stat = result.get() except self.DISCONNECT_EXCEPTIONS: self._once(KazooState.CONNECTED, do_info) return except ke.NoNodeException: future = self._members.pop(member, Future()) future.set_result(Membership.error()) return except ke.KazooException as e: log.warning('Unexpected Kazoo result in info: (%s)%s' % (type(e), e)) future = self._members.pop(member, Future()) future.set_result(Membership.error()) return self._members[member].set_result(content) if dispatch: path = posixpath.join(self._path, self.id_to_znode(member.id)) do_info() return capture()
def info(self, member, callback=None): if member == Membership.error(): raise self.InvalidMemberError('Cannot get info on error member!') capture = Capture(callback) def do_info(): self._zk.aget(path, None, info_completion) with self._member_lock: if member not in self._members: self._members[member] = Future() member_future = self._members[member] member_future.add_done_callback( lambda future: capture.set(future.result())) dispatch = False with self._member_lock: if not member_future.done() and not member_future.running(): try: dispatch = member_future.set_running_or_notify_cancel() except: pass def info_completion(_, rc, content, stat): if rc in self._zk.COMPLETION_RETRY: do_info() return if rc == zookeeper.NONODE: future = self._members.pop(member, Future()) future.set_result(Membership.error()) return elif rc != zookeeper.OK: return self._members[member].set_result(content) if dispatch: path = posixpath.join(self._path, self.id_to_znode(member.id)) do_info() return capture()
def acreate_completion(result): try: path = result.get() except self.DISCONNECT_EXCEPTIONS: self._once(KazooState.CONNECTED, do_join) return except ke.KazooException as e: log.warning('Unexpected Kazoo result in join: (%s)%s' % (type(e), e)) membership = Membership.error() else: created_id = self.znode_to_id(path) membership = Membership(created_id) with self._member_lock: result_future = self._members.get(membership, Future()) result_future.set_result(blob) self._members[membership] = result_future if expire_callback: self._once(KazooState.CONNECTED, expire_notifier) do_exists(path) membership_capture.set(membership)