Grab Daemon
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
static
tests
.gitignore
LICENSE
README.md
grab.js
grab.py
grab_json.py
restart.sh
runtest.sh
sample.sh

README.md

grab

A Hierarchical Perishable Lock Service

Perishable locks are locks with a relatively short time to live (usually about a minute or so), and which are expected to be refreshed via some keep-alive or polling process until they are no longer required.

The intended use is for continuous builds via jenkins or similar services.

Builds are notoriously fickle, and crash or are terminated by impatient users. Builds also make use of shared resources, and sometimes require exclusive access. Using traditional locking mechanisms requires cleanup to avoid stale locks.

This service works around the problem of stale locks by incorporating the cleanup mechanism and releasing locks that haven't been refreshed within a given timespan.

Features include:

  • Hierarchical locking structure via resource paths. The last item in the path gets an exclusive lock, and the items in the path get shared locks.
  • Queues for every resource ensure "first come first serve", as opposed to "whoever shows up at the right time gets it".
  • REST api using simple GET requests returning JSON responses.
  • Pure in memory state, no databases or files required.
  • Clean shutdown to preserve continuous service even during upgrades.
  • Support for long term locking (e.g. code freeze / maintenance) by setting lock expiration time into the future.
  • Client "keepalive" process monitors parent process and is able to run a cleanup script should the parent process die or be killed.

Components

grab.js Node script containing the actual server code. Run "node grab.js --help" to see the configuration options.
grab.py Python client script. Run "python grab.py --help" to see the options.
restart.sh Wrapper script to cleanly restart the service.
runtest.sh Unit test runner.
sample.sh Sample grab() and release() shell functions using the locking service with keep-alive process.

Sample Usage

First ensure you have python and node installed, then:

  1. start the service by running ./restart.sh
  2. optionally, in a separate window, tail -f ./log
  3. run the sample script: ./sample.sh
  4. try more experiments by using grab.py
  5. stop the service: ./grab.py shutdown
  6. inspect the log file:

See Also

http://blog.fortified-bikesheds.com/2013/05/reinventing-wheel-hierarchical.html