summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgregs <greg@10gen.com>2011-09-29 10:41:10 -0400
committergregs <greg@10gen.com>2011-10-04 17:37:54 -0400
commit3461007a7a706c9fa06b15a26ca70f5e3eaa7029 (patch)
tree65ef5ac2ef2be930f591235ad2695c8f299a55cc
parent4063312d6044196be67fd29c6daac8768f6f6110 (diff)
downloadmongo-3461007a7a706c9fa06b15a26ca70f5e3eaa7029.tar.gz
share lastpings between dist locks SERVER-3959
-rw-r--r--client/distlock.cpp18
-rw-r--r--client/distlock.h28
2 files changed, 35 insertions, 11 deletions
diff --git a/client/distlock.cpp b/client/distlock.cpp
index cb711590524..9702d96ddc1 100644
--- a/client/distlock.cpp
+++ b/client/distlock.cpp
@@ -22,6 +22,7 @@
namespace mongo {
LabeledLevel DistributedLock::logLvl( 1 );
+ DistributedLock::LastPings DistributedLock::lastPings;
ThreadLocalValue<string> distLockIds("");
@@ -303,6 +304,18 @@ namespace mongo {
log( logLvl - 1 ) << "created new distributed lock for " << name << " on " << conn
<< " ( lock timeout : " << _lockTimeout
<< ", ping interval : " << _lockPing << ", process : " << asProcess << " )" << endl;
+
+
+ }
+
+ DistributedLock::PingData DistributedLock::LastPings::getLastPing( const ConnectionString& conn, const string& lockName ){
+ scoped_lock lock( _mutex );
+ return _lastPings[ std::pair< string, string >( conn.toString(), lockName ) ];
+ }
+
+ void DistributedLock::LastPings::setLastPing( const ConnectionString& conn, const string& lockName, const PingData& pd ){
+ scoped_lock lock( _mutex );
+ _lastPings[ std::pair< string, string >( conn.toString(), lockName ) ] = pd;
}
Date_t DistributedLock::getRemoteTime() {
@@ -512,6 +525,7 @@ namespace mongo {
unsigned long long elapsed = 0;
unsigned long long takeover = _lockTimeout;
+ PingData _lastPingCheck = getLastPing();
log( logLvl ) << "checking last ping for lock '" << lockName << "'" << " against process " << _lastPingCheck.get<0>() << " and ping " << _lastPingCheck.get<1>() << endl;
@@ -527,8 +541,7 @@ namespace mongo {
if( recPingChange || recTSChange ) {
// If the ping has changed since we last checked, mark the current date and time
- scoped_lock lk( _mutex );
- _lastPingCheck = boost::tuple<string, Date_t, Date_t, OID>( lastPing["_id"].String().c_str(), lastPing["ping"].Date(), remote, o["ts"].OID() );
+ setLastPing( PingData( lastPing["_id"].String().c_str(), lastPing["ping"].Date(), remote, o["ts"].OID() ) );
}
else {
@@ -540,7 +553,6 @@ namespace mongo {
else
elapsed = remote - _lastPingCheck.get<2>();
}
-
}
catch( LockException& e ) {
diff --git a/client/distlock.h b/client/distlock.h
index 898567211e0..106a5d00001 100644
--- a/client/distlock.h
+++ b/client/distlock.h
@@ -71,6 +71,22 @@ namespace mongo {
static LabeledLevel logLvl;
+ typedef boost::tuple<string, Date_t, Date_t, OID> PingData;
+
+ class LastPings {
+ public:
+ LastPings() : _mutex( "DistributedLock::LastPings" ) {}
+ ~LastPings(){}
+
+ PingData getLastPing( const ConnectionString& conn, const string& lockName );
+ void setLastPing( const ConnectionString& conn, const string& lockName, const PingData& pd );
+
+ mongo::mutex _mutex;
+ map< std::pair<string, string>, PingData > _lastPings;
+ };
+
+ static LastPings lastPings;
+
/**
* 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.
@@ -145,16 +161,12 @@ namespace mongo {
private:
- void resetLastPing(){
- scoped_lock lk( _mutex );
- _lastPingCheck = boost::tuple<string, Date_t, Date_t, OID>();
- }
-
- mongo::mutex _mutex;
+ void resetLastPing(){ lastPings.setLastPing( _conn, _name, PingData() ); }
+ void setLastPing( const PingData& pd ){ lastPings.setLastPing( _conn, _name, pd ); }
+ PingData getLastPing(){ return lastPings.getLastPing( _conn, _name ); }
- // Data from last check of process with ping time
- boost::tuple<string, Date_t, Date_t, OID> _lastPingCheck;
// May or may not exist, depending on startup
+ mongo::mutex _mutex;
string _threadId;
};