changeset 2366:2241433a77e5

obshashrange: warm the cache at the end of each transaction This will help having warmed cache for read only client. The warming is still imperfect in case of markers that trigger a reset, but we are in a better place than what we used to be.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Fri, 12 May 2017 21:21:31 +0200
parents 4b8b7fd135eb
children b73e1f879646
files README hgext3rd/evolve/obsdiscovery.py
diffstat 2 files changed, 19 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/README	Fri May 12 21:00:39 2017 +0200
+++ b/README	Fri May 12 21:21:31 2017 +0200
@@ -119,6 +119,9 @@
  - topic: have thg display topic name if possible,
  - obscache: more efficient update in the (rare) case of a transaction adding
    markers without changesets
+ - obshashrange-cache: update incrementally in the (common) case of a
+   transaction not affecting existing range,
+ - obshashrange-cache: keep the cache mostly warm after each transaction.
 
 6.1.1 - in progress
 -------------------
--- a/hgext3rd/evolve/obsdiscovery.py	Fri May 12 21:00:39 2017 +0200
+++ b/hgext3rd/evolve/obsdiscovery.py	Fri May 12 21:21:31 2017 +0200
@@ -443,7 +443,10 @@
     def get(self, rangeid):
         # revision should be covered by out tiprev
         # XXX should be a programming error
-        assert rangeid[0] <= self._cachekey[0]
+        #
+        # XXX there are issue with cache warming, we hack around it for now
+        if not getattr(self, '_updating', False):
+            assert rangeid[0] <= self._cachekey[0]
 
         value = super(_obshashcache, self).get(rangeid)
         if value is None and self._con is not None:
@@ -469,6 +472,8 @@
         # 1) new revisions does not get their entry updated (not update)
         # 2) if we detect markers affecting non-new revision we reset the cache
 
+        self._updating = True
+
         revs = set(revs)
         rev = repo.changelog.nodemap.get
         # if we have a new markers affecting a node already covered by the
@@ -484,6 +489,16 @@
                         self.clear(reset=True)
                         break
 
+        # XXX the current reset is too strong we could just drop the affected range
+
+        # XXX if we reset, we should warm the cache for existing heads (draft and public)
+
+        # warm the cache for the new revs
+        for r in revs:
+            _obshashrange(repo, (r, 0))
+
+        del self._updating
+
     @property
     def _fullcachekey(self):
         return (self._schemaversion, ) + self._cachekey