From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1QJt00-0002qV-Em for garchives@archives.gentoo.org; Tue, 10 May 2011 19:53:40 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 24CC61C002; Tue, 10 May 2011 19:53:31 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id D21EC1C002 for ; Tue, 10 May 2011 19:53:30 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 544AF1B4031 for ; Tue, 10 May 2011 19:53:30 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id C48473D468 for ; Tue, 10 May 2011 19:53:29 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <0ed15bb56ce1f5d33a0974f197d99aa234c277af.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/dbapi/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/dbapi/_MergeProcess.py X-VCS-Directories: pym/portage/dbapi/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 0ed15bb56ce1f5d33a0974f197d99aa234c277af Date: Tue, 10 May 2011 19:53:29 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 45fa8bdb6f52c8833b577212d8063f75 commit: 0ed15bb56ce1f5d33a0974f197d99aa234c277af Author: Zac Medico gentoo org> AuthorDate: Tue May 10 19:52:36 2011 +0000 Commit: Zac Medico gentoo org> CommitDate: Tue May 10 19:52:36 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D0ed15bb5 MergeProcess: lock vdb earlier when appropriate --- pym/portage/dbapi/_MergeProcess.py | 30 +++++++++++++++++++++++++++++- 1 files changed, 29 insertions(+), 1 deletions(-) diff --git a/pym/portage/dbapi/_MergeProcess.py b/pym/portage/dbapi/_Merg= eProcess.py index 05f45d5..62f5bec 100644 --- a/pym/portage/dbapi/_MergeProcess.py +++ b/pym/portage/dbapi/_MergeProcess.py @@ -27,7 +27,7 @@ class MergeProcess(SpawnProcess): __slots__ =3D ('dblink', 'mycat', 'mypkg', 'settings', 'treetype', 'vartree', 'scheduler', 'blockers', 'pkgloc', 'infloc', 'myebuild', 'mydbapi', 'prev_mtimes', '_elog_reader_fd', '_elog_reg_id', - '_buf', '_elog_keys') + '_buf', '_elog_keys', '_locked_vdb') =20 def _start(self): # Portage should always call setcpv prior to this @@ -48,6 +48,25 @@ class MergeProcess(SpawnProcess): self._handle_self_reinstall() super(MergeProcess, self)._start() =20 + def _lock_vdb(self): + """ + Lock the vdb if FEATURES=3Dparallel-install is NOT enabled, + otherwise do nothing. This is implemented with + vardbapi.lock(), which supports reentrance by the + subprocess that we spawn. + """ + if "parallel-install" not in self.settings.features: + self.vartree.dbapi.lock() + self._locked_vdb =3D True + + def _unlock_vdb(self): + """ + Unlock the vdb if we hold a lock, otherwise do nothing. + """ + if self._locked_vdb: + self.vartree.dbapi.unlock() + self._locked_vdb =3D False + def _handle_self_reinstall(self): """ If portage is reinstalling itself, create temporary @@ -143,6 +162,14 @@ class MergeProcess(SpawnProcess): fd_pipes[elog_writer_fd] =3D elog_writer_fd self._elog_reg_id =3D self.scheduler.register(elog_reader_fd, self._registered_events, self._elog_output_handler) + + # If a concurrent emerge process tries to install a package + # in the same SLOT as this one at the same time, there is an + # extremely unlikely chance that the COUNTER values will not be + # ordered correctly unless we lock the vdb here. + # FEATURES=3Dparallel-install skips this lock in order to + # improve performance, and the risk is practically negligible. + self._lock_vdb() counter =3D self.vartree.dbapi.counter_tick() =20 pid =3D os.fork() @@ -211,6 +238,7 @@ class MergeProcess(SpawnProcess): """ Unregister from the scheduler and close open files. """ + self._unlock_vdb() if self._elog_reg_id is not None: self.scheduler.unregister(self._elog_reg_id) self._elog_reg_id =3D None