mongo::DistributedLock Class Reference

The distributed lock is a configdb backed way of synchronizing system-wide tasks. More...

#include <distlock.h>

List of all members.

Public Member Functions

 DistributedLock (const ConnectionString &conn, const string &name, unsigned takeoverMinutes=15)
 The constructor does not connect to the configdb yet and constructing does not mean the lock was acquired.
bool lock_try (string why, BSONObj *other=0)
 Attempts to aquire 'this' lock, checking if it could or should be stolen from the previous holder.
void unlock ()
 Releases a previously taken lock.

Detailed Description

The distributed lock is a configdb backed way of synchronizing system-wide tasks.

A task must be identified by a unique name across the system (e.g., "balancer"). A lock is taken by writing a document in the configdb's locks collection with that name.

To be maintained, each taken lock needs to be revalidaded ("pinged") within a pre-established amount of time. This class does this maintenance automatically once a DistributedLock object was constructed.


Constructor & Destructor Documentation

mongo::DistributedLock::DistributedLock ( const ConnectionString conn,
const string &  name,
unsigned  takeoverMinutes = 15 
)

The constructor does not connect to the configdb yet and constructing does not mean the lock was acquired.

Construction does trigger a lock "pinging" mechanism, though.

Parameters:
conn address of config(s) server(s)
name identifier for the lock
takeoverMinutes how long can the log go "unpinged" before a new attempt to lock steals it (in minutes)

Member Function Documentation

bool mongo::DistributedLock::lock_try ( string  why,
BSONObj other = 0 
)

Attempts to aquire 'this' lock, checking if it could or should be stolen from the previous holder.

Please consider using the dist_lock_try construct to acquire this lock in an exception safe way.

Parameters:
why human readable description of why the lock is being taken (used to log)
other configdb's lock document that is currently holding the lock, if lock is taken
Returns:
true if it managed to grab the lock

The documentation for this class was generated from the following files:
Generated on Wed Sep 14 01:46:38 2011 for MongoDB by  doxygen 1.6.3