Ticket #738: 738-dumpblock.diff

File 738-dumpblock.diff, 3.6 KB (added by warner, at 2009-06-24T01:33:33Z)

patch to dump the offending block into logs/

  • src/allmydata/immutable/checker.py

    diff --git a/src/allmydata/immutable/checker.py b/src/allmydata/immutable/checker.py
    index c565bc3..77edff8 100644
    a b class Checker(log.PrefixingLogMixin): 
    159159            self._share_hash_tree = hashtree.IncompleteHashTree(self._verifycap.total_shares)
    160160            self._share_hash_tree.set_hashes({0: vup.share_root_hash})
    161161
    162             vrbp = download.ValidatedReadBucketProxy(sharenum, b, self._share_hash_tree, vup.num_segments, vup.block_size, vup.share_size)
     162            vrbp = download.ValidatedReadBucketProxy(sharenum, b, self._share_hash_tree, vup.num_segments, vup.block_size, vup.share_size, self._verifycap.storage_index)
    163163
    164164            ds = []
    165165            for blocknum in range(vup.num_segments):
  • src/allmydata/immutable/download.py

    diff --git a/src/allmydata/immutable/download.py b/src/allmydata/immutable/download.py
    index 9dfc0bb..efb5454 100644
    a b class ValidatedReadBucketProxy(log.PrefixingLogMixin): 
    318318    My get_block() method is used by BlockDownloaders.
    319319    """
    320320
    321     def __init__(self, sharenum, bucket, share_hash_tree, num_blocks, block_size, share_size):
     321    def __init__(self, sharenum, bucket, share_hash_tree, num_blocks, block_size, share_size,
     322                 storage_index):
    322323        """ share_hash_tree is required to have already been initialized with the root hash
    323324        (the number-0 hash), using the share_root_hash from the UEB """
    324325        precondition(share_hash_tree[0] is not None, share_hash_tree)
    class ValidatedReadBucketProxy(log.PrefixingLogMixin): 
    331332        self.block_size = block_size
    332333        self.share_size = share_size
    333334        self.block_hash_tree = hashtree.IncompleteHashTree(self.num_blocks)
     335        self.storage_index = storage_index
    334336
    335337    def get_block(self, blocknum):
    336338        # the first time we use this bucket, we need to fetch enough elements
    class ValidatedReadBucketProxy(log.PrefixingLogMixin): 
    408410            # likely a programming error
    409411            self.log("hash failure in block=%d, shnum=%d on %s" %
    410412                    (blocknum, self.sharenum, self.bucket))
     413            try:
     414                fn = ("logs/badhash-from-%s-SI-%s-shnum-%d-blocknum-%d" %
     415                      (idlib.shortnodeid_b2a(self.bucket._peerid),
     416                       base32.b2a(self.storage_index), self.sharenum, blocknum))
     417                f = open(fn, "wb")
     418                f.write(blockdata)
     419                f.close()
     420            except Exception, e:
     421                self.log(" (unable to write blockdata: %s)" % (e,))
    411422            if self.block_hash_tree.needed_hashes(blocknum):
    412423                self.log(""" failure occurred when checking the block_hash_tree.
    413424                This suggests that either the block data was bad, or that the
    class CiphertextDownloader(log.PrefixingLogMixin): 
    923934
    924935    def _download_all_segments(self, res):
    925936        for sharenum, bucket in self._share_buckets:
    926             vbucket = ValidatedReadBucketProxy(sharenum, bucket, self._share_hash_tree, self._vup.num_segments, self._vup.block_size, self._vup.share_size)
     937            vbucket = ValidatedReadBucketProxy(sharenum, bucket, self._share_hash_tree,
     938                                               self._vup.num_segments,
     939                                               self._vup.block_size, self._vup.share_size,
     940                                               self._storage_index)
    927941            self._share_vbuckets.setdefault(sharenum, set()).add(vbucket)
    928942
    929943        # after the above code, self._share_vbuckets contains enough