[wplug] Python and file locking - NFS or MySQL?

Christopher DeMarco cmd at alephant.net
Thu Aug 25 22:18:48 EDT 2005


Hi all...

...I've got a Python script running on a bunch of boxen sharing some
common NFS-exported space.  I need (not want :) to lock files for
writing, and I need (not want :) to do it safely (i.e. atomically).
As I understand it, my options are (please bear in mind that all of
this is Python):

1.  fcntl(2) is claimed to work "mostly" over NFS v >= 3.

2.  open(2) is atomic on a local FS, I've read discussions that imply
that link(2) is atomic over NFS (is it?), so I can link from local
lockfile to remote target atomically.  I don't grok this; open(2) +
link(2) + stat(2) == 3 calls on my fingers.  HTH is this supposed to
work?

3.  Atomically update a MySQL database indicating that the file is
locked - MySQL has atomic transactions now, right?  And how good is
the Python MySQL API - IIRC Perl didn't have atomic transactions last
year; will this work in contemporary Python?

I've got a while (several weeks) to chew this problem over (my current
implementation is ``assert("Poof!  File locked")'') so let's thrash
this out nicely.  Coffee-or-tea bought for helpful hackers;
alternately I'll base64encode you a beer.


I was present at an undersea, unexplained mass sponge migration.
-- 
Christopher DeMarco <cmd at alephant.net>
Alephant Systems (http://alephant.net)
PGP public key at http://pgp.alephant.net
+1 412 708 9660
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.wplug.org/pipermail/wplug/attachments/20050825/fc1f96ce/attachment.bin


More information about the wplug mailing list