From patchwork Tue Mar 17 03:36:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [6,of,6] revbranchcache: write cache even during read operations From: Durham Goode X-Patchwork-Id: 8113 Message-Id: <4c09b9396f289af720cc.1426563378@dev2000.prn2.facebook.com> To: Cc: pierre-yves.david@ens-lyon.org Date: Mon, 16 Mar 2015 20:36:18 -0700 # HG changeset patch # User Durham Goode # Date 1424832211 28800 # Tue Feb 24 18:43:31 2015 -0800 # Node ID 4c09b9396f289af720cca3b729a4e013faf97bd6 # Parent 2b0ed15d3e874a69f0ee5cd5b0f04cd8f0ecab41 revbranchcache: write cache even during read operations Previously we would only actually write the revbranchcache to disk if we were in the middle of a write operation (like commit). Now we will also write it during any read operation. The cache knows how to invalidate itself, so it shouldn't become corrupt if multiple writers try at once (and the write-on-read behavior/risk is the same as all our other caches). diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -97,9 +97,6 @@ def updatecache(repo): partial.update(repo, revs) partial.write(repo) - if repo._revbranchcache is not None: - repo._revbranchcache.write() - assert partial.validfor(repo), filtername repo._branchcaches[repo.filtername] = partial diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -303,7 +303,11 @@ class localrepository(object): self.names = namespaces.namespaces() def close(self): - pass + self._writecaches() + + def _writecaches(self): + if self._revbranchcache: + self._revbranchcache.write() def _restrictcapabilities(self, caps): # bundle2 is not ready for prime time, drop it unless explicitly diff --git a/tests/test-branches.t b/tests/test-branches.t --- a/tests/test-branches.t +++ b/tests/test-branches.t @@ -550,8 +550,8 @@ revision branch cache is created when bu recovery from invalid cache revs file with trailing data $ echo >> .hg/cache/rbc-revs-v1 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug + 5 truncating cache/rbc-revs-v1 to 120 - 5 $ f --size .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=120 recovery from invalid cache file with partial last record @@ -560,8 +560,8 @@ recovery from invalid cache file with pa $ f --size .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=119 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug + 5 truncating cache/rbc-revs-v1 to 112 - 5 $ f --size .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=120 recovery from invalid cache file with missing record - no truncation @@ -579,11 +579,11 @@ recovery from invalid cache file with so $ f -qDB 112 rbc-revs-v1 >> .hg/cache/rbc-revs-v1 $ f --size .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=120 - $ hg log -r 'branch(.)' -T '{rev} ' - 3 4 8 9 10 11 12 13 (no-eol) + $ hg log -r 'branch(.)' -T '{rev} ' --debug + 3 4 8 9 10 11 12 13 truncating cache/rbc-revs-v1 to 8 $ rm -f .hg/cache/branch* && hg head a -T '{rev}\n' --debug - truncating cache/rbc-revs-v1 to 8 5 + truncating cache/rbc-revs-v1 to 104 $ f --size --hexdump --bytes=16 .hg/cache/rbc-revs* .hg/cache/rbc-revs-v1: size=120 0000: 19 70 9c 5a 00 00 00 00 dd 6b 44 0d 00 00 00 01 |.p.Z.....kD.....| diff --git a/tests/test-rebase-conflicts.t b/tests/test-rebase-conflicts.t --- a/tests/test-rebase-conflicts.t +++ b/tests/test-rebase-conflicts.t @@ -322,6 +322,6 @@ Check that the right ancestors is used w files: 1/1 chunks (100.00%) added 2 changesets with 2 changes to 1 files invalid branchheads cache (served): tip differs - truncating cache/rbc-revs-v1 to 72 rebase completed updating the branch cache + truncating cache/rbc-revs-v1 to 72