Skip to content
A simple, fault-tolerant distributed lock server in erlang.
Find file
Latest commit 90bc142 Dec 8, 2009 @dustin Release updates.
Failed to load latest commit information.
include Core server watches for clients to disappear and handles unregistration. May 30, 2008
src Some whitespace cleanup. Apr 5, 2009
.gitignore Simplfied the app so it's just a single supervisor starting point. Jun 3, 2008
Emakefile Initial TCP handling stuff. May 28, 2008
Makefile Simplfied the app so it's just a single supervisor starting point. Jun 4, 2008
README.markdown Documented the STATS command. Oct 29, 2008
TODO.markdown Auto-release all held locks on disconnection. May 29, 2008
lock_supervisor.rel Release updates. Dec 8, 2009


A Simple Distributed Lock Server

This is still an early project, but the goal is pretty simple:

A simple, distributed, fault-tolerant lock server.



Lock has two forms. The first is a non-blocking form that either tells you the lock is already taken, or acquires it.

lock lock_name

The second form allows you to wait for a certain number of seconds for the lock to become available:

lock lock_name timeout_in_seconds

Possible return values:

  • 200 - Lock has been acquired
  • 409 - The resource is locked -- you lose

Any acquired lock will be held until it's specifically unlocked, unlocked with unlock_all, or the client disconnects.


Unlock releases the lock with the given key if the current client has acquired that lock:

unlock lock_name

Possible return values:

  • 200 - The lock has been released
  • 403 - You do not own this lock (therefore you didn't release it)


Release any locks this client may be holding.

Possible return values:

  • 200 - It just blows it all away


Retrieve your current session ID. This may be resumed later.


  • 200 [some_string]

conn_id [string]

Attempts to set your connection ID to the given value.

This allows you to resume a session if you get disconnected.


  • 200 - Resumed
  • 403 - Could not resume connection (you either already have a new one, or that one belongs to someone else)

set_timeout [integer]

Set the amount of time after disconnect (in milliseconds) before your locks are all automatically freed. Default is 30,000 (30 seconds).


  • 200 - the new value was set


Disconnect your connection.


Get some server stats.


  • 200 STATS - beginning of a stat stream (see below)

The stats output is multi-line, so the protocol handling is a little different from all of the other commands.

The initial response is


which is followed by several values in the following form:

STAT [key] [value]

and then one terminating value:


A complete example is as follows:

STAT clients 0
STAT locks 0
STAT monitoring 0
Something went wrong with that request. Please try again.