~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/chk_map.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
_INTERESTING_NEW_SIZE = 50
91
91
# If a ChildNode shrinks by more than this amount, we check for a remap
92
92
_INTERESTING_SHRINKAGE_LIMIT = 20
 
93
# If we delete more than this many nodes applying a delta, we check for a remap
 
94
_INTERESTING_DELETES_LIMIT = 5
93
95
 
94
96
 
95
97
def _search_key_plain(key):
133
135
            into the map; if old_key is not None, then the old mapping
134
136
            of old_key is removed.
135
137
        """
136
 
        has_deletes = False
 
138
        delete_count = 0
137
139
        # Check preconditions first.
138
140
        as_st = StaticTuple.from_sequence
139
141
        new_items = set([as_st(key) for (old, key, value) in delta
146
148
        for old, new, value in delta:
147
149
            if old is not None and old != new:
148
150
                self.unmap(old, check_remap=False)
149
 
                has_deletes = True
 
151
                delete_count += 1
150
152
        for old, new, value in delta:
151
153
            if new is not None:
152
154
                self.map(new, value)
153
 
        if has_deletes:
 
155
        if delete_count > _INTERESTING_DELETES_LIMIT:
 
156
            trace.mutter("checking remap as %d deletions", delete_count)
154
157
            self._check_remap()
155
158
        return self._save()
156
159
 
570
573
        """Check if nodes can be collapsed."""
571
574
        self._ensure_root()
572
575
        if type(self._root_node) is InternalNode:
573
 
            self._root_node = self._root_node._check_remap(self._store)
 
576
            self._root_node._check_remap(self._store)
574
577
 
575
578
    def _save(self):
576
579
        """Save the map completely.
689
692
        the key/value pairs.
690
693
    """
691
694
 
692
 
    __slots__ = ('_common_serialised_prefix',)
 
695
    __slots__ = ('_common_serialised_prefix', '_serialise_key')
693
696
 
694
697
    def __init__(self, search_key_func=None):
695
698
        Node.__init__(self)
696
699
        # All of the keys in this leaf node share this common prefix
697
700
        self._common_serialised_prefix = None
 
701
        self._serialise_key = '\x00'.join
698
702
        if search_key_func is None:
699
703
            self._search_key_func = _search_key_plain
700
704
        else:
884
888
                raise AssertionError('%r must be known' % self._search_prefix)
885
889
            return self._search_prefix, [("", self)]
886
890
 
887
 
    _serialise_key = '\x00'.join
888
 
 
889
891
    def serialise(self, store):
890
892
        """Serialise the LeafNode to store.
891
893
 
1724
1726
 
1725
1727
try:
1726
1728
    from bzrlib._chk_map_pyx import (
1727
 
        _bytes_to_text_key,
1728
1729
        _search_key_16,
1729
1730
        _search_key_255,
1730
1731
        _deserialise_leaf_node,
1733
1734
except ImportError, e:
1734
1735
    osutils.failed_to_load_extension(e)
1735
1736
    from bzrlib._chk_map_py import (
1736
 
        _bytes_to_text_key,
1737
1737
        _search_key_16,
1738
1738
        _search_key_255,
1739
1739
        _deserialise_leaf_node,