本文整理汇总了Python中kazoo.client.KazooState.LOST属性的典型用法代码示例。如果您正苦于以下问题:Python KazooState.LOST属性的具体用法?Python KazooState.LOST怎么用?Python KazooState.LOST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类kazoo.client.KazooState
的用法示例。
在下文中一共展示了KazooState.LOST属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _lock_listener
# 需要导入模块: from kazoo.client import KazooState [as 别名]
# 或者: from kazoo.client.KazooState import LOST [as 别名]
def _lock_listener(self, state):
"""
Listener to handle ZK disconnection/reconnection. Since I don't know of safe way to check if a lock is still in
ZK after a reconnect, we simply release the lock and try and re-acquire it.
Args:
state (kazoo.client.KazooState): The state of the ZK connection
Returns:
None
"""
if state in [KazooState.LOST, KazooState.SUSPENDED]:
self._logger.warn(u'Disconnected from Zookeeper, waiting to reconnect lock for {}'.format(str(self)))
self._locked = False
elif state == KazooState.CONNECTED:
self._logger.warn(
u'Reconnected to Zookeeper, trying to release and re-acquire lock for {}'.format(str(self)))
self._context.zookeeper_client.handler.spawn(self._release_and_reacquire)
else:
self._logger.warn(u'Got unknown state "{}" from Zookeeper'.format(state))
示例2: event_listener
# 需要导入模块: from kazoo.client import KazooState [as 别名]
# 或者: from kazoo.client.KazooState import LOST [as 别名]
def event_listener(self, state):
if state == KazooState.LOST or state == KazooState.SUSPENDED:
logger.info('ZK state transitioned to %s. Resetting master status.', state)
# cancel pending attempts to acquire lock which will break and leave
# us in bad state
self.lock.cancel()
# make us try to re-acquire lock during next iteration when we're connected
if self.lock.is_acquired:
self.lock.is_acquired = False
# make us try to rejoin the party during next iteration when we're connected
if self.party.participating:
self.party.participating = False
# in the meantime we're not master
self.is_master = None
示例3: state_listener
# 需要导入模块: from kazoo.client import KazooState [as 别名]
# 或者: from kazoo.client.KazooState import LOST [as 别名]
def state_listener(self, state):
'''
Restarts the session if we get anything besides CONNECTED
'''
if state == KazooState.SUSPENDED:
self.set_valid(False)
self.call_error(self.BAD_CONNECTION)
elif state == KazooState.LOST and not self.do_not_restart:
self.threaded_start()
elif state == KazooState.CONNECTED:
# This is going to throw a SUSPENDED kazoo error
# which will cause the sessions to be wiped and re established.
# Used b/c of massive connection pool issues
self.zoo_client.stop()
示例4: _on_conn_change
# 需要导入模块: from kazoo.client import KazooState [as 别名]
# 或者: from kazoo.client.KazooState import LOST [as 别名]
def _on_conn_change(self, state):
logger.debug('state changed: {state}'.format(state=state,))
with self.state_lock:
if state == KazooState.LOST or state == KazooState.SUSPENDED:
self.connected = False
示例5: connection_listener
# 需要导入模块: from kazoo.client import KazooState [as 别名]
# 或者: from kazoo.client.KazooState import LOST [as 别名]
def connection_listener(self, state: KazooState) -> None:
self.log.warning(f"Zookeeper connection transitioned to: {state}")
if state == KazooState.SUSPENDED:
self.log.warning(
"Zookeeper connection suspended, waiting to see if it recovers."
)
if not self.waiting_for_reconnect:
self.waiting_for_reconnect = True
reconnection_checker = PaastaThread(target=self.reconnection_listener)
reconnection_checker.daemon = True
reconnection_checker.start()
elif state == KazooState.LOST:
self.log.error("Leadership lost, quitting!")
self._terminate()
示例6: test_connection_listener
# 需要导入模块: from kazoo.client import KazooState [as 别名]
# 或者: from kazoo.client.KazooState import LOST [as 别名]
def test_connection_listener(self):
with mock.patch(
"paasta_tools.deployd.leader.PaastaThread", autospec=True
) as mock_paasta_thread:
self.election.connection_listener(KazooState.CONNECTED)
self.election.connection_listener(KazooState.SUSPENDED)
mock_paasta_thread.assert_called_with(
target=self.election.reconnection_listener
)
assert self.election.waiting_for_reconnect
self.election.connection_listener(KazooState.LOST)
self.mock_control.put.assert_called_with("ABORT")
示例7: session_listener
# 需要导入模块: from kazoo.client import KazooState [as 别名]
# 或者: from kazoo.client.KazooState import LOST [as 别名]
def session_listener(self, state):
if state in [KazooState.SUSPENDED, KazooState.LOST]:
self.cluster_watcher(None)