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

Norman Ramsey <[email protected]> Thu, 10 Apr 2008 14:58:01 -0400
Newsgroups gmane.comp.djb.cdb
Message-ID <[email protected]>
 > Your concern seems to center around something you call "losing an
 > update". What does that mean? Presumably, you're going to run your steps
 > 1-2-3 periodically. If so, then any update that you "missed" this time
 > around will show up the next. 
 > 
 > Am I missing something?

Imagine that every time a mail message is delivered, our server spawns
a process which analyzes the mail message and then adds a key-value
pair to the database.  Two or more of these processes could be running
simultaneously; without a locking protocol an update could be lost:

  process A reads database version 101
  process B reads database version 101
  process A builds a new version 102 = 101 + (k, v)
  process B builds a new version 103 = 101 + (k', v')
  process A writes version 102 to disk and atomically replaces version 101
  process B writes version 103 to disk and atomically replaces version 102

In this scenario the addition of the pair (k, v) is lost.


Norman