Rev 2699: Add new get_raw_records_unsorted method on knit access, to allow low level sorting and optimisation when the upper layer does not need results in a particular order. in http://people.ubuntu.com/~robertc/baz2.0/knits
Robert Collins
robertc at robertcollins.net
Thu Aug 16 09:08:24 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/knits
------------------------------------------------------------
revno: 2699
revision-id: robertc at robertcollins.net-20070816080814-49b7t5gghdrhcx4d
parent: pqm at pqm.ubuntu.com-20070814221506-6rw0b0oolfdeqrdw
committer: Robert Collins <robertc at robertcollins.net>
branch nick: knits
timestamp: Thu 2007-08-16 18:08:14 +1000
message:
Add new get_raw_records_unsorted method on knit access, to allow low level sorting and optimisation when the upper layer does not need results in a particular order.
modified:
bzrlib/knit.py knit.py-20051212171256-f056ac8f0fbe1bd9
bzrlib/tests/test_knit.py test_knit.py-20051212171302-95d4c00dd5f11f2b
=== modified file 'bzrlib/knit.py'
--- a/bzrlib/knit.py 2007-08-08 02:26:02 +0000
+++ b/bzrlib/knit.py 2007-08-16 08:08:14 +0000
@@ -1681,7 +1681,25 @@
return set((version_id, ) for version_id in version_ids)
-class _KnitAccess(object):
+class _Access(object):
+ """Base class with common logic for accessing knit record data."""
+
+ def get_raw_records_unsorted(self, memos_for_retrieval):
+ """Get the raw bytes for many records with 'best' IO.
+
+ :param memos_for_retrieval: An iterable containing the memo's to
+ use when retrieving the bytes. The Pack access method looks up the
+ pack to use for a given record in its index_to_pack map.
+ :return: An iterator over (memos, bytes) for all the requested
+ records.
+ """
+ # sort the memos
+ sorted_memos = sorted(memos_for_retrieval)
+ # delegate to the concrete class to get the now sorted records.
+ return izip(sorted_memos, self.get_raw_records(sorted_memos))
+
+
+class _KnitAccess(_Access):
"""Access to knit records in a .knit file."""
def __init__(self, transport, filename, _file_mode, _dir_mode,
@@ -1761,7 +1779,7 @@
yield data
-class _PackAccess(object):
+class _PackAccess(_Access):
"""Access to knit records via a collection of packs."""
def __init__(self, index_to_packs, writer=None):
@@ -2022,6 +2040,7 @@
The result will be returned in whatever is the fastest to read.
Not by the order requested. Also, multiple requests for the same
record will only yield 1 response.
+
:param records: A list of (version_id, pos, len) entries
:return: Yields (version_id, contents, digest) in the order
read, not the order requested
=== modified file 'bzrlib/tests/test_knit.py'
--- a/bzrlib/tests/test_knit.py 2007-08-02 23:43:57 +0000
+++ b/bzrlib/tests/test_knit.py 2007-08-16 08:08:14 +0000
@@ -187,6 +187,16 @@
access.create()
self.assertAccessExists(access)
+ def test_get_raw_records_unsorted(self):
+ """get_raw_records_unsorted returns in best-read order."""
+ access = self.get_access()
+ memos = access.add_raw_records([10, 2, 5], '12345678901234567')
+ expected_result = zip(memos, ['1234567890', '12', '34567'])
+ self.assertEqual(expected_result,
+ list(access.get_raw_records_unsorted(memos)))
+ self.assertEqual(expected_result,
+ list(access.get_raw_records_unsorted(reversed(memos))))
+
def test_open_file(self):
"""open_file never errors."""
access = self.get_access()
More information about the bazaar-commits
mailing list