2 from zope.interface import implements
3 from allmydata.interfaces import ICheckResults, ICheckAndRepairResults, \
4 IDeepCheckResults, IDeepCheckAndRepairResults, IURI, IDisplayableServer
5 from allmydata.util import base32, dictutil
8 implements(ICheckResults)
10 def __init__(self, uri, storage_index,
11 healthy, recoverable, needs_rebalancing,
12 count_shares_needed, count_shares_expected,
13 count_shares_good, count_good_share_hosts,
14 count_recoverable_versions, count_unrecoverable_versions,
15 servers_responding, sharemap,
16 count_wrong_shares, list_corrupt_shares, count_corrupt_shares,
17 list_incompatible_shares, count_incompatible_shares,
18 summary, report, share_problems, servermap):
19 assert IURI.providedBy(uri), uri
21 self._storage_index = storage_index
23 self._healthy = bool(healthy)
30 summary = "not healthy"
31 self._recoverable = recoverable
32 if not self._recoverable:
33 assert not self._healthy
34 self._needs_rebalancing_p = bool(needs_rebalancing)
36 self._count_shares_needed = count_shares_needed
37 self._count_shares_expected = count_shares_expected
38 self._count_shares_good = count_shares_good
39 self._count_good_share_hosts = count_good_share_hosts
40 self._count_recoverable_versions = count_recoverable_versions
41 self._count_unrecoverable_versions = count_unrecoverable_versions
42 for s in servers_responding:
43 assert isinstance(s, str), s
44 self._servers_responding = servers_responding
45 for shnum, servers in sharemap.items():
46 for server in servers:
47 assert IDisplayableServer.providedBy(server), server
48 self._sharemap = sharemap
49 self._count_wrong_shares = count_wrong_shares
50 for (serverid, SI, shnum) in list_corrupt_shares:
51 assert isinstance(serverid, str), serverid
52 self._list_corrupt_shares = list_corrupt_shares
53 self._count_corrupt_shares = count_corrupt_shares
54 for (serverid, SI, shnum) in list_incompatible_shares:
55 assert isinstance(serverid, str), serverid
56 self._list_incompatible_shares = list_incompatible_shares
57 self._count_incompatible_shares = count_incompatible_shares
59 assert isinstance(summary, str) # should be a single string
60 self._summary = summary
61 assert not isinstance(report, str) # should be list of strings
64 from allmydata.mutable.servermap import ServerMap
65 assert isinstance(servermap, ServerMap), servermap
66 self._servermap = servermap # mutable only
67 self._share_problems = share_problems
69 def get_storage_index(self):
70 return self._storage_index
71 def get_storage_index_string(self):
72 return base32.b2a(self._storage_index)
78 def is_recoverable(self):
79 return self._recoverable
81 def needs_rebalancing(self):
82 return self._needs_rebalancing_p
84 def get_encoding_needed(self):
85 return self._count_shares_needed
86 def get_encoding_expected(self):
87 return self._count_shares_expected
89 def get_share_counter_good(self):
90 return self._count_shares_good
91 def get_share_counter_wrong(self):
92 return self._count_wrong_shares
94 def get_corrupt_shares(self):
95 return self._list_corrupt_shares
97 def get_incompatible_shares(self):
98 return self._list_incompatible_shares
100 def get_servers_responding(self):
101 return self._servers_responding
103 def get_host_counter_good_shares(self):
104 return self._count_good_share_hosts
106 def get_version_counter_recoverable(self):
107 return self._count_recoverable_versions
108 def get_version_counter_unrecoverable(self):
109 return self._count_unrecoverable_versions
111 def get_sharemap(self):
112 sharemap = dictutil.DictOfSets()
113 for shnum, servers in self._sharemap.items():
115 sharemap.add(shnum, s.get_serverid())
117 def get_new_sharemap(self):
118 # this one returns IServers, even when get_sharemap returns serverids
119 return self._sharemap
123 for shnum, servers in self._sharemap.items():
124 sharemap[shnum] = sorted([s.get_serverid() for s in servers])
125 d = {"count-shares-needed": self._count_shares_needed,
126 "count-shares-expected": self._count_shares_expected,
127 "count-shares-good": self._count_shares_good,
128 "count-good-share-hosts": self._count_good_share_hosts,
129 "count-recoverable-versions": self._count_recoverable_versions,
130 "count-unrecoverable-versions": self._count_unrecoverable_versions,
131 "servers-responding": self._servers_responding,
132 "sharemap": sharemap,
133 "count-wrong-shares": self._count_wrong_shares,
134 "list-corrupt-shares": self._list_corrupt_shares,
135 "count-corrupt-shares": self._count_corrupt_shares,
136 "list-incompatible-shares": self._list_incompatible_shares,
137 "count-incompatible-shares": self._count_incompatible_shares,
141 def get_summary(self):
143 def get_report(self):
145 def get_share_problems(self):
146 return self._share_problems
147 def get_servermap(self):
148 return self._servermap
150 class CheckAndRepairResults:
151 implements(ICheckAndRepairResults)
153 def __init__(self, storage_index):
154 self.storage_index = storage_index
155 self.repair_attempted = False
157 def get_storage_index(self):
158 return self.storage_index
159 def get_storage_index_string(self):
160 return base32.b2a(self.storage_index)
161 def get_repair_attempted(self):
162 return self.repair_attempted
163 def get_repair_successful(self):
164 if not self.repair_attempted:
166 return self.repair_successful
167 def get_pre_repair_results(self):
168 return self.pre_repair_results
169 def get_post_repair_results(self):
170 return self.post_repair_results
173 class DeepResultsBase:
175 def __init__(self, root_storage_index):
176 self.root_storage_index = root_storage_index
177 if root_storage_index is None:
178 self.root_storage_index_s = "<none>" # is this correct?
180 self.root_storage_index_s = base32.b2a(root_storage_index)
182 self.objects_checked = 0
183 self.objects_healthy = 0
184 self.objects_unhealthy = 0
185 self.objects_unrecoverable = 0
186 self.corrupt_shares = []
187 self.all_results = {}
188 self.all_results_by_storage_index = {}
191 def update_stats(self, new_stats):
192 self.stats.update(new_stats)
194 def get_root_storage_index_string(self):
195 return self.root_storage_index_s
197 def get_corrupt_shares(self):
198 return self.corrupt_shares
200 def get_all_results(self):
201 return self.all_results
203 def get_results_for_storage_index(self, storage_index):
204 return self.all_results_by_storage_index[storage_index]
210 class DeepCheckResults(DeepResultsBase):
211 implements(IDeepCheckResults)
213 def add_check(self, r, path):
215 return # non-distributed object, i.e. LIT file
217 assert isinstance(path, (list, tuple))
218 self.objects_checked += 1
220 self.objects_healthy += 1
222 self.objects_unhealthy += 1
223 if not r.is_recoverable():
224 self.objects_unrecoverable += 1
225 self.all_results[tuple(path)] = r
226 self.all_results_by_storage_index[r.get_storage_index()] = r
227 self.corrupt_shares.extend(r.get_corrupt_shares())
229 def get_counters(self):
230 return {"count-objects-checked": self.objects_checked,
231 "count-objects-healthy": self.objects_healthy,
232 "count-objects-unhealthy": self.objects_unhealthy,
233 "count-objects-unrecoverable": self.objects_unrecoverable,
234 "count-corrupt-shares": len(self.corrupt_shares),
238 class DeepCheckAndRepairResults(DeepResultsBase):
239 implements(IDeepCheckAndRepairResults)
241 def __init__(self, root_storage_index):
242 DeepResultsBase.__init__(self, root_storage_index)
243 self.objects_healthy_post_repair = 0
244 self.objects_unhealthy_post_repair = 0
245 self.objects_unrecoverable_post_repair = 0
246 self.repairs_attempted = 0
247 self.repairs_successful = 0
248 self.repairs_unsuccessful = 0
249 self.corrupt_shares_post_repair = []
251 def add_check_and_repair(self, r, path):
253 return # non-distributed object, i.e. LIT file
254 r = ICheckAndRepairResults(r)
255 assert isinstance(path, (list, tuple))
256 pre_repair = r.get_pre_repair_results()
257 post_repair = r.get_post_repair_results()
258 self.objects_checked += 1
259 if pre_repair.is_healthy():
260 self.objects_healthy += 1
262 self.objects_unhealthy += 1
263 if not pre_repair.is_recoverable():
264 self.objects_unrecoverable += 1
265 self.corrupt_shares.extend(pre_repair.get_corrupt_shares())
266 if r.get_repair_attempted():
267 self.repairs_attempted += 1
268 if r.get_repair_successful():
269 self.repairs_successful += 1
271 self.repairs_unsuccessful += 1
272 if post_repair.is_healthy():
273 self.objects_healthy_post_repair += 1
275 self.objects_unhealthy_post_repair += 1
276 if not post_repair.is_recoverable():
277 self.objects_unrecoverable_post_repair += 1
278 self.all_results[tuple(path)] = r
279 self.all_results_by_storage_index[r.get_storage_index()] = r
280 self.corrupt_shares_post_repair.extend(post_repair.get_corrupt_shares())
282 def get_counters(self):
283 return {"count-objects-checked": self.objects_checked,
284 "count-objects-healthy-pre-repair": self.objects_healthy,
285 "count-objects-unhealthy-pre-repair": self.objects_unhealthy,
286 "count-objects-unrecoverable-pre-repair": self.objects_unrecoverable,
287 "count-objects-healthy-post-repair": self.objects_healthy_post_repair,
288 "count-objects-unhealthy-post-repair": self.objects_unhealthy_post_repair,
289 "count-objects-unrecoverable-post-repair": self.objects_unrecoverable_post_repair,
290 "count-repairs-attempted": self.repairs_attempted,
291 "count-repairs-successful": self.repairs_successful,
292 "count-repairs-unsuccessful": self.repairs_unsuccessful,
293 "count-corrupt-shares-pre-repair": len(self.corrupt_shares),
294 "count-corrupt-shares-post-repair": len(self.corrupt_shares_post_repair),
297 def get_remaining_corrupt_shares(self):
298 return self.corrupt_shares_post_repair