Skip to content

Commit e705586

Browse files
committed
SERVER-13635: remove Database::getFileFormat
1 parent 9c0c4ff commit e705586

File tree

6 files changed

+47
-26
lines changed

6 files changed

+47
-26
lines changed

src/mongo/db/catalog/database.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
#include "mongo/db/introspect.h"
4949
#include "mongo/db/pdfile.h"
5050
#include "mongo/db/server_parameters.h"
51-
#include "mongo/db/storage/data_file.h" //XXX
5251
#include "mongo/db/storage/mmap_v1/mmap_v1_engine.h" //XXX
5352
#include "mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h" //XXX
5453
#include "mongo/db/storage_options.h"
@@ -524,17 +523,6 @@ namespace mongo {
524523
uassertStatusOK( loc.getStatus() );
525524
}
526525

527-
void Database::getFileFormat( OperationContext* txn, int* major, int* minor ) {
528-
if ( getExtentManager()->numFiles() == 0 ) {
529-
*major = 0;
530-
*minor = 0;
531-
return;
532-
}
533-
const DataFile* df = getExtentManager()->getFile( txn, 0 );
534-
*major = df->getHeader()->version;
535-
*minor = df->getHeader()->versionMinor;
536-
}
537-
538526
MmapV1ExtentManager* Database::getExtentManager() {
539527
return _dbEntry->getExtentManager();
540528
}

src/mongo/db/catalog/database.h

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

7575
void clearTmpCollections(OperationContext* txn);
7676

77-
void getFileFormat( OperationContext* txn, int* major, int* minor );
78-
7977
/**
8078
* @return true if success. false if bad level or error creating profile ns
8179
*/

src/mongo/db/catalog/database_catalog_entry.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ namespace mongo {
5656
BSONObjBuilder* out,
5757
double scale ) const = 0;
5858

59+
virtual bool isOlderThan24( OperationContext* opCtx ) const = 0;
60+
virtual void markIndexSafe24AndUp( OperationContext* opCtx ) = 0;
61+
5962
// ----
6063

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

src/mongo/db/catalog/index_catalog.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,8 @@ namespace mongo {
169169
string pluginName = IndexNames::findPluginName(keyPattern);
170170
bool known = IndexNames::isKnownName(pluginName);
171171

172-
int majorVersion;
173-
int minorVersion;
174-
175-
_collection->_database->getFileFormat( txn, &majorVersion, &minorVersion );
176-
177-
if (minorVersion == PDFILE_VERSION_MINOR_24_AND_NEWER) {
178-
// RulesFor24
172+
if ( !_collection->_database->getDatabaseCatalogEntry()->isOlderThan24( txn ) ) {
173+
// RulesFor24+
179174
// This assert will be triggered when downgrading from a future version that
180175
// supports an index plugin unsupported by this version.
181176
uassert(17197, str::stream() << "Invalid index type '" << pluginName << "' "
@@ -223,13 +218,10 @@ namespace mongo {
223218

224219
Database* db = _collection->_database;
225220

226-
DataFileHeader* dfh = db->getExtentManager()->getFile(txn, 0)->getHeader();
227-
if ( dfh->versionMinor == PDFILE_VERSION_MINOR_24_AND_NEWER ) {
221+
if ( !db->getDatabaseCatalogEntry()->isOlderThan24( txn ) ) {
228222
return Status::OK(); // these checks have already been done
229223
}
230224

231-
fassert(16737, dfh->versionMinor == PDFILE_VERSION_MINOR_22_AND_OLDER);
232-
233225
auto_ptr<Runner> runner(
234226
InternalPlanner::collectionScan(db->_indexesName,
235227
db->getCollection(txn, db->_indexesName)));
@@ -255,7 +247,7 @@ namespace mongo {
255247
warning() << "Internal error while reading system.indexes collection";
256248
}
257249

258-
txn->recoveryUnit()->writingInt(dfh->versionMinor) = PDFILE_VERSION_MINOR_24_AND_NEWER;
250+
db->_dbEntry->markIndexSafe24AndUp( txn );
259251

260252
return Status::OK();
261253
}

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
#include "mongo/db/index/hash_access_method.h"
4040
#include "mongo/db/index/haystack_access_method.h"
4141
#include "mongo/db/index/s2_access_method.h"
42+
#include "mongo/db/pdfile_version.h"
4243
#include "mongo/db/server_parameters.h"
44+
#include "mongo/db/storage/data_file.h"
4345
#include "mongo/db/structure/catalog/namespace_details.h"
4446
#include "mongo/db/structure/catalog/namespace_details_collection_entry.h"
4547
#include "mongo/db/structure/catalog/namespace_details_rsv1_metadata.h"
@@ -324,6 +326,41 @@ namespace mongo {
324326

325327
}
326328

329+
bool MMAP1DatabaseCatalogEntry::isOlderThan24( OperationContext* opCtx ) const {
330+
if ( _extentManager.numFiles() == 0 )
331+
return false;
332+
333+
int major = 0;
334+
int minor = 0;
335+
336+
_extentManager.getFileFormat( opCtx, &major, &minor );
337+
338+
invariant( major == PDFILE_VERSION );
339+
340+
return minor == PDFILE_VERSION_MINOR_22_AND_OLDER;
341+
}
342+
343+
void MMAP1DatabaseCatalogEntry::markIndexSafe24AndUp( OperationContext* opCtx ) {
344+
if ( _extentManager.numFiles() == 0 )
345+
return;
346+
347+
int major = 0;
348+
int minor = 0;
349+
350+
_extentManager.getFileFormat( opCtx, &major, &minor );
351+
352+
invariant( major == PDFILE_VERSION );
353+
354+
if ( minor == PDFILE_VERSION_MINOR_24_AND_NEWER )
355+
return;
356+
357+
invariant( minor == PDFILE_VERSION_MINOR_22_AND_OLDER );
358+
359+
DataFile* df = _extentManager.getFile( opCtx, 0 );
360+
opCtx->recoveryUnit()->writingInt(df->getHeader()->versionMinor) =
361+
PDFILE_VERSION_MINOR_24_AND_NEWER;
362+
}
363+
327364
void MMAP1DatabaseCatalogEntry::getCollectionNamespaces( std::list<std::string>* tofill ) const {
328365
_namespaceIndex.getCollectionNamespaces( tofill );
329366
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ namespace mongo {
6161
bool exists() const { return _namespaceIndex.pathExists(); }
6262
bool isEmpty() const { return !_namespaceIndex.allocated(); }
6363

64+
virtual bool isOlderThan24( OperationContext* opCtx ) const;
65+
virtual void markIndexSafe24AndUp( OperationContext* opCtx );
66+
6467
virtual void appendExtraStats( OperationContext* opCtx,
6568
BSONObjBuilder* out,
6669
double scale ) const;

0 commit comments

Comments
 (0)