Warn if read_affinity is configured but not enabled
To get the proxy's read affinity to work, you have to set both "read_affinity = <stuff>" and "sorting_method = affinity" in the proxy config. If you set the first but not the second, then you don't get read affinity, and Swift doesn't help you determine why not. Now the proxy will emit a warning message if read_affinity is set but sorting_method is a value other than "affinity", so if you check your logs to see why it isn't working, you'll get a hint. Note that the message comes out twice per proxy process, so with 2 workers you'll see the warning 6 times on startup (2 for master + 2 * 2 per worker). It's sort of annoying, but at least it's not per-request. Bonus docstring fix: remove a sentence that's not true Change-Id: Iad37d4979a1b7c45c0e3d1b83336dbcf7a68a0c9
This commit is contained in:
parent
c709cf90fc
commit
5196eae0f1
@ -1796,8 +1796,7 @@ def affinity_key_function(affinity_str):
|
||||
priority values are what comes after the equals sign.
|
||||
|
||||
If affinity_str is empty or all whitespace, then the resulting function
|
||||
will not alter the ordering of the nodes. However, if affinity_str
|
||||
contains an invalid value, then None is returned.
|
||||
will not alter the ordering of the nodes.
|
||||
|
||||
:param affinity_str: affinity config value, e.g. "r1z2=3"
|
||||
or "r1=1, r2z1=2, r2z2=2"
|
||||
|
@ -138,7 +138,7 @@ class Application(object):
|
||||
raise ValueError(
|
||||
'Invalid request_node_count value: %r' % ''.join(value))
|
||||
try:
|
||||
read_affinity = conf.get('read_affinity', '')
|
||||
self._read_affinity = read_affinity = conf.get('read_affinity', '')
|
||||
self.read_affinity_sort_key = affinity_key_function(read_affinity)
|
||||
except ValueError as err:
|
||||
# make the message a little more useful
|
||||
@ -200,6 +200,15 @@ class Application(object):
|
||||
max_container_name_length=constraints.MAX_CONTAINER_NAME_LENGTH,
|
||||
max_object_name_length=constraints.MAX_OBJECT_NAME_LENGTH)
|
||||
|
||||
def check_config(self):
|
||||
"""
|
||||
Check the configuration for possible errors
|
||||
"""
|
||||
if self._read_affinity and self.sorting_method != 'affinity':
|
||||
self.logger.warn("sorting_method is set to '%s', not 'affinity'; "
|
||||
"read_affinity setting will have no effect." %
|
||||
self.sorting_method)
|
||||
|
||||
def get_controller(self, path):
|
||||
"""
|
||||
Get the controller to handle a request.
|
||||
@ -530,4 +539,6 @@ def app_factory(global_conf, **local_conf):
|
||||
"""paste.deploy app factory for creating WSGI proxy apps."""
|
||||
conf = global_conf.copy()
|
||||
conf.update(local_conf)
|
||||
return Application(conf)
|
||||
app = Application(conf)
|
||||
app.check_config()
|
||||
return app
|
||||
|
Loading…
Reference in New Issue
Block a user