61
62
class DBTryLockTimeoutException : public std::exception {
63
DBTryLockTimeoutException() {}
64
virtual ~DBTryLockTimeoutException() throw() { }
64
DBTryLockTimeoutException() {}
65
virtual ~DBTryLockTimeoutException() throw() { }
82
83
in different directories with the same name, it will be ok but they are sharing a lock
85
static mapsf<string,WrapperForRWLock*> dblocks;
86
typedef mapsf< StringMap<WrapperForRWLock*> > DBLocksMap;
87
static DBLocksMap dblocks;
87
89
/* we don't want to touch dblocks too much as a mutex is involved. thus party for that,
200
202
return &qlk.stats;
203
void reportLockStats(BSONObjBuilder& result) {
205
b.append(".", qlk.stats.report());
206
b.append("admin", nestableLocks[Lock::admin]->stats.report());
207
b.append("local", nestableLocks[Lock::local]->stats.report());
209
mapsf<string,WrapperForRWLock*>::ref r(dblocks);
210
for( map<string,WrapperForRWLock*>::const_iterator i = r.r.begin(); i != r.r.end(); i++ ) {
211
b.append(i->first, i->second->stats.report());
214
result.append("locks", b.obj());
217
205
int Lock::isLocked() {
218
206
return threadState();
523
void Lock::DBWrite::lockOther(const string& db) {
511
void Lock::DBWrite::lockOther(const StringData& db) {
524
512
fassert( 16252, !db.empty() );
525
513
LockState& ls = lockState();
538
526
if( db != ls.otherName() )
540
mapsf<string,WrapperForRWLock*>::ref r(dblocks);
528
DBLocksMap::ref r(dblocks);
541
529
WrapperForRWLock*& lock = r[db];
543
lock = new WrapperForRWLock(db.c_str());
531
lock = new WrapperForRWLock(db);
544
532
ls.lockedOther( db , 1 , lock );
553
541
_weLocked = ls.otherLock();
556
static Lock::Nestable n(const char *db) {
557
if( str::equals(db, "local") )
544
static Lock::Nestable n(const StringData& db) {
558
546
return Lock::local;
559
if( str::equals(db, "admin") )
560
548
return Lock::admin;
561
549
return Lock::notnestable;
578
566
if (DB_LEVEL_LOCKING_ENABLED) {
579
char db[MaxDatabaseNameLen];
580
nsToDatabase(ns.data(), db);
567
StringData db = nsToDatabaseSubstring( ns );
581
568
Nestable nested = n(db);
582
569
if( nested == admin ) {
583
570
// we can't nestedly lock both admin and local as implemented. so lock_W.
626
Lock::DBWrite::DBWrite( const StringData& ns )
627
: ScopedLock( 'w' ), _what(ns.data()), _nested(false) {
612
Lock::DBWrite::DBWrite( const StringData& ns )
613
: ScopedLock( 'w' ), _what(ns.toString()), _nested(false) {
631
Lock::DBRead::DBRead( const StringData& ns )
632
: ScopedLock( 'r' ), _what(ns.data()), _nested(false) {
617
Lock::DBRead::DBRead( const StringData& ns )
618
: ScopedLock( 'r' ), _what(ns.toString()), _nested(false) {
715
void Lock::DBRead::lockOther(const string& db) {
701
void Lock::DBRead::lockOther(const StringData& db) {
716
702
fassert( 16255, !db.empty() );
717
703
LockState& ls = lockState();
730
716
if( db != ls.otherName() )
732
mapsf<string,WrapperForRWLock*>::ref r(dblocks);
718
DBLocksMap::ref r(dblocks);
733
719
WrapperForRWLock*& lock = r[db];
735
lock = new WrapperForRWLock(db.c_str());
721
lock = new WrapperForRWLock(db);
736
722
ls.lockedOther( db , -1 , lock );
813
799
dur::releasingWriteLock();
802
class GlobalLockServerStatusSection : public ServerStatusSection {
804
GlobalLockServerStatusSection() : ServerStatusSection( "globalLock" ){
805
_started = curTimeMillis64();
808
virtual bool includeByDefault() const { return true; }
810
virtual BSONObj generateSection( const BSONElement& configElement ) const {
813
t.append( "totalTime" , (long long)(1000 * ( curTimeMillis64() - _started ) ) );
814
t.append( "lockTime" , Lock::globalLockStat()->getTimeLocked( 'W' ) );
817
BSONObjBuilder ttt( t.subobjStart( "currentQueue" ) );
819
Client::recommendedYieldMicros( &w , &r, true );
820
ttt.append( "total" , w + r );
821
ttt.append( "readers" , r );
822
ttt.append( "writers" , w );
827
BSONObjBuilder ttt( t.subobjStart( "activeClients" ) );
829
Client::getActiveClientCount( w , r );
830
ttt.append( "total" , w + r );
831
ttt.append( "readers" , r );
832
ttt.append( "writers" , w );
840
unsigned long long _started;
842
} globalLockServerStatusSection;
844
class LockStatsServerStatusSection : public ServerStatusSection {
846
LockStatsServerStatusSection() : ServerStatusSection( "locks" ){}
847
virtual bool includeByDefault() const { return true; }
849
BSONObj generateSection( const BSONElement& configElement ) const {
851
b.append(".", qlk.stats.report());
852
b.append("admin", nestableLocks[Lock::admin]->stats.report());
853
b.append("local", nestableLocks[Lock::local]->stats.report());
855
DBLocksMap::ref r(dblocks);
856
for( DBLocksMap::const_iterator i = r.r.begin(); i != r.r.end(); ++i ) {
857
b.append(i->first, i->second->stats.report());
863
} lockStatsServerStatusSection;