/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/index.py

  • Committer: John Arbash Meinel
  • Date: 2008-09-02 17:52:00 UTC
  • mto: This revision was merged to the branch mainline in revision 3679.
  • Revision ID: john@arbash-meinel.com-20080902175200-nge9qgk0gklkd5ew
Move the point at which we 'buffer_all' if we've read >50% of the index.

We were doing it as soon as you entered 'iter_entries', but often you may already have enough
info to return results. And for small mostly local ops, we don't need to buffer all.
(This happens mostly with moderate size indexes, where the first read of the header
is enough to give you the data you need, but happens to be >50% of the whole file.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
480
480
        if self._size is None and self._nodes is None:
481
481
            self._buffer_all()
482
482
 
483
 
        if self._nodes is None and self._bytes_read * 2 >= self._size:
484
 
            # We've already read more than 50% of the file, go ahead and buffer
485
 
            # the whole thing
486
 
            self._buffer_all()
487
 
 
488
483
        # We fit about 20 keys per minimum-read (4K), so if we are looking for
489
484
        # more than 1/20th of the index its likely (assuming homogenous key
490
485
        # spread) that we'll read the entire index. If we're going to do that,
714
709
            if length > 0:
715
710
                readv_ranges.append((location, length))
716
711
        self._read_and_parse(readv_ranges)
 
712
        if self._nodes is not None:
 
713
            # The _read_and_parse triggered a _buffer_all, grab the data and
 
714
            # return it
 
715
            for location, key in pending_references:
 
716
                value, refs = self._nodes[key]
 
717
                result.append(((location, key), (self, key, value, refs)))
 
718
            return result
717
719
        for location, key in pending_references:
718
720
            # answer key references we had to look-up-late.
719
 
            index = self._parsed_key_index(key)
720
721
            value, refs = self._bisect_nodes[key]
721
722
            result.append(((location, key), (self, key,
722
723
                value, self._resolve_references(refs))))
992
993
 
993
994
        :param readv_ranges: A prepared readv range list.
994
995
        """
995
 
        if readv_ranges:
996
 
            readv_data = self._transport.readv(self._name, readv_ranges, True,
997
 
                self._size)
998
 
            # parse
999
 
            for offset, data in readv_data:
1000
 
                self._bytes_read += len(data)
1001
 
                if offset == 0 and len(data) == self._size:
1002
 
                    # We read the whole range, most likely because the
1003
 
                    # Transport upcast our readv ranges into one long request
1004
 
                    # for enough total data to grab the whole index.
1005
 
                    self._buffer_all(StringIO(data))
1006
 
                    return
1007
 
                if self._bisect_nodes is None:
1008
 
                    # this must be the start
1009
 
                    if not (offset == 0):
1010
 
                        raise AssertionError()
1011
 
                    offset, data = self._parse_header_from_bytes(data)
1012
 
                # print readv_ranges, "[%d:%d]" % (offset, offset + len(data))
1013
 
                self._parse_region(offset, data)
 
996
        if not readv_ranges:
 
997
            return
 
998
        if self._nodes is None and self._bytes_read * 2 >= self._size:
 
999
            # We've already read more than 50% of the file and we are about to
 
1000
            # request more data, just _buffer_all() and be done
 
1001
            self._buffer_all()
 
1002
            return
 
1003
 
 
1004
        readv_data = self._transport.readv(self._name, readv_ranges, True,
 
1005
            self._size)
 
1006
        # parse
 
1007
        for offset, data in readv_data:
 
1008
            self._bytes_read += len(data)
 
1009
            if offset == 0 and len(data) == self._size:
 
1010
                # We read the whole range, most likely because the
 
1011
                # Transport upcast our readv ranges into one long request
 
1012
                # for enough total data to grab the whole index.
 
1013
                self._buffer_all(StringIO(data))
 
1014
                return
 
1015
            if self._bisect_nodes is None:
 
1016
                # this must be the start
 
1017
                if not (offset == 0):
 
1018
                    raise AssertionError()
 
1019
                offset, data = self._parse_header_from_bytes(data)
 
1020
            # print readv_ranges, "[%d:%d]" % (offset, offset + len(data))
 
1021
            self._parse_region(offset, data)
1014
1022
 
1015
1023
    def _signature(self):
1016
1024
        """The file signature for this index type."""