0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00

DistributedLock::unlock() handles partition from config DB

This commit is contained in:
Alberto Lerner 2010-08-05 11:52:14 -04:00
parent c116e1b395
commit fd94900d91
2 changed files with 22 additions and 20 deletions

View File

@ -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;
}
}

View File

@ -36,14 +36,6 @@ namespace mongo {
*/
DistributedLock( const ConnectionString& conn , const string& name , unsigned takeoverMinutes = 10 );
int getState(){
return _state.get();
}
bool isLocked(){
return _state.get() != 0;
}
bool lock_try( string why , BSONObj * other = 0 );
void unlock();
@ -54,8 +46,6 @@ namespace mongo {
string _ns;
BSONObj _id;
ThreadLocalValue<int> _state;
};
class dist_lock_try {