summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/catalog/database.cpp32
-rw-r--r--src/mongo/db/catalog/database.h15
-rw-r--r--src/mongo/db/catalog/database_catalog_entry.h34
-rw-r--r--src/mongo/db/db.cpp76
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp7
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_engine.h2
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp7
-rw-r--r--src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h2
-rw-r--r--src/mongo/dbtests/pdfiletests.cpp39
9 files changed, 79 insertions, 135 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index 113594e0433..d3b67c97557 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -49,7 +49,6 @@
#include "mongo/db/pdfile.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/storage/mmap_v1/mmap_v1_engine.h" //XXX
-#include "mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h" //XXX
#include "mongo/db/storage_options.h"
#include "mongo/db/catalog/collection.h"
@@ -500,37 +499,6 @@ namespace mongo {
return collection;
}
-
- void Database::_addNamespaceToCatalog( OperationContext* txn,
- const StringData& ns,
- const BSONObj* options ) {
- LOG(1) << "Database::_addNamespaceToCatalog ns: " << ns << endl;
- if ( nsToCollectionSubstring( ns ) == "system.namespaces" ) {
- // system.namespaces holds all the others, so it is not explicitly listed in the catalog.
- return;
- }
-
- BSONObjBuilder b;
- b.append("name", ns);
- if ( options && !options->isEmpty() )
- b.append("options", *options);
- BSONObj obj = b.done();
-
- Collection* collection = getCollection( txn, _namespacesName );
- if ( !collection )
- collection = createCollection( txn, _namespacesName );
- StatusWith<DiskLoc> loc = collection->insertDocument( txn, obj, false );
- uassertStatusOK( loc.getStatus() );
- }
-
- MmapV1ExtentManager* Database::getExtentManager() {
- return _dbEntry->getExtentManager();
- }
-
- const MmapV1ExtentManager* Database::getExtentManager() const {
- return _dbEntry->getExtentManager();
- }
-
const DatabaseCatalogEntry* Database::getDatabaseCatalogEntry() const {
return _dbEntry.get();
}
diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h
index ec05223ee58..3e45fe64fea 100644
--- a/src/mongo/db/catalog/database.h
+++ b/src/mongo/db/catalog/database.h
@@ -41,12 +41,10 @@
namespace mongo {
class Collection;
- class DatabaseCatalogEntry;
class DataFile;
+ class DatabaseCatalogEntry;
class ExtentManager;
class IndexCatalog;
- class MMAP1DatabaseCatalogEntry;
- class MmapV1ExtentManager;
class NamespaceDetails;
class OperationContext;
@@ -101,10 +99,6 @@ namespace mongo {
const DatabaseCatalogEntry* getDatabaseCatalogEntry() const;
- // TODO: do not think this method should exist, so should try and encapsulate better
- MmapV1ExtentManager* getExtentManager();
- const MmapV1ExtentManager* getExtentManager() const;
-
Status dropCollection( OperationContext* txn, const StringData& fullns );
Collection* createCollection( OperationContext* txn,
@@ -150,15 +144,10 @@ namespace mongo {
~Database(); // closes files and other cleanup see below.
- // TODO(ERH) remove XXX
- void _addNamespaceToCatalog( OperationContext* txn,
- const StringData& ns,
- const BSONObj* options );
-
const std::string _name; // "alleyinsider"
const std::string _path; // "/data/db"
- boost::scoped_ptr<MMAP1DatabaseCatalogEntry> _dbEntry;
+ boost::scoped_ptr<DatabaseCatalogEntry> _dbEntry;
const std::string _profileName; // "alleyinsider.system.profile"
const std::string _namespacesName; // "alleyinsider.system.namespaces"
diff --git a/src/mongo/db/catalog/database_catalog_entry.h b/src/mongo/db/catalog/database_catalog_entry.h
index 02e674445fe..3b095fb9438 100644
--- a/src/mongo/db/catalog/database_catalog_entry.h
+++ b/src/mongo/db/catalog/database_catalog_entry.h
@@ -38,7 +38,13 @@
namespace mongo {
class BSONObjBuilder;
+ class CollectionCatalogEntry;
+ class IndexAccessMethod;
+ class IndexCatalogEntry;
class OperationContext;
+ class RecordStore;
+
+ struct CollectionOptions;
class DatabaseCatalogEntry {
public:
@@ -50,19 +56,47 @@ namespace mongo {
const std::string& name() const { return _name; }
+ virtual bool exists() const = 0;
virtual bool isEmpty() const = 0;
virtual void appendExtraStats( OperationContext* opCtx,
BSONObjBuilder* out,
double scale ) const = 0;
+ // these are hacks :(
virtual bool isOlderThan24( OperationContext* opCtx ) const = 0;
virtual void markIndexSafe24AndUp( OperationContext* opCtx ) = 0;
+ /**
+ * @return true if current files on disk are compatibile with the current version.
+ * if we return false, then an upgrade will be required
+ */
+ virtual bool currentFilesCompatible( OperationContext* opCtx ) const = 0;
+
// ----
virtual void getCollectionNamespaces( std::list<std::string>* out ) const = 0;
+ virtual CollectionCatalogEntry* getCollectionCatalogEntry( OperationContext* txn,
+ const StringData& ns ) = 0;
+
+ virtual RecordStore* getRecordStore( OperationContext* txn,
+ const StringData& ns ) = 0;
+
+ virtual IndexAccessMethod* getIndex( OperationContext* txn,
+ const CollectionCatalogEntry* collection,
+ IndexCatalogEntry* index ) = 0;
+
+ virtual Status createCollection( OperationContext* txn,
+ const StringData& ns,
+ const CollectionOptions& options,
+ bool allocateDefaultSpace ) = 0;
+
+ virtual Status renameCollection( OperationContext* txn,
+ const StringData& fromNS,
+ const StringData& toNS,
+ bool stayTemp ) = 0;
+
virtual Status dropCollection( OperationContext* opCtx,
const StringData& ns ) = 0;
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 51c36c14443..532e701b12a 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -298,35 +298,6 @@ namespace mongo {
server->run();
}
-
- void doDBUpgrade( const string& dbName, DataFileHeader* h ) {
- OperationContextImpl txn;
- DBDirectClient db(&txn);
-
- if ( h->version == 4 && h->versionMinor == 4 ) {
- verify( PDFILE_VERSION == 4 );
- verify( PDFILE_VERSION_MINOR_22_AND_OLDER == 5 );
-
- list<string> colls = db.getCollectionNames( dbName );
- for ( list<string>::iterator i=colls.begin(); i!=colls.end(); i++) {
- string c = *i;
- log() << "\t upgrading collection:" << c << endl;
- BSONObj out;
- bool ok = db.runCommand( dbName , BSON( "reIndex" << c.substr( dbName.size() + 1 ) ) , out );
- if ( ! ok ) {
- log() << "\t\t reindex failed: " << out;
- fassertFailed( 17393 );
- }
- }
-
- txn.recoveryUnit()->writingInt(h->versionMinor) = 5;
- return;
- }
-
- // do this in the general case
- fassert( 17401, repairDatabase( &txn, dbName ) );
- }
-
void checkForIdIndexes( OperationContext* txn, Database* db ) {
if ( db->name() == "local") {
@@ -376,8 +347,6 @@ namespace mongo {
LOG(1) << "\t" << dbName << endl;
Client::Context ctx( dbName );
- DataFile *p = ctx.db()->getExtentManager()->getFile(&txn, 0);
- DataFileHeader *h = p->getHeader();
if (repl::replSettings.usingReplSets()) {
// we only care about the _id index if we are in a replset
@@ -387,38 +356,21 @@ namespace mongo {
if (shouldClearNonLocalTmpCollections || dbName == "local")
ctx.db()->clearTmpCollections(&txn);
- if (!h->isCurrentVersion() || mongodGlobalParams.repair) {
-
- if( h->version <= 0 ) {
- uasserted(14026,
- str::stream() << "db " << dbName << " appears corrupt pdfile version: " << h->version
- << " info: " << h->versionMinor << ' ' << h->fileLength);
- }
-
- if ( !h->isCurrentVersion() ) {
- log() << "****" << endl;
- log() << "****" << endl;
- log() << "need to upgrade database " << dbName << " "
- << "with pdfile version " << h->version << "." << h->versionMinor << ", "
- << "new version: "
- << PDFILE_VERSION << "." << PDFILE_VERSION_MINOR_22_AND_OLDER
- << endl;
- }
-
- if (mongodGlobalParams.upgrade) {
- // QUESTION: Repair even if file format is higher version than code?
- doDBUpgrade( dbName, h );
- }
- else {
- log() << "\t Not upgrading, exiting" << endl;
- log() << "\t run --upgrade to upgrade dbs, then start again" << endl;
- log() << "****" << endl;
- dbexit( EXIT_NEED_UPGRADE );
- mongodGlobalParams.upgrade = 1;
- return;
- }
+ OperationContextImpl opCtx;
+ if ( mongodGlobalParams.repair ) {
+ fassert( 18506, repairDatabase( &opCtx, dbName ) );
+ }
+ else if ( !ctx.db()->getDatabaseCatalogEntry()->currentFilesCompatible( &opCtx ) ) {
+ log() << "****";
+ log() << "cannot do this upgrade without an upgrade in the middle";
+ log() << "please do a --repair with 2.6 and then start this version";
+ dbexit( EXIT_NEED_UPGRADE );
+ invariant( false );
+ return;
}
else {
+ // major versions match, check indexes
+
const string systemIndexes = ctx.db()->name() + ".system.indexes";
Collection* coll = ctx.db()->getCollection( &txn, systemIndexes );
auto_ptr<Runner> runner(InternalPlanner::collectionScan(systemIndexes,coll));
@@ -428,7 +380,7 @@ namespace mongo {
const BSONObj key = index.getObjectField("key");
const string plugin = IndexNames::findPluginName(key);
- if (h->versionMinor == PDFILE_VERSION_MINOR_22_AND_OLDER) {
+ if (ctx.db()->getDatabaseCatalogEntry()->isOlderThan24( &opCtx )) {
if (IndexNames::existedBefore24(plugin))
continue;
diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp b/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp
index 95ff9a72c17..34beec058f0 100644
--- a/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp
+++ b/src/mongo/db/storage/mmap_v1/mmap_v1_engine.cpp
@@ -361,6 +361,13 @@ namespace mongo {
PDFILE_VERSION_MINOR_24_AND_NEWER;
}
+ bool MMAP1DatabaseCatalogEntry::currentFilesCompatible( OperationContext* opCtx ) const {
+ if ( _extentManager.numFiles() == 0 )
+ return true;
+
+ return _extentManager.getOpenFile( 0 )->getHeader()->isCurrentVersion();
+ }
+
void MMAP1DatabaseCatalogEntry::getCollectionNamespaces( std::list<std::string>* tofill ) const {
_namespaceIndex.getCollectionNamespaces( tofill );
}
diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_engine.h b/src/mongo/db/storage/mmap_v1/mmap_v1_engine.h
index 121ea49ca96..ef040e03769 100644
--- a/src/mongo/db/storage/mmap_v1/mmap_v1_engine.h
+++ b/src/mongo/db/storage/mmap_v1/mmap_v1_engine.h
@@ -64,6 +64,8 @@ namespace mongo {
virtual bool isOlderThan24( OperationContext* opCtx ) const;
virtual void markIndexSafe24AndUp( OperationContext* opCtx );
+ virtual bool currentFilesCompatible( OperationContext* opCtx ) const;
+
virtual void appendExtraStats( OperationContext* opCtx,
BSONObjBuilder* out,
double scale ) const;
diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp
index 77cbad7dad3..79115de2df2 100644
--- a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp
+++ b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.cpp
@@ -186,7 +186,6 @@ namespace mongo {
}
size_t MmapV1ExtentManager::numFiles() const {
- DEV Lock::assertAtLeastReadLocked( _dbname );
return _files.size();
}
@@ -558,5 +557,11 @@ namespace mongo {
const DataFile* df = _getOpenFile( 0 );
*major = df->getHeader()->version;
*minor = df->getHeader()->versionMinor;
+
+ if ( *major <= 0 || *major >= 100 ||
+ *minor <= 0 || *minor >= 100 ) {
+ error() << "corrupt pdfile version? major: " << *major << " minor: " << *minor;
+ fassertFailed( 14026 );
+ }
}
}
diff --git a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h
index 3caea9f15a0..1ba960fcac3 100644
--- a/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h
+++ b/src/mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h
@@ -145,6 +145,8 @@ namespace mongo {
void getFileFormat( OperationContext* txn, int* major, int* minor ) const;
+ const DataFile* getOpenFile( int n ) const { return _getOpenFile( n ); }
+
virtual int maxSize() const;
diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp
index effb9cb2359..cfbd6f930cc 100644
--- a/src/mongo/dbtests/pdfiletests.cpp
+++ b/src/mongo/dbtests/pdfiletests.cpp
@@ -156,43 +156,27 @@ namespace PdfileTests {
class ExtentSizing {
public:
- struct SmallFilesControl {
- SmallFilesControl() {
- old = storageGlobalParams.smallfiles;
- storageGlobalParams.smallfiles = false;
- }
- ~SmallFilesControl() {
- storageGlobalParams.smallfiles = old;
- }
- bool old;
- };
void run() {
- SmallFilesControl c;
-
- OperationContextImpl txn;
- Client::ReadContext ctx(&txn, "local");
- Database* db = ctx.ctx().db();
- ExtentManager* em = db->getExtentManager();
+ MmapV1ExtentManager em( "x", "x", false );
- ASSERT_EQUALS( em->maxSize(),
- em->quantizeExtentSize( em->maxSize() ) );
+ ASSERT_EQUALS( em.maxSize(), em.quantizeExtentSize( em.maxSize() ) );
// test that no matter what we start with, we always get to max extent size
for ( int obj=16; obj<BSONObjMaxUserSize; obj += 111 ) {
- int sz = em->initialSize( obj );
+ int sz = em.initialSize( obj );
double totalExtentSize = sz;
int numFiles = 1;
- int sizeLeftInExtent = em->maxSize() - 1;
+ int sizeLeftInExtent = em.maxSize() - 1;
for ( int i=0; i<100; i++ ) {
- sz = em->followupSize( obj , sz );
+ sz = em.followupSize( obj , sz );
ASSERT( sz >= obj );
- ASSERT( sz >= em->minSize() );
- ASSERT( sz <= em->maxSize() );
- ASSERT( sz <= em->maxSize() );
+ ASSERT( sz >= em.minSize() );
+ ASSERT( sz <= em.maxSize() );
+ ASSERT( sz <= em.maxSize() );
totalExtentSize += sz;
@@ -201,15 +185,16 @@ namespace PdfileTests {
}
else {
numFiles++;
- sizeLeftInExtent = em->maxSize() - sz;
+ sizeLeftInExtent = em.maxSize() - sz;
}
}
- ASSERT_EQUALS( em->maxSize() , sz );
+ ASSERT_EQUALS( em.maxSize(), sz );
- double allocatedOnDisk = (double)numFiles * em->maxSize();
+ double allocatedOnDisk = (double)numFiles * em.maxSize();
ASSERT( ( totalExtentSize / allocatedOnDisk ) > .95 );
+ invariant( em.numFiles() == 0 );
}
}
};