Patchwork [1,of,2,V4] hg: make cachedlocalrepo cache appropriate repoview object

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Feb. 13, 2016, 4:39 p.m.
Message ID <4f589e36e0a5879f243c.1455381542@feefifofum>
Download mbox | patch
Permalink /patch/13168/
State Accepted
Delegated to: Yuya Nishihara
Headers show

Comments

Katsunori FUJIWARA - Feb. 13, 2016, 4:39 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1455381235 -32400
#      Sun Feb 14 01:33:55 2016 +0900
# Node ID 4f589e36e0a5879f243cf958ea2e03f24c204670
# Parent  8515b813976bfab2abadfc95011807bd8c7a2816
hg: make cachedlocalrepo cache appropriate repoview object

Before this patch, 'cachedlocalrepo' always caches "visible" repoview
object, because 'cachedlocalrepo' uses "visible" repoview returned by
'hg.repository()' without any additional processing.

If the client of 'cachedlocalrepo' wants "served" repoview, some
objects to be cached are discarded unintentionally.

    1. 'cachedlocalrepo' newly caches "visible" repoview object
       (call it VIEW1)

    2. 'cachedlocalrepo' returns VIEW1 to the client of it at 'fetch()'

    3. the client gets "served" repoview object by 'filtered("served")'
       on VIEW1 (call this "served" repoview VIEW2)

    4. accessing to 'repo.changelog' implies:
       - instantiation of changelog via 'localrepository.changelog'
       - instantiation of "filtered changelog" via 'repoview.changelog'

    5. "filtered changelog" above is cached in VIEW2

    6. VIEW2 is discarded after processing, because there is no
       reference to it

    7. 'cachedlocalrepo' returns VIEW1 cached at (1) above to the
       client at next 'fetch()'

    8. 'filtered("served")' on VIEW1 at the client side creates new
       "served" repoview again, because VIEW1 is "visible"
       (call this new "served" repoview VIEW3)

    9. accessing to 'repo.changelog' implies instantiation of filtered
       changelog again, because "filtered changelog" is cached in
       VIEW2 at (5), but not in VIEW3 currently used

    10. (go to (7) above)

As described above, "served" repoview object and "filtered changelog"
cached in it are discarded always, even if the repository itself
hasn't been changed since last access.

For example, in the case of 'hgweb_mod.hgweb', "newly caching" occurs,
when:

  - all cached objects are already assigned to another threads
    (in this case, repoview is created in 'cachedlocalrepo.copy()')

  - or, stat of '00changelog.i' is changed from last access
    (in this case, repoview is created in 'cachedlocalrepo.fetch()')

    once changes are pushed via HTTP, this always occurs.

The root cause of this inefficiency is that 'cachedlocalrepo' always
caches "visible" repoview object, even if the client of it wants
another view.

To make 'cachedlocalrepo' cache appropriate repoview object, this
patch adds additional filtering on the repo object returned by
'hg.repository()'. It is assumed that initial repoview object should
be already filtered by expected view.

After this patch:

  - 'filtered("served")' on VIEW1 at (3)/(7) above returns VIEW1
    itself, because VIEW1 is now "served", and

  - VIEW2 and VIEW3 equal VIEW1

  - therefore, "filtered changelog" is cached in VIEW1, and reused
    intentionally
Yuya Nishihara - Feb. 14, 2016, 2:47 p.m.
On Sun, 14 Feb 2016 01:39:02 +0900, FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
> # Date 1455381235 -32400
> #      Sun Feb 14 01:33:55 2016 +0900
> # Node ID 4f589e36e0a5879f243cf958ea2e03f24c204670
> # Parent  8515b813976bfab2abadfc95011807bd8c7a2816
> hg: make cachedlocalrepo cache appropriate repoview object

Queued this to the clowncopter, thanks!

Patch

diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -865,6 +865,7 @@  class cachedlocalrepo(object):
         assert isinstance(repo, localrepo.localrepository)
         self._repo = repo
         self._state, self.mtime = self._repostate()
+        self._filtername = repo.filtername
 
     def fetch(self):
         """Refresh (if necessary) and return a repository.
@@ -884,7 +885,11 @@  class cachedlocalrepo(object):
         if state == self._state:
             return self._repo, False
 
-        self._repo = repository(self._repo.baseui, self._repo.url())
+        repo = repository(self._repo.baseui, self._repo.url())
+        if self._filtername:
+            self._repo = repo.filtered(self._filtername)
+        else:
+            self._repo = repo.unfiltered()
         self._state = state
         self.mtime = mtime
 
@@ -912,6 +917,10 @@  class cachedlocalrepo(object):
         completely independent of the original.
         """
         repo = repository(self._repo.baseui, self._repo.origroot)
+        if self._filtername:
+            repo = repo.filtered(self._filtername)
+        else:
+            repo = repo.unfiltered()
         c = cachedlocalrepo(repo)
         c._state = self._state
         c.mtime = self.mtime