@@ -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
0 commit comments