From: Brian Warner Date: Tue, 22 May 2012 04:18:37 +0000 (-0700) Subject: change UploadResults to return IServers, update users to match X-Git-Url: https://git.rkrishnan.org/simplejson/components//%22file:/%22?a=commitdiff_plain;h=3a1c02cfdfd0d7ca09037c05b5e82dd3d402df40;p=tahoe-lafs%2Ftahoe-lafs.git change UploadResults to return IServers, update users to match This finally changes all callers of get_servermap()/get_sharemap() to accept IServers, and changes UploadResults to provide them. --- diff --git a/src/allmydata/immutable/filenode.py b/src/allmydata/immutable/filenode.py index e159be03..4afeeda3 100644 --- a/src/allmydata/immutable/filenode.py +++ b/src/allmydata/immutable/filenode.py @@ -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) diff --git a/src/allmydata/immutable/offloaded.py b/src/allmydata/immutable/offloaded.py index 428cb1ce..20a4fd7c 100644 --- a/src/allmydata/immutable/offloaded.py +++ b/src/allmydata/immutable/offloaded.py @@ -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() diff --git a/src/allmydata/immutable/upload.py b/src/allmydata/immutable/upload.py index c609d37f..ba2c53b9 100644 --- a/src/allmydata/immutable/upload.py +++ b/src/allmydata/immutable/upload.py @@ -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): diff --git a/src/allmydata/interfaces.py b/src/allmydata/interfaces.py index 8fb0aba7..42b0c4a7 100644 --- a/src/allmydata/interfaces.py +++ b/src/allmydata/interfaces.py @@ -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: diff --git a/src/allmydata/web/status.py b/src/allmydata/web/status.py index a51e5bae..7ca8e4a5 100644 --- a/src/allmydata/web/status.py +++ b/src/allmydata/web/status.py @@ -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