summaryrefslogtreecommitdiff
path: root/src/mongo/db/d_concurrency.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-12-21 10:36:59 -0500
committerEliot Horowitz <eliot@10gen.com>2012-12-21 10:37:23 -0500
commite6b9a252c4155b0fdf629dd0f0e1bce99b67edc0 (patch)
treeb0de906681db7a1962ab0a48339806d9154d4036 /src/mongo/db/d_concurrency.cpp
parent5bf0b0bc360b9be0ecc5b8c7ebec1b5fe8ae4cb3 (diff)
downloadmongo-e6b9a252c4155b0fdf629dd0f0e1bce99b67edc0.tar.gz
use StringData in more places, and change mapsf to use any type of map
Diffstat (limited to 'src/mongo/db/d_concurrency.cpp')
-rw-r--r--src/mongo/db/d_concurrency.cpp56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/mongo/db/d_concurrency.cpp b/src/mongo/db/d_concurrency.cpp
index 49b0e40d9fc..0595b229565 100644
--- a/src/mongo/db/d_concurrency.cpp
+++ b/src/mongo/db/d_concurrency.cpp
@@ -61,8 +61,8 @@ namespace mongo {
class DBTryLockTimeoutException : public std::exception {
public:
- DBTryLockTimeoutException() {}
- virtual ~DBTryLockTimeoutException() throw() { }
+ DBTryLockTimeoutException() {}
+ virtual ~DBTryLockTimeoutException() throw() { }
};
namespace dur {
@@ -83,7 +83,8 @@ namespace mongo {
in different directories with the same name, it will be ok but they are sharing a lock
then.
*/
- static mapsf<string,WrapperForRWLock*> dblocks;
+ typedef mapsf< StringMap<WrapperForRWLock*> > DBLocksMap;
+ static DBLocksMap dblocks;
/* we don't want to touch dblocks too much as a mutex is involved. thus party for that,
this is here...
@@ -507,7 +508,7 @@ namespace mongo {
}
}
- void Lock::DBWrite::lockOther(const string& db) {
+ void Lock::DBWrite::lockOther(const StringData& db) {
fassert( 16252, !db.empty() );
LockState& ls = lockState();
@@ -524,10 +525,10 @@ namespace mongo {
if( db != ls.otherName() )
{
- mapsf<string,WrapperForRWLock*>::ref r(dblocks);
+ DBLocksMap::ref r(dblocks);
WrapperForRWLock*& lock = r[db];
if( lock == 0 )
- lock = new WrapperForRWLock(db.c_str());
+ lock = new WrapperForRWLock(db);
ls.lockedOther( db , 1 , lock );
}
else {
@@ -540,10 +541,10 @@ namespace mongo {
_weLocked = ls.otherLock();
}
- static Lock::Nestable n(const char *db) {
- if( str::equals(db, "local") )
+ static Lock::Nestable n(const StringData& db) {
+ if( db == "local" )
return Lock::local;
- if( str::equals(db, "admin") )
+ if( db == "admin" )
return Lock::admin;
return Lock::notnestable;
}
@@ -563,8 +564,7 @@ namespace mongo {
return;
if (DB_LEVEL_LOCKING_ENABLED) {
- char db[MaxDatabaseNameLen];
- nsToDatabase(ns.data(), db);
+ StringData db = nsToDatabaseSubstring( ns );
Nestable nested = n(db);
if( nested == admin ) {
// we can't nestedly lock both admin and local as implemented. so lock_W.
@@ -595,8 +595,7 @@ namespace mongo {
if ( ls.isRW() )
return;
if (DB_LEVEL_LOCKING_ENABLED) {
- char db[MaxDatabaseNameLen];
- nsToDatabase(ns.data(), db);
+ StringData db = nsToDatabaseSubstring(ns);
Nestable nested = n(db);
if( !nested )
lockOther(db);
@@ -699,7 +698,7 @@ namespace mongo {
}
}
- void Lock::DBRead::lockOther(const string& db) {
+ void Lock::DBRead::lockOther(const StringData& db) {
fassert( 16255, !db.empty() );
LockState& ls = lockState();
@@ -716,10 +715,10 @@ namespace mongo {
if( db != ls.otherName() )
{
- mapsf<string,WrapperForRWLock*>::ref r(dblocks);
+ DBLocksMap::ref r(dblocks);
WrapperForRWLock*& lock = r[db];
if( lock == 0 )
- lock = new WrapperForRWLock(db.c_str());
+ lock = new WrapperForRWLock(db);
ls.lockedOther( db , -1 , lock );
}
else {
@@ -800,7 +799,6 @@ namespace mongo {
dur::releasingWriteLock();
}
-
class GlobalLockServerStatusSection : public ServerStatusSection {
public:
GlobalLockServerStatusSection() : ServerStatusSection( "globalLock" ){
@@ -809,12 +807,12 @@ namespace mongo {
virtual bool includeByDefault() const { return true; }
- virtual BSONObj generateSection(const BSONElement& configElement) const {
+ virtual BSONObj generateSection( const BSONElement& configElement ) const {
BSONObjBuilder t;
-
+
t.append( "totalTime" , (long long)(1000 * ( curTimeMillis64() - _started ) ) );
t.append( "lockTime" , Lock::globalLockStat()->getTimeLocked( 'W' ) );
-
+
{
BSONObjBuilder ttt( t.subobjStart( "currentQueue" ) );
int w=0, r=0;
@@ -824,7 +822,7 @@ namespace mongo {
ttt.append( "writers" , w );
ttt.done();
}
-
+
{
BSONObjBuilder ttt( t.subobjStart( "activeClients" ) );
int w=0, r=0;
@@ -834,28 +832,28 @@ namespace mongo {
ttt.append( "writers" , w );
ttt.done();
}
-
+
return t.obj();
}
-
+
private:
- unsigned long long _started;
-
+ unsigned long long _started;
+
} globalLockServerStatusSection;
class LockStatsServerStatusSection : public ServerStatusSection {
public:
LockStatsServerStatusSection() : ServerStatusSection( "locks" ){}
virtual bool includeByDefault() const { return true; }
-
- BSONObj generateSection( const BSONElement& configElement) const {
+
+ BSONObj generateSection( const BSONElement& configElement ) const {
BSONObjBuilder b;
b.append(".", qlk.stats.report());
b.append("admin", nestableLocks[Lock::admin]->stats.report());
b.append("local", nestableLocks[Lock::local]->stats.report());
{
- mapsf<string,WrapperForRWLock*>::ref r(dblocks);
- for( unordered_map<string,WrapperForRWLock*>::const_iterator i = r.r.begin(); i != r.r.end(); i++ ) {
+ DBLocksMap::ref r(dblocks);
+ for( DBLocksMap::const_iterator i = r.r.begin(); i != r.r.end(); ++i ) {
b.append(i->first, i->second->stats.report());
}
}