changeset 44826:35b255e474d9 stable

dirstate: make sure the dirstate is loaded before the changelog (issue6303) Before this change, it was possible for the changelog to be loaded before the dirstate. If a transaction happens betwen the changelog and dirstate reading, the dirstate can up end poitning toward a revision not existing in the (olded) changelog. This lead to a warning. With this revision, we preload the dirstate parent before reading the changelog. This has a negligible performance impact on performance for all case we are tracking. Differential Revision: https://phab.mercurial-scm.org/D8528
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Mon, 11 May 2020 13:08:02 +0200
parents 18e36ff8b414
children f445a4f7e8a7
files mercurial/dirstate.py mercurial/localrepo.py tests/test-static-http.t
diffstat 3 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/dirstate.py	Mon May 11 16:44:11 2020 +0200
+++ b/mercurial/dirstate.py	Mon May 11 13:08:02 2020 +0200
@@ -103,6 +103,13 @@
         # raises an exception).
         self._cwd
 
+    def prefetch_parents(self):
+        """make sure the parents are loaded
+
+        Used to avoid a race condition.
+        """
+        self._pl
+
     @contextlib.contextmanager
     def parentchange(self):
         '''Context manager for handling dirstate parents.
--- a/mercurial/localrepo.py	Mon May 11 16:44:11 2020 +0200
+++ b/mercurial/localrepo.py	Mon May 11 13:08:02 2020 +0200
@@ -1450,6 +1450,8 @@
 
     @storecache(b'00changelog.i')
     def changelog(self):
+        # load dirstate before changelog to avoid race see issue6303
+        self.dirstate.prefetch_parents()
         return self.store.changelog(txnutil.mayhavepending(self.root))
 
     @storecache(b'00manifest.i')
--- a/tests/test-static-http.t	Mon May 11 16:44:11 2020 +0200
+++ b/tests/test-static-http.t	Mon May 11 13:08:02 2020 +0200
@@ -233,6 +233,7 @@
   /.hg/cache/hgtagsfnodes1
   /.hg/cache/rbc-names-v1
   /.hg/cache/rbc-revs-v1
+  /.hg/dirstate
   /.hg/requires
   /.hg/store/00changelog.i
   /.hg/store/00manifest.i
@@ -250,6 +251,7 @@
   /remote-with-names/.hg/cache/rbc-names-v1
   /remote-with-names/.hg/cache/rbc-revs-v1
   /remote-with-names/.hg/cache/tags2-served
+  /remote-with-names/.hg/dirstate
   /remote-with-names/.hg/localtags
   /remote-with-names/.hg/requires
   /remote-with-names/.hg/store/00changelog.i
@@ -266,6 +268,7 @@
   /remote/.hg/cache/rbc-names-v1
   /remote/.hg/cache/rbc-revs-v1
   /remote/.hg/cache/tags2-served
+  /remote/.hg/dirstate
   /remote/.hg/localtags
   /remote/.hg/requires
   /remote/.hg/store/00changelog.i
@@ -278,6 +281,7 @@
   /remote/.hg/store/data/~2ehgtags.i (py37 !)
   /remotempty/.hg/bookmarks
   /remotempty/.hg/bookmarks.current
+  /remotempty/.hg/dirstate
   /remotempty/.hg/requires
   /remotempty/.hg/store/00changelog.i
   /remotempty/.hg/store/00manifest.i
@@ -286,6 +290,7 @@
   /sub/.hg/cache/hgtagsfnodes1
   /sub/.hg/cache/rbc-names-v1
   /sub/.hg/cache/rbc-revs-v1
+  /sub/.hg/dirstate
   /sub/.hg/requires
   /sub/.hg/store/00changelog.i
   /sub/.hg/store/00manifest.i