On Tue, 10 Feb 2004, Nigel Metheringham wrote:
> On Tue, 2004-02-10 at 13:36, Richard Gilbert wrote:
> > cdb_encode.pl aliases | $(CDBMAKE) tmp_aliases.cdb aliases.tmp
> > cdb_encode.pl invaliases | $(CDBMAKE) tmp_invaliases.cdb invaliases.tmp
> > mv invaliases.cdb invaliases.cdb.old
> > mv tmp_invaliases.cdb invaliases.cdb
> > mv aliases.cdb aliases.cdb.old
> > mv tmp_aliases.cdb aliases.cdb
>
> This is mostly superfluous - cdbmake already does a rename(tmpfile,
> realfile) as the last part of its operation.
>
> I'd say you are suffering from one of 2 problems:-
> 1. Your filesystem does not follow full unix semantics, such as
> fully atomic renames [can you say NFS]
> 2. You have 2 of these scripts running simultaneously and are
> racing on the use of the *.tmp files.
Thank you Nigel -- you were spot on with 2. I used to update the CDB
files every 15 minutes from a makefile which had the flag file
database_updated as a dependency. I then wanted to provide an expedite
facility so I introduced another flag file called rebuild_tables. I had
cron run a makefile every 15 minutes to touch rebuild_tables if
database_updated, but also had it run the main makefile every minute with
rebuild_tables as the dependency. The idea was that rebuild_tables could
be touched at any time to expedite the rebuild. The problem was that the
complete rebuild was taking more than a minute and so there was indeed a
race condition.
Thank you to everyone who responded (and apologies for appearing to reply
to a previous unrelated message -- I hadn't realised that there were still
invisible headers which were used for threading).
Richard
--
Richard Gilbert
Corporate Information and Computing Services
University of Sheffield, Sheffield, S10 2TN, UK
Phone: +44 114 222 3028 Fax: +44 114 222 3040