From: Brian Warner Date: Wed, 17 Oct 2007 09:25:50 +0000 (-0700) Subject: checker: return more information per CHK file, including the shareholder list X-Git-Tag: allmydata-tahoe-0.7.0~368 X-Git-Url: https://git.rkrishnan.org/%5B/%5D%20/uri/%22doc.html/running.html?a=commitdiff_plain;h=aff059dd4bb176dd82182b14d5d11f446f572bcf;p=tahoe-lafs%2Ftahoe-lafs.git checker: return more information per CHK file, including the shareholder list --- diff --git a/src/allmydata/checker.py b/src/allmydata/checker.py index 57565246..08c2c57b 100644 --- a/src/allmydata/checker.py +++ b/src/allmydata/checker.py @@ -14,10 +14,14 @@ from allmydata import uri, download from allmydata.util import hashutil, idlib class SimpleCHKFileChecker: + """Return a list of (needed, total, found, sharemap), where sharemap maps + share number to a list of (binary) nodeids of the shareholders.""" - def __init__(self, peer_getter): + def __init__(self, peer_getter, uri_to_check): self.peer_getter = peer_getter self.found_shares = set() + self.uri_to_check = uri_to_check + self.sharemap = {} ''' def check_synchronously(self, si): @@ -30,8 +34,8 @@ class SimpleCHKFileChecker: return len(found) ''' - def check(self, uri_to_check): - d = self._get_all_shareholders(uri_to_check.storage_index) + def check(self): + d = self._get_all_shareholders(self.uri_to_check.storage_index) d.addCallback(self._done) return d @@ -41,13 +45,18 @@ class SimpleCHKFileChecker: d = connection.callRemote("get_service", "storageserver") d.addCallback(lambda ss: ss.callRemote("get_buckets", storage_index)) - d.addCallbacks(self._got_response, self._got_error) + d.addCallbacks(self._got_response, self._got_error, + callbackArgs=(peerid,)) dl.append(d) return defer.DeferredList(dl) - def _got_response(self, buckets): + def _got_response(self, buckets, peerid): # buckets is a dict: maps shum to an rref of the server who holds it self.found_shares.update(buckets.keys()) + for k in buckets: + if k not in self.sharemap: + self.sharemap[k] = [] + self.sharemap[k].append(peerid) def _got_error(self, f): if f.check(KeyError): @@ -56,7 +65,9 @@ class SimpleCHKFileChecker: pass def _done(self, res): - return len(self.found_shares) + u = self.uri_to_check + return (u.needed_shares, u.total_shares, len(self.found_shares), + self.sharemap) class SimpleDirnodeChecker: @@ -93,8 +104,8 @@ class Checker(service.MultiService): return defer.succeed(True) elif isinstance(uri_to_check, uri.CHKFileVerifierURI): peer_getter = self.parent.get_permuted_peers - c = SimpleCHKFileChecker(peer_getter) - return c.check(uri_to_check) + c = SimpleCHKFileChecker(peer_getter, uri_to_check) + return c.check() elif isinstance(uri_to_check, uri.DirnodeVerifierURI): tub = self.parent.tub c = SimpleDirnodeChecker(tub) diff --git a/src/allmydata/test/test_system.py b/src/allmydata/test/test_system.py index fab60167..2b6c0720 100644 --- a/src/allmydata/test/test_system.py +++ b/src/allmydata/test/test_system.py @@ -806,7 +806,18 @@ class SystemTest(testutil.SignalMixin, unittest.TestCase): d.addCallback(_check_all) def _done(res): for i in res: - self.failUnless(i is True or i == 10) + if type(i) is bool: + self.failUnless(i is True) + else: + (needed, total, found, sharemap) = i + self.failUnlessEqual(needed, 3) + self.failUnlessEqual(total, 10) + self.failUnlessEqual(found, total) + self.failUnlessEqual(len(sharemap.keys()), 10) + peers = set() + for shpeers in sharemap.values(): + peers.update(shpeers) + self.failUnlessEqual(len(peers), self.numclients-1) d.addCallback(_done) return d