/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/transport/smart.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-16 03:26:49 UTC
  • mto: This revision was merged to the branch mainline in revision 2020.
  • Revision ID: john@arbash-meinel.com-20060916032649-140a79a2134b1c0d
Update the client-side requests, so that we collapse nearby ranges, rather than requesting lots of small chunks

Show diffs side-by-side

added added

removed removed

Lines of Context:
720
720
            return
721
721
 
722
722
        offsets = list(offsets)
 
723
 
 
724
        sorted_offsets = sorted(offsets)
 
725
        # turn the list of offsets into a stack
 
726
        offset_stack = iter(offsets)
 
727
        cur_offset_and_size = offset_stack.next()
 
728
        coalesced = list(self._coalesce_offsets(sorted_offsets,
 
729
                               limit=self._max_readv_combine,
 
730
                               fudge_factor=self._bytes_to_read_before_seek))
 
731
 
 
732
 
723
733
        resp = self._client._call_with_upload(
724
734
            'readv',
725
735
            (self._remote_path(relpath),),
726
 
            self._serialise_offsets(offsets))
 
736
            self._serialise_offsets((c.start, c.length) for c in coalesced))
727
737
 
728
738
        if resp[0] != 'readv':
 
739
            # This should raise an exception
729
740
            self._translate_error(resp)
730
 
        else:
731
 
            data = self._client._recv_bulk()
732
 
            cur_pos = 0
733
 
            for start, length in offsets:
734
 
                next_pos = cur_pos + length
735
 
                if len(data) < next_pos:
736
 
                    raise errors.ShortReadvError(relpath, start, length,
737
 
                                                 actual=len(data)-cur_pos)
738
 
                cur_data = data[cur_pos:next_pos]
739
 
                cur_pos = next_pos
740
 
                yield start, cur_data
 
741
            return
 
742
 
 
743
        data = self._client._recv_bulk()
 
744
        # Cache the results, but only until they have been fulfilled
 
745
        data_map = {}
 
746
        for c_offset in coalesced:
 
747
            if len(data) < c_offset.length:
 
748
                raise errors.ShortReadvError(relpath, c_offset.start,
 
749
                            c_offset.length, actual=len(data))
 
750
            for suboffset, subsize in c_offset.ranges:
 
751
                key = (c_offset.start+suboffset, subsize)
 
752
                data_map[key] = data[suboffset:suboffset+subsize]
 
753
            data = data[c_offset.length:]
 
754
 
 
755
            # Now that we've read some data, see if we can yield anything back
 
756
            while cur_offset_and_size in data_map:
 
757
                this_data = data_map.pop(cur_offset_and_size)
 
758
                yield cur_offset_and_size[0], this_data
 
759
                cur_offset_and_size = offset_stack.next()
741
760
 
742
761
    def rename(self, rel_from, rel_to):
743
762
        self._call('rename',