523
523
def __init__(self, backing_vf):
524
"""Create a RecordingVersionedFileDsecorator decorating backing_vf.
524
"""Create a RecordingVersionedFilesDecorator decorating backing_vf.
526
526
:param backing_vf: The versioned file to answer all methods.
562
562
return self._backing_vf.keys()
565
class OrderingVersionedFilesDecorator(RecordingVersionedFilesDecorator):
566
"""A VF that records calls, and returns keys in specific order.
568
:ivar calls: A list of the calls made; can be reset at any time by
572
def __init__(self, backing_vf, key_priority):
573
"""Create a RecordingVersionedFilesDecorator decorating backing_vf.
575
:param backing_vf: The versioned file to answer all methods.
576
:param key_priority: A dictionary defining what order keys should be
577
returned from an 'unordered' get_record_stream request.
578
Keys with lower priority are returned first, keys not present in
579
the map get an implicit priority of 0, and are returned in
580
lexicographical order.
582
RecordingVersionedFilesDecorator.__init__(self, backing_vf)
583
self._key_priority = key_priority
585
def get_record_stream(self, keys, sort_order, include_delta_closure):
586
self.calls.append(("get_record_stream", list(keys), sort_order,
587
include_delta_closure))
588
if sort_order == 'unordered':
590
return (self._key_priority.get(key, 0), key)
591
# Use a defined order by asking for the keys one-by-one from the
593
for key in sorted(keys, key=sort_key):
594
for record in self._backing_vf.get_record_stream([key],
595
'unordered', include_delta_closure):
598
for record in self._backing_vf.get_record_stream(keys, sort_order,
599
include_delta_closure):
565
603
class KeyMapper(object):
566
604
"""KeyMappers map between keys and underlying partitioned storage."""