Fix etcd watching

Etcd can miss events on watches if they are occurring fast enough, so if we can get an exception indicating that we've missed an index, we reset the state of our local tracking structures by re-reading the *full* list and starting a new watch at HEAD
This commit is contained in:
Joseph Schorr 2015-06-25 21:22:39 -04:00
parent 05d5238cc8
commit 52fa9aad5b
2 changed files with 34 additions and 1 deletions

View file

@ -36,6 +36,7 @@ class BuilderServer(object):
self._loop = None
self._current_status = BuildServerStatus.STARTING
self._current_components = []
self._realm_map = {}
self._job_count = 0
self._session_factory = RouterSessionFactory(RouterFactory())
@ -111,6 +112,9 @@ class BuilderServer(object):
BaseComponent.
"""
logger.debug('Registering component with realm %s', realm)
if realm in self._realm_map:
logger.debug('Component with realm %s already registered', realm)
return self._realm_map[realm]
component = component_klass(types.ComponentConfig(realm=realm), realm=realm, **kwargs)
component.server = self
@ -119,6 +123,7 @@ class BuilderServer(object):
component.user_files = self._user_files
component.registry_hostname = self._registry_hostname
self._realm_map[realm] = component
self._current_components.append(component)
self._session_factory.add(component)
return component
@ -127,6 +132,7 @@ class BuilderServer(object):
logger.debug('Unregistering component with realm %s and token %s',
component.builder_realm, component.expected_token)
self._realm_map.pop(component.builder_realm)
self._current_components.remove(component)
self._session_factory.remove(component)