Mercurial > public > mercurial-scm > hg
comparison mercurial/localrepo.py @ 32263:604d65e2c0b2
caches: introduce a function to warm cache
We have multiple caches that gain from being kept up to date. For example in a
server setup, we want to make sure the branchcache cache is hot for other
read-only clients.
Right now each cache tries to update themself in place where new data have been
added. However the approach is error prone (we might miss some spot) and
fragile. When nested transaction are involved, such cache updates might happen
before a top level transaction is committed. Writing caches for uncommitted
data on disk.
Having a single entry point, run at the end of each successful transaction,
helps to ensure the cache is up to date and refreshed at the right time.
We start with updating the branchmap cache but other will come.
author | Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
---|---|
date | Tue, 02 May 2017 21:39:43 +0200 |
parents | 85ef5a073114 |
children | a72caf0af38e |
comparison
equal
deleted
inserted
replaced
32262:85ef5a073114 | 32263:604d65e2c0b2 |
---|---|
1091 def hook(): | 1091 def hook(): |
1092 reporef().hook('txnclose', throw=False, txnname=desc, | 1092 reporef().hook('txnclose', throw=False, txnname=desc, |
1093 **pycompat.strkwargs(hookargs)) | 1093 **pycompat.strkwargs(hookargs)) |
1094 reporef()._afterlock(hook) | 1094 reporef()._afterlock(hook) |
1095 tr.addfinalize('txnclose-hook', txnclosehook) | 1095 tr.addfinalize('txnclose-hook', txnclosehook) |
1096 def warmscache(tr2): | |
1097 repo = reporef() | |
1098 repo.updatecaches(tr2) | |
1099 tr.addpostclose('warms-cache', warmscache) | |
1096 def txnaborthook(tr2): | 1100 def txnaborthook(tr2): |
1097 """To be run if transaction is aborted | 1101 """To be run if transaction is aborted |
1098 """ | 1102 """ |
1099 reporef().hook('txnabort', throw=False, txnname=desc, | 1103 reporef().hook('txnabort', throw=False, txnname=desc, |
1100 **tr2.hookargs) | 1104 **tr2.hookargs) |
1224 # TODO: if we know which new heads may result from this rollback, pass | 1228 # TODO: if we know which new heads may result from this rollback, pass |
1225 # them to destroy(), which will prevent the branchhead cache from being | 1229 # them to destroy(), which will prevent the branchhead cache from being |
1226 # invalidated. | 1230 # invalidated. |
1227 self.destroyed() | 1231 self.destroyed() |
1228 return 0 | 1232 return 0 |
1233 | |
1234 @unfilteredmethod | |
1235 def updatecaches(self, tr): | |
1236 """warm appropriate caches after a transaction closed""" | |
1237 if tr.hookargs.get('source') == 'strip': | |
1238 # During strip, many caches are invalid but | |
1239 # later call to `destroyed` will refresh them. | |
1240 return | |
1241 | |
1242 if tr.changes['revs']: | |
1243 branchmap.updatecache(self.filtered('served')) | |
1229 | 1244 |
1230 def invalidatecaches(self): | 1245 def invalidatecaches(self): |
1231 | 1246 |
1232 if '_tagscache' in vars(self): | 1247 if '_tagscache' in vars(self): |
1233 # can't use delattr on proxy | 1248 # can't use delattr on proxy |