]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
checker: return more information per CHK file, including the shareholder list
authorBrian Warner <warner@lothar.com>
Wed, 17 Oct 2007 09:25:50 +0000 (02:25 -0700)
committerBrian Warner <warner@lothar.com>
Wed, 17 Oct 2007 09:25:50 +0000 (02:25 -0700)
src/allmydata/checker.py
src/allmydata/test/test_system.py

index 57565246c907f7638e20fb0e023f3af02391fb22..08c2c57b8c71b315a2a3d095f53e1e94a418689c 100644 (file)
@@ -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)
index fab60167105c3f01844cacd2aafbcda2b093b7ff..2b6c0720a0082369001b7251985b0b4d1af07101 100644 (file)
@@ -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