Rev 4749: Change to a generic 'VersionedFiles.clear_cache()' api. in http://bazaar.launchpad.net/~jameinel/bzr/2.1-peak-mem-tweak

John Arbash Meinel john at arbash-meinel.com
Mon Oct 19 16:07:04 BST 2009


At http://bazaar.launchpad.net/~jameinel/bzr/2.1-peak-mem-tweak

------------------------------------------------------------
revno: 4749
revision-id: john at arbash-meinel.com-20091019150658-tot6ofpswqytwzpj
parent: john at arbash-meinel.com-20091018175325-m7s57yrmm3bvj9b3
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 2.1-peak-mem-tweak
timestamp: Mon 2009-10-19 10:06:58 -0500
message:
  Change to a generic 'VersionedFiles.clear_cache()' api.
  
  The base implementation does nothing, the one for GroupCompressVersionedFiles
  only clears the _group_cache so far. We'll do more later.
-------------- next part --------------
=== modified file 'bzrlib/groupcompress.py'
--- a/bzrlib/groupcompress.py	2009-10-18 17:53:25 +0000
+++ b/bzrlib/groupcompress.py	2009-10-19 15:06:58 +0000
@@ -1265,6 +1265,10 @@
         else:
             return self.get_record_stream(keys, 'unordered', True)
 
+    def clear_cache(self):
+        """See VersionedFiles.clear_cache()"""
+        self._group_cache.clear()
+
     def _check_add(self, key, lines, random_id, check_content):
         """check that version_id and lines are safe to add."""
         version_id = key[-1]

=== modified file 'bzrlib/repofmt/groupcompress_repo.py'
--- a/bzrlib/repofmt/groupcompress_repo.py	2009-10-14 16:42:42 +0000
+++ b/bzrlib/repofmt/groupcompress_repo.py	2009-10-19 15:06:58 +0000
@@ -1105,9 +1105,9 @@
         for stream_info in self._fetch_revision_texts(revision_ids):
             yield stream_info
         self._revision_keys = [(rev_id,) for rev_id in revision_ids]
-        self.from_repository.revisions._group_cache.clear()
+        self.from_repository.revisions.clear_cache()
         yield self._get_inventory_stream(self._revision_keys)
-        self.from_repository.inventories._group_cache.clear()
+        self.from_repository.inventories.clear_cache()
         # TODO: The keys to exclude might be part of the search recipe
         # For now, exclude all parents that are at the edge of ancestry, for
         # which we have inventories
@@ -1116,9 +1116,9 @@
                         self._revision_keys)
         for stream_info in self._get_filtered_chk_streams(parent_keys):
             yield stream_info
-        self.from_repository.chk_bytes._group_cache.clear()
+        self.from_repository.chk_bytes.clear_cache()
         yield self._get_text_stream()
-        self.from_repository.texts._group_cache.clear()
+        self.from_repository.texts.clear_cache()
 
     def get_stream_for_missing_keys(self, missing_keys):
         # missing keys can only occur when we are byte copying and not

=== modified file 'bzrlib/tests/per_versionedfile.py'
--- a/bzrlib/tests/per_versionedfile.py	2009-08-26 16:44:27 +0000
+++ b/bzrlib/tests/per_versionedfile.py	2009-10-19 15:06:58 +0000
@@ -1581,6 +1581,10 @@
         # All texts should be output.
         self.assertEqual(set(keys), seen)
 
+    def test_clear_cache(self):
+        files = self.get_versionedfiles()
+        files.clear_cache()
+
     def test_construct(self):
         """Each parameterised test can be constructed on a transport."""
         files = self.get_versionedfiles()

=== modified file 'bzrlib/tests/test_groupcompress.py'
--- a/bzrlib/tests/test_groupcompress.py	2009-10-18 17:53:25 +0000
+++ b/bzrlib/tests/test_groupcompress.py	2009-10-19 15:06:58 +0000
@@ -459,7 +459,8 @@
                          ], block._dump())
 
 
-class TestCaseWithGroupCompressVersionedFiles(tests.TestCaseWithTransport):
+class TestCaseWithGroupCompressVersionedFiles(
+        tests.TestCaseWithMemoryTransport):
 
     def make_test_vf(self, create_graph, keylength=1, do_cleanup=True,
                      dir='.', inconsistency_fatal=True):
@@ -732,6 +733,17 @@
                               " \('b',\) \('42 32 0 8', \(\(\),\)\) \('74 32"
                               " 0 8', \(\(\('a',\),\),\)\)")
 
+    def test_clear_cache(self):
+        vf = self.make_source_with_b(True, 'source')
+        vf.writer.end()
+        for record in vf.get_record_stream([('a',), ('b',)], 'unordered',
+                                           True):
+            pass
+        self.assertTrue(len(vf._group_cache) > 0)
+        vf.clear_cache()
+        self.assertEqual(0, len(vf._group_cache))
+
+
 
 class StubGCVF(object):
     def __init__(self, canned_get_blocks=None):

=== modified file 'bzrlib/versionedfile.py'
--- a/bzrlib/versionedfile.py	2009-08-17 22:08:21 +0000
+++ b/bzrlib/versionedfile.py	2009-10-19 15:06:58 +0000
@@ -930,6 +930,13 @@
     def check_not_reserved_id(version_id):
         revision.check_not_reserved_id(version_id)
 
+    def clear_cache(self):
+        """Clear whatever caches this VersionedFile holds.
+
+        This is generally called after an operation has been performed, when we
+        don't expect to be using this versioned file again soon.
+        """
+
     def _check_lines_not_unicode(self, lines):
         """Check that lines being added to a versioned file are not unicode."""
         for line in lines:



More information about the bazaar-commits mailing list