Record Locking Help ....
Roger Oberholtzer
roger
Mon Aug 15 09:29:54 PDT 2005
On Mon, 2005-08-15 at 15:59, Ben Duncan wrote:
> Thanks Kurt.
>
> I am looking at modifying (heavily) tdb (Samba Team's Multi User GDBM)
> in to a multi value like dbm.
>
> It already does RECORD locking via fcntl, but also uses mmap (I am sooo in the
> dark about mmap). One of the things it does is traverse locking, which in my case
> is frivolous (SLAG is interactive, so you work on ONE record at a time, except for
> batch mode processing).
>
> Here is what I am thinking on the modifications:
>
> The RECORD header will be modified to include a user id and a PID and a "lockbyte".
> When a "READ" with lock is done, fcntl will be employed to "LOCK" the lock byte,
> obviously if that fails, the record is in "transition" of being locked.
> On success, the PID, UID and LB (LOCKBYTE) will all be set and the header rewritten and
> the fcntl lock released.
> The data buffer is returned to the user. If a "READ is done and it is LOCKING and
> the LOCKBYTE is set, a "RECORD LOCKED BY" message will appear, giving the interactive
> user an option to "VIEW" the record.
>
> When the process that did the LOCKING, either reads a NEW record, or writes
> the old record back out, the UID, PID, an LB will be cleared.
>
> Does this sound about right?
As long as your locks are atomic. This will eliminate race conditions.
As was mentioned by Kurt, semaphores are good for this. If you use
semaphores on a record, you should not also need the fcntl locking as
well. Start with 'man semctl', 'man semopt' and 'man semget'.
+????????????????????????????+???????????????????????????????+
? Roger Oberholtzer ? E-mail: roger at opq.se ?
? OPQ Systems AB ? WWW: http://www.opq.se/ ?
? Kapellgr?nd 7 ? ?
? P. O. Box 4205 ? Phone: Int + 46 8 314223 ?
? 102 65 Stockholm ? Mobile: Int + 46 733 621657 ?
? Sweden ? Fax: Int + 46 8 314223 ?
+????????????????????????????+???????????????????????????????+
More information about the Linux-users
mailing list