From 5196eae0f1a91f7d2d0ddbd2136251bd714e9723 Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Wed, 8 Jan 2014 17:20:14 -0800 Subject: [PATCH] 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 = " 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 --- swift/common/utils.py | 3 +-- swift/proxy/server.py | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/swift/common/utils.py b/swift/common/utils.py index f19fd7a48d..8cfbf2b3dd 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -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" diff --git a/swift/proxy/server.py b/swift/proxy/server.py index 1d5f968d3c..9721186ee5 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -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