From owner-freebsd-hackers@FreeBSD.ORG Wed May 14 20:04:03 2008 Return-Path: Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 139701065670 for ; Wed, 14 May 2008 20:04:03 +0000 (UTC) (envelope-from reg@openpave.org) Received: from mx1.ucdavis.edu (mx1.ucdavis.edu [128.120.32.31]) by mx1.freebsd.org (Postfix) with ESMTP id D71048FC1E for ; Wed, 14 May 2008 20:04:02 +0000 (UTC) (envelope-from reg@openpave.org) Received: from flint.openpave.org ([169.237.230.40]) by mx1.ucdavis.edu (8.13.7/8.13.1/it-defang-5.4.0) with ESMTP id m4EK3sir026562 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 14 May 2008 13:04:00 -0700 (PDT) Received: from sandy.local (flint.local [192.168.1.5]) by flint.openpave.org (8.14.2/8.14.2) with ESMTP id m4EK3rTv077440; Wed, 14 May 2008 20:03:53 GMT (envelope-from reg@sandy.local) Received: (from reg@localhost) by sandy.local (8.14.2/8.14.2/Submit) id m4EK3rj8077439; Wed, 14 May 2008 13:03:53 -0700 (PDT) (envelope-from reg) Date: Wed, 14 May 2008 13:03:53 -0700 From: Jeremy Lea To: "Daniel O'Connor" Message-ID: <20080514200353.GA77403@flint.openpave.org> References: <20080512204558.GA44114@flint.openpave.org> <48291719.5010801@freebsd.org> <200805141755.35892.doconnor@gsoft.com.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200805141755.35892.doconnor@gsoft.com.au> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.93, clamav-milter version 0.93 on av4 X-Virus-Status: Clean X-Scanned-By: MIMEDefang 2.57 on 128.120.32.8 Cc: freebsd-hackers@FreeBSD.ORG, Tim Kientzle , Anders Nore Subject: Re: Adding .db support to pkg_tools X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 May 2008 20:04:03 -0000 Hi, On Wed, May 14, 2008 at 05:55:33PM +0930, Daniel O'Connor wrote: > So long as you can tell it is corrupted.. > It's also a drag from a user POV when the tool crashes because the DB is > hosed (seen in portupgrade a number of times) The simplest way to achieve some measure of protection (provided the database itself is not buggy), is to use a single lock file in /var/db/pkg. The ports tools can create and lock this as needed, and if the file exists, but they are able to obtain an exclusive lock on it, then it's a dangling lock. In that case, the tools crashed, and the database caches should be rebuilt. This is not fool proof, but it would reduce the number of FAQs on the mailing lists. This kills two birds with one stone, since it would serialize access to /var/db/pkg, so that various tools don't stomp on one another. An exclusive lock can be held by pkg_create, pkg_add and pkg_delete as needed. pkg_info and pkg_version can downgrade the lock to a shared lock, and just continue if they can get a shared lock, or block if the file is exclusively locked. One problem is the pkg_add calls itself recursively, so it would have to drop the lock around those calls. That could be hard. If I recall correctly, it was not that hard to remove this recursive behaviour. Also, since bsd.port.mk grubs around in /var/db/pkg, it would need to learn to participate in the locking. Regards, -Jeremy -- FreeBSD - Because the best things in life are free... http://www.freebsd.org/