~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/btree_index.py

  • Committer: John Arbash Meinel
  • Date: 2008-10-09 20:54:50 UTC
  • mto: This revision was merged to the branch mainline in revision 3805.
  • Revision ID: john@arbash-meinel.com-20081009205450-z4k6rnvj5j1tqcmu
Fix the logic a bit, and add a bit more tweaking opportunities

Show diffs side-by-side

added added

removed removed

Lines of Context:
687
687
        # return node_indexes
688
688
 
689
689
        # TODO: This could be cached
690
 
        recommended_read = self._transport.recommended_page_size() / 4
 
690
        recommended_read = self._transport.recommended_page_size()
691
691
        recommended_pages = int(math.ceil(recommended_read /
692
692
                                          float(_PAGE_SIZE)))
 
693
        # Disable the algorithm
 
694
        # recommended_pages = 1
693
695
        if len(node_indexes) >= recommended_pages:
694
696
            # Don't add more, we are already requesting more than enough
695
697
            return node_indexes
705
707
        if self._root_node is not None:
706
708
            cached_nodes.add(0)
707
709
 
 
710
        # if len(cached_nodes) < 2: # We haven't read enough to justify expansion
 
711
        #     return node_indexes
 
712
 
708
713
        # If reading recommended_pages would read the rest of the index, just
709
714
        # do so.
710
715
        if max_page - len(cached_nodes) <= recommended_pages:
736
741
            #         if len(final_nodes) >= recommended_pages:
737
742
            #             break
738
743
        else:
739
 
            while len(final_nodes) < recommended_pages:
740
 
                for pos in sorted(final_nodes):
 
744
            new_tips = set(final_nodes)
 
745
            while len(final_nodes) < recommended_pages and new_tips:
 
746
                next_tips = set()
 
747
                for pos in sorted(new_tips):
741
748
                    if pos > 0:
742
749
                        previous = pos - 1
743
 
                        if previous not in cached_nodes:
 
750
                        if (previous not in cached_nodes
 
751
                            and previous not in final_nodes):
744
752
                            final_nodes.add(previous)
745
 
                    if pos < max_page:
746
 
                        after = pos + 1
747
 
                        if after not in cached_nodes:
 
753
                            next_tips.add(previous)
 
754
                    after = pos + 1
 
755
                    if after < max_page:
 
756
                        if (after not in cached_nodes
 
757
                            and after not in final_nodes):
748
758
                            final_nodes.add(after)
 
759
                            next_tips.add(previous)
749
760
                    # if len(final_nodes) > recommended_pages:
750
761
                    #     break
 
762
                new_tips = next_tips
751
763
 
752
764
        final_nodes = sorted(final_nodes)
753
 
        trace.note('\t\t\t\t%s', final_nodes)
 
765
        trace.note('\t\t%s', final_nodes)
754
766
        return final_nodes
755
767
 
756
768
    def _get_nodes(self, cache, node_indexes):
765
777
            except KeyError:
766
778
                needed.append(idx)
767
779
        if not needed:
 
780
            # trace.note('cached: %s\tnodes: %s', self._name[-14:], node_indexes)
768
781
            return found
769
782
        needed = self._expand_nodes(needed)
770
783
        found.update(self._cache_nodes(needed, cache))
1182
1195
                    self._size = len(start)
1183
1196
                    size = min(_PAGE_SIZE, self._size)
1184
1197
            else:
 
1198
                if offset > self._size:
 
1199
                    raise AssertionError('tried to read past the end'
 
1200
                                         ' of the file %s > %s'
 
1201
                                         % (offset, self._size))
1185
1202
                size = min(size, self._size - offset)
1186
1203
            ranges.append((offset, size))
1187
1204
        if not ranges: