Allow specifying a kazoo async handler 'kind'

In situations where the built-in (and default) kazoo
threading async handler does not work (which sometimes
appears to happen under eventlet) allow for specifying
a different handler (ie the 'eventlet' one) that should
work better under those scenarios.

Closes-bug: #1512001

Change-Id: Iec5e39928b223a3ffca0b9b5b4d0fd61abaa0f2b
This commit is contained in:
Joshua Harlow 2015-11-03 11:08:54 -08:00
parent 924fd939ce
commit 9c5cb6fd0b
1 changed files with 22 additions and 0 deletions

View File

@ -19,6 +19,8 @@ import copy
from kazoo import client
from kazoo import exceptions
from kazoo.handlers import eventlet as eventlet_handler
from kazoo.handlers import threading as threading_handler
from kazoo.protocol import paths
from oslo_utils import strutils
import six
@ -381,6 +383,16 @@ class KazooDriver(BaseZooKeeperDriver):
.. _msgpack: http://msgpack.org/
"""
HANDLERS = {
'eventlet': eventlet_handler.SequentialEventletHandler,
'threading': threading_handler.SequentialThreadingHandler,
}
"""
Restricted immutable dict of handler 'kinds' -> handler classes that
this driver can accept via 'handler' option key (the expected value for
this option is one of the keys in this dictionary).
"""
def __init__(self, member_id, parsed_url, options):
super(KazooDriver, self).__init__(member_id, parsed_url, options)
self._coord = self._make_client(parsed_url, self._options)
@ -403,6 +415,16 @@ class KazooDriver(BaseZooKeeperDriver):
'command_retry': options.get('command_retry'),
'randomize_hosts': strutils.bool_from_string(randomize_hosts),
}
handler_kind = options.get('handler')
if handler_kind:
try:
handler_cls = self.HANDLERS[handler_kind]
except KeyError:
raise ValueError("Unknown handler '%s' requested"
" valid handlers are %s"
% (handler_kind,
sorted(self.HANDLERS.keys())))
client_kwargs['handler'] = handler_cls()
return client.KazooClient(**client_kwargs)
def _watch_group(self, group_id):