Skip to content

Commit c4db577

Browse files
committed
SERVER-13635: remove Database::getExtentManager
1 parent 73d7eff commit c4db577

9 files changed

Lines changed: 79 additions & 135 deletions

File tree

src/mongo/db/catalog/database.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
#include "mongo/db/pdfile.h"
5050
#include "mongo/db/server_parameters.h"
5151
#include "mongo/db/storage/mmap_v1/mmap_v1_engine.h" //XXX
52-
#include "mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h" //XXX
5352
#include "mongo/db/storage_options.h"
5453
#include "mongo/db/catalog/collection.h"
5554

@@ -500,37 +499,6 @@ namespace mongo {
500499
return collection;
501500
}
502501

503-
504-
void Database::_addNamespaceToCatalog( OperationContext* txn,
505-
const StringData& ns,
506-
const BSONObj* options ) {
507-
LOG(1) << "Database::_addNamespaceToCatalog ns: " << ns << endl;
508-
if ( nsToCollectionSubstring( ns ) == "system.namespaces" ) {
509-
// system.namespaces holds all the others, so it is not explicitly listed in the catalog.
510-
return;
511-
}
512-
513-
BSONObjBuilder b;
514-
b.append("name", ns);
515-
if ( options && !options->isEmpty() )
516-
b.append("options", *options);
517-
BSONObj obj = b.done();
518-
519-
Collection* collection = getCollection( txn, _namespacesName );
520-
if ( !collection )
521-
collection = createCollection( txn, _namespacesName );
522-
StatusWith<DiskLoc> loc = collection->insertDocument( txn, obj, false );
523-
uassertStatusOK( loc.getStatus() );
524-
}
525-
526-
MmapV1ExtentManager* Database::getExtentManager() {
527-
return _dbEntry->getExtentManager();
528-
}
529-
530-
const MmapV1ExtentManager* Database::getExtentManager() const {
531-
return _dbEntry->getExtentManager();
532-
}
533-
534502
const DatabaseCatalogEntry* Database::getDatabaseCatalogEntry() const {
535503
return _dbEntry.get();
536504
}

src/mongo/db/catalog/database.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,10 @@
4141
namespace mongo {
4242

4343
class Collection;
44-
class DatabaseCatalogEntry;
4544
class DataFile;
45+
class DatabaseCatalogEntry;
4646
class ExtentManager;
4747
class IndexCatalog;
48-
class MMAP1DatabaseCatalogEntry;
49-
class MmapV1ExtentManager;
5048
class NamespaceDetails;
5149
class OperationContext;
5250

@@ -101,10 +99,6 @@ namespace mongo {
10199

102100
const DatabaseCatalogEntry* getDatabaseCatalogEntry() const;
103101

104-
// TODO: do not think this method should exist, so should try and encapsulate better
105-
MmapV1ExtentManager* getExtentManager();
106-
const MmapV1ExtentManager* getExtentManager() const;
107-
108102
Status dropCollection( OperationContext* txn, const StringData& fullns );
109103

110104
Collection* createCollection( OperationContext* txn,
@@ -150,15 +144,10 @@ namespace mongo {
150144

151145
~Database(); // closes files and other cleanup see below.
152146

153-
// TODO(ERH) remove XXX
154-
void _addNamespaceToCatalog( OperationContext* txn,
155-
const StringData& ns,
156-
const BSONObj* options );
157-
158147
const std::string _name; // "alleyinsider"
159148
const std::string _path; // "/data/db"
160149

161-
boost::scoped_ptr<MMAP1DatabaseCatalogEntry> _dbEntry;
150+
boost::scoped_ptr<DatabaseCatalogEntry> _dbEntry;
162151

163152
const std::string _profileName; // "alleyinsider.system.profile"
164153
const std::string _namespacesName; // "alleyinsider.system.namespaces"

src/mongo/db/catalog/database_catalog_entry.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@
3838
namespace mongo {
3939

4040
class BSONObjBuilder;
41+
class CollectionCatalogEntry;
42+
class IndexAccessMethod;
43+
class IndexCatalogEntry;
4144
class OperationContext;
45+
class RecordStore;
46+
47+
struct CollectionOptions;
4248

4349
class DatabaseCatalogEntry {
4450
public:
@@ -50,19 +56,47 @@ namespace mongo {
5056

5157
const std::string& name() const { return _name; }
5258

59+
virtual bool exists() const = 0;
5360
virtual bool isEmpty() const = 0;
5461

5562
virtual void appendExtraStats( OperationContext* opCtx,
5663
BSONObjBuilder* out,
5764
double scale ) const = 0;
5865

66+
// these are hacks :(
5967
virtual bool isOlderThan24( OperationContext* opCtx ) const = 0;
6068
virtual void markIndexSafe24AndUp( OperationContext* opCtx ) = 0;
6169

70+
/**
71+
* @return true if current files on disk are compatibile with the current version.
72+
* if we return false, then an upgrade will be required
73+
*/
74+
virtual bool currentFilesCompatible( OperationContext* opCtx ) const = 0;
75+
6276
// ----
6377

6478
virtual void getCollectionNamespaces( std::list<std::string>* out ) const = 0;
6579

80+
virtual CollectionCatalogEntry* getCollectionCatalogEntry( OperationContext* txn,
81+
const StringData& ns ) = 0;
82+
83+
virtual RecordStore* getRecordStore( OperationContext* txn,
84+
const StringData& ns ) = 0;
85+
86+
virtual IndexAccessMethod* getIndex( OperationContext* txn,
87+
const CollectionCatalogEntry* collection,
88+
IndexCatalogEntry* index ) = 0;
89+
90+
virtual Status createCollection( OperationContext* txn,
91+
const StringData& ns,
92+
const CollectionOptions& options,
93+
bool allocateDefaultSpace ) = 0;
94+
95+
virtual Status renameCollection( OperationContext* txn,
96+
const StringData& fromNS,
97+
const StringData& toNS,
98+
bool stayTemp ) = 0;
99+
66100
virtual Status dropCollection( OperationContext* opCtx,
67101
const StringData& ns ) = 0;
68102

src/mongo/db/db.cpp

Lines changed: 14 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -298,35 +298,6 @@ namespace mongo {
298298
server->run();
299299
}
300300

301-
302-
void doDBUpgrade( const string& dbName, DataFileHeader* h ) {
303-
OperationContextImpl txn;
304-
DBDirectClient db(&txn);
305-
306-
if ( h->version == 4 && h->versionMinor == 4 ) {
307-
verify( PDFILE_VERSION == 4 );
308-
verify( PDFILE_VERSION_MINOR_22_AND_OLDER == 5 );
309-
310-
list<string> colls = db.getCollectionNames( dbName );
311-
for ( list<string>::iterator i=colls.begin(); i!=colls.end(); i++) {
312-
string c = *i;
313-
log() << "\t upgrading collection:" << c << endl;
314-
BSONObj out;
315-
bool ok = db.runCommand( dbName , BSON( "reIndex" << c.substr( dbName.size() + 1 ) ) , out );
316-
if ( ! ok ) {
317-
log() << "\t\t reindex failed: " << out;
318-
fassertFailed( 17393 );
319-
}
320-
}
321-
322-
txn.recoveryUnit()->writingInt(h->versionMinor) = 5;
323-
return;
324-
}
325-
326-
// do this in the general case
327-
fassert( 17401, repairDatabase( &txn, dbName ) );
328-
}
329-
330301
void checkForIdIndexes( OperationContext* txn, Database* db ) {
331302

332303
if ( db->name() == "local") {
@@ -376,8 +347,6 @@ namespace mongo {
376347
LOG(1) << "\t" << dbName << endl;
377348

378349
Client::Context ctx( dbName );
379-
DataFile *p = ctx.db()->getExtentManager()->getFile(&txn, 0);
380-
DataFileHeader *h = p->getHeader();
381350

382351
if (repl::replSettings.usingReplSets()) {
383352
// we only care about the _id index if we are in a replset
@@ -387,38 +356,21 @@ namespace mongo {
387356
if (shouldClearNonLocalTmpCollections || dbName == "local")
388357
ctx.db()->clearTmpCollections(&txn);
389358

390-
if (!h->isCurrentVersion() || mongodGlobalParams.repair) {
391-
392-
if( h->version <= 0 ) {
393-
uasserted(14026,
394-
str::stream() << "db " << dbName << " appears corrupt pdfile version: " << h->version
395-
<< " info: " << h->versionMinor << ' ' << h->fileLength);
396-
}
397-
398-
if ( !h->isCurrentVersion() ) {
399-
log() << "****" << endl;
400-
log() << "****" << endl;
401-
log() << "need to upgrade database " << dbName << " "
402-
<< "with pdfile version " << h->version << "." << h->versionMinor << ", "
403-
<< "new version: "
404-
<< PDFILE_VERSION << "." << PDFILE_VERSION_MINOR_22_AND_OLDER
405-
<< endl;
406-
}
407-
408-
if (mongodGlobalParams.upgrade) {
409-
// QUESTION: Repair even if file format is higher version than code?
410-
doDBUpgrade( dbName, h );
411-
}
412-
else {
413-
log() << "\t Not upgrading, exiting" << endl;
414-
log() << "\t run --upgrade to upgrade dbs, then start again" << endl;
415-
log() << "****" << endl;
416-
dbexit( EXIT_NEED_UPGRADE );
417-
mongodGlobalParams.upgrade = 1;
418-
return;
419-
}
359+
OperationContextImpl opCtx;
360+
if ( mongodGlobalParams.repair ) {
361+
fassert( 18506, repairDatabase( &opCtx, dbName ) );
362+
}
363+
else if ( !ctx.db()->getDatabaseCatalogEntry()->currentFilesCompatible( &opCtx ) ) {
364+
log() << "****";
365+
log() << "cannot do this upgrade without an upgrade in the middle";
366+
log() << "please do a --repair with 2.6 and then start this version";
367+
dbexit( EXIT_NEED_UPGRADE );
368+
invariant( false );
369+
return;
420370
}
421371
else {
372+
// major versions match, check indexes
373+
422374
const string systemIndexes = ctx.db()->name() + ".system.indexes";
423375
Collection* coll = ctx.db()->getCollection( &txn, systemIndexes );
424376
auto_ptr<Runner> runner(InternalPlanner::collectionScan(systemIndexes,coll));
@@ -428,7 +380,7 @@ namespace mongo {
428380
const BSONObj key = index.getObjectField("key");
429381
const string plugin = IndexNames::findPluginName(key);
430382

431-
if (h->versionMinor == PDFILE_VERSION_MINOR_22_AND_OLDER) {
383+
if (ctx.db()->getDatabaseCatalogEntry()->isOlderThan24( &opCtx )) {
432384
if (IndexNames::existedBefore24(plugin))
433385
continue;
434386

src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,13 @@ namespace mongo {
361361
PDFILE_VERSION_MINOR_24_AND_NEWER;
362362
}
363363

364+
bool MMAP1DatabaseCatalogEntry::currentFilesCompatible( OperationContext* opCtx ) const {
365+
if ( _extentManager.numFiles() == 0 )
366+
return true;
367+
368+
return _extentManager.getOpenFile( 0 )->getHeader()->isCurrentVersion();
369+
}
370+
364371
void MMAP1DatabaseCatalogEntry::getCollectionNamespaces( std::list<std::string>* tofill ) const {
365372
_namespaceIndex.getCollectionNamespaces( tofill );
366373
}

src/mongo/db/storage/mmap_v1/mmap_v1_engine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ namespace mongo {
6464
virtual bool isOlderThan24( OperationContext* opCtx ) const;
6565
virtual void markIndexSafe24AndUp( OperationContext* opCtx );
6666

67+
virtual bool currentFilesCompatible( OperationContext* opCtx ) const;
68+
6769
virtual void appendExtraStats( OperationContext* opCtx,
6870
BSONObjBuilder* out,
6971
double scale ) const;

src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ namespace mongo {
186186
}
187187

188188
size_t MmapV1ExtentManager::numFiles() const {
189-
DEV Lock::assertAtLeastReadLocked( _dbname );
190189
return _files.size();
191190
}
192191

@@ -558,5 +557,11 @@ namespace mongo {
558557
const DataFile* df = _getOpenFile( 0 );
559558
*major = df->getHeader()->version;
560559
*minor = df->getHeader()->versionMinor;
560+
561+
if ( *major <= 0 || *major >= 100 ||
562+
*minor <= 0 || *minor >= 100 ) {
563+
error() << "corrupt pdfile version? major: " << *major << " minor: " << *minor;
564+
fassertFailed( 14026 );
565+
}
561566
}
562567
}

src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ namespace mongo {
145145

146146
void getFileFormat( OperationContext* txn, int* major, int* minor ) const;
147147

148+
const DataFile* getOpenFile( int n ) const { return _getOpenFile( n ); }
149+
148150
virtual int maxSize() const;
149151

150152

src/mongo/dbtests/pdfiletests.cpp

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -156,43 +156,27 @@ namespace PdfileTests {
156156

157157
class ExtentSizing {
158158
public:
159-
struct SmallFilesControl {
160-
SmallFilesControl() {
161-
old = storageGlobalParams.smallfiles;
162-
storageGlobalParams.smallfiles = false;
163-
}
164-
~SmallFilesControl() {
165-
storageGlobalParams.smallfiles = old;
166-
}
167-
bool old;
168-
};
169159
void run() {
170-
SmallFilesControl c;
171-
172-
OperationContextImpl txn;
173-
Client::ReadContext ctx(&txn, "local");
174-
Database* db = ctx.ctx().db();
175-
ExtentManager* em = db->getExtentManager();
160+
MmapV1ExtentManager em( "x", "x", false );
176161

177-
ASSERT_EQUALS( em->maxSize(),
178-
em->quantizeExtentSize( em->maxSize() ) );
162+
ASSERT_EQUALS( em.maxSize(), em.quantizeExtentSize( em.maxSize() ) );
179163

180164
// test that no matter what we start with, we always get to max extent size
181165
for ( int obj=16; obj<BSONObjMaxUserSize; obj += 111 ) {
182166

183-
int sz = em->initialSize( obj );
167+
int sz = em.initialSize( obj );
184168

185169
double totalExtentSize = sz;
186170

187171
int numFiles = 1;
188-
int sizeLeftInExtent = em->maxSize() - 1;
172+
int sizeLeftInExtent = em.maxSize() - 1;
189173

190174
for ( int i=0; i<100; i++ ) {
191-
sz = em->followupSize( obj , sz );
175+
sz = em.followupSize( obj , sz );
192176
ASSERT( sz >= obj );
193-
ASSERT( sz >= em->minSize() );
194-
ASSERT( sz <= em->maxSize() );
195-
ASSERT( sz <= em->maxSize() );
177+
ASSERT( sz >= em.minSize() );
178+
ASSERT( sz <= em.maxSize() );
179+
ASSERT( sz <= em.maxSize() );
196180

197181
totalExtentSize += sz;
198182

@@ -201,15 +185,16 @@ namespace PdfileTests {
201185
}
202186
else {
203187
numFiles++;
204-
sizeLeftInExtent = em->maxSize() - sz;
188+
sizeLeftInExtent = em.maxSize() - sz;
205189
}
206190
}
207-
ASSERT_EQUALS( em->maxSize() , sz );
191+
ASSERT_EQUALS( em.maxSize(), sz );
208192

209-
double allocatedOnDisk = (double)numFiles * em->maxSize();
193+
double allocatedOnDisk = (double)numFiles * em.maxSize();
210194

211195
ASSERT( ( totalExtentSize / allocatedOnDisk ) > .95 );
212196

197+
invariant( em.numFiles() == 0 );
213198
}
214199
}
215200
};

0 commit comments

Comments
 (0)