]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blobdiff - src/allmydata/immutable/checker.py
Add comments and a caveat in webapi.rst indicating that
[tahoe-lafs/tahoe-lafs.git] / src / allmydata / immutable / checker.py
index 4b7a00590aedd5a830a67e5ef8571ec176a60a57..41000f7e0d14df68ae0a5bf0faedefeb017867aa 100644 (file)
@@ -738,67 +738,69 @@ class Checker(log.PrefixingLogMixin):
 
     def _format_results(self, results):
         SI = self._verifycap.get_storage_index()
-        cr = CheckResults(self._verifycap, SI)
-        d = {}
-        d['count-shares-needed'] = self._verifycap.needed_shares
-        d['count-shares-expected'] = self._verifycap.total_shares
 
-        verifiedshares = dictutil.DictOfSets() # {sharenum: set(serverid)}
-        servers = {} # {serverid: set(sharenums)}
-        corruptshare_locators = [] # (serverid, storageindex, sharenum)
-        incompatibleshare_locators = [] # (serverid, storageindex, sharenum)
-        servers_responding = set() # serverid
+        verifiedshares = dictutil.DictOfSets() # {sharenum: set(server)}
+        servers = {} # {server: set(sharenums)}
+        corruptshare_locators = [] # (server, storageindex, sharenum)
+        incompatibleshare_locators = [] # (server, storageindex, sharenum)
+        servers_responding = set() # server
 
         for verified, server, corrupt, incompatible, responded in results:
-            server_id = server.get_serverid()
-            servers.setdefault(server_id, set()).update(verified)
+            servers.setdefault(server, set()).update(verified)
             for sharenum in verified:
-                verifiedshares.setdefault(sharenum, set()).add(server_id)
+                verifiedshares.setdefault(sharenum, set()).add(server)
             for sharenum in corrupt:
-                corruptshare_locators.append((server_id, SI, sharenum))
+                corruptshare_locators.append((server, SI, sharenum))
             for sharenum in incompatible:
-                incompatibleshare_locators.append((server_id, SI, sharenum))
+                incompatibleshare_locators.append((server, SI, sharenum))
             if responded:
-                servers_responding.add(server_id)
+                servers_responding.add(server)
 
-        d['count-shares-good'] = len(verifiedshares)
-        d['count-good-share-hosts'] = len([s for s in servers.keys() if servers[s]])
+        good_share_hosts = len([s for s in servers.keys() if servers[s]])
 
         assert len(verifiedshares) <= self._verifycap.total_shares, (verifiedshares.keys(), self._verifycap.total_shares)
         if len(verifiedshares) == self._verifycap.total_shares:
-            cr.set_healthy(True)
-            cr.set_summary("Healthy")
+            healthy = True
+            summary = "Healthy"
         else:
-            cr.set_healthy(False)
-            cr.set_summary("Not Healthy: %d shares (enc %d-of-%d)" %
-                           (len(verifiedshares),
-                            self._verifycap.needed_shares,
-                            self._verifycap.total_shares))
+            healthy = False
+            summary = ("Not Healthy: %d shares (enc %d-of-%d)" %
+                       (len(verifiedshares),
+                        self._verifycap.needed_shares,
+                        self._verifycap.total_shares))
         if len(verifiedshares) >= self._verifycap.needed_shares:
-            cr.set_recoverable(True)
-            d['count-recoverable-versions'] = 1
-            d['count-unrecoverable-versions'] = 0
+            recoverable = 1
+            unrecoverable = 0
         else:
-            cr.set_recoverable(False)
-            d['count-recoverable-versions'] = 0
-            d['count-unrecoverable-versions'] = 1
-
-        d['servers-responding'] = list(servers_responding)
-        d['sharemap'] = verifiedshares
-        # no such thing as wrong shares of an immutable file
-        d['count-wrong-shares'] = 0
-        d['list-corrupt-shares'] = corruptshare_locators
-        d['count-corrupt-shares'] = len(corruptshare_locators)
-        d['list-incompatible-shares'] = incompatibleshare_locators
-        d['count-incompatible-shares'] = len(incompatibleshare_locators)
-
+            recoverable = 0
+            unrecoverable = 1
 
         # The file needs rebalancing if the set of servers that have at least
         # one share is less than the number of uniquely-numbered shares
         # available.
-        cr.set_needs_rebalancing(d['count-good-share-hosts'] < d['count-shares-good'])
-
-        cr.set_data(d)
+        # TODO: this may be wrong, see ticket #1115 comment:27 and ticket #1784.
+        needs_rebalancing = bool(good_share_hosts < len(verifiedshares))
+
+        cr = CheckResults(self._verifycap, SI,
+                          healthy=healthy, recoverable=bool(recoverable),
+                          needs_rebalancing=needs_rebalancing,
+                          count_shares_needed=self._verifycap.needed_shares,
+                          count_shares_expected=self._verifycap.total_shares,
+                          count_shares_good=len(verifiedshares),
+                          count_good_share_hosts=good_share_hosts,
+                          count_recoverable_versions=recoverable,
+                          count_unrecoverable_versions=unrecoverable,
+                          servers_responding=list(servers_responding),
+                          sharemap=verifiedshares,
+                          count_wrong_shares=0, # no such thing, for immutable
+                          list_corrupt_shares=corruptshare_locators,
+                          count_corrupt_shares=len(corruptshare_locators),
+                          list_incompatible_shares=incompatibleshare_locators,
+                          count_incompatible_shares=len(incompatibleshare_locators),
+                          summary=summary,
+                          report=[],
+                          share_problems=[],
+                          servermap=None)
 
         return cr