diff options
Diffstat (limited to 'client/distlock.cpp')
-rw-r--r-- | client/distlock.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/client/distlock.cpp b/client/distlock.cpp index c264597..245eb7e 100644 --- a/client/distlock.cpp +++ b/client/distlock.cpp @@ -109,9 +109,6 @@ namespace mongo { bool DistributedLock::lock_try( string why , BSONObj * other ){ - // check for recrusive - assert( getState() == 0 ); - ScopedDbConnection conn( _conn ); BSONObjBuilder queryBuilder; @@ -208,18 +205,33 @@ namespace mongo { if ( ! gotLock ) return false; - _state.set( 1 ); return true; } void DistributedLock::unlock(){ - ScopedDbConnection conn( _conn ); - conn->update( _ns , _id, BSON( "$set" << BSON( "state" << 0 ) ) ); - log(1) << "dist_lock unlock: " << conn->findOne( _ns , _id ) << endl; - conn.done(); + const int maxAttempts = 3; + int attempted = 0; + while ( ++attempted <= maxAttempts ) { + + try { + ScopedDbConnection conn( _conn ); + conn->update( _ns , _id, BSON( "$set" << BSON( "state" << 0 ) ) ); + log(1) << "dist_lock unlock: " << conn->findOne( _ns , _id ) << endl; + conn.done(); + + return; + - _state.set( 0 ); - } + } catch ( std::exception& e) { + log( LL_WARNING ) << "dist_lock " << _name << " failed to contact config server in unlock attempt " + << attempted << ": " << e.what() << endl; + sleepsecs(1 << attempted); + } + } + + log( LL_WARNING ) << "dist_lock couldn't consumate unlock request. " << "Lock " << _name + << " will be taken over after " << _takeoverMinutes << " minutes timeout" << endl; + } } |