Browse Source

Add ZK session timeout option

Change-Id: If804c18f2103baa12c9c3bd0344a166fac1ea749
changes/51/508251/1
James E. Blair 4 years ago
parent
commit
e2f0a87ad8
  1. 5
      doc/source/admin/components.rst
  2. 4
      zuul/cmd/scheduler.py
  3. 8
      zuul/zk.py

5
doc/source/admin/components.rst

@ -115,6 +115,11 @@ The following sections of ``zuul.conf`` are used by all Zuul components:
A list of zookeeper hosts for Zuul to use when communicating
with Nodepool.
.. attr:: session_timeout
:default: 10.0
The ZooKeeper session timeout, in seconds.
.. _scheduler:

4
zuul/cmd/scheduler.py

@ -154,8 +154,10 @@ class Scheduler(zuul.cmd.ZuulApp):
zookeeper = zuul.zk.ZooKeeper()
zookeeper_hosts = get_default(self.config, 'zookeeper',
'hosts', '127.0.0.1:2181')
zookeeper_timeout = float(get_default(self.config, 'zookeeper',
'session_timeout', 10.0))
zookeeper.connect(zookeeper_hosts)
zookeeper.connect(zookeeper_hosts, timeout=zookeeper_timeout)
cache_expiry = get_default(self.config, 'webapp', 'status_expiry', 1)
listen_address = get_default(self.config, 'webapp', 'listen_address',

8
zuul/zk.py

@ -90,7 +90,7 @@ class ZooKeeper(object):
def resetLostFlag(self):
self._became_lost = False
def connect(self, hosts, read_only=False):
def connect(self, hosts, read_only=False, timeout=10.0):
'''
Establish a connection with ZooKeeper cluster.
@ -100,10 +100,12 @@ class ZooKeeper(object):
:param str hosts: Comma-separated list of hosts to connect to (e.g.
127.0.0.1:2181,127.0.0.1:2182,[::1]:2183).
:param bool read_only: If True, establishes a read-only connection.
:param float timeout: The ZooKeeper session timeout, in
seconds (default: 10.0).
'''
if self.client is None:
self.client = KazooClient(hosts=hosts, read_only=read_only)
self.client = KazooClient(hosts=hosts, read_only=read_only,
timeout=timeout)
self.client.add_listener(self._connection_listener)
self.client.start()

Loading…
Cancel
Save