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 long long lockTimeout=0, bool asProcess=false)
 The constructor does not connect to the configdb yet and constructing does not mean the lock was acquired.
bool lock_try (const string &why, bool reenter=false, BSONObj *other=0)
 Attempts to acquire 'this' lock, checking if it could or should be stolen from the previous holder.
void unlock (BSONObj *oldLockPtr=NULL)
 Releases a previously taken lock.
Date_t getRemoteTime ()
bool isRemoteTimeSkewed ()
const string & getProcessId ()
const ConnectionStringgetRemoteConnection ()

Static Public Member Functions

static bool checkSkew (const ConnectionString &cluster, unsigned skewChecks=NUM_LOCK_SKEW_CHECKS, unsigned long long maxClockSkew=MAX_LOCK_CLOCK_SKEW, unsigned long long maxNetSkew=MAX_LOCK_NET_SKEW)
 Check the skew between a cluster of servers.
static Date_t remoteTime (const ConnectionString &cluster, unsigned long long maxNetSkew=MAX_LOCK_NET_SKEW)
 Get the remote time from a server or cluster.
static bool killPinger (DistributedLock &lock)

Public Attributes

const ConnectionString _conn
const string _name
const BSONObj _id
const string _processId
const unsigned long long _lockTimeout
const unsigned long long _maxClockSkew
const unsigned long long _maxNetSkew
const unsigned long long _lockPing

Static Public Attributes

static LabeledLevel logLvl
static const string lockPingNS = "config.lockpings"
 Namespace for lock pings.
static const string locksNS = "config.locks"
 Namespace for locks.

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 long long  lockTimeout = 0,
bool  asProcess = false 
)

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

Create a new distributed lock, potentially with a custom sleep and takeover time.

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

Parameters:
conn address of config(s) server(s)
name identifier for the lock
lockTimeout how long can the log go "unpinged" before a new attempt to lock steals it (in minutes).
lockPing how long to wait between lock pings
legacy use legacy logic

If a custom sleep time is specified (time between pings)


Member Function Documentation

bool mongo::DistributedLock::lock_try ( const string &  why,
bool  reenter = false,
BSONObj other = 0 
)

Attempts to acquire '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)
whether this is a lock re-entry or a new lock
other configdb's lock document that is currently holding the lock, if lock is taken, or our own lock details if not
Returns:
true if it managed to grab the lock
Date_t mongo::DistributedLock::remoteTime ( const ConnectionString cluster,
unsigned long long  maxNetSkew = MAX_LOCK_NET_SKEW 
) [static]

Get the remote time from a server or cluster.

Returns the remote time as reported by the cluster or server.

The maximum difference between the reported time and the actual time on the remote server (at the completion of the function) is the maxNetSkew


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