~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/btree_index.py

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 15:06:17 UTC
  • mto: This revision was merged to the branch mainline in revision 5836.
  • Revision ID: john@arbash-meinel.com-20110420150617-i41caxgemg32tq1r
Start adding tests that _worth_saving_limit works as expected.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""B+Tree indices"""
19
19
 
20
 
from __future__ import absolute_import
21
 
 
22
20
import cStringIO
23
21
 
24
22
from bzrlib.lazy_import import lazy_import
164
162
        :param references: An iterable of iterables of keys. Each is a
165
163
            reference to another key.
166
164
        :param value: The value to associate with the key. It may be any
167
 
            bytes as long as it does not contain \\0 or \\n.
 
165
            bytes as long as it does not contain \0 or \n.
168
166
        """
169
167
        # Ensure that 'key' is a StaticTuple
170
168
        key = static_tuple.StaticTuple.from_sequence(key).intern()
199
197
            new_backing_file, size = self._spill_mem_keys_without_combining()
200
198
        # Note: The transport here isn't strictly needed, because we will use
201
199
        #       direct access to the new_backing._file object
202
 
        new_backing = BTreeGraphIndex(transport.get_transport_from_path('.'),
 
200
        new_backing = BTreeGraphIndex(transport.get_transport('.'),
203
201
                                      '<temp>', size)
204
202
        # GC will clean up the file
205
203
        new_backing._file = new_backing_file
296
294
            flag when writing out. This is used by the _spill_mem_keys_to_disk
297
295
            functionality.
298
296
        """
299
 
        new_leaf = False
300
297
        if rows[-1].writer is None:
301
298
            # opening a new leaf chunk;
302
 
            new_leaf = True
303
299
            for pos, internal_row in enumerate(rows[:-1]):
304
300
                # flesh out any internal nodes that are needed to
305
301
                # preserve the height of the tree
324
320
                optimize_for_size=self._optimize_for_size)
325
321
            rows[-1].writer.write(_LEAF_FLAG)
326
322
        if rows[-1].writer.write(line):
327
 
            # if we failed to write, despite having an empty page to write to,
328
 
            # then line is too big. raising the error avoids infinite recursion
329
 
            # searching for a suitably large page that will not be found.
330
 
            if new_leaf:
331
 
                raise errors.BadIndexKey(string_key)
332
323
            # this key did not fit in the node:
333
324
            rows[-1].finish_node()
334
325
            key_line = string_key + "\n"