Changed logic to attempts_left; added comment for uncommon iterator usage.

This commit is contained in:
gholt
2010-10-18 08:49:33 -07:00
parent 6bf591ee14
commit c13c7f5607

View File

@@ -363,23 +363,26 @@ class ObjectReplicator(Daemon):
do_listdir=(self.replication_count % 10) == 0,
reclaim_age=self.reclaim_age)
self.suffix_hash += hashed
unmounted = 0
attempted = 0
attempts_left = self.object_ring.replica_count
nodes = itertools.chain(job['nodes'],
self.object_ring.get_more_nodes(int(job['partition'])))
while (attempted - unmounted) < (self.object_ring.replica_count - 1):
while attempts_left > 0:
# If this throws StopIterator it will be caught way below
node = next(nodes)
attempted += 1
attempts_left -= 1
try:
with Timeout(60):
resp = http_connect(node['ip'], node['port'],
node['device'], job['partition'], 'REPLICATE',
'', headers={'Content-Length': '0'}).getresponse()
if resp.status == 507:
self.logger.error('%s/%s responded as unmounted' %
(node['ip'], node['device']))
attempts_left += 1
continue
if resp.status != 200:
self.logger.error("Invalid response %s from %s" %
(resp.status, node['ip']))
if resp.status == 507:
unmounted += 1
continue
remote_hash = pickle.loads(resp.read())
del resp