From: david-sarah Date: Sat, 24 Sep 2011 20:50:04 +0000 (-0700) Subject: mutable/publish.py: simplify by refactoring self.outstanding to self.num_outstanding... X-Git-Url: https://git.rkrishnan.org/pf/content/en/nxhtml.html?a=commitdiff_plain;h=f94eb86fc9232ce6c850151c710b0c269a0903ae;p=tahoe-lafs%2Ftahoe-lafs.git mutable/publish.py: simplify by refactoring self.outstanding to self.num_outstanding. refs #393 --- diff --git a/src/allmydata/mutable/publish.py b/src/allmydata/mutable/publish.py index e5f44c78..a20ab15e 100644 --- a/src/allmydata/mutable/publish.py +++ b/src/allmydata/mutable/publish.py @@ -228,11 +228,11 @@ class Publish: # existing servermap. self.goal = set() # pairs of (peerid, shnum) tuples - # the second table is our list of outstanding queries: those which - # are in flight and may or may not be delivered, accepted, or - # acknowledged. Items are added to this table when the request is - # sent, and removed when the response returns (or errbacks). - self.outstanding = set() # (peerid, shnum) tuples + # the number of outstanding queries: those that are in flight and + # may or may not be delivered, accepted, or acknowledged. This is + # incremented when a query is sent, and decremented when the response + # returns or errbacks. + self.num_outstanding = 0 # the third is a table of successes: share which have actually been # placed. These are populated when responses come back with success. @@ -425,11 +425,11 @@ class Publish: # existing servermap. self.goal = set() # pairs of (peerid, shnum) tuples - # the second table is our list of outstanding queries: those which - # are in flight and may or may not be delivered, accepted, or - # acknowledged. Items are added to this table when the request is - # sent, and removed when the response returns (or errbacks). - self.outstanding = set() # (peerid, shnum) tuples + # the number of outstanding queries: those that are in flight and + # may or may not be delivered, accepted, or acknowledged. This is + # incremented when a query is sent, and decremented when the response + # returns or errbacks. + self.num_outstanding = 0 # the third is a table of successes: share which have actually been # placed. These are populated when responses come back with success. @@ -535,7 +535,7 @@ class Publish: "%d messages outstanding" % (len(self.placed), len(self.goal), - len(self.outstanding))) + self.num_outstanding)) self._status.set_progress(1.0 * len(self.placed) / len(self.goal)) @@ -866,12 +866,14 @@ class Publish: # make a copy, or just use a non-iterated value. for (shnum, writer) in self.writers.iteritems(): writer.put_verification_key(verification_key) + self.num_outstanding += 1 + def _no_longer_outstanding(res): + self.num_outstanding -= 1 + return res + d = writer.finish_publishing() + d.addBoth(_no_longer_outstanding) d.addErrback(self._connection_problem, writer) - # Add the (peerid, shnum) tuple to our list of outstanding - # queries. This gets used by _loop if some of our queries - # fail to place shares. - self.outstanding.add((writer.peerid, writer.shnum)) d.addCallback(self._got_write_answer, writer, started) ds.append(d) self._record_verinfo()