From: Brian Warner Date: Tue, 20 Nov 2007 02:07:10 +0000 (-0700) Subject: download: use hierarchical logging X-Git-Url: https://git.rkrishnan.org/pf/content/en/seg/something?a=commitdiff_plain;h=869b69037898ad9715948126e49f5c490c8ac71b;p=tahoe-lafs%2Ftahoe-lafs.git download: use hierarchical logging --- diff --git a/src/allmydata/checker.py b/src/allmydata/checker.py index fcb699d0..22811916 100644 --- a/src/allmydata/checker.py +++ b/src/allmydata/checker.py @@ -141,6 +141,8 @@ class SimpleCHKFileVerifier(download.FileDownloader): self._size = u.size self._num_needed_shares = u.needed_shares + self.init_logging() + self._output = VerifyingOutput(self._size) self._paused = False self._stopped = False @@ -159,6 +161,18 @@ class SimpleCHKFileVerifier(download.FileDownloader): "crypttext_hashtree": 0, } + def init_logging(self): + self._log_prefix = prefix = idlib.b2a(self._storage_index)[:6] + num = self._client.log("SimpleCHKFileVerifier(%s): starting" % prefix) + self._log_number = num + + def log(self, msg, parent=None): + if parent is None: + parent = self._log_number + return self._client.log("SimpleCHKFileVerifier(%s): %s" + % (self._log_prefix, msg), + parent=parent) + def start(self): log.msg("starting download [%s]" % idlib.b2a(self._storage_index)[:6]) diff --git a/src/allmydata/download.py b/src/allmydata/download.py index 9317032e..962473a7 100644 --- a/src/allmydata/download.py +++ b/src/allmydata/download.py @@ -301,6 +301,8 @@ class FileDownloader: self._size = u.size self._num_needed_shares = u.needed_shares + self.init_logging() + if IConsumer.providedBy(downloadable): downloadable.registerProducer(self, True) self._downloadable = downloadable @@ -322,6 +324,18 @@ class FileDownloader: "crypttext_hashtree": 0, } + def init_logging(self): + self._log_prefix = prefix = idlib.b2a(self._storage_index)[:6] + num = self._client.log("FileDownloader(%s): starting" % prefix) + self._log_number = num + + def log(self, msg, parent=None): + if parent is None: + parent = self._log_number + return self._client.log("FileDownloader(%s): %s" % (self._log_prefix, + msg), + parent=parent) + def pauseProducing(self): if self._paused: return @@ -334,11 +348,11 @@ class FileDownloader: eventually(p.callback, None) def stopProducing(self): - log.msg("Download.stopProducing") + self.log("Download.stopProducing") self._stopped = True def start(self): - log.msg("starting download [%s]" % idlib.b2a(self._storage_index)[:6]) + self.log("starting download") # first step: who should we download from? d = defer.maybeDeferred(self._get_all_shareholders) @@ -440,7 +454,7 @@ class FileDownloader: d.addCallback(lambda res: getattr(bucket, methname)(*args)) d.addCallback(validatorfunc, bucket) def _bad(f): - log.msg("%s from vbucket %s failed: %s" % (name, bucket, f)) # WEIRD + self.log("WEIRD: %s from vbucket %s failed: %s" % (name, bucket, f)) if not sources: raise NotEnoughPeersError("ran out of peers, last error was %s" % (f,)) @@ -588,9 +602,9 @@ class FileDownloader: return res def _download_segment(self, res, segnum): - log.msg("downloading seg#%d of %d (%d%%)" - % (segnum, self._total_segments, - 100.0 * segnum / self._total_segments)) + self.log("downloading seg#%d of %d (%d%%)" + % (segnum, self._total_segments, + 100.0 * segnum / self._total_segments)) # memory footprint: when the SegmentDownloader finishes pulling down # all shares, we have 1*segment_size of usage. segmentdler = SegmentDownloader(self, segnum, self._num_needed_shares) @@ -622,9 +636,9 @@ class FileDownloader: return d def _download_tail_segment(self, res, segnum): - log.msg("downloading seg#%d of %d (%d%%)" - % (segnum, self._total_segments, - 100.0 * segnum / self._total_segments)) + self.log("downloading seg#%d of %d (%d%%)" + % (segnum, self._total_segments, + 100.0 * segnum / self._total_segments)) segmentdler = SegmentDownloader(self, segnum, self._num_needed_shares) d = segmentdler.start() # pause before using more memory @@ -647,7 +661,7 @@ class FileDownloader: return d def _done(self, res): - log.msg("download done [%s]" % idlib.b2a(self._storage_index)[:6]) + self.log("download done") self._output.close() if self.check_crypttext_hash: _assert(self._crypttext_hash == self._output.crypttext_hash, diff --git a/src/allmydata/test/test_encode.py b/src/allmydata/test/test_encode.py index 19bb2c5e..a05ec767 100644 --- a/src/allmydata/test/test_encode.py +++ b/src/allmydata/test/test_encode.py @@ -14,6 +14,10 @@ class LostPeerError(Exception): def flip_bit(good): # flips the last bit return good[:-1] + chr(ord(good[-1]) ^ 0x01) +class FakeClient: + def log(self, *args, **kwargs): + pass + class FakeBucketWriterProxy: implements(IStorageBucketWriter, IStorageBucketReader) # these are used for both reading and writing @@ -330,7 +334,7 @@ class Roundtrip(unittest.TestCase): size=file_size) URI = u.to_string() - client = None + client = FakeClient() target = download.Data() fd = download.FileDownloader(client, URI, target)