245
246
raise NotImplementedError
248
def readv(self, relpath, offsets):
249
"""Get parts of the file at the given relative path.
251
:offsets: A list of (offset, size) tuples.
252
:return: A list or generator of (offset, data) tuples
254
def do_combined_read(combined_offsets):
256
for offset, size in combined_offsets:
258
mutter('readv coalesced %d reads.', len(combined_offsets))
259
offset = combined_offsets[0][0]
261
data = fp.read(total_size)
263
for offset, size in combined_offsets:
264
yield offset, data[pos:pos + size]
269
fp = self.get(relpath)
270
pending_offsets = deque(offsets)
271
combined_offsets = []
272
while len(pending_offsets):
273
offset, size = pending_offsets.popleft()
274
if not combined_offsets:
275
combined_offsets = [[offset, size]]
277
if (len (combined_offsets) < 50 and
278
combined_offsets[-1][0] + combined_offsets[-1][1] == offset):
280
combined_offsets.append([offset, size])
282
# incompatible, or over the threshold issue a read and yield
283
pending_offsets.appendleft((offset, size))
284
for result in do_combined_read(combined_offsets):
286
combined_offsets = []
287
# whatever is left is a single coalesced request
288
if len(combined_offsets):
289
for result in do_combined_read(combined_offsets):
247
292
def get_multi(self, relpaths, pb=None):
248
293
"""Get a list of file-like objects, one for each entry in relpaths.
630
675
# from running this test
680
class TransportLogger(object):
681
"""Adapt a transport to get clear logging data on api calls.
683
Feel free to extend to log whatever calls are of interest.
686
def __init__(self, adapted):
687
self._adapted = adapted
691
self._calls.append((name,))
692
return self._adapted.get(name)
694
def __getattr__(self, name):
695
"""Thunk all undefined access through to self._adapted."""
696
# raise AttributeError, name
697
return getattr(self._adapted, name)
699
def readv(self, name, offsets):
700
self._calls.append((name, offsets))
701
return self._adapted.readv(name, offsets)
635
704
# None is the default transport, for things with no url scheme