From patchwork Fri Aug 5 13:59:18 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5, of, 7] branchmap: acquires lock before writting the rev branch cache From: Pierre-Yves David X-Patchwork-Id: 16116 Message-Id: <51046e1ff9b1d5817a95.1470405558@nodosa.octopoid.net> To: mercurial-devel@mercurial-scm.org Date: Fri, 05 Aug 2016 15:59:18 +0200 # HG changeset patch # User Pierre-Yves David # Date 1470401836 -7200 # Fri Aug 05 14:57:16 2016 +0200 # Node ID 51046e1ff9b1d5817a95163a25ca3dc975db7e8f # Parent 0b54d56b4217578079157532deea74045046d4c4 # EXP-Topic vfsward branchmap: acquires lock before writting the rev branch cache We now attempt to acquire a lock and write the branch cache within that lock. This would prevent cache corruption when multiple processes try to write the cache at the same time. diff -r 0b54d56b4217 -r 51046e1ff9b1 mercurial/branchmap.py --- a/mercurial/branchmap.py Fri Aug 05 14:54:46 2016 +0200 +++ b/mercurial/branchmap.py Fri Aug 05 14:57:16 2016 +0200 @@ -470,8 +470,10 @@ class revbranchcache(object): def write(self, tr=None): """Save branch cache if it is dirty.""" repo = self._repo - if True: + wlock = None + try: if self._rbcnamescount < len(self._names): + wlock = repo.wlock(wait=False) try: if self._rbcnamescount != 0: f = repo.vfs.open(_rbcnames, 'ab') @@ -501,6 +503,7 @@ class revbranchcache(object): start = self._rbcrevslen * _rbcrecsize if start != len(self._rbcrevs): + wlock = repo.wlock(wait=False) revs = min(len(repo.changelog), len(self._rbcrevs) // _rbcrecsize) try: @@ -521,3 +524,8 @@ class revbranchcache(object): inst) return self._rbcrevslen = revs + except error.LockHeld as inst: + repo.ui.debug("couldn't write revision branch cache: %s\n" % inst) + finally: + if wlock is not None: + wlock.release()