Re: using cdb for 'update' without race condition?

ari edelkind <[email protected]> Thu, 10 Apr 2008 20:00:04 -0400
Newsgroups gmane.comp.djb.cdb
Message-ID <[email protected]>
[email protected] wrote:

> > You ought to have the source file around already, which would obviate
> > these two steps.  You can have your program edit the source file, which
> > is easily machine-parseable, and regenerate it as desired.
> 
> That's assuming there is a source file.  Using the C API, it's
> possible to have only the database file.

It's possible even without the C API, using cdbdump.  But cdb was
originally intended to be built from a master source, so it makes sense
that your master source might exist.

> > Or lock your output file if you must dump the database every time --
> > in which case, you'd lock the output file before opening the
> > database, and unlock it after completing the update.
> 
> That doesn't work, since the output file becomes the new database.  To
> ensure that all process are using the same lock file, you have to use
> a lock file that never gets renamed.

Actually, the output file to which i was referring becomes the new
master file, not the new database file.  But you could use the temporary
database file for this purpose instead, if you read your keys from the
database and skip the remastering step.

And yes, you'd use the same name every time.  If you have permission to
create a new database file and rename it into place, you won't need to
write anything into /tmp.

ari