Mercurial > hg
comparison mercurial/revlog.py @ 39872:733db72f0f54
revlog: move revision verification out of verify
File revision verification is performing low-level checks of file
storage, namely that flags are appropriate and revision data can
be resolved.
Since these checks are somewhat revlog-specific and may not
be appropriate for alternate storage backends, this commit moves
those checks from verify.py to revlog.py.
Because we're now emitting warnings/errors that apply to specific
revisions, we taught the iverifyproblem interface to expose the
problematic node and to report this node in verify output. This
was necessary to prevent unwanted test changes.
After this change, revlog.verifyintegrity() and file verify code
in verify.py both iterate over revisions and resolve their fulltext.
But they do so in separate loops. (verify.py needs to resolve
fulltexts as part of calling renamed() - at least when using revlogs.)
This should add overhead.
But on the mozilla-unified repo:
$ hg verify
before: time: real 700.640 secs (user 585.520+0.000 sys 23.480+0.000)
after: time: real 682.380 secs (user 570.370+0.000 sys 22.240+0.000)
I'm not sure what's going on. Maybe avoiding the filelog attribute
proxies shaved off enough time to offset the losses? Maybe fulltext
resolution has less overhead than I thought?
I've left a comment indicating the potential for optimization. But
because it doesn't produce a performance regression on a large
repository, I'm not going to worry about it.
Differential Revision: https://phab.mercurial-scm.org/D4745
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 24 Sep 2018 11:27:47 -0700 |
parents | 14e500b58263 |
children | f8eb71f9e3bd |
comparison
equal
deleted
inserted
replaced
39871:01c0f01b562b | 39872:733db72f0f54 |
---|---|
27 bin, | 27 bin, |
28 hex, | 28 hex, |
29 nullhex, | 29 nullhex, |
30 nullid, | 30 nullid, |
31 nullrev, | 31 nullrev, |
32 short, | |
32 wdirfilenodeids, | 33 wdirfilenodeids, |
33 wdirhex, | 34 wdirhex, |
34 wdirid, | 35 wdirid, |
35 wdirrev, | 36 wdirrev, |
36 ) | 37 ) |
258 @interfaceutil.implementer(repository.iverifyproblem) | 259 @interfaceutil.implementer(repository.iverifyproblem) |
259 @attr.s(frozen=True) | 260 @attr.s(frozen=True) |
260 class revlogproblem(object): | 261 class revlogproblem(object): |
261 warning = attr.ib(default=None) | 262 warning = attr.ib(default=None) |
262 error = attr.ib(default=None) | 263 error = attr.ib(default=None) |
264 node = attr.ib(default=None) | |
263 | 265 |
264 # index v0: | 266 # index v0: |
265 # 4 bytes: offset | 267 # 4 bytes: offset |
266 # 4 bytes: compressed length | 268 # 4 bytes: compressed length |
267 # 4 bytes: base rev | 269 # 4 bytes: base rev |
2642 if version != state['expectedversion']: | 2644 if version != state['expectedversion']: |
2643 yield revlogproblem( | 2645 yield revlogproblem( |
2644 warning=_("warning: '%s' uses revlog format %d; expected %d") % | 2646 warning=_("warning: '%s' uses revlog format %d; expected %d") % |
2645 (self.indexfile, version, state['expectedversion'])) | 2647 (self.indexfile, version, state['expectedversion'])) |
2646 | 2648 |
2649 state['skipread'] = set() | |
2650 | |
2651 for rev in self: | |
2652 node = self.node(rev) | |
2653 | |
2654 # Verify contents. 4 cases to care about: | |
2655 # | |
2656 # common: the most common case | |
2657 # rename: with a rename | |
2658 # meta: file content starts with b'\1\n', the metadata | |
2659 # header defined in filelog.py, but without a rename | |
2660 # ext: content stored externally | |
2661 # | |
2662 # More formally, their differences are shown below: | |
2663 # | |
2664 # | common | rename | meta | ext | |
2665 # ------------------------------------------------------- | |
2666 # flags() | 0 | 0 | 0 | not 0 | |
2667 # renamed() | False | True | False | ? | |
2668 # rawtext[0:2]=='\1\n'| False | True | True | ? | |
2669 # | |
2670 # "rawtext" means the raw text stored in revlog data, which | |
2671 # could be retrieved by "revision(rev, raw=True)". "text" | |
2672 # mentioned below is "revision(rev, raw=False)". | |
2673 # | |
2674 # There are 3 different lengths stored physically: | |
2675 # 1. L1: rawsize, stored in revlog index | |
2676 # 2. L2: len(rawtext), stored in revlog data | |
2677 # 3. L3: len(text), stored in revlog data if flags==0, or | |
2678 # possibly somewhere else if flags!=0 | |
2679 # | |
2680 # L1 should be equal to L2. L3 could be different from them. | |
2681 # "text" may or may not affect commit hash depending on flag | |
2682 # processors (see revlog.addflagprocessor). | |
2683 # | |
2684 # | common | rename | meta | ext | |
2685 # ------------------------------------------------- | |
2686 # rawsize() | L1 | L1 | L1 | L1 | |
2687 # size() | L1 | L2-LM | L1(*) | L1 (?) | |
2688 # len(rawtext) | L2 | L2 | L2 | L2 | |
2689 # len(text) | L2 | L2 | L2 | L3 | |
2690 # len(read()) | L2 | L2-LM | L2-LM | L3 (?) | |
2691 # | |
2692 # LM: length of metadata, depending on rawtext | |
2693 # (*): not ideal, see comment in filelog.size | |
2694 # (?): could be "- len(meta)" if the resolved content has | |
2695 # rename metadata | |
2696 # | |
2697 # Checks needed to be done: | |
2698 # 1. length check: L1 == L2, in all cases. | |
2699 # 2. hash check: depending on flag processor, we may need to | |
2700 # use either "text" (external), or "rawtext" (in revlog). | |
2701 | |
2702 try: | |
2703 skipflags = state.get('skipflags', 0) | |
2704 if skipflags: | |
2705 skipflags &= self.flags(rev) | |
2706 | |
2707 if skipflags: | |
2708 state['skipread'].add(node) | |
2709 else: | |
2710 # Side-effect: read content and verify hash. | |
2711 self.revision(node) | |
2712 | |
2713 l1 = self.rawsize(rev) | |
2714 l2 = len(self.revision(node, raw=True)) | |
2715 | |
2716 if l1 != l2: | |
2717 yield revlogproblem( | |
2718 error=_('unpacked size is %d, %d expected') % (l2, l1), | |
2719 node=node) | |
2720 | |
2721 except error.CensoredNodeError: | |
2722 if state['erroroncensored']: | |
2723 yield revlogproblem(error=_('censored file data'), | |
2724 node=node) | |
2725 state['skipread'].add(node) | |
2726 except Exception as e: | |
2727 yield revlogproblem( | |
2728 error=_('unpacking %s: %s') % (short(node), e), | |
2729 node=node) | |
2730 state['skipread'].add(node) | |
2731 | |
2647 def storageinfo(self, exclusivefiles=False, sharedfiles=False, | 2732 def storageinfo(self, exclusivefiles=False, sharedfiles=False, |
2648 revisionscount=False, trackedsize=False, | 2733 revisionscount=False, trackedsize=False, |
2649 storedsize=False): | 2734 storedsize=False): |
2650 d = {} | 2735 d = {} |
2651 | 2736 |