contrib/dirstatenonnormalcheck.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Fri, 23 Jun 2017 13:49:34 +0200
changeset 33207 895ecec31c70
parent 29100 3fd94f603190
child 34674 60927b19ed65
permissions -rw-r--r--
revlog: add an experimental option to mitigated delta issues (issue5480) The general delta heuristic to select a delta do not scale with the number of branch. The delta base is frequently too far away to be able to reuse a chain according to the "distance" criteria. This leads to insertion of larger delta (or even full text) that themselves push the bases for the next delta further away leading to more large deltas and full texts. This full text and frequent recomputation throw Mercurial performance in disarray. For example of a slightly large repository 280 000 files (2 150 000 versions) 430 000 changesets (10 000 topological heads) Number below compares repository with and without the distance criteria: manifest size: with: 21.4 GB without: 0.3 GB store size: with: 28.7 GB without 7.4 GB bundle last 15 00 revisions: with: 800 seconds 971 MB without: 50 seconds 73 MB unbundle time (of the last 15K revisions): with: 1150 seconds (~19 minutes) without: 35 seconds Similar issues has been observed in other repositories. Adding a new option or "feature" on stable is uncommon. However, given that this issues is making Mercurial practically unusable, I'm exceptionally targeting this patch for stable. What is actually needed is a full rework of the delta building and reading logic. However, that will be a longer process and churn not suitable for stable. In the meantime, we introduces a quick and dirty mitigation of this in the 'experimental' config space. The new option introduces a way to set the maximum amount of memory usable to store a diff in memory. This extend the ability for Mercurial to create chains without removing all safe guard regarding memory access. The option should be phased out when core has a more proper solution available. Setting the limit to '0' remove all limits, setting it to '-1' use the default limit (textsize x 4).
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     1
# dirstatenonnormalcheck.py - extension to check the consistency of the
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     2
# dirstate's non-normal map
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     3
#
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     4
# For most operations on dirstate, this extensions checks that the nonnormalset
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     5
# contains the right entries.
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     6
# It compares the nonnormal file to a nonnormalset built from the map of all
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     7
# the files in the dirstate to check that they contain the same files.
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     8
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
     9
from __future__ import absolute_import
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    10
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    11
from mercurial import (
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    12
    dirstate,
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    13
    extensions,
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    14
)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    15
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    16
def nonnormalentries(dmap):
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    17
    """Compute nonnormal entries from dirstate's dmap"""
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    18
    res = set()
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    19
    for f, e in dmap.iteritems():
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    20
        if e[0] != 'n' or e[3] == -1:
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    21
            res.add(f)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    22
    return res
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    23
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    24
def checkconsistency(ui, orig, dmap, _nonnormalset, label):
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    25
    """Compute nonnormalset from dmap, check that it matches _nonnormalset"""
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    26
    nonnormalcomputedmap = nonnormalentries(dmap)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    27
    if _nonnormalset != nonnormalcomputedmap:
29100
3fd94f603190 devel: use the 'config' argument for the dirstate normalisation develwarn
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27637
diff changeset
    28
        ui.develwarn("%s call to %s\n" % (label, orig), config='dirstate')
3fd94f603190 devel: use the 'config' argument for the dirstate normalisation develwarn
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27637
diff changeset
    29
        ui.develwarn("inconsistency in nonnormalset\n", config='dirstate')
3fd94f603190 devel: use the 'config' argument for the dirstate normalisation develwarn
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27637
diff changeset
    30
        ui.develwarn("[nonnormalset] %s\n" % _nonnormalset, config='dirstate')
3fd94f603190 devel: use the 'config' argument for the dirstate normalisation develwarn
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 27637
diff changeset
    31
        ui.develwarn("[map] %s\n" % nonnormalcomputedmap, config='dirstate')
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    32
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    33
def _checkdirstate(orig, self, arg):
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    34
    """Check nonnormal set consistency before and after the call to orig"""
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    35
    checkconsistency(self._ui, orig, self._map, self._nonnormalset, "before")
27637
b502138f5faa cleanup: remove superfluous space after space after equals (python)
timeless <timeless@mozdev.org>
parents: 27591
diff changeset
    36
    r = orig(self, arg)
27591
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    37
    checkconsistency(self._ui, orig, self._map, self._nonnormalset, "after")
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    38
    return r
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    39
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    40
def extsetup(ui):
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    41
    """Wrap functions modifying dirstate to check nonnormalset consistency"""
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    42
    dirstatecl = dirstate.dirstate
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    43
    devel = ui.configbool('devel', 'all-warnings')
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    44
    paranoid = ui.configbool('experimental', 'nonnormalparanoidcheck')
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    45
    if devel:
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    46
        extensions.wrapfunction(dirstatecl, '_writedirstate', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    47
        if paranoid:
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    48
            # We don't do all these checks when paranoid is disable as it would
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    49
            # make the extension run very slowly on large repos
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    50
            extensions.wrapfunction(dirstatecl, 'normallookup', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    51
            extensions.wrapfunction(dirstatecl, 'otherparent', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    52
            extensions.wrapfunction(dirstatecl, 'normal', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    53
            extensions.wrapfunction(dirstatecl, 'write', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    54
            extensions.wrapfunction(dirstatecl, 'add', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    55
            extensions.wrapfunction(dirstatecl, 'remove', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    56
            extensions.wrapfunction(dirstatecl, 'merge', _checkdirstate)
127cc7f78475 dirstate: add test for non-normal set consistency
Laurent Charignon <lcharignon@fb.com>
parents:
diff changeset
    57
            extensions.wrapfunction(dirstatecl, 'drop', _checkdirstate)