Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 May 2008 13:03:53 -0700
From:      Jeremy Lea <reg@FreeBSD.ORG>
To:        "Daniel O'Connor" <doconnor@gsoft.com.au>
Cc:        freebsd-hackers@FreeBSD.ORG, Tim Kientzle <kientzle@FreeBSD.ORG>, Anders Nore <andenore@start.no>
Subject:   Re: Adding .db support to pkg_tools
Message-ID:  <20080514200353.GA77403@flint.openpave.org>
In-Reply-To: <200805141755.35892.doconnor@gsoft.com.au>
References:  <op.uavxx8ip2n4ijf@duckjen.nextgentel.no> <20080512204558.GA44114@flint.openpave.org> <48291719.5010801@freebsd.org> <200805141755.35892.doconnor@gsoft.com.au>

next in thread | previous in thread | raw e-mail | index | archive | help
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/



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20080514200353.GA77403>