From: Brian Warner Date: Tue, 2 Jun 2009 02:25:11 +0000 (-0700) Subject: more storage_broker refactoring: downloader gets a broker instead of a client, X-Git-Tag: trac-3900~4 X-Git-Url: https://git.rkrishnan.org/%5B/frontends/nxhtml.html?a=commitdiff_plain;h=b1290633b8cb75225f8d918424ec70c19035d0a3;p=tahoe-lafs%2Ftahoe-lafs.git more storage_broker refactoring: downloader gets a broker instead of a client, use Client.get_storage_broker() accessor instead of direct attribute access. --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index 106b1b72..465c546a 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -263,6 +263,9 @@ class Client(node.Node, pollmixin.PollMixin): default=True, boolean=True): sb.use_introducer(self.introducer_client) + def get_storage_broker(self): + return self.storage_broker + def init_stub_client(self): def _publish(res): # we publish an empty object so that the introducer can count how diff --git a/src/allmydata/immutable/download.py b/src/allmydata/immutable/download.py index 38841024..39101c4c 100644 --- a/src/allmydata/immutable/download.py +++ b/src/allmydata/immutable/download.py @@ -616,21 +616,22 @@ class DownloadStatus: self.results = value class CiphertextDownloader(log.PrefixingLogMixin): - """ I download shares, check their integrity, then decode them, check the integrity of the - resulting ciphertext, then and write it to my target. Before I send any new request to a - server, I always ask the "monitor" object that was passed into my constructor whether this - task has been cancelled (by invoking its raise_if_cancelled() method). """ + """ I download shares, check their integrity, then decode them, check the + integrity of the resulting ciphertext, then and write it to my target. + Before I send any new request to a server, I always ask the 'monitor' + object that was passed into my constructor whether this task has been + cancelled (by invoking its raise_if_cancelled() method).""" implements(IPushProducer) _status = None - def __init__(self, client, v, target, monitor): + def __init__(self, storage_broker, v, target, monitor): precondition(IVerifierURI.providedBy(v), v) precondition(IDownloadTarget.providedBy(target), target) prefix=base32.b2a_l(v.storage_index[:8], 60) log.PrefixingLogMixin.__init__(self, facility="tahoe.immutable.download", prefix=prefix) - self._client = client + self._storage_broker = storage_broker self._verifycap = v self._storage_index = v.storage_index @@ -743,7 +744,7 @@ class CiphertextDownloader(log.PrefixingLogMixin): def _get_all_shareholders(self): dl = [] - sb = self._client.storage_broker + sb = self._storage_broker for (peerid,ss) in sb.get_servers(self._storage_index): d = ss.callRemote("get_buckets", self._storage_index) d.addCallbacks(self._got_response, self._got_error, @@ -1191,11 +1192,13 @@ class Downloader(service.MultiService): # include LIT files self.stats_provider.count('downloader.files_downloaded', 1) self.stats_provider.count('downloader.bytes_downloaded', u.get_size()) + storage_broker = self.parent.get_storage_broker() target = DecryptingTarget(t, u.key, _log_msg_id=_log_msg_id) if not monitor: monitor=Monitor() - dl = CiphertextDownloader(self.parent, u.get_verify_cap(), target, monitor=monitor) + dl = CiphertextDownloader(storage_broker, u.get_verify_cap(), target, + monitor=monitor) self._all_downloads[dl] = None if history: history.add_download(dl.get_download_status()) diff --git a/src/allmydata/immutable/offloaded.py b/src/allmydata/immutable/offloaded.py index 01dc1ed4..a71bf132 100644 --- a/src/allmydata/immutable/offloaded.py +++ b/src/allmydata/immutable/offloaded.py @@ -618,7 +618,7 @@ class Helper(Referenceable, service.MultiService): # see if this file is already in the grid lp2 = self.log("doing a quick check+UEBfetch", parent=lp, level=log.NOISY) - sb = self.parent.storage_broker + sb = self.parent.get_storage_broker() c = CHKCheckerAndUEBFetcher(sb.get_servers, storage_index, lp2) d = c.check() def _checked(res): diff --git a/src/allmydata/immutable/upload.py b/src/allmydata/immutable/upload.py index 4bf07fed..9a0bce97 100644 --- a/src/allmydata/immutable/upload.py +++ b/src/allmydata/immutable/upload.py @@ -166,7 +166,7 @@ class Tahoe2PeerSelector: self.use_peers = set() # PeerTrackers that have shares assigned to them self.preexisting_shares = {} # sharenum -> peerid holding the share - sb = client.storage_broker + sb = client.get_storage_broker() peers = list(sb.get_servers(storage_index)) if not peers: raise NoServersError("client gave us zero peers") diff --git a/src/allmydata/mutable/publish.py b/src/allmydata/mutable/publish.py index 8ac19ef9..b833b8f4 100644 --- a/src/allmydata/mutable/publish.py +++ b/src/allmydata/mutable/publish.py @@ -190,7 +190,7 @@ class Publish: assert self._privkey self._encprivkey = self._node.get_encprivkey() - sb = self._node._client.storage_broker + sb = self._node._client.get_storage_broker() full_peerlist = sb.get_servers(self._storage_index) self.full_peerlist = full_peerlist # for use later, immutable self.bad_peers = set() # peerids who have errbacked/refused requests diff --git a/src/allmydata/mutable/servermap.py b/src/allmydata/mutable/servermap.py index 565975b2..9c598580 100644 --- a/src/allmydata/mutable/servermap.py +++ b/src/allmydata/mutable/servermap.py @@ -421,7 +421,7 @@ class ServermapUpdater: self._queries_completed = 0 - sb = self._node._client.storage_broker + sb = self._node._client.get_storage_broker() full_peerlist = list(sb.get_servers(self._node._storage_index)) self.full_peerlist = full_peerlist # for use later, immutable self.extra_peers = full_peerlist[:] # peers are removed as we use them diff --git a/src/allmydata/test/test_checker.py b/src/allmydata/test/test_checker.py index e9d88a33..03b57530 100644 --- a/src/allmydata/test/test_checker.py +++ b/src/allmydata/test/test_checker.py @@ -9,6 +9,8 @@ from common_web import WebRenderingMixin class FakeClient: def get_nickname_for_serverid(self, serverid): return self.storage_broker.get_nickname_for_serverid(serverid) + def get_storage_broker(self): + return self.storage_broker class WebResultsRendering(unittest.TestCase, WebRenderingMixin): diff --git a/src/allmydata/test/test_helper.py b/src/allmydata/test/test_helper.py index 32b3ab86..38ce5eee 100644 --- a/src/allmydata/test/test_helper.py +++ b/src/allmydata/test/test_helper.py @@ -68,6 +68,8 @@ class FakeClient(service.MultiService): return log.msg(*args, **kwargs) def get_encoding_parameters(self): return self.DEFAULT_ENCODING_PARAMETERS + def get_storage_broker(self): + return self.storage_broker def flush_but_dont_ignore(res): d = flushEventualQueue() diff --git a/src/allmydata/test/test_mutable.py b/src/allmydata/test/test_mutable.py index 1ac21f94..942fa762 100644 --- a/src/allmydata/test/test_mutable.py +++ b/src/allmydata/test/test_mutable.py @@ -181,6 +181,8 @@ class FakeClient: def get_all_serverids(self): return self.storage_broker.get_all_serverids() + def get_storage_broker(self): + return self.storage_broker def debug_break_connection(self, peerid): self.storage_broker.servers[peerid].broken = True def debug_remove_connection(self, peerid): diff --git a/src/allmydata/test/test_upload.py b/src/allmydata/test/test_upload.py index 52d17796..4d0f764f 100644 --- a/src/allmydata/test/test_upload.py +++ b/src/allmydata/test/test_upload.py @@ -177,6 +177,8 @@ class FakeClient: pass def get_encoding_parameters(self): return self.DEFAULT_ENCODING_PARAMETERS + def get_storage_broker(self): + return self.storage_broker def get_renewal_secret(self): return "" diff --git a/src/allmydata/test/test_web.py b/src/allmydata/test/test_web.py index 1eb92bb3..0570473c 100644 --- a/src/allmydata/test/test_web.py +++ b/src/allmydata/test/test_web.py @@ -69,6 +69,8 @@ class FakeClient(service.MultiService): return u"John Doe" storage_broker = StorageFarmBroker() + def get_storage_broker(self): + return self.storage_broker def create_node_from_uri(self, auri): precondition(isinstance(auri, str), auri) diff --git a/src/allmydata/web/check_results.py b/src/allmydata/web/check_results.py index 3228f299..cf5634a7 100644 --- a/src/allmydata/web/check_results.py +++ b/src/allmydata/web/check_results.py @@ -137,7 +137,7 @@ class ResultsBase: add("Unrecoverable Versions", data["count-unrecoverable-versions"]) # this table is sorted by permuted order - sb = c.storage_broker + sb = c.get_storage_broker() permuted_peer_ids = [peerid for (peerid, rref) in sb.get_servers(cr.get_storage_index())]