Patchwork D8173: nodemap: warm the persistent nodemap on disk with debugupdatecache

login
register
mail settings
Submitter phabricator
Date Feb. 27, 2020, 9:10 a.m.
Message ID <differential-rev-PHID-DREV-4b4mfprj3g4yuiatz6qo-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45361/
State Superseded
Headers show

Comments

phabricator - Feb. 27, 2020, 9:10 a.m.
marmoute created this revision.
Herald added a reviewer: indygreg.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  When appropriate, the nodemap cache file will be created.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8173

AFFECTED FILES
  mercurial/localrepo.py
  mercurial/revlog.py
  mercurial/revlogutils/nodemap.py
  tests/test-persistent-nodemap.t

CHANGE DETAILS




To: marmoute, indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -118,3 +118,22 @@ 
   $ f --sha256 .hg/store/00changelog-*.nd --size
   .hg/store/00changelog-????????????????.nd: size=122944, sha256=755976b22b64ab680401b45395953504e64e7fa8c31ac570f58dee21e15f9bc0 (glob)
 #endif
+
+Test force warming the cache
+
+  $ rm .hg/store/00changelog.n
+  $ hg debugnodemap --metadata
+  $ hg debugupdatecache
+#if pure
+  $ hg debugnodemap --metadata
+  uid: ???????????????? (glob)
+  tip-rev: 5002
+  data-length: 122944
+  data-unused: 0
+#else
+  $ hg debugnodemap --metadata
+  uid: ???????????????? (glob)
+  tip-rev: 5002
+  data-length: 122944
+  data-unused: 0
+#endif
diff --git a/mercurial/revlogutils/nodemap.py b/mercurial/revlogutils/nodemap.py
--- a/mercurial/revlogutils/nodemap.py
+++ b/mercurial/revlogutils/nodemap.py
@@ -73,10 +73,24 @@ 
     callback_id = b"revlog-persistent-nodemap-%s" % revlog.nodemap_file
     if tr.hasfinalize(callback_id):
         return  # no need to register again
-    tr.addfinalize(callback_id, lambda tr: _persist_nodemap(tr, revlog))
+    tr.addfinalize(
+        callback_id, lambda tr: _persist_nodemap(tr.addpostclose, revlog)
+    )
 
 
-def _persist_nodemap(tr, revlog):
+def update_persistent_nodemap(revlog):
+    """update the persistent nodemap right now
+
+    To be used for updating the nodemap on disk outside of a normal transaction
+    setup (eg, `debugupdatecache`).
+    """
+    cleanups = []
+    _persist_nodemap((lambda x, y: cleanups.append(y)), revlog)
+    for c in cleanups:
+        c(None)
+
+
+def _persist_nodemap(cleaner, revlog):
     """Write nodemap data on disk for a given revlog
     """
     if getattr(revlog, 'filteredrevs', ()):
@@ -163,7 +177,7 @@ 
                 realvfs.tryunlink(oldfile)
 
         callback_id = b"revlog-cleanup-nodemap-%s" % revlog.nodemap_file
-        tr.addpostclose(callback_id, cleanup)
+        cleaner(callback_id, cleanup)
 
 
 ### Nodemap docket file
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -748,6 +748,13 @@ 
             return False
         return True
 
+    def update_caches(self, transaction):
+        if self.nodemap_file is not None:
+            if transaction is None:
+                nodemaputil.update_persistent_nodemap(self)
+            else:
+                nodemaputil.setup_persistent_nodemap(transaction, self)
+
     def clearcaches(self):
         self._revisioncache = None
         self._chainbasecache.clear()
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -2504,6 +2504,9 @@ 
 
         if full:
             unfi = self.unfiltered()
+
+            self.changelog.update_caches(transaction=tr)
+
             rbc = unfi.revbranchcache()
             for r in unfi.changelog:
                 rbc.branchinfo(r)