#include <distlock.h>
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 |
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.
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.
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) |
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.
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 |
void mongo::DistributedLock::unlock | ( | ) |
Releases a previously taken lock.
Definition at line 54 of file distlock.h.
BSONObj mongo::DistributedLock::_id [private] |
Definition at line 59 of file distlock.h.
string mongo::DistributedLock::_name [private] |
Definition at line 55 of file distlock.h.
string mongo::DistributedLock::_ns [private] |
Definition at line 58 of file distlock.h.
unsigned mongo::DistributedLock::_takeoverMinutes [private] |
Definition at line 56 of file distlock.h.