manifestcache: protect write with `wlock` instead of `lock`
authorPierre-Yves David <pierre-yves.david@octobus.net>
Fri, 15 Mar 2019 15:07:43 +0000
changeset 41964 d121823072b8
parent 41963 6386f9a421d2
child 41965 e4ac7e63c213
manifestcache: protect write with `wlock` instead of `lock` The `wlock` is taken by both `update` and `commit` type operation. This would help persisting the cache more aggressively. An explicit test is introduced. However, we can already see the effect of this change on earlier test output.
mercurial/debugcommands.py
mercurial/manifest.py
tests/test-clone.t
tests/test-hardlinks.t
tests/test-manifest.t
--- a/mercurial/debugcommands.py	Thu Mar 14 09:12:55 2019 +0000
+++ b/mercurial/debugcommands.py	Fri Mar 15 15:07:43 2019 +0000
@@ -1476,13 +1476,13 @@
             raise error.Abort(msg)
 
     if opts.get(r'clear'):
-        with repo.lock():
+        with repo.wlock():
             cache = getcache()
             cache.clear(clear_persisted_data=True)
             return
 
     if add:
-        with repo.lock():
+        with repo.wlock():
             m = repo.manifestlog
             store = m.getstorage(b'')
             for n in add:
--- a/mercurial/manifest.py	Thu Mar 14 09:12:55 2019 +0000
+++ b/mercurial/manifest.py	Fri Mar 15 15:07:43 2019 +0000
@@ -1435,11 +1435,11 @@
 
     def _setupmanifestcachehooks(self, repo):
         """Persist the manifestfulltextcache on lock release"""
-        if not util.safehasattr(repo, '_lockref'):
+        if not util.safehasattr(repo, '_wlockref'):
             return
 
         self._fulltextcache._opener = repo.cachevfs
-        if repo._currentlock(repo._lockref) is None:
+        if repo._currentlock(repo._wlockref) is None:
             return
 
         reporef = weakref.ref(repo)
--- a/tests/test-clone.t	Thu Mar 14 09:12:55 2019 +0000
+++ b/tests/test-clone.t	Fri Mar 15 15:07:43 2019 +0000
@@ -58,6 +58,7 @@
 
   $ ls .hg/cache
   branch2-served
+  manifestfulltextcache
   rbc-names-v1
   rbc-revs-v1
 
--- a/tests/test-hardlinks.t	Thu Mar 14 09:12:55 2019 +0000
+++ b/tests/test-hardlinks.t	Fri Mar 15 15:07:43 2019 +0000
@@ -290,7 +290,7 @@
   1 r4/.hg/branch
   2 r4/.hg/cache/branch2-base
   2 r4/.hg/cache/branch2-served
-  2 r4/.hg/cache/manifestfulltextcache (reporevlogstore !)
+  1 r4/.hg/cache/manifestfulltextcache (reporevlogstore !)
   2 r4/.hg/cache/rbc-names-v1
   2 r4/.hg/cache/rbc-revs-v1
   1 r4/.hg/dirstate
--- a/tests/test-manifest.t	Thu Mar 14 09:12:55 2019 +0000
+++ b/tests/test-manifest.t	Fri Mar 15 15:07:43 2019 +0000
@@ -106,7 +106,9 @@
 Showing the content of the caches after the above operations
 
   $ hg debugmanifestfulltextcache
-  cache empty
+  cache contains 1 manifest entries, in order of most to least recent:
+  id: 1e01206b1d2f72bd55f2a33fa8ccad74144825b7, size 133 bytes
+  total cache data size 157 bytes, on-disk 157 bytes
 
 (Clearing the cache in case of any content)
 
@@ -183,3 +185,19 @@
   $ hg log -r 'ancestors(., 1)' --debug | grep 'manifest:'
   manifest:    1:1e01206b1d2f72bd55f2a33fa8ccad74144825b7
   manifest:    2:26b8653b67af8c1a0a0317c4ee8dac50a41fdb65
+
+hg update should warm the cache too
+
+(force dirstate check to avoid flackiness in manifest order)
+  $ hg debugrebuilddirstate
+
+  $ hg update 0
+  0 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg debugmanifestfulltextcache
+  cache contains 3 manifest entries, in order of most to least recent:
+  id: fce2a30dedad1eef4da95ca1dc0004157aa527cf, size 87 bytes
+  id: 26b8653b67af8c1a0a0317c4ee8dac50a41fdb65, size 133 bytes
+  id: 1e01206b1d2f72bd55f2a33fa8ccad74144825b7, size 133 bytes
+  total cache data size 425 bytes, on-disk 425 bytes
+  $ hg log -r '0' --debug | grep 'manifest:'
+  manifest:    0:fce2a30dedad1eef4da95ca1dc0004157aa527cf