mongo::DistributedLock Class Reference

#include <distlock.h>

List of all members.

Public Member Functions

 DistributedLock (const ConnectionString &conn, const string &name, unsigned takeoverMinutes=15)
bool lock_try (string why, BSONObj *other=0)
void unlock ()

Private Attributes

ConnectionString _conn
BSONObj _id
string _name
string _ns
unsigned _takeoverMinutes

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.

Definition at line 35 of file distlock.h.


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
void mongo::DistributedLock::unlock (  ) 

Releases a previously taken lock.


Member Data Documentation

Definition at line 54 of file distlock.h.

Definition at line 59 of file distlock.h.

Definition at line 55 of file distlock.h.

string mongo::DistributedLock::_ns [private]

Definition at line 58 of file distlock.h.

Definition at line 56 of file distlock.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


mongodb
Author(s): Nate Koenig
autogenerated on Fri Jan 11 12:15:55 2013