Mercurial > hg-stable
comparison mercurial/localrepo.py @ 26251:5c0f5db65c6b
localrepo: refresh filecache stats only if transaction finished successfully
If commit is aborted by pretxncommit hook, in-memory changelog and manifest
have entries that would be added. So they must be discarded on invalidate().
But the mechanism introduced by a710936c3037 doesn't handle this case well.
It tries to mitigate the penalty of invalidate() by marking in-memory cache
as "clean" on unlock assuming that they are identical to the stored data.
But this assumption is wrong if stored data are rolled back by tr.abort().
This patch moves the hook to post-close action so that it will never be
triggered on abort.
This bug was originally reported to thg, which is only reproducible in
command-server process on unix, evolve disabled.
https://bitbucket.org/tortoisehg/thg/issues/4285/
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 15 Sep 2015 00:32:39 +0900 |
parents | bc1f8a79b4e4 |
children | 3ac7acb99b04 |
comparison
equal
deleted
inserted
replaced
26250:bc1f8a79b4e4 | 26251:5c0f5db65c6b |
---|---|
1019 """To be run if transaction is aborted | 1019 """To be run if transaction is aborted |
1020 """ | 1020 """ |
1021 reporef().hook('txnabort', throw=False, txnname=desc, | 1021 reporef().hook('txnabort', throw=False, txnname=desc, |
1022 **tr2.hookargs) | 1022 **tr2.hookargs) |
1023 tr.addabort('txnabort-hook', txnaborthook) | 1023 tr.addabort('txnabort-hook', txnaborthook) |
1024 # avoid eager cache invalidation. in-memory data should be identical | |
1025 # to stored data if transaction has no error. | |
1026 tr.addpostclose('refresh-filecachestats', self._refreshfilecachestats) | |
1024 self._transref = weakref.ref(tr) | 1027 self._transref = weakref.ref(tr) |
1025 return tr | 1028 return tr |
1026 | 1029 |
1027 def _journalfiles(self): | 1030 def _journalfiles(self): |
1028 return ((self.svfs, 'journal'), | 1031 return ((self.svfs, 'journal'), |
1196 subsequent operation to reread any outside changes.''' | 1199 subsequent operation to reread any outside changes.''' |
1197 # extension should hook this to invalidate its caches | 1200 # extension should hook this to invalidate its caches |
1198 self.invalidate() | 1201 self.invalidate() |
1199 self.invalidatedirstate() | 1202 self.invalidatedirstate() |
1200 | 1203 |
1201 def _refreshfilecachestats(self): | 1204 def _refreshfilecachestats(self, tr): |
1202 """Reload stats of cached files so that they are flagged as valid""" | 1205 """Reload stats of cached files so that they are flagged as valid""" |
1203 for k, ce in self._filecache.items(): | 1206 for k, ce in self._filecache.items(): |
1204 if k == 'dirstate' or k not in self.__dict__: | 1207 if k == 'dirstate' or k not in self.__dict__: |
1205 continue | 1208 continue |
1206 ce.refresh() | 1209 ce.refresh() |
1245 l = self._lockref and self._lockref() | 1248 l = self._lockref and self._lockref() |
1246 if l is not None and l.held: | 1249 if l is not None and l.held: |
1247 l.lock() | 1250 l.lock() |
1248 return l | 1251 return l |
1249 | 1252 |
1250 l = self._lock(self.svfs, "lock", wait, self._refreshfilecachestats, | 1253 l = self._lock(self.svfs, "lock", wait, None, |
1251 self.invalidate, _('repository %s') % self.origroot) | 1254 self.invalidate, _('repository %s') % self.origroot) |
1252 self._lockref = weakref.ref(l) | 1255 self._lockref = weakref.ref(l) |
1253 return l | 1256 return l |
1254 | 1257 |
1255 def wlock(self, wait=True): | 1258 def wlock(self, wait=True): |