diff --git a/db/db.h b/db/db.h index 917fb5c253b..ddb7507d13a 100644 --- a/db/db.h +++ b/db/db.h @@ -48,6 +48,17 @@ namespace mongo { public: DatabaseHolder() : _size(0){ } + + bool isLoaded( const string& ns , const string& path ){ + dbMutex.assertAtLeastReadLocked(); + map& m = _paths[path]; + + string db = _todb( ns ); + + map::iterator it = m.find(db); + return it != m.end(); + } + Database * get( const string& ns , const string& path ){ dbMutex.assertAtLeastReadLocked(); @@ -116,7 +127,7 @@ namespace mongo { } } } - + private: string _todb( const string& ns ){ diff --git a/db/instance.cpp b/db/instance.cpp index 8d1d38383cc..0f399327b87 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -365,8 +365,13 @@ namespace mongo { } else { mongolock lk(true); - Client::Context c( currentOp.getNS() ); - profile(ss.str().c_str(), ms); + if ( dbHolder.isLoaded( nsToDatabase( currentOp.getNS() ) , dbpath ) ){ + Client::Context c( currentOp.getNS() ); + profile(ss.str().c_str(), ms); + } + else { + mongo::log() << "warning: not profiling because db went away - probably a close on: " << currentOp.getNS() << endl; + } } }