]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
immutable: Make more parts of download use logging mixins and know what their "parent...
authorZooko O'Whielacronx <zooko@zooko.com>
Thu, 8 Jan 2009 18:25:30 +0000 (11:25 -0700)
committerZooko O'Whielacronx <zooko@zooko.com>
Thu, 8 Jan 2009 18:25:30 +0000 (11:25 -0700)
src/allmydata/client.py
src/allmydata/immutable/download.py
src/allmydata/immutable/filenode.py
src/allmydata/test/test_filenode.py

index d1465d6d5582789483e373d92bc4f7b22cc014a7..3395f7f6d1f0c4f4e0a696f172203d78068ba835 100644 (file)
@@ -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)
index 310b181dfcd475b45b16503c4b26e5ed43d8f9ac..2ba3492dcbdf3cbdc522d92d4fa21a2d53f7d2a0 100644 (file)
@@ -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
index 45a4a600a9b0a0e725aa8fdbcc933fd9a0cd7c93..4b1150417f981f8322c830932d5eb91a463f8508 100644 (file)
@@ -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")
index 0fdc05139821ee7f512c17cee1b1ae3aa65a3805..abf82220fd7e8470882557b9e23c99ef81d3704c 100644 (file)
@@ -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")