2 from zope.interface import implements
3 from allmydata.interfaces import ICheckResults, ICheckAndRepairResults, \
4 IDeepCheckResults, IDeepCheckAndRepairResults, IURI
5 from allmydata.util import base32
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, serverids in sharemap.items():
46 for serverid in serverids:
47 assert isinstance(serverid, str), serverid
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 return self._sharemap
115 d = {"count-shares-needed": self._count_shares_needed,
116 "count-shares-expected": self._count_shares_expected,
117 "count-shares-good": self._count_shares_good,
118 "count-good-share-hosts": self._count_good_share_hosts,
119 "count-recoverable-versions": self._count_recoverable_versions,
120 "count-unrecoverable-versions": self._count_unrecoverable_versions,
121 "servers-responding": self._servers_responding,
122 "sharemap": self._sharemap,
123 "count-wrong-shares": self._count_wrong_shares,
124 "list-corrupt-shares": self._list_corrupt_shares,
125 "count-corrupt-shares": self._count_corrupt_shares,
126 "list-incompatible-shares": self._list_incompatible_shares,
127 "count-incompatible-shares": self._count_incompatible_shares,
131 def get_summary(self):
133 def get_report(self):
135 def get_share_problems(self):
136 return self._share_problems
137 def get_servermap(self):
138 return self._servermap
140 class CheckAndRepairResults:
141 implements(ICheckAndRepairResults)
143 def __init__(self, storage_index):
144 self.storage_index = storage_index
145 self.repair_attempted = False
147 def get_storage_index(self):
148 return self.storage_index
149 def get_storage_index_string(self):
150 return base32.b2a(self.storage_index)
151 def get_repair_attempted(self):
152 return self.repair_attempted
153 def get_repair_successful(self):
154 if not self.repair_attempted:
156 return self.repair_successful
157 def get_pre_repair_results(self):
158 return self.pre_repair_results
159 def get_post_repair_results(self):
160 return self.post_repair_results
163 class DeepResultsBase:
165 def __init__(self, root_storage_index):
166 self.root_storage_index = root_storage_index
167 if root_storage_index is None:
168 self.root_storage_index_s = "<none>" # is this correct?
170 self.root_storage_index_s = base32.b2a(root_storage_index)
172 self.objects_checked = 0
173 self.objects_healthy = 0
174 self.objects_unhealthy = 0
175 self.objects_unrecoverable = 0
176 self.corrupt_shares = []
177 self.all_results = {}
178 self.all_results_by_storage_index = {}
181 def update_stats(self, new_stats):
182 self.stats.update(new_stats)
184 def get_root_storage_index_string(self):
185 return self.root_storage_index_s
187 def get_corrupt_shares(self):
188 return self.corrupt_shares
190 def get_all_results(self):
191 return self.all_results
193 def get_results_for_storage_index(self, storage_index):
194 return self.all_results_by_storage_index[storage_index]
200 class DeepCheckResults(DeepResultsBase):
201 implements(IDeepCheckResults)
203 def add_check(self, r, path):
205 return # non-distributed object, i.e. LIT file
207 assert isinstance(path, (list, tuple))
208 self.objects_checked += 1
210 self.objects_healthy += 1
212 self.objects_unhealthy += 1
213 if not r.is_recoverable():
214 self.objects_unrecoverable += 1
215 self.all_results[tuple(path)] = r
216 self.all_results_by_storage_index[r.get_storage_index()] = r
217 self.corrupt_shares.extend(r.get_corrupt_shares())
219 def get_counters(self):
220 return {"count-objects-checked": self.objects_checked,
221 "count-objects-healthy": self.objects_healthy,
222 "count-objects-unhealthy": self.objects_unhealthy,
223 "count-objects-unrecoverable": self.objects_unrecoverable,
224 "count-corrupt-shares": len(self.corrupt_shares),
228 class DeepCheckAndRepairResults(DeepResultsBase):
229 implements(IDeepCheckAndRepairResults)
231 def __init__(self, root_storage_index):
232 DeepResultsBase.__init__(self, root_storage_index)
233 self.objects_healthy_post_repair = 0
234 self.objects_unhealthy_post_repair = 0
235 self.objects_unrecoverable_post_repair = 0
236 self.repairs_attempted = 0
237 self.repairs_successful = 0
238 self.repairs_unsuccessful = 0
239 self.corrupt_shares_post_repair = []
241 def add_check_and_repair(self, r, path):
243 return # non-distributed object, i.e. LIT file
244 r = ICheckAndRepairResults(r)
245 assert isinstance(path, (list, tuple))
246 pre_repair = r.get_pre_repair_results()
247 post_repair = r.get_post_repair_results()
248 self.objects_checked += 1
249 if pre_repair.is_healthy():
250 self.objects_healthy += 1
252 self.objects_unhealthy += 1
253 if not pre_repair.is_recoverable():
254 self.objects_unrecoverable += 1
255 self.corrupt_shares.extend(pre_repair.get_corrupt_shares())
256 if r.get_repair_attempted():
257 self.repairs_attempted += 1
258 if r.get_repair_successful():
259 self.repairs_successful += 1
261 self.repairs_unsuccessful += 1
262 if post_repair.is_healthy():
263 self.objects_healthy_post_repair += 1
265 self.objects_unhealthy_post_repair += 1
266 if not post_repair.is_recoverable():
267 self.objects_unrecoverable_post_repair += 1
268 self.all_results[tuple(path)] = r
269 self.all_results_by_storage_index[r.get_storage_index()] = r
270 self.corrupt_shares_post_repair.extend(post_repair.get_corrupt_shares())
272 def get_counters(self):
273 return {"count-objects-checked": self.objects_checked,
274 "count-objects-healthy-pre-repair": self.objects_healthy,
275 "count-objects-unhealthy-pre-repair": self.objects_unhealthy,
276 "count-objects-unrecoverable-pre-repair": self.objects_unrecoverable,
277 "count-objects-healthy-post-repair": self.objects_healthy_post_repair,
278 "count-objects-unhealthy-post-repair": self.objects_unhealthy_post_repair,
279 "count-objects-unrecoverable-post-repair": self.objects_unrecoverable_post_repair,
280 "count-repairs-attempted": self.repairs_attempted,
281 "count-repairs-successful": self.repairs_successful,
282 "count-repairs-unsuccessful": self.repairs_unsuccessful,
283 "count-corrupt-shares-pre-repair": len(self.corrupt_shares),
284 "count-corrupt-shares-post-repair": len(self.corrupt_shares_post_repair),
287 def get_remaining_corrupt_shares(self):
288 return self.corrupt_shares_post_repair