diff options
author | gregs <greg@10gen.com> | 2011-05-11 17:34:08 -0400 |
---|---|---|
committer | gregs <greg@10gen.com> | 2011-05-12 10:30:05 -0400 |
commit | 9850500a4e3090ff4d54588296e2e4fda11f0910 (patch) | |
tree | 4c1242faba9bae07f9423e3d3add4c65907bb93f /client | |
parent | fcbcbdac954522f7af2cd804bf06ef1701ad9b42 (diff) | |
download | mongo-9850500a4e3090ff4d54588296e2e4fda11f0910.tar.gz |
fix failing test - need to make dist lock thread-safe SERVER-3058
Diffstat (limited to 'client')
-rw-r--r-- | client/distlock.cpp | 9 | ||||
-rw-r--r-- | client/distlock.h | 7 |
2 files changed, 12 insertions, 4 deletions
diff --git a/client/distlock.cpp b/client/distlock.cpp index e26c855025f..e17f58b2eb0 100644 --- a/client/distlock.cpp +++ b/client/distlock.cpp @@ -298,7 +298,7 @@ namespace mongo { DistributedLock::DistributedLock( const ConnectionString& conn , const string& name , unsigned long long lockTimeout, bool asProcess ) : _conn(conn) , _name(name) , _id( BSON( "_id" << name ) ), _processId( asProcess ? getDistLockId() : getDistLockProcess() ), _lockTimeout( lockTimeout == 0 ? LOCK_TIMEOUT : lockTimeout ), _maxClockSkew( _lockTimeout / LOCK_SKEW_FACTOR ), _maxNetSkew( _maxClockSkew ), _lockPing( _maxClockSkew ), - _lastPingCheck( string(""), (mongo::Date_t) 0, (mongo::Date_t) 0, OID() ) + _mutex( "DistributedLock" ) { log( logLvl - 1 ) << "created new distributed lock for " << name << " on " << conn << " ( lock timeout : " << _lockTimeout @@ -450,8 +450,10 @@ namespace mongo { // TODO: Start pinging only when we actually get the lock? // If we don't have a thread pinger, make sure we shouldn't have one - if( _threadId == "" ) + if( _threadId == "" ){ + scoped_lock lk( _mutex ); _threadId = distLockPinger.got( *this, _lockPing ); + } // This should always be true, if not, we are using the lock incorrectly. assert( _name != "" ); @@ -525,7 +527,8 @@ namespace mongo { if( recPingChange || recTSChange ) { // If the ping has changed since we last checked, mark the current date and time - _lastPingCheck = make_tuple(lastPing["_id"].String(), lastPing["ping"].Date(), remote, o["ts"].OID() ); + 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() ); } else { diff --git a/client/distlock.h b/client/distlock.h index e1f63821f1b..898567211e0 100644 --- a/client/distlock.h +++ b/client/distlock.h @@ -145,7 +145,12 @@ namespace mongo { private: - void resetLastPing(){ _lastPingCheck = make_tuple(string(""), 0, 0, OID()); } + void resetLastPing(){ + scoped_lock lk( _mutex ); + _lastPingCheck = boost::tuple<string, Date_t, Date_t, OID>(); + } + + mongo::mutex _mutex; // Data from last check of process with ping time boost::tuple<string, Date_t, Date_t, OID> _lastPingCheck; |