From: Brian Warner Date: Thu, 17 Jul 2008 21:25:04 +0000 (-0700) Subject: dirnode deep-check: rearrange traversal approach, simplify code a bit X-Git-Url: https://git.rkrishnan.org/pf/content/en/footer/bar.txt?a=commitdiff_plain;h=acf3180facd2a30ed744797a57f44777a5aff449;p=tahoe-lafs%2Ftahoe-lafs.git dirnode deep-check: rearrange traversal approach, simplify code a bit --- diff --git a/src/allmydata/dirnode.py b/src/allmydata/dirnode.py index d8d3e93b..31066b53 100644 --- a/src/allmydata/dirnode.py +++ b/src/allmydata/dirnode.py @@ -535,47 +535,43 @@ class NewDirectoryNode: return d def deep_check(self, verify=False, repair=False): + # shallow-check each object first, then traverse children results = DeepCheckResults() found = set() - found.add(self.get_verifier()) - limiter = ConcurrencyLimiter(10) - d = self._add_check_from_node(self, results, limiter, verify, repair) - d.addCallback(lambda res: - self._add_deepcheck_from_dirnode(self, - found, results, limiter, - verify, repair)) + d = self._add_deepcheck_from_node(self, results, found, limiter, + verify, repair) d.addCallback(lambda res: results) return d - def _add_check_from_node(self, node, results, limiter, verify, repair): + def _add_deepcheck_from_node(self, node, results, found, limiter, + verify, repair): + verifier = node.get_verifier() + if verifier in found: + # avoid loops + return None + found.add(verifier) + d = limiter.add(node.check, verify, repair) d.addCallback(results.add_check) - return d - def _add_deepcheck_from_dirnode(self, node, found, results, limiter, - verify, repair): - d = limiter.add(node.list) - def _got_list(children): - dl = [] - for name, (child, metadata) in children.iteritems(): - verifier = child.get_verifier() - if verifier in found: - # avoid loops - continue - dl.append(self._add_check_from_node(child, - results, limiter, - verify, repair)) - if IDirectoryNode.providedBy(child): - dl.append(self._add_deepcheck_from_node(child, found, - results, limiter, - verify, repair)) - if dl: - return defer.DeferredList(dl) - d.addCallback(_got_list) + if IDirectoryNode.providedBy(node): + d.addCallback(lambda res: node.list()) + def _got_children(children): + dl = [] + for name, (child, metadata) in children.iteritems(): + d2 = self._add_deepcheck_from_node(child, + results, limiter, + verify, repair) + if d2: + dl.append(d1) + if dl: + return defer.DeferredList(dl) + d.addCallback(_got_children) return d + class DeepStats: def __init__(self): self.stats = {}