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.
This commit is contained in:
Brian Warner 2012-05-21 21:18:37 -07:00
parent 843739486a
commit 3a1c02cfdf
5 changed files with 25 additions and 29 deletions

View File

@ -115,12 +115,13 @@ class CiphertextFileNode:
prr = CheckResults(cr.uri, cr.storage_index) prr = CheckResults(cr.uri, cr.storage_index)
prr.data = copy.deepcopy(cr.data) prr.data = copy.deepcopy(cr.data)
servers_responding = set(prr.data['servers-responding'])
sm = prr.data['sharemap'] sm = prr.data['sharemap']
assert isinstance(sm, DictOfSets), sm assert isinstance(sm, DictOfSets), sm
sm.update(ur.get_sharemap()) for shnum, servers in ur.get_sharemap().items():
servers_responding = set(prr.data['servers-responding']) for s in servers:
for shnum, serverids in ur.get_sharemap().items(): sm.add(shnum, s.get_serverid())
servers_responding.update(serverids) servers_responding.add(s.get_serverid())
servers_responding = sorted(servers_responding) servers_responding = sorted(servers_responding)
prr.data['servers-responding'] = servers_responding prr.data['servers-responding'] = servers_responding
prr.data['count-shares-good'] = len(sm) prr.data['count-shares-good'] = len(sm)

View File

@ -216,8 +216,14 @@ class CHKUploadHelper(Referenceable, upload.CHKUploader):
hur.uri_extension_hash = v.uri_extension_hash hur.uri_extension_hash = v.uri_extension_hash
hur.ciphertext_fetched = self._fetcher.get_ciphertext_fetched() hur.ciphertext_fetched = self._fetcher.get_ciphertext_fetched()
hur.preexisting_shares = ur.get_preexisting_shares() hur.preexisting_shares = ur.get_preexisting_shares()
hur.sharemap = ur.get_sharemap() # hur.sharemap needs to be {shnum: set(serverid)}
hur.servermap = ur.get_servermap() 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.pushed_shares = ur.get_pushed_shares()
hur.file_size = ur.get_file_size() hur.file_size = ur.get_file_size()
hur.uri_extension_data = ur.get_uri_extension_data() hur.uri_extension_data = ur.get_uri_extension_data()

View File

@ -95,17 +95,9 @@ class UploadResults:
def get_pushed_shares(self): def get_pushed_shares(self):
return self._pushed_shares return self._pushed_shares
def get_sharemap(self): def get_sharemap(self):
# returns {shnum: set(serverid)} return self._sharemap
sharemap = {}
for shnum, servers in self._sharemap.items():
sharemap[shnum] = set([s.get_serverid() for s in servers])
return sharemap
def get_servermap(self): def get_servermap(self):
# returns {serverid: set(shnum)} return self._servermap
servermap = {}
for server, shnums in self._servermap.items():
servermap[server.get_serverid()] = set(shnums)
return servermap
def get_timings(self): def get_timings(self):
return self._timings return self._timings
def get_uri_extension_data(self): def get_uri_extension_data(self):

View File

@ -1952,14 +1952,14 @@ class IUploadResults(Interface):
def get_pushed_shares(): def get_pushed_shares():
"""Return the number of shares that were uploaded.""" """Return the number of shares that were uploaded."""
def get_sharemap(): def get_sharemap():
"""Return a dict mapping share identifier to set of serverids (binary """Return a dict mapping share identifier to set of IServer
strings). This indicates which servers were given which shares. For instances. This indicates which servers were given which shares. For
immutable files, the shareid is an integer (the share number, from 0 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 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 'seq%d-%s-sh%d', containing the sequence number, the roothash, and
the share number.""" the share number."""
def get_servermap(): 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(): def get_timings():
"""Return dict of timing information, mapping name to seconds. All """Return dict of timing information, mapping name to seconds. All
times are floats: times are floats:

View File

@ -37,9 +37,9 @@ class UploadResultsRendererMixin(RateAndTimeMixin):
if sharemap is None: if sharemap is None:
return "None" return "None"
l = T.ul() l = T.ul()
for shnum, peerids in sorted(sharemap.items()): for shnum, servers in sorted(sharemap.items()):
peerids = ', '.join([idlib.shortnodeid_b2a(i) for i in peerids]) server_names = ', '.join([s.get_name() for s in servers])
l[T.li["%d -> placed on [%s]" % (shnum, peerids)]] l[T.li["%d -> placed on [%s]" % (shnum, server_names)]]
return l return l
d.addCallback(_render) d.addCallback(_render)
return d return d
@ -51,13 +51,10 @@ class UploadResultsRendererMixin(RateAndTimeMixin):
if servermap is None: if servermap is None:
return "None" return "None"
l = T.ul() l = T.ul()
for peerid in sorted(servermap.keys()): for server, shnums in sorted(servermap.items()):
peerid_s = idlib.shortnodeid_b2a(peerid) shares_s = ",".join(["#%d" % shnum for shnum in shnums])
shares_s = ",".join(["#%d" % shnum l[T.li["[%s] got share%s: %s" % (server.get_name(),
for shnum in servermap[peerid]]) plural(shnums), shares_s)]]
l[T.li["[%s] got share%s: %s" % (peerid_s,
plural(servermap[peerid]),
shares_s)]]
return l return l
d.addCallback(_render) d.addCallback(_render)
return d return d