db.h   db.h 
skipping to change at line 49 skipping to change at line 49
could be slightly larger. could be slightly larger.
*/ */
const int MaxBSONObjectSize = 4 * 1024 * 1024; const int MaxBSONObjectSize = 4 * 1024 * 1024;
/** /**
* class to hold path + dbname -> Database * class to hold path + dbname -> Database
* might be able to optimizer further * might be able to optimizer further
*/ */
class DatabaseHolder { class DatabaseHolder {
public: public:
typedef map<string,Database*> DBs;
typedef map<string,DBs> Paths;
DatabaseHolder() : _size(0){ DatabaseHolder() : _size(0){
} }
bool isLoaded( const string& ns , const string& path ){ bool isLoaded( const string& ns , const string& path ) const {
dbMutex.assertAtLeastReadLocked(); dbMutex.assertAtLeastReadLocked();
map<string,Database*>& m = _paths[path]; Paths::const_iterator x = _paths.find( path );
if ( x == _paths.end() )
return false;
const DBs& m = x->second;
string db = _todb( ns ); string db = _todb( ns );
map<string,Database*>::iterator it = m.find(db); DBs::const_iterator it = m.find(db);
return it != m.end(); return it != m.end();
} }
Database * get( const string& ns , const string& path ){ Database * get( const string& ns , const string& path ) const {
dbMutex.assertAtLeastReadLocked(); dbMutex.assertAtLeastReadLocked();
map<string,Database*>& m = _paths[path]; Paths::const_iterator x = _paths.find( path );
if ( x == _paths.end() )
return 0;
const DBs& m = x->second;
string db = _todb( ns ); string db = _todb( ns );
map<string,Database*>::iterator it = m.find(db); DBs::const_iterator it = m.find(db);
if ( it != m.end() ) if ( it != m.end() )
return it->second; return it->second;
return 0; return 0;
} }
void put( const string& ns , const string& path , Database * db ){ void put( const string& ns , const string& path , Database * db ){
dbMutex.assertWriteLocked(); dbMutex.assertWriteLocked();
map<string,Database*>& m = _paths[path]; DBs& m = _paths[path];
Database*& d = m[_todb(ns)]; Database*& d = m[_todb(ns)];
if ( ! d ) if ( ! d )
_size++; _size++;
d = db; d = db;
} }
Database* getOrCreate( const string& ns , const string& path , bool & justCreated ){ Database* getOrCreate( const string& ns , const string& path , bool & justCreated ){
dbMutex.assertWriteLocked(); dbMutex.assertWriteLocked();
map<string,Database*>& m = _paths[path]; DBs& m = _paths[path];
string dbname = _todb( ns ); string dbname = _todb( ns );
Database* & db = m[dbname]; Database* & db = m[dbname];
if ( db ){ if ( db ){
justCreated = false; justCreated = false;
return db; return db;
} }
log(1) << "Accessing: " << dbname << " for the first time" << e ndl; log(1) << "Accessing: " << dbname << " for the first time" << e ndl;
db = new Database( dbname.c_str() , justCreated , path ); db = new Database( dbname.c_str() , justCreated , path );
_size++; _size++;
return db; return db;
} }
void erase( const string& ns , const string& path ){ void erase( const string& ns , const string& path ){
dbMutex.assertWriteLocked(); dbMutex.assertWriteLocked();
map<string,Database*>& m = _paths[path]; DBs& m = _paths[path];
_size -= (int)m.erase( _todb( ns ) ); _size -= (int)m.erase( _todb( ns ) );
} }
/* force - force close even if something underway - use at shutdown */ /* force - force close even if something underway - use at shutdown */
bool closeAll( const string& path , BSONObjBuilder& result, bool fo rce ); bool closeAll( const string& path , BSONObjBuilder& result, bool fo rce );
int size(){ int size(){
return _size; return _size;
} }
/** /**
* gets all unique db names, ignoring paths * gets all unique db names, ignoring paths
*/ */
void getAllShortNames( set<string>& all ) const{ void getAllShortNames( set<string>& all ) const {
dbMutex.assertAtLeastReadLocked(); dbMutex.assertAtLeastReadLocked();
for ( map<string, map<string,Database*> >::const_iterator i=_pa for ( Paths::const_iterator i=_paths.begin(); i!=_paths.end();
ths.begin(); i!=_paths.end(); i++ ){ i++ ){
map<string,Database*> m = i->second; DBs m = i->second;
for( map<string,Database*>::const_iterator j=m.begin(); j!= for( DBs::const_iterator j=m.begin(); j!=m.end(); j++ ){
m.end(); j++ ){
all.insert( j->first ); all.insert( j->first );
} }
} }
} }
private: private:
string _todb( const string& ns ){ string _todb( const string& ns ) const {
size_t i = ns.find( '.' ); size_t i = ns.find( '.' );
if ( i == string::npos ) if ( i == string::npos )
return ns; return ns;
return ns.substr( 0 , i ); return ns.substr( 0 , i );
} }
map<string, map<string,Database*> > _paths; Paths _paths;
int _size; int _size;
}; };
extern DatabaseHolder dbHolder; extern DatabaseHolder dbHolder;
// shared functionality for removing references to a database from this program instance // shared functionality for removing references to a database from this program instance
// does not delete the files on disk // does not delete the files on disk
void closeDatabase( const char *cl, const string& path = dbpath ); void closeDatabase( const char *cl, const string& path = dbpath );
 End of changes. 14 change blocks. 
17 lines changed or deleted 25 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/