315
312
limit=self._max_readv_combine,
316
313
fudge_factor=self._bytes_to_read_before_seek))
318
# now that we've coallesced things, avoid making enormous requests
323
if c.length + cur_len > self._max_readv_bytes:
324
requests.append(cur_request)
328
cur_request.append(c)
331
requests.append(cur_request)
332
if 'hpss' in debug.debug_flags:
333
trace.mutter('%s.readv %s offsets => %s coalesced'
334
' => %s requests (%s)',
335
self.__class__.__name__, len(offsets), len(coalesced),
336
len(requests), sum(map(len, requests)))
337
# Cache the results, but only until they have been fulfilled
339
# turn the list of offsets into a single stack to iterate
316
result = self._client.call_with_body_readv_array(
317
('readv', self._remote_path(relpath),),
318
[(c.start, c.length) for c in coalesced])
319
resp, response_handler = result
320
except errors.ErrorFromSmartServer, err:
321
self._translate_error(err)
323
if resp[0] != 'readv':
324
# This should raise an exception
325
response_handler.cancel_read_body()
326
raise errors.UnexpectedSmartServerResponse(resp)
328
return self._handle_response(offsets, coalesced, response_handler)
330
def _handle_response(self, offsets, coalesced, response_handler):
331
# turn the list of offsets into a stack
340
332
offset_stack = iter(offsets)
341
# using a list so it can be modified when passing down and coming back
342
next_offset = [offset_stack.next()]
343
for cur_request in requests:
345
result = self._client.call_with_body_readv_array(
346
('readv', self._remote_path(relpath),),
347
[(c.start, c.length) for c in cur_request])
348
resp, response_handler = result
349
except errors.ErrorFromSmartServer, err:
350
self._translate_error(err)
352
if resp[0] != 'readv':
353
# This should raise an exception
354
response_handler.cancel_read_body()
355
raise errors.UnexpectedSmartServerResponse(resp)
357
for res in self._handle_response(offset_stack, cur_request,
363
def _handle_response(self, offset_stack, coalesced, response_handler,
364
data_map, next_offset):
365
cur_offset_and_size = next_offset[0]
333
cur_offset_and_size = offset_stack.next()
366
334
# FIXME: this should know how many bytes are needed, for clarity.
367
335
data = response_handler.read_body_bytes()
336
# Cache the results, but only until they have been fulfilled
369
339
for c_offset in coalesced:
370
340
if len(data) < c_offset.length: