nodemap: warm the persistent nodemap on disk with debugupdatecache
When appropriate, the nodemap cache file will be created.
Differential Revision: https://phab.mercurial-scm.org/D8173
--- a/mercurial/localrepo.py Sat Feb 29 19:31:33 2020 +0100
+++ b/mercurial/localrepo.py Tue Feb 18 19:11:13 2020 +0100
@@ -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)
--- a/mercurial/revlog.py Sat Feb 29 19:31:33 2020 +0100
+++ b/mercurial/revlog.py Tue Feb 18 19:11:13 2020 +0100
@@ -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()
--- a/mercurial/revlogutils/nodemap.py Sat Feb 29 19:31:33 2020 +0100
+++ b/mercurial/revlogutils/nodemap.py Tue Feb 18 19:11:13 2020 +0100
@@ -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
--- a/tests/test-persistent-nodemap.t Sat Feb 29 19:31:33 2020 +0100
+++ b/tests/test-persistent-nodemap.t Tue Feb 18 19:11:13 2020 +0100
@@ -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