Skip to content

Commit 4e13ac7

Browse files
committed
SERVER-13635: remove path concept from DatabaseHolder, and move repair and listDatabase into storageEngine
1 parent e11156f commit 4e13ac7

38 files changed

+203
-216
lines changed

src/mongo/SConscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ serverOnlyFiles = [ "db/curop.cpp",
559559
"db/storage/mmap_v1/dur_recovery_unit.cpp",
560560
"db/storage/mmap_v1/mmap_v1_database_catalog_entry.cpp",
561561
"db/storage/mmap_v1/mmap_v1_engine.cpp",
562+
"db/storage/mmap_v1/repair_database.cpp",
562563
"db/operation_context_impl.cpp",
563564
"db/storage/mmap_v1/mmap_v1_extent_manager.cpp",
564565
"db/introspect.cpp",
@@ -627,7 +628,6 @@ serverOnlyFiles = [ "db/curop.cpp",
627628
"db/catalog/database_holder.cpp",
628629
"db/background.cpp",
629630
"db/pdfile.cpp",
630-
"db/repair_database.cpp",
631631
"db/structure/catalog/index_details.cpp",
632632
"db/index_builder.cpp",
633633
"db/index_rebuilder.cpp",

src/mongo/db/auth/authz_manager_external_state_d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "mongo/db/instance.h"
4141
#include "mongo/db/jsobj.h"
4242
#include "mongo/db/operation_context_impl.h"
43+
#include "mongo/db/storage/storage_engine.h"
4344
#include "mongo/util/assert_util.h"
4445
#include "mongo/util/mongoutils/str.h"
4546

@@ -99,8 +100,7 @@ namespace mongo {
99100

100101
Status AuthzManagerExternalStateMongod::getAllDatabaseNames(
101102
OperationContext* txn, std::vector<std::string>* dbnames) {
102-
Lock::GlobalRead lk(txn->lockState());
103-
getDatabaseNames(*dbnames);
103+
globalStorageEngine->listDatabases( dbnames );
104104
return Status::OK();
105105
}
106106

src/mongo/db/catalog/collection_cursor_cache.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ namespace mongo {
188188
}
189189

190190
Lock::DBRead lock(txn->lockState(), ns);
191-
Database* db = dbHolder().get(txn, ns, storageGlobalParams.dbpath);
191+
Database* db = dbHolder().get(txn, ns);
192192
if ( !db )
193193
return false;
194194
Client::Context context( ns, db );
@@ -218,7 +218,7 @@ namespace mongo {
218218
for ( unsigned i = 0; i < todo.size(); i++ ) {
219219
const string& ns = todo[i];
220220
Lock::DBRead lock(txn->lockState(), ns);
221-
Database* db = dbHolder().get(txn, ns, storageGlobalParams.dbpath);
221+
Database* db = dbHolder().get(txn, ns);
222222
if ( !db )
223223
continue;
224224
Client::Context context( ns, db );

src/mongo/db/catalog/database.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include "mongo/db/pdfile.h"
5151
#include "mongo/db/server_parameters.h"
5252
#include "mongo/db/storage_options.h"
53+
#include "mongo/db/storage/storage_engine.h"
5354
#include "mongo/db/catalog/collection.h"
5455

5556
namespace mongo {
@@ -124,13 +125,13 @@ namespace mongo {
124125

125126

126127
/*static*/
127-
string Database::duplicateUncasedName(const string &name, const string &path, set< string > *duplicates) {
128+
string Database::duplicateUncasedName(const string &name, set< string > *duplicates) {
128129
if ( duplicates ) {
129130
duplicates->clear();
130131
}
131132

132133
vector<string> others;
133-
getDatabaseNames( others , path );
134+
globalStorageEngine->listDatabases( &others );
134135

135136
set<string> allShortNames;
136137
dbHolder().getAllShortNames(allShortNames);

src/mongo/db/catalog/database.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ namespace mongo {
6464
/* you must use this to close - there is essential code in this method that is not in the ~Database destructor.
6565
thus the destructor is private. this could be cleaned up one day...
6666
*/
67-
static void closeDatabase(
68-
OperationContext* txn, const std::string& db, const std::string& path);
67+
static void closeDatabase(OperationContext* txn,
68+
const std::string& db);
69+
70+
// do not use!
71+
~Database(); // closes files and other cleanup see below.
6972

7073
const std::string& name() const { return _name; }
7174

@@ -129,7 +132,6 @@ namespace mongo {
129132
// TODO move???
130133
*/
131134
static string duplicateUncasedName( const std::string &name,
132-
const std::string &path,
133135
std::set< std::string > *duplicates = 0 );
134136

135137
static Status validateDBName( const StringData& dbname );
@@ -141,8 +143,6 @@ namespace mongo {
141143

142144
void _clearCollectionCache_inlock( const StringData& fullns );
143145

144-
~Database(); // closes files and other cleanup see below.
145-
146146
const std::string _name; // "alleyinsider"
147147

148148
boost::scoped_ptr<DatabaseCatalogEntry> _dbEntry;

src/mongo/db/catalog/database_holder.cpp

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,21 @@
4747
namespace mongo {
4848

4949
Database* DatabaseHolder::get(OperationContext* txn,
50-
const std::string& ns,
51-
const std::string& path) const {
50+
const std::string& ns) const {
5251

5352
txn->lockState()->assertAtLeastReadLocked(ns);
5453

5554
SimpleMutex::scoped_lock lk(_m);
56-
Paths::const_iterator x = _paths.find( path );
57-
if ( x == _paths.end() )
58-
return 0;
59-
const DBs& m = x->second;
6055
const std::string db = _todb( ns );
61-
DBs::const_iterator it = m.find(db);
62-
if ( it != m.end() )
56+
DBs::const_iterator it = _dbs.find(db);
57+
if ( it != _dbs.end() )
6358
return it->second;
6459
return NULL;
6560
}
6661

67-
Database* DatabaseHolder::getOrCreate(
68-
OperationContext* txn, const string& ns, const string& path, bool& justCreated) {
62+
Database* DatabaseHolder::getOrCreate(OperationContext* txn,
63+
const string& ns,
64+
bool& justCreated) {
6965

7066
const string dbname = _todb( ns );
7167
invariant(txn->lockState()->isAtLeastReadLocked(dbname));
@@ -76,10 +72,9 @@ namespace mongo {
7672

7773
{
7874
SimpleMutex::scoped_lock lk(_m);
79-
DBs& m = _paths[path];
8075
{
81-
DBs::iterator i = m.find(dbname);
82-
if( i != m.end() ) {
76+
DBs::iterator i = _dbs.find(dbname);
77+
if( i != _dbs.end() ) {
8378
justCreated = false;
8479
return i->second;
8580
}
@@ -90,10 +85,8 @@ namespace mongo {
9085
// perhaps just log it, which is what we do here with the "> 40" :
9186
bool cant = !txn->lockState()->isWriteLocked(ns);
9287
if( logger::globalLogDomain()->shouldLog(logger::LogSeverity::Debug(1)) ||
93-
m.size() > 40 || cant || DEBUG_BUILD ) {
94-
log() << "opening db: "
95-
<< (path == storageGlobalParams.dbpath ? "" : path) << ' ' << dbname
96-
<< endl;
88+
_dbs.size() > 40 || cant || DEBUG_BUILD ) {
89+
log() << "opening db: " << dbname;
9790
}
9891
massert(15927, "can't open database in a read lock. if db was just closed, consider retrying the query. might otherwise indicate an internal error", !cant);
9992
}
@@ -107,43 +100,36 @@ namespace mongo {
107100
dbname,
108101
justCreated,
109102
new MMAPV1DatabaseCatalogEntry(txn,
110-
dbname,
111-
path,
112-
storageGlobalParams.directoryperdb));
103+
dbname,
104+
storageGlobalParams.dbpath,
105+
storageGlobalParams.directoryperdb,
106+
false));
113107

114108
{
115109
SimpleMutex::scoped_lock lk(_m);
116-
DBs& m = _paths[path];
117-
verify( m[dbname] == 0 );
118-
m[dbname] = db;
119-
_size++;
110+
_dbs[dbname] = db;
120111
}
121112

122113
return db;
123114
}
124115

125116
void DatabaseHolder::erase(OperationContext* txn,
126-
const std::string& ns,
127-
const std::string& path) {
117+
const std::string& ns) {
128118
invariant(txn->lockState()->isW());
129119

130120
SimpleMutex::scoped_lock lk(_m);
131-
DBs& m = _paths[path];
132-
_size -= (int)m.erase(_todb(ns));
121+
_dbs.erase(_todb(ns));
133122
}
134123

135-
bool DatabaseHolder::closeAll(
136-
OperationContext* txn, const string& path, BSONObjBuilder& result, bool force) {
137-
log() << "DatabaseHolder::closeAll path:" << path << endl;
124+
bool DatabaseHolder::closeAll(OperationContext* txn,
125+
BSONObjBuilder& result,
126+
bool force) {
138127
invariant(txn->lockState()->isW());
139128

140129
getDur().commitNow(txn); // bad things happen if we close a DB with outstanding writes
141130

142-
map<string,Database*>& m = _paths[path];
143-
_size -= m.size();
144-
145131
set< string > dbs;
146-
for ( map<string,Database*>::iterator i = m.begin(); i != m.end(); i++ ) {
132+
for ( map<string,Database*>::iterator i = _dbs.begin(); i != _dbs.end(); i++ ) {
147133
dbs.insert( i->first );
148134
}
149135

@@ -152,8 +138,8 @@ namespace mongo {
152138
int nNotClosed = 0;
153139
for( set< string >::iterator i = dbs.begin(); i != dbs.end(); ++i ) {
154140
string name = *i;
155-
LOG(2) << "DatabaseHolder::closeAll path:" << path << " name:" << name << endl;
156-
Client::Context ctx( name , path );
141+
LOG(2) << "DatabaseHolder::closeAll name:" << name;
142+
Client::Context ctx( name );
157143
if( !force && BackgroundOperation::inProgForDb(name) ) {
158144
log() << "WARNING: can't close database "
159145
<< name
@@ -162,7 +148,7 @@ namespace mongo {
162148
nNotClosed++;
163149
}
164150
else {
165-
Database::closeDatabase(txn, name.c_str(), path);
151+
Database::closeDatabase(txn, name.c_str());
166152
bb.append( bb.numStr( n++ ) , name );
167153
}
168154
}

src/mongo/db/catalog/database_holder.h

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -34,52 +34,40 @@
3434
#include "mongo/db/d_concurrency.h"
3535
#include "mongo/db/namespace_string.h"
3636

37-
namespace mongo {
37+
namespace mongo {
3838

3939
/**
40-
* path + dbname -> Database
40+
* dbname -> Database
4141
*/
4242
class DatabaseHolder {
4343
typedef std::map<std::string,Database*> DBs;
44-
typedef std::map<std::string,DBs> Paths;
4544
// todo: we want something faster than this if called a lot:
4645
mutable SimpleMutex _m;
47-
Paths _paths;
48-
int _size;
46+
DBs _dbs;
4947
public:
50-
DatabaseHolder() : _m("dbholder"),_size(0) { }
48+
DatabaseHolder() : _m("dbholder"){ }
5149

5250
Database* get(OperationContext* txn,
53-
const std::string& ns,
54-
const std::string& path) const;
51+
const std::string& ns) const;
5552

5653
Database* getOrCreate(OperationContext* txn,
5754
const std::string& ns,
58-
const std::string& path,
5955
bool& justCreated);
6056

61-
void erase(OperationContext* txn, const std::string& ns, const std::string& path);
57+
void erase(OperationContext* txn, const std::string& ns);
6258

6359
/** @param force - force close even if something underway - use at shutdown */
6460
bool closeAll(OperationContext* txn,
65-
const std::string& path,
6661
BSONObjBuilder& result,
6762
bool force);
6863

69-
// "info" as this is informational only could change on you if you are not write locked
70-
int sizeInfo() const { return _size; }
71-
7264
/**
73-
* gets all unique db names, ignoring paths
7465
* need some lock
7566
*/
7667
void getAllShortNames( std::set<std::string>& all ) const {
7768
SimpleMutex::scoped_lock lk(_m);
78-
for ( Paths::const_iterator i=_paths.begin(); i!=_paths.end(); i++ ) {
79-
DBs m = i->second;
80-
for( DBs::const_iterator j=m.begin(); j!=m.end(); j++ ) {
81-
all.insert( j->first );
82-
}
69+
for( DBs::const_iterator j=_dbs.begin(); j!=_dbs.end(); j++ ) {
70+
all.insert( j->first );
8371
}
8472
}
8573

src/mongo/db/client.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ namespace mongo {
164164
BSONObj CachedBSONObjBase::_tooBig = fromjson("{\"$msg\":\"query not recording (too large)\"}");
165165
Client::Context::Context(const std::string& ns , Database * db) :
166166
_client( currentClient.get() ),
167-
_path(storageGlobalParams.dbpath), // is this right? could be a different db?
168-
// may need a dassert for this
169167
_justCreated(false),
170168
_doVersion( true ),
171169
_ns( ns ),
@@ -174,9 +172,8 @@ namespace mongo {
174172

175173
}
176174

177-
Client::Context::Context(const string& ns, const std::string& path, bool doVersion) :
175+
Client::Context::Context(const string& ns, bool doVersion) :
178176
_client( currentClient.get() ),
179-
_path( path ),
180177
_justCreated(false), // set for real in finishInit
181178
_doVersion(doVersion),
182179
_ns( ns ),
@@ -192,9 +189,9 @@ namespace mongo {
192189
OperationContext* txn, const string& ns, bool doVersion) {
193190
{
194191
_lk.reset(new Lock::DBRead(txn->lockState(), ns));
195-
Database *db = dbHolder().get(txn, ns, storageGlobalParams.dbpath);
192+
Database *db = dbHolder().get(txn, ns);
196193
if( db ) {
197-
_c.reset(new Context(storageGlobalParams.dbpath, ns, db, doVersion));
194+
_c.reset(new Context(ns, db, doVersion));
198195
return;
199196
}
200197
}
@@ -205,18 +202,18 @@ namespace mongo {
205202
if (txn->lockState()->isW()) {
206203
// write locked already
207204
DEV RARELY log() << "write locked on ReadContext construction " << ns << endl;
208-
_c.reset(new Context(ns, storageGlobalParams.dbpath, doVersion));
205+
_c.reset(new Context(ns, doVersion));
209206
}
210207
else if (!txn->lockState()->isRecursive()) {
211208
_lk.reset(0);
212209
{
213210
Lock::GlobalWrite w(txn->lockState());
214-
Context c(ns, storageGlobalParams.dbpath, doVersion);
211+
Context c(ns, doVersion);
215212
}
216213

217214
// db could be closed at this interim point -- that is ok, we will throw, and don't mind throwing.
218215
_lk.reset(new Lock::DBRead(txn->lockState(), ns));
219-
_c.reset(new Context(ns, storageGlobalParams.dbpath, doVersion));
216+
_c.reset(new Context(ns, doVersion));
220217
}
221218
else {
222219
uasserted(15928, str::stream() << "can't open a database from a nested read lock " << ns);
@@ -231,7 +228,7 @@ namespace mongo {
231228
Client::WriteContext::WriteContext(
232229
OperationContext* opCtx, const std::string& ns, bool doVersion)
233230
: _lk(opCtx->lockState(), ns),
234-
_c(ns, storageGlobalParams.dbpath, doVersion) {
231+
_c(ns, doVersion) {
235232
}
236233

237234

@@ -255,9 +252,8 @@ namespace mongo {
255252
}
256253

257254
// invoked from ReadContext
258-
Client::Context::Context(const string& path, const string& ns, Database *db, bool doVersion) :
255+
Client::Context::Context(const string& ns, Database *db, bool doVersion) :
259256
_client( currentClient.get() ),
260-
_path( path ),
261257
_justCreated(false),
262258
_doVersion( doVersion ),
263259
_ns( ns ),
@@ -270,7 +266,7 @@ namespace mongo {
270266

271267
void Client::Context::_finishInit() {
272268
OperationContextImpl txn; // TODO get rid of this once reads require transactions
273-
_db = dbHolder().getOrCreate(&txn, _ns, _path, _justCreated);
269+
_db = dbHolder().getOrCreate(&txn, _ns, _justCreated);
274270
invariant(_db);
275271

276272
if( _doVersion ) checkNotStale();

0 commit comments

Comments
 (0)