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 assert IURI.providedBy(uri), uri
13 self.storage_index = storage_index
18 def set_healthy(self, healthy):
19 self.healthy = bool(healthy)
21 assert (not hasattr(self, 'recoverable')) or self.recoverable, hasattr(self, 'recoverable') and self.recoverable
22 self.recoverable = True
23 self.summary = "healthy"
25 self.summary = "not healthy"
26 def set_recoverable(self, recoverable):
27 self.recoverable = recoverable
28 if not self.recoverable:
29 assert (not hasattr(self, 'healthy')) or not self.healthy
31 def set_needs_rebalancing(self, needs_rebalancing):
32 self.needs_rebalancing_p = bool(needs_rebalancing)
34 count_shares_needed, count_shares_expected,
35 count_shares_good, count_good_share_hosts,
36 count_recoverable_versions, count_unrecoverable_versions,
37 servers_responding, sharemap,
38 count_wrong_shares, list_corrupt_shares, count_corrupt_shares,
39 list_incompatible_shares, count_incompatible_shares):
40 data = {"count-shares-needed": count_shares_needed,
41 "count-shares-expected": count_shares_expected,
42 "count-shares-good": count_shares_good,
43 "count-good-share-hosts": count_good_share_hosts,
44 "count-recoverable-versions": count_recoverable_versions,
45 "count-unrecoverable-versions": count_unrecoverable_versions,
46 "servers-responding": servers_responding,
48 "count-wrong-shares": count_wrong_shares,
49 "list-corrupt-shares": list_corrupt_shares,
50 "count-corrupt-shares": count_corrupt_shares,
51 "list-incompatible-shares": list_incompatible_shares,
52 "count-incompatible-shares": count_incompatible_shares,
55 def set_summary(self, summary):
56 assert isinstance(summary, str) # should be a single string
57 self.summary = summary
58 def set_report(self, report):
59 assert not isinstance(report, str) # should be list of strings
62 def set_servermap(self, smap):
67 def get_storage_index(self):
68 return self.storage_index
69 def get_storage_index_string(self):
70 return base32.b2a(self.storage_index)
76 def is_recoverable(self):
77 return self.recoverable
79 def needs_rebalancing(self):
80 return self.needs_rebalancing_p
84 def get_summary(self):
88 def get_servermap(self):
91 class CheckAndRepairResults:
92 implements(ICheckAndRepairResults)
94 def __init__(self, storage_index):
95 self.storage_index = storage_index
96 self.repair_attempted = False
98 def get_storage_index(self):
99 return self.storage_index
100 def get_storage_index_string(self):
101 return base32.b2a(self.storage_index)
102 def get_repair_attempted(self):
103 return self.repair_attempted
104 def get_repair_successful(self):
105 if not self.repair_attempted:
107 return self.repair_successful
108 def get_pre_repair_results(self):
109 return self.pre_repair_results
110 def get_post_repair_results(self):
111 return self.post_repair_results
114 class DeepResultsBase:
116 def __init__(self, root_storage_index):
117 self.root_storage_index = root_storage_index
118 if root_storage_index is None:
119 self.root_storage_index_s = "<none>" # is this correct?
121 self.root_storage_index_s = base32.b2a(root_storage_index)
123 self.objects_checked = 0
124 self.objects_healthy = 0
125 self.objects_unhealthy = 0
126 self.objects_unrecoverable = 0
127 self.corrupt_shares = []
128 self.all_results = {}
129 self.all_results_by_storage_index = {}
132 def update_stats(self, new_stats):
133 self.stats.update(new_stats)
135 def get_root_storage_index_string(self):
136 return self.root_storage_index_s
138 def get_corrupt_shares(self):
139 return self.corrupt_shares
141 def get_all_results(self):
142 return self.all_results
144 def get_results_for_storage_index(self, storage_index):
145 return self.all_results_by_storage_index[storage_index]
151 class DeepCheckResults(DeepResultsBase):
152 implements(IDeepCheckResults)
154 def add_check(self, r, path):
156 return # non-distributed object, i.e. LIT file
158 assert isinstance(path, (list, tuple))
159 self.objects_checked += 1
161 self.objects_healthy += 1
163 self.objects_unhealthy += 1
164 if not r.is_recoverable():
165 self.objects_unrecoverable += 1
166 self.all_results[tuple(path)] = r
167 self.all_results_by_storage_index[r.get_storage_index()] = r
168 self.corrupt_shares.extend(r.get_data()["list-corrupt-shares"])
170 def get_counters(self):
171 return {"count-objects-checked": self.objects_checked,
172 "count-objects-healthy": self.objects_healthy,
173 "count-objects-unhealthy": self.objects_unhealthy,
174 "count-objects-unrecoverable": self.objects_unrecoverable,
175 "count-corrupt-shares": len(self.corrupt_shares),
179 class DeepCheckAndRepairResults(DeepResultsBase):
180 implements(IDeepCheckAndRepairResults)
182 def __init__(self, root_storage_index):
183 DeepResultsBase.__init__(self, root_storage_index)
184 self.objects_healthy_post_repair = 0
185 self.objects_unhealthy_post_repair = 0
186 self.objects_unrecoverable_post_repair = 0
187 self.repairs_attempted = 0
188 self.repairs_successful = 0
189 self.repairs_unsuccessful = 0
190 self.corrupt_shares_post_repair = []
192 def add_check_and_repair(self, r, path):
194 return # non-distributed object, i.e. LIT file
195 r = ICheckAndRepairResults(r)
196 assert isinstance(path, (list, tuple))
197 pre_repair = r.get_pre_repair_results()
198 post_repair = r.get_post_repair_results()
199 self.objects_checked += 1
200 if pre_repair.is_healthy():
201 self.objects_healthy += 1
203 self.objects_unhealthy += 1
204 if not pre_repair.is_recoverable():
205 self.objects_unrecoverable += 1
206 self.corrupt_shares.extend(pre_repair.get_data()["list-corrupt-shares"])
207 if r.get_repair_attempted():
208 self.repairs_attempted += 1
209 if r.get_repair_successful():
210 self.repairs_successful += 1
212 self.repairs_unsuccessful += 1
213 if post_repair.is_healthy():
214 self.objects_healthy_post_repair += 1
216 self.objects_unhealthy_post_repair += 1
217 if not post_repair.is_recoverable():
218 self.objects_unrecoverable_post_repair += 1
219 self.all_results[tuple(path)] = r
220 self.all_results_by_storage_index[r.get_storage_index()] = r
221 self.corrupt_shares_post_repair.extend(post_repair.get_data()["list-corrupt-shares"])
223 def get_counters(self):
224 return {"count-objects-checked": self.objects_checked,
225 "count-objects-healthy-pre-repair": self.objects_healthy,
226 "count-objects-unhealthy-pre-repair": self.objects_unhealthy,
227 "count-objects-unrecoverable-pre-repair": self.objects_unrecoverable,
228 "count-objects-healthy-post-repair": self.objects_healthy_post_repair,
229 "count-objects-unhealthy-post-repair": self.objects_unhealthy_post_repair,
230 "count-objects-unrecoverable-post-repair": self.objects_unrecoverable_post_repair,
231 "count-repairs-attempted": self.repairs_attempted,
232 "count-repairs-successful": self.repairs_successful,
233 "count-repairs-unsuccessful": self.repairs_unsuccessful,
234 "count-corrupt-shares-pre-repair": len(self.corrupt_shares),
235 "count-corrupt-shares-post-repair": len(self.corrupt_shares_post_repair),
238 def get_remaining_corrupt_shares(self):
239 return self.corrupt_shares_post_repair