mutable/retrieve.py: inline the single-use function _remove_reader.

A simple refactoring. Doesn't even require a new or updated unit test.

Author: Zooko O'Whielacronx <zooko@zooko.com>
Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
This commit is contained in:
Daira Hopwood 2013-05-10 22:21:23 +01:00
parent 2fa832b060
commit a74b09ec86

View File

@ -527,40 +527,6 @@ class Retrieve:
"indicate an uncoordinated write")
# Otherwise, we're okay -- no issues.
def _remove_reader(self, reader):
"""
At various points, we will wish to remove a server from
consideration and/or use. These include, but are not necessarily
limited to:
- A connection error.
- A mismatched prefix (that is, a prefix that does not match
our conception of the version information string).
- A failing block hash, salt hash, or share hash, which can
indicate disk failure/bit flips, or network trouble.
This method will do that. I will make sure that the
(shnum,reader) combination represented by my reader argument is
not used for anything else during this download. I will not
advise the reader of any corruption, something that my callers
may wish to do on their own.
"""
# TODO: When you're done writing this, see if this is ever
# actually used for something that _mark_bad_share isn't. I have
# a feeling that they will be used for very similar things, and
# that having them both here is just going to be an epic amount
# of code duplication.
#
# (well, okay, not epic, but meaningful)
self.log("removing reader %s" % reader)
# Remove the reader from _active_readers
self._active_readers.remove(reader)
# TODO: self.readers.remove(reader)?
for shnum in list(self.remaining_sharemap.keys()):
self.remaining_sharemap.discard(shnum, reader.server)
def _mark_bad_share(self, server, shnum, reader, f):
"""
I mark the given (server, shnum) as a bad share, which means that it
@ -585,14 +551,18 @@ class Retrieve:
(shnum, server.get_name()))
prefix = self.verinfo[-2]
self.servermap.mark_bad_share(server, shnum, prefix)
self._remove_reader(reader)
self._bad_shares.add((server, shnum, f))
self._status.add_problem(server, f)
self._last_failure = f
# Remove the reader from _active_readers
self._active_readers.remove(reader)
for shnum in list(self.remaining_sharemap.keys()):
self.remaining_sharemap.discard(shnum, reader.server)
if f.check(BadShareError):
self.notify_server_corruption(server, shnum, str(f.value))
def _download_current_segment(self):
"""
I download, validate, decode, decrypt, and assemble the segment