[ANN] lockfile-0.0.0

A

Ara.T.Howard

URLS

http://raa.ruby-lang.org/list.rhtml?name=lockfile
http://www.codeforpeople.com/lib/ruby/lockfile/


SYNOPSIS

lib/lockfile.rb : ruby library for creating NFS safe lockfiles

bin/rlock : ruby command line tool which uses this library to create
lockfiles. run 'rlock -h' for more info


INSTALL

sudo ruby install.rb


BASIC ALGORITHIM

* create a globally uniq filename in the same filesystem as the desired
lockfile - this can be nfs mounted

* link(2) this file to the desired lockfile, ignore all errors

* stat the uniq filename and desired lockfile to determine is they are the
same, use only stat.rdev and stat.ino - ignore stat.nlink as NFS can cause
this report incorrect values

* iff same, you have lock. either return or run optional code block with
optional refresher thread keeping lockfile fresh during execution of code
block, ensuring that the lockfile is removed..

* iff not same, sleep using incremental backoff time. optionally remove
lockfile if it is older than a certain time, timeout if more than a certain
amount of time has passed attempting to lock file.


BASIC USAGE

1)
lockfile = Lockfile.new 'file.lock'
begin
lockfile.lock
p 42
ensure
lockfile.unlock
end


2)
require 'pstore' # which is NOT nfs safe on it's own

lock_opts = { # the keys can be symbols or strings
:retries => 42, # we will try 42 times to aquire the lock
:sleep_inc => 2, # we will sleep 2 seconds longer after each retry
:max_sleep => 30, # we will never sleep longer than 30 seconds however
:max_age => 3600, # we will blow away any files older than this
:suspend => 16, # iff we steal the lock from someone else - wait this
# long to give them a chance to realize it
:refresh => 8, # we will spawn a bg thread that touches file every 8 sec
# this thread also causes a StolenLockError to be
# thrown if the lock disappears from under us - note
# that the 'detection' is limited to the poll interval
:timeout => 300 # we simply cannot wait longer than five minutes
}

pstore = PStore.new 'file.db'
lockfile = Lockfile.new 'file.db.lock', opts
lockfile.lock do
pstore.transaction do
pstore[:last_update_time] = Time.now
end
end


SAMPLES

* see samples/a.rb
* see samples/nfsstore.rb
* see bin/rlock


enjoy.

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
===============================================================================
 
J

Jim Freeze

BASIC USAGE

1)
lockfile = Lockfile.new 'file.lock'
begin
lockfile.lock
p 42
ensure
lockfile.unlock
end

Can this form be supported:

Lockfile.new('file') { |lock|
... code here
}
 
A

Ara.T.Howard

Can this form be supported:

Lockfile.new('file') { |lock|
... code here
}

here you go:

http://www.codeforpeople.com/lib/ruby/lockfile/lockfile-0.0.1.tgz

-a
--
===============================================================================
| EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
| PHONE :: 303.497.6469
| ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
| URL :: http://www.ngdc.noaa.gov/stp/
| TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[ANN] lockfile-1.4.1 2
[ANN] lockfile-1.4.0 0
[ANN] lockfile-0.2.0 0
[ANN] lockfile-1.2.0 0
[ANN] lockfile-1.0.0 0
[ANN] nfsstore-0.4.0 0
[ANN] sldb-0.0.0 0
[ANN] traits-0.0.0 5

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top