module Nfs:An implementation neutral NFS lock file scheme that relies on the atomicity of link over NFS (see NFS Illustrated, atomicity for more information). Rather than relying on a working traditional advisory lock system over NFS we create a hard link between the file given to the create call and a new file <filename>.nfs_lock. This link call is atomic (in that it succeeds or fails) across all systems that have the same filesystem mounted. The link file must be cleaned up on program exit (normally accomplished by an at_exit handler, but see caveats below).sig
..end
There are a few caveats compared to local file locks:
val create : ?message:string -> string -> bool
lock ?message path
tries to create and lock the file at path
by creating a hard
link to path
.nfs_lock. The contents of path will be replaced with message
,
which will be the caller's hostname:pid by default.
Efforts will be made to release this lock when the calling program exits. But there
is no guarantee that this will occur under some types of program crash
val create_exn : ?message:string -> string -> unit
create_exn ?message path
like create, but throws an exception when it fails to
obtain the lockval blocking_create : ?message:string -> string -> unit
blocking_create ?message path
like create, but sleeps for 1 second between lock
attempts and does not return until it succeedsval critical_section : ?message:string -> string -> f:(unit -> 'a) -> 'a
critical_section ?message path ~f
wrap function f
(including exceptions escaping
it) by first locking (using Lock_file.Nfs.create_exn
) and then unlocking the given lock
file.val get_hostname_and_pid : string -> (string * int) option
get_hostname_and_pid path
reads the lock file at path
and returns the hostname
and path in the file if it can be parsed.