/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/btree_index.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-21 02:47:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4187.
  • Revision ID: john@arbash-meinel.com-20090321024706-drh9950i56vb484i
Restore the ability to spill, but prepare a flag to disable it.

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
        # Indicate it hasn't been built yet
141
141
        self._nodes_by_key = None
142
142
        self._optimize_for_size = False
 
143
        self._combine_spilled_indices = True
143
144
 
144
145
    def add_node(self, key, value, references=()):
145
146
        """Add a node to the index.
180
181
        combine mem with the first and second indexes, creating a new one of
181
182
        size 4x. On the fifth create a single new one, etc.
182
183
        """
183
 
        (new_backing_file,
184
 
         size) = self._write_nodes(self._iter_mem_nodes(), allow_optimize=False)
 
184
        iterators_to_combine = [self._iter_mem_nodes()]
 
185
        pos = -1
 
186
        for pos, backing in enumerate(self._backing_indices):
 
187
            if backing is None:
 
188
                pos -= 1
 
189
                break
 
190
            iterators_to_combine.append(backing.iter_all_entries())
 
191
        backing_pos = pos + 1
 
192
        new_backing_file, size = \
 
193
            self._write_nodes(self._iter_smallest(iterators_to_combine),
 
194
                              allow_optimize=False)
185
195
        dir_path, base_name = osutils.split(new_backing_file.name)
186
196
        # Note: The transport here isn't strictly needed, because we will use
187
197
        #       direct access to the new_backing._file object
189
199
                                      base_name, size)
190
200
        # GC will clean up the file
191
201
        new_backing._file = new_backing_file
192
 
        self._backing_indices.append(new_backing)
 
202
        if len(self._backing_indices) == backing_pos:
 
203
            self._backing_indices.append(None)
 
204
        self._backing_indices[backing_pos] = new_backing
 
205
        for pos in range(backing_pos):
 
206
            self._backing_indices[pos] = None
193
207
        self._keys = set()
194
208
        self._nodes = {}
195
209
        self._nodes_by_key = None