本文整理汇总了Python中kazoo.retry.KazooRetry方法的典型用法代码示例。如果您正苦于以下问题:Python retry.KazooRetry方法的具体用法?Python retry.KazooRetry怎么用?Python retry.KazooRetry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kazoo.retry
的用法示例。
在下文中一共展示了retry.KazooRetry方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getMockServerSet
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def getMockServerSet(smox):
listeners = []
def add_listener(listener):
listeners.append(listener)
zk = smox.CreateMock(KazooClient)
zk.connected = True
zk.handler = SequentialGeventHandler()
zk.retry = KazooRetry()
mock_stat = smox.CreateMock(ZnodeStat)
mock_stat.mzxid = 1
zk.exists(TEST_PATH).AndReturn(True)
zk.add_listener(mox.IgnoreArg()).WithSideEffects(add_listener)
zk.get(TEST_PATH, mox.IgnoreArg()).AndReturn((1, mock_stat))
zk.add_listener(mox.IgnoreArg()).WithSideEffects(add_listener)
return zk
示例2: __init__
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def __init__(self, handler=SequentialGeventHandler(), hosts=None):
self.handler = handler
self.hosts = hosts
self._state = KazooState.LOST
self._listeners = []
self.Party = partial(Party, self)
self.ShallowParty = partial(ShallowParty, self)
self.retry = KazooRetry(
max_tries=3,
delay=0.0,
backoff=1,
max_jitter=0.0,
sleep_func=gevent.sleep
)
self.ChildrenWatch = partial(ChildrenWatch, self)
self.DataWatch = partial(DataWatch, self)
self._children_watches = {}
self._data_watches = {}
示例3: start
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def start(self):
"""Create a new group and wait until the partitions have been
acquired. This function should never be called twice.
:raises: PartitionerError upon partitioner failures
.. note: This is a blocking operation.
"""
self.kazoo_retry = KazooRetry(**KAZOO_RETRY_DEFAULTS)
self.kazoo_client = KazooClient(
self.config.zookeeper,
connection_retry=self.kazoo_retry,
)
self.kafka_client = KafkaClient(self.config.broker_list)
self.log.debug("Starting a new group for topics %s", self.topics)
self.released_flag = True
self._refresh()
示例4: _lazy_initialize
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def _lazy_initialize(self):
if not self.client:
hosts = _parse_hosts(self.config.remote_db_hosts)
_handler = eventlet.SequentialEventletHandler()
_retry = retry.KazooRetry(max_tries=CLIENT_CONNECTION_RETRIES,
delay=0.5,
backoff=2,
sleep_func=_handler.sleep_func)
self.client = client.KazooClient(hosts=hosts,
handler=_handler,
connection_retry=_retry)
self.client.start()
self.client.ensure_path(ROOT_NS)
示例5: __enter__
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def __enter__(self):
kazooRetry = KazooRetry(
max_tries=5,
)
self.zk = KazooClient(
hosts=self.cluster_config.zookeeper,
read_only=True,
connection_retry=kazooRetry,
)
_log.debug(
"ZK: Creating new zookeeper connection: {zookeeper}"
.format(zookeeper=self.cluster_config.zookeeper),
)
self.zk.start()
return self
示例6: __init__
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def __init__(self):
retry_policy = KazooRetry(max_tries=self.max_tries)
self.zk_client = self.get_kazoo_client(command_retry=retry_policy)
self.zk_client.start()
self.register_signal_handlers()
示例7: zk
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk() -> KazooClient:
conn_retry_policy = KazooRetry(max_tries=-1, delay=0.1, max_delay=0.1)
cmd_retry_policy = KazooRetry(
max_tries=3, delay=0.3, backoff=1, max_delay=1, ignore_expire=False)
zk = KazooClient(
hosts='zk-1.zk:2181,zk-2.zk:2181,zk-3.zk:2181',
connection_retry=conn_retry_policy,
command_retry=cmd_retry_policy,
)
zk.start()
yield zk
zk.stop()
示例8: zk_connect
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_connect():
print("Connecting to ZooKeeper")
zk_user = os.environ.get('CALICO_ZK_USER')
zk_secret = os.environ.get('CALICO_ZK_SECRET')
conn_retry_policy = KazooRetry(
max_tries=-1,
delay=0.3,
backoff=1.3,
max_jitter=1,
max_delay=3,
ignore_expire=True,
)
# Retry commands every 0.3 seconds, for a total of <1s (usually 0.9)
cmd_retry_policy = KazooRetry(
max_tries=3,
delay=0.3,
backoff=1,
max_jitter=0.1,
max_delay=1,
ignore_expire=False,
)
default_acl = None
auth_data = None
if zk_user and zk_secret:
default_acl = [make_digest_acl(zk_user, zk_secret, all=True)]
scheme = 'digest'
credential = "{}:{}".format(zk_user, zk_secret)
auth_data = [(scheme, credential)]
zk = KazooClient(
hosts=ZK_SERVER,
timeout=30,
connection_retry=conn_retry_policy,
command_retry=cmd_retry_policy,
default_acl=default_acl,
auth_data=auth_data,
)
zk.start()
return zk
示例9: zk_conn
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_conn():
conn_retry_policy = KazooRetry(max_tries=-1,
delay=0.1,
backoff=2,
max_delay=3600)
handler = SequentialThreadingHandler()
conn = KazooClient(hosts="127.0.0.1:2181",
timeout=60,
handler=handler,
connection_retry=conn_retry_policy,
command_retry=conn_retry_policy)
conn.start()
yield conn
conn.stop()
示例10: __init__
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def __init__(self, zk_hosts):
conn_retry_policy = KazooRetry(max_tries=-1, delay=0.1, max_delay=0.1)
cmd_retry_policy = KazooRetry(max_tries=3, delay=0.3, backoff=1, max_delay=1, ignore_expire=False)
self._zk = KazooClient(hosts=zk_hosts, connection_retry=conn_retry_policy, command_retry=cmd_retry_policy)
示例11: zk_client
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_client(three_master_cluster: Cluster) -> KazooClient:
"""
ZooKeeper client connected to a given DC/OS cluster.
"""
zk_hostports = ','.join(['{}:2181'.format(m.public_ip_address)
for m in three_master_cluster.masters])
retry_policy = KazooRetry(
max_tries=-1,
delay=1,
backoff=1,
max_delay=600,
ignore_expire=True,
)
zk_client = KazooClient(
hosts=zk_hostports,
# Avoid failure due to client session timeout.
timeout=40,
# Work around https://github.com/python-zk/kazoo/issues/374
connection_retry=retry_policy,
command_retry=retry_policy,
)
zk_client.start()
try:
yield zk_client
finally:
zk_client.stop()
zk_client.close()
示例12: _zookeeper_resolver
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def _zookeeper_resolver(self, cfg):
hosts, path = cfg[5:].split("/", 1)
path = "/" + path
retry = KazooRetry(max_tries=10)
with zookeeper.client(
hosts=hosts, read_only=True, connection_retry=retry, command_retry=retry
) as zk:
def master_id(key):
return int(key.split("_")[-1])
def get_masters():
return [x for x in zk.get_children(path) if re.search(r"\d+", x)]
leader = sorted(get_masters(), key=lambda x: master_id(x))
if len(leader) == 0:
raise exceptions.MasterNotAvailableException(
f"cannot find any masters at {cfg}"
)
data, stat = zk.get(os.path.join(path, leader[0]))
if not data:
exceptions.MasterNotAvailableException(
"Cannot retrieve valid MasterInfo data from ZooKeeper"
)
else:
data = data.decode("utf8")
try:
parsed = json.loads(data)
if parsed and "address" in parsed:
ip = parsed["address"].get("ip")
port = parsed["address"].get("port")
if ip and port:
return f"{ip}:{port}"
except ValueError as parse_error:
log.debug(
"[WARN] No JSON content, probably connecting to older "
"Mesos version. Reason: {}".format(parse_error)
)
raise exceptions.MasterNotAvailableException(
"Failed to parse mesos master ip from ZK"
)
示例13: zk_connect
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_connect(zk_addr: str,
zk_user: Optional[str] = None,
zk_secret: Optional[str] = None) -> KazooClient:
"""Connect to ZooKeeper.
On connection failure, the function attempts to reconnect indefinitely with
exponential backoff up to 3 seconds. If a command fails, that command is
retried every 300ms for 3 attempts before failing.
These values are chosen to suit a human-interactive time.
Args:
zk_addr: The address to connect to
zk_user: The username to use when connecting to ZooKeeper or `None`
if no authentication is necessary.
zk_secret: The secret to use when connecting to ZooKeeper or `None`
if no authentication is necessary.
Returns:
A ZooKeeper client connection in the form of a `kazoo.client.KazooClient`.
"""
# Try to reconnect indefinitely, with time between updates going
# exponentially to ~3s. Then every retry occurs every ~3 seconds.
conn_retry_policy = KazooRetry(
max_tries=-1,
delay=0.3,
backoff=1.3,
max_delay=3,
ignore_expire=True,
)
# Retry commands every 0.3 seconds, for a total of <1s (usually 0.9)
cmd_retry_policy = KazooRetry(
max_tries=3,
delay=0.3,
backoff=1,
max_delay=1,
ignore_expire=False,
)
default_acl = None
auth_data = None
if zk_user and zk_secret:
default_acl = [make_digest_acl(zk_user, zk_secret, all=True)]
scheme = 'digest'
credential = "{}:{}".format(zk_user, zk_secret)
auth_data = [(scheme, credential)]
zk = KazooClient(
hosts=zk_addr,
timeout=30,
connection_retry=conn_retry_policy,
command_retry=cmd_retry_policy,
default_acl=default_acl,
auth_data=auth_data,
)
zk.start()
return zk
示例14: zk_connect
# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_connect(zk_user: Optional[str] = None, zk_secret: Optional[str] = None) -> KazooClient:
"""Connect to ZooKeeper.
On connection failure, the function attempts to reconnect indefinitely with exponential backoff
up to 3 seconds. If a command fails, that command is retried every 300ms for 3 attempts before failing.
These values are chosen to suit a human-interactive time.
Args:
zk_user:
The username to use when connecting to ZooKeeper or `None` if no authentication is necessary.
zk_secret:
The secret to use when connecting to ZooKeeper or `None` if no authentication is necessary.
Returns:
A ZooKeeper client connection in the form of a `kazoo.client.KazooClient`.
"""
# Try to reconnect indefinitely, with time between updates going
# exponentially to ~3s. Then every retry occurs every ~3 seconds.
conn_retry_policy = KazooRetry(
max_tries=-1,
delay=0.3,
backoff=1.3,
max_jitter=1,
max_delay=3,
ignore_expire=True,
)
# Retry commands every 0.3 seconds, for a total of <1s (usually 0.9)
cmd_retry_policy = KazooRetry(
max_tries=3,
delay=0.3,
backoff=1,
max_jitter=0.1,
max_delay=1,
ignore_expire=False,
)
default_acl = None
auth_data = None
if zk_user and zk_secret:
default_acl = [make_digest_acl(zk_user, zk_secret, all=True)]
scheme = 'digest'
credential = "{}:{}".format(zk_user, zk_secret)
auth_data = [(scheme, credential)]
zk = KazooClient(
hosts="127.0.0.1:2181",
timeout=30,
connection_retry=conn_retry_policy,
command_retry=cmd_retry_policy,
default_acl=default_acl,
auth_data=auth_data,
)
zk.start()
return zk
# The prefix used for cockroachdb in ZK.