From d2b51dd2b66afc796f297ba73ea438ce5b66ec98 Mon Sep 17 00:00:00 2001 From: gholt Date: Wed, 1 Aug 2012 21:07:32 +0000 Subject: [PATCH] Updated use of iter_nodes for handoff logging Change-Id: I95a750613b01bdc4d64444d7e7fae8190760d697 --- swift/proxy/server.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/swift/proxy/server.py b/swift/proxy/server.py index 29899d13f6..716076d6bf 100644 --- a/swift/proxy/server.py +++ b/swift/proxy/server.py @@ -397,7 +397,13 @@ class Controller(object): attempts_left = len(nodes) path = '/%s' % account headers = {'x-trans-id': self.trans_id, 'Connection': 'close'} - for node in self.iter_nodes(partition, nodes, self.app.account_ring): + iternodes = self.iter_nodes(partition, nodes, self.app.account_ring) + while attempts_left > 0: + try: + node = iternodes.next() + except StopIteration: + break + attempts_left -= 1 try: with ConnectionTimeout(self.app.conn_timeout): conn = http_connect(node['ip'], node['port'], @@ -420,9 +426,6 @@ class Controller(object): continue else: result_code = -1 - attempts_left -= 1 - if attempts_left <= 0: - break except (Exception, Timeout): self.exception_occurred(node, _('Account'), _('Trying to get account info for %s') % path) @@ -489,7 +492,13 @@ class Controller(object): versions = None attempts_left = len(nodes) headers = {'x-trans-id': self.trans_id, 'Connection': 'close'} - for node in self.iter_nodes(partition, nodes, self.app.container_ring): + iternodes = self.iter_nodes(partition, nodes, self.app.container_ring) + while attempts_left > 0: + try: + node = iternodes.next() + except StopIteration: + break + attempts_left -= 1 try: with ConnectionTimeout(self.app.conn_timeout): conn = http_connect(node['ip'], node['port'], @@ -516,9 +525,6 @@ class Controller(object): continue else: result_code = -1 - attempts_left -= 1 - if attempts_left <= 0: - break except (Exception, Timeout): self.exception_occurred(node, _('Container'), _('Trying to get container info for %s') % path) @@ -758,8 +764,11 @@ class Controller(object): bodies = [] source = None newest = req.headers.get('x-newest', 'f').lower() in TRUE_VALUES - for node in nodes: - if len(statuses) >= attempts: + nodes = iter(nodes) + while len(statuses) < attempts: + try: + node = nodes.next() + except StopIteration: break if self.error_limited(node): continue @@ -803,6 +812,9 @@ class Controller(object): source = possible_source else: source = possible_source + statuses.append(source.status) + reasons.append(source.reason) + bodies.append('') continue else: source = possible_source