change UploadResults to return IServers, update users to match 8/head
authorBrian Warner <warner@lothar.com>
Tue, 22 May 2012 04:18:37 +0000 (21:18 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 22 May 2012 04:18:37 +0000 (21:18 -0700)
This finally changes all callers of get_servermap()/get_sharemap() to
accept IServers, and changes UploadResults to provide them.

src/allmydata/immutable/filenode.py
src/allmydata/immutable/offloaded.py
src/allmydata/immutable/upload.py
src/allmydata/interfaces.py
src/allmydata/web/status.py

index e159be033329637ff30a557b63806395541df9d2..4afeeda3c807a2124506d0e74f0f3cd7980506ee 100644 (file)
@@ -115,12 +115,13 @@ class CiphertextFileNode:
                     prr = CheckResults(cr.uri, cr.storage_index)
                     prr.data = copy.deepcopy(cr.data)
 
+                    servers_responding = set(prr.data['servers-responding'])
                     sm = prr.data['sharemap']
                     assert isinstance(sm, DictOfSets), sm
-                    sm.update(ur.get_sharemap())
-                    servers_responding = set(prr.data['servers-responding'])
-                    for shnum, serverids in ur.get_sharemap().items():
-                        servers_responding.update(serverids)
+                    for shnum, servers in ur.get_sharemap().items():
+                        for s in servers:
+                            sm.add(shnum, s.get_serverid())
+                            servers_responding.add(s.get_serverid())
                     servers_responding = sorted(servers_responding)
                     prr.data['servers-responding'] = servers_responding
                     prr.data['count-shares-good'] = len(sm)
index 428cb1ce20c8f826cb32c1f3c76e4efd679248f7..20a4fd7cbd3de2c2d188c315b62f8f6a77721907 100644 (file)
@@ -216,8 +216,14 @@ class CHKUploadHelper(Referenceable, upload.CHKUploader):
         hur.uri_extension_hash = v.uri_extension_hash
         hur.ciphertext_fetched = self._fetcher.get_ciphertext_fetched()
         hur.preexisting_shares = ur.get_preexisting_shares()
-        hur.sharemap = ur.get_sharemap()
-        hur.servermap = ur.get_servermap()
+        # hur.sharemap needs to be {shnum: set(serverid)}
+        hur.sharemap = {}
+        for shnum, servers in ur.get_sharemap().items():
+            hur.sharemap[shnum] = set([s.get_serverid() for s in servers])
+        # and hur.servermap needs to be {serverid: set(shnum)}
+        hur.servermap = {}
+        for server, shnums in ur.get_servermap().items():
+            hur.servermap[server.get_serverid()] = set(shnums)
         hur.pushed_shares = ur.get_pushed_shares()
         hur.file_size = ur.get_file_size()
         hur.uri_extension_data = ur.get_uri_extension_data()
index c609d37f4fa626bbca7fc8996ade1f45595aec9b..ba2c53b9074485d9e1574b37d08bff9c60021be7 100644 (file)
@@ -95,17 +95,9 @@ class UploadResults:
     def get_pushed_shares(self):
         return self._pushed_shares
     def get_sharemap(self):
-        # returns {shnum: set(serverid)}
-        sharemap = {}
-        for shnum, servers in self._sharemap.items():
-            sharemap[shnum] = set([s.get_serverid() for s in servers])
-        return sharemap
+        return self._sharemap
     def get_servermap(self):
-        # returns {serverid: set(shnum)}
-        servermap = {}
-        for server, shnums in self._servermap.items():
-            servermap[server.get_serverid()] = set(shnums)
-        return servermap
+        return self._servermap
     def get_timings(self):
         return self._timings
     def get_uri_extension_data(self):
index 8fb0aba79b4fba0088893a5bef112ddb06336193..42b0c4a7fa71ec21b82355d3fd82480c67d6a3fb 100644 (file)
@@ -1952,14 +1952,14 @@ class IUploadResults(Interface):
     def get_pushed_shares():
         """Return the number of shares that were uploaded."""
     def get_sharemap():
-        """Return a dict mapping share identifier to set of serverids (binary
-        strings). This indicates which servers were given which shares. For
+        """Return a dict mapping share identifier to set of IServer
+        instances. This indicates which servers were given which shares. For
         immutable files, the shareid is an integer (the share number, from 0
         to N-1). For mutable files, it is a string of the form
         'seq%d-%s-sh%d', containing the sequence number, the roothash, and
         the share number."""
     def get_servermap():
-        """Return dict mapping server peerid to a set of share numbers."""
+        """Return dict mapping IServer instance to a set of share numbers."""
     def get_timings():
         """Return dict of timing information, mapping name to seconds. All
         times are floats:
index a51e5bae976decd33fd0cc81a4b11044ee032ac3..7ca8e4a5323cbeb32c11fec37018d961cb0fef81 100644 (file)
@@ -37,9 +37,9 @@ class UploadResultsRendererMixin(RateAndTimeMixin):
             if sharemap is None:
                 return "None"
             l = T.ul()
-            for shnum, peerids in sorted(sharemap.items()):
-                peerids = ', '.join([idlib.shortnodeid_b2a(i) for i in peerids])
-                l[T.li["%d -> placed on [%s]" % (shnum, peerids)]]
+            for shnum, servers in sorted(sharemap.items()):
+                server_names = ', '.join([s.get_name() for s in servers])
+                l[T.li["%d -> placed on [%s]" % (shnum, server_names)]]
             return l
         d.addCallback(_render)
         return d
@@ -51,13 +51,10 @@ class UploadResultsRendererMixin(RateAndTimeMixin):
             if servermap is None:
                 return "None"
             l = T.ul()
-            for peerid in sorted(servermap.keys()):
-                peerid_s = idlib.shortnodeid_b2a(peerid)
-                shares_s = ",".join(["#%d" % shnum
-                                     for shnum in servermap[peerid]])
-                l[T.li["[%s] got share%s: %s" % (peerid_s,
-                                                 plural(servermap[peerid]),
-                                                 shares_s)]]
+            for server, shnums in sorted(servermap.items()):
+                shares_s = ",".join(["#%d" % shnum for shnum in shnums])
+                l[T.li["[%s] got share%s: %s" % (server.get_name(),
+                                                 plural(shnums), shares_s)]]
             return l
         d.addCallback(_render)
         return d