From: Zooko O'Whielacronx Date: Thu, 8 Jan 2009 18:25:30 +0000 (-0700) Subject: immutable: Make more parts of download use logging mixins and know what their "parent... X-Git-Url: https://git.rkrishnan.org/pf/content/en/service/somewhere?a=commitdiff_plain;h=ecabcc674ca284c910527fa1c949d61997f891c3;p=tahoe-lafs%2Ftahoe-lafs.git immutable: Make more parts of download use logging mixins and know what their "parent msg id" is. --- diff --git a/src/allmydata/client.py b/src/allmydata/client.py index d1465d6d..3395f7f6 100644 --- a/src/allmydata/client.py +++ b/src/allmydata/client.py @@ -361,7 +361,7 @@ class Client(node.Node, pollmixin.PollMixin): else: key = base32.b2a(u.storage_index) cachefile = self.download_cache.get_file(key) - node = FileNode(u, self, cachefile) # CHK + node = FileNode(u.to_string(), self, cachefile) # CHK else: assert IMutableFileURI.providedBy(u), u node = MutableFileNode(self).init_from_uri(u) diff --git a/src/allmydata/immutable/download.py b/src/allmydata/immutable/download.py index 310b181d..2ba3492d 100644 --- a/src/allmydata/immutable/download.py +++ b/src/allmydata/immutable/download.py @@ -1186,7 +1186,7 @@ class Downloader(service.MultiService): self._all_download_statuses = weakref.WeakKeyDictionary() self._recent_download_statuses = [] - def download(self, u, t): + def download(self, u, t, _log_msg_id=None): assert self.parent assert self.running u = IFileURI(u) @@ -1206,12 +1206,12 @@ class Downloader(service.MultiService): return d # utility functions - def download_to_data(self, uri): - return self.download(uri, Data()) - def download_to_filename(self, uri, filename): - return self.download(uri, FileName(filename)) - def download_to_filehandle(self, uri, filehandle): - return self.download(uri, FileHandle(filehandle)) + def download_to_data(self, uri, _log_msg_id=None): + return self.download(uri, Data(), _log_msg_id=_log_msg_id) + def download_to_filename(self, uri, filename, _log_msg_id=None): + return self.download(uri, FileName(filename), _log_msg_id=_log_msg_id) + def download_to_filehandle(self, uri, filehandle, _log_msg_id=None): + return self.download(uri, FileHandle(filehandle), _log_msg_id=_log_msg_id) def _add_download(self, downloader): self._all_downloads[downloader] = None diff --git a/src/allmydata/immutable/filenode.py b/src/allmydata/immutable/filenode.py index 45a4a600..4b115041 100644 --- a/src/allmydata/immutable/filenode.py +++ b/src/allmydata/immutable/filenode.py @@ -9,6 +9,7 @@ from foolscap.eventual import eventually from allmydata.interfaces import IFileNode, IFileURI, ICheckable, \ IDownloadTarget from allmydata.util import log, base32 +from allmydata import uri as urimodule from allmydata.immutable.checker import Checker from allmydata.check_results import CheckAndRepairResults from allmydata.immutable.repairer import Repairer @@ -167,10 +168,13 @@ class DownloadCache: -class FileNode(_ImmutableFileNodeBase): +class FileNode(_ImmutableFileNodeBase, log.PrefixingLogMixin): def __init__(self, uri, client, cachefile): _ImmutableFileNodeBase.__init__(self, uri, client) self.download_cache = DownloadCache(self, cachefile) + prefix = urimodule.from_string(uri).get_verify_cap().to_string() + log.PrefixingLogMixin.__init__(self, "allmydata.immutable.filenode", prefix=prefix) + self.log("starting", level=log.OPERATIONAL) def get_uri(self): return self.u.to_string() @@ -219,10 +223,7 @@ class FileNode(_ImmutableFileNodeBase): if offset == 0 and size == self.get_size(): # don't use the cache, just do a normal streaming download - log.msg(format=("immutable filenode read [%(si)s]: " + - "doing normal full download"), - si=base32.b2a(self.u.storage_index), - umid="VRSBwg", level=log.OPERATIONAL) + self.log("doing normal full download", umid="VRSBwg", level=log.OPERATIONAL) return self.download(download.ConsumerAdapter(consumer)) d = self.download_cache.when_range_available(offset, size) @@ -232,7 +233,7 @@ class FileNode(_ImmutableFileNodeBase): def download(self, target): downloader = self._client.getServiceNamed("downloader") - return downloader.download(self.get_uri(), target) + return downloader.download(self.get_uri(), target, self._parentmsgid) def download_to_data(self): downloader = self._client.getServiceNamed("downloader") diff --git a/src/allmydata/test/test_filenode.py b/src/allmydata/test/test_filenode.py index 0fdc0513..abf82220 100644 --- a/src/allmydata/test/test_filenode.py +++ b/src/allmydata/test/test_filenode.py @@ -27,7 +27,7 @@ class Node(unittest.TestCase): size=1000) c = FakeClient() cf = cachedir.CacheFile("none") - fn1 = filenode.FileNode(u, c, cf) + fn1 = filenode.FileNode(u.to_string(), c, cf) fn2 = filenode.FileNode(u.to_string(), c, cf) self.failUnlessEqual(fn1, fn2) self.failIfEqual(fn1, "I am not a filenode")