diff options
author | indianwhocodes <nairashwin952013@gmail.com> | 2022-10-10 10:27:00 -0700 |
---|---|---|
committer | Alistair Coles <alistairncoles@gmail.com> | 2023-02-10 09:34:59 +0000 |
commit | 9ec90d4d56c598ab5567128fd59dca8c54fe8dc4 (patch) | |
tree | 15d6566dcf9b9eb17420077fb5fd373f485808f8 /swift/common/request_helpers.py | |
parent | d9bf70ae2b28222f62470bba5f6877bbbe057532 (diff) | |
download | swift-9ec90d4d56c598ab5567128fd59dca8c54fe8dc4.tar.gz |
proxy-server exception logging shows replication_ip/port
Adding a "use_replication" field to the node dict, a helper function to
set use_replication dict value for a node copy by looking up the header
value for x-backend-use-replication-network
Change-Id: Ie05af464765dc10cf585be851f462033fc6bdec7
Diffstat (limited to 'swift/common/request_helpers.py')
-rw-r--r-- | swift/common/request_helpers.py | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/swift/common/request_helpers.py b/swift/common/request_helpers.py index 0d4d538eb..7fa97c731 100644 --- a/swift/common/request_helpers.py +++ b/swift/common/request_helpers.py @@ -40,7 +40,7 @@ from swift.common.utils import split_path, validate_device_partition, \ close_if_possible, maybe_multipart_byteranges_to_document_iters, \ multipart_byteranges_to_document_iters, parse_content_type, \ parse_content_range, csv_append, list_from_csv, Spliterator, quote, \ - RESERVED, config_true_value, md5, CloseableChain + RESERVED, config_true_value, md5, CloseableChain, select_ip_port from swift.common.wsgi import make_subrequest @@ -901,13 +901,39 @@ def update_ignore_range_header(req, name): req.headers[hdr] = csv_append(req.headers.get(hdr), name) +def is_use_replication_network(headers=None): + """ + Determine if replication network should be used. + + :param headers: a dict of headers + :return: the value of the ``x-backend-use-replication-network`` item from + ``headers``. If no ``headers`` are given or the item is not found then + False is returned. + """ + if headers: + for h, v in headers.items(): + if h.lower() == USE_REPLICATION_NETWORK_HEADER: + return config_true_value(v) + return False + + def get_ip_port(node, headers): - use_replication_network = False - for h, v in headers.items(): - if h.lower() == USE_REPLICATION_NETWORK_HEADER: - use_replication_network = config_true_value(v) - break - if use_replication_network: - return node['replication_ip'], node['replication_port'] - else: - return node['ip'], node['port'] + """ + Get the ip address and port that should be used for the given ``node``. + The normal ip address and port are returned unless the ``node`` or + ``headers`` indicate that the replication ip address and port should be + used. + + If the ``headers`` dict has an item with key + ``x-backend-use-replication-network`` and a truthy value then the + replication ip address and port are returned. Otherwise if the ``node`` + dict has an item with key ``use_replication`` and truthy value then the + replication ip address and port are returned. Otherwise the normal ip + address and port are returned. + + :param node: a dict describing a node + :param headers: a dict of headers + :return: a tuple of (ip address, port) + """ + return select_ip_port( + node, use_replication=is_use_replication_network(headers)) |