Re: using cdb for 'update' without race condition?
[email protected] (Paul Jarc) Thu, 10 Apr 2008 17:07:29 -0400
| Newsgroups | gmane.comp.djb.cdb |
|---|---|
| Organization | What did you have in mind? A short, blunt, human pyramid? |
| Message-ID | <[email protected]> |
ari edelkind <[email protected]> wrote: > [email protected] wrote: >> 1. My app reads a database and extracts all the key-value pairs. >> >> 2. My app produces a new set of key-value pairs. > > 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. > 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. > And frankly, for locking in this case, you may as well simply use > open(...,O_CREAT|O_EXCL) for the output file That works, but the disadvantage is that you have to busy-wait, instead of letting the kernel wake you up when it's your turn to acquire the lock. paul