from zope.interface import implements
from allmydata.interfaces import ICheckResults, ICheckAndRepairResults, \
- IDeepCheckResults, IDeepCheckAndRepairResults, IURI
-from allmydata.util import base32
+ IDeepCheckResults, IDeepCheckAndRepairResults, IURI, IDisplayableServer
+from allmydata.util import base32, dictutil
class CheckResults:
implements(ICheckResults)
for s in servers_responding:
assert isinstance(s, str), s
self._servers_responding = servers_responding
- for shnum, serverids in sharemap.items():
- for serverid in serverids:
- assert isinstance(serverid, str), serverid
+ for shnum, servers in sharemap.items():
+ for server in servers:
+ assert IDisplayableServer.providedBy(server), server
self._sharemap = sharemap
self._count_wrong_shares = count_wrong_shares
for (serverid, SI, shnum) in list_corrupt_shares:
return self._count_unrecoverable_versions
def get_sharemap(self):
+ sharemap = dictutil.DictOfSets()
+ for shnum, servers in self._sharemap.items():
+ for s in servers:
+ sharemap.add(shnum, s.get_serverid())
+ return sharemap
+ def get_new_sharemap(self):
+ # this one returns IServers, even when get_sharemap returns serverids
return self._sharemap
def as_dict(self):
+ sharemap = {}
+ for shnum, servers in self._sharemap.items():
+ sharemap[shnum] = sorted([s.get_serverid() for s in servers])
d = {"count-shares-needed": self._count_shares_needed,
"count-shares-expected": self._count_shares_expected,
"count-shares-good": self._count_shares_good,
"count-recoverable-versions": self._count_recoverable_versions,
"count-unrecoverable-versions": self._count_unrecoverable_versions,
"servers-responding": self._servers_responding,
- "sharemap": self._sharemap,
+ "sharemap": sharemap,
"count-wrong-shares": self._count_wrong_shares,
"list-corrupt-shares": self._list_corrupt_shares,
"count-corrupt-shares": self._count_corrupt_shares,
def _format_results(self, results):
SI = self._verifycap.get_storage_index()
- verifiedshares = dictutil.DictOfSets() # {sharenum: set(serverid)}
+ verifiedshares = dictutil.DictOfSets() # {sharenum: set(server)}
servers = {} # {serverid: set(sharenums)}
corruptshare_locators = [] # (serverid, storageindex, sharenum)
incompatibleshare_locators = [] # (serverid, storageindex, sharenum)
server_id = server.get_serverid()
servers.setdefault(server_id, 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))
for sharenum in incompatible:
servers_responding = set(cr.get_servers_responding())
sm = DictOfSets()
assert isinstance(cr.get_sharemap(), DictOfSets)
- for shnum, serverids in cr.get_sharemap().items():
- for serverid in serverids:
- sm.add(shnum, serverid)
+ for shnum, servers in cr.get_new_sharemap().items():
+ for server in servers:
+ sm.add(shnum, server)
for shnum, servers in ur.get_sharemap().items():
- for s in servers:
- sm.add(shnum, s.get_serverid())
- servers_responding.add(s.get_serverid())
+ for server in servers:
+ sm.add(shnum, server)
+ servers_responding.add(server.get_serverid())
servers_responding = sorted(servers_responding)
good_hosts = len(reduce(set.union, sm.values(), set()))
from allmydata.uri import from_string
-from allmydata.util import base32, log
+from allmydata.util import base32, log, dictutil
from allmydata.check_results import CheckAndRepairResults, CheckResults
from allmydata.mutable.common import MODE_CHECK, MODE_WRITE, CorruptShareError
where=ft,
level=log.WEIRD, umid="EkK8QA")
- sharemap = {}
+ sharemap = dictutil.DictOfSets()
for verinfo in vmap:
for (shnum, server, timestamp) in vmap[verinfo]:
shareid = "%s-sh%d" % (smap.summarize_version(verinfo), shnum)
- if shareid not in sharemap:
- sharemap[shareid] = []
- sharemap[shareid].append(server.get_serverid())
+ sharemap.add(shareid, server)
servers_responding = [s.get_serverid() for s in
list(smap.get_reachable_servers())]
if healthy:
MDMF_VERSION
from allmydata.check_results import CheckResults, CheckAndRepairResults, \
DeepCheckResults, DeepCheckAndRepairResults
+from allmydata.storage_client import StubServer
from allmydata.mutable.layout import unpack_header
from allmydata.mutable.publish import MutableData
from allmydata.storage.mutable import MutableShareFile
def check(self, monitor, verify=False, add_lease=False):
nodeid = "\x00"*20
+ s = StubServer(nodeid)
r = CheckResults(self.my_uri, self.storage_index,
healthy=True, recoverable=True,
needs_rebalancing=False,
count_recoverable_versions=1,
count_unrecoverable_versions=0,
servers_responding=[nodeid],
- sharemap={1: [nodeid]},
+ sharemap={1: [s]},
count_wrong_shares=0,
list_corrupt_shares=[],
count_corrupt_shares=0,
def check(self, monitor, verify=False, add_lease=False):
nodeid = "\x00"*20
+ s = StubServer(nodeid)
r = CheckResults(self.my_uri, self.storage_index,
healthy=True, recoverable=True,
needs_rebalancing=False,
count_recoverable_versions=1,
count_unrecoverable_versions=0,
servers_responding=[nodeid],
- sharemap={"seq1-abcd-sh0": [nodeid]},
+ sharemap={"seq1-abcd-sh0": [s]},
count_wrong_shares=0,
list_corrupt_shares=[],
count_corrupt_shares=0,
def test_check(self):
c = self.create_fake_client()
+ sb = c.storage_broker
serverid_1 = "\x00"*20
serverid_f = "\xff"*20
u = uri.CHKFileURI("\x00"*16, "\x00"*32, 3, 10, 1234)
"count_recoverable_versions": 1,
"count_unrecoverable_versions": 0,
"servers_responding": [],
- "sharemap": {"shareid1": [serverid_1, serverid_f]},
+ "sharemap": {"shareid1": [sb.get_stub_server(serverid_1),
+ sb.get_stub_server(serverid_f)]},
"count_wrong_shares": 0,
"list_corrupt_shares": [],
"count_corrupt_shares": 0,
'count-unrecoverable-versions': 0,
'count-shares-needed': 3,
'sharemap': {"shareid1":
- ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
- "77777777777777777777777777777777"]},
+ ["77777777777777777777777777777777",
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]},
'count-recoverable-versions': 1,
'list-corrupt-shares':
[["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
def test_check_and_repair(self):
c = self.create_fake_client()
+ sb = c.storage_broker
serverid_1 = "\x00"*20
serverid_f = "\xff"*20
u = uri.CHKFileURI("\x00"*16, "\x00"*32, 3, 10, 1234)
"count_recoverable_versions": 1,
"count_unrecoverable_versions": 0,
"servers_responding": [],
- "sharemap": {"shareid1": [serverid_1, serverid_f]},
+ "sharemap": {"shareid1": [sb.get_stub_server(serverid_1),
+ sb.get_stub_server(serverid_f)]},
"count_wrong_shares": 0,
"list_corrupt_shares": [],
"count_corrupt_shares": 0,
"count_recoverable_versions": 1,
"count_unrecoverable_versions": 0,
"servers_responding": [],
- "sharemap": {"shareid1": [serverid_1, serverid_f]},
+ "sharemap": {"shareid1": [sb.get_stub_server(serverid_1),
+ sb.get_stub_server(serverid_f)]},
"count_wrong_shares": 0,
"count_corrupt_shares": 0,
"list_corrupt_shares": [],