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:
parent
c116e1b395
commit
fd94900d91
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user