diff options
-rw-r--r-- | src/mongo/db/catalog/collection.cpp | 50 | ||||
-rw-r--r-- | src/mongo/db/catalog/collection.h | 11 | ||||
-rw-r--r-- | src/mongo/db/catalog/database.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/catalog/index_catalog.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/dbcommands.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/structure/catalog/namespace_details.cpp | 30 | ||||
-rw-r--r-- | src/mongo/db/structure/catalog/namespace_details.h | 3 |
7 files changed, 70 insertions, 47 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp index ffee6812c27..2e6ce4f8b77 100644 --- a/src/mongo/db/catalog/collection.cpp +++ b/src/mongo/db/catalog/collection.cpp @@ -37,7 +37,9 @@ #include "mongo/db/curop.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/index_create.h" +#include "mongo/db/dbhelpers.h" #include "mongo/db/index/index_access_method.h" +#include "mongo/db/ops/update.h" #include "mongo/db/structure/catalog/namespace_details.h" #include "mongo/db/structure/catalog/namespace_details_rsv1_metadata.h" #include "mongo/db/structure/record_store_v1_capped.h" @@ -590,4 +592,52 @@ namespace mongo { return Status::OK(); } + bool Collection::isUserFlagSet( int flag ) const { + return _details->isUserFlagSet( flag ); + } + + bool Collection::setUserFlag( int flag ) { + if ( !_details->setUserFlag( flag ) ) + return false; + _syncUserFlags(); + return true; + } + + bool Collection::clearUserFlag( int flag ) { + if ( !_details->clearUserFlag( flag ) ) + return false; + _syncUserFlags(); + return true; + } + + void Collection::_syncUserFlags() { + if ( _ns.coll() == "system.namespaces" ) + return; + string system_namespaces = _ns.getSisterNS( "system.namespaces" ); + Collection* coll = _database->getCollection( system_namespaces ); + + DiskLoc oldLocation = Helpers::findOne( coll, BSON( "name" << _ns.ns() ), false ); + fassert( 17247, !oldLocation.isNull() ); + + BSONObj oldEntry = coll->docFor( oldLocation ); + + BSONObj newEntry = applyUpdateOperators( oldEntry, + BSON( "$set" << + BSON( "options.flags" << + _details->userFlags() ) ) ); + + StatusWith<DiskLoc> loc = coll->updateDocument( oldLocation, newEntry, false, NULL ); + if ( !loc.isOK() ) { + // TODO: should this be an fassert? + error() << "syncUserFlags failed! " + << " ns: " << _ns + << " error: " << loc.toString(); + } + + } + + void Collection::setMaxCappedDocs( long long max ) { + _details->setMaxCappedDocs( max ); + } + } diff --git a/src/mongo/db/catalog/collection.h b/src/mongo/db/catalog/collection.h index 43f4478bae5..5ef2231b9d1 100644 --- a/src/mongo/db/catalog/collection.h +++ b/src/mongo/db/catalog/collection.h @@ -251,6 +251,14 @@ namespace mongo { return static_cast<int>( dataSize() / n ); } + // TODO- below till next mark are suspect + bool isUserFlagSet( int flag ) const; + bool setUserFlag( int flag ); + bool clearUserFlag( int flag ); + + void setMaxCappedDocs( long long max ); + // --- end suspect things + private: /** * same semantics as insertDocument, but doesn't do: @@ -264,6 +272,9 @@ namespace mongo { MultiIndexBlock& indexesToInsertTo, const CompactOptions* compactOptions, CompactStats* stats ); + void _syncUserFlags(); // TODO: this is bizarre, should go away + + // @return 0 for inf., otherwise a number of files int largestFileNumberInQuota() const; diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp index 84140528024..d33c6a3efec 100644 --- a/src/mongo/db/catalog/database.cpp +++ b/src/mongo/db/catalog/database.cpp @@ -693,20 +693,18 @@ namespace mongo { Collection* collection = getCollection( ns ); massert( 17400, "_namespaceIndex.add_ns failed?", collection ); - NamespaceDetails* nsd = collection->detailsWritable(); - // allocation strategy set explicitly in flags or by server-wide default if ( !options.capped ) { if ( options.flagsSet ) { - nsd->setUserFlag( options.flags ); + collection->setUserFlag( options.flags ); } else if ( newCollectionsUsePowerOf2Sizes ) { - nsd->setUserFlag( NamespaceDetails::Flag_UsePowerOf2Sizes ); + collection->setUserFlag( NamespaceDetails::Flag_UsePowerOf2Sizes ); } } if ( options.cappedMaxDocs > 0 ) - nsd->setMaxCappedDocs( options.cappedMaxDocs ); + collection->setMaxCappedDocs( options.cappedMaxDocs ); if ( allocateDefaultSpace ) { if ( options.initialNumExtents > 0 ) { diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp index 743d58450cf..7359d1ac42e 100644 --- a/src/mongo/db/catalog/index_catalog.cpp +++ b/src/mongo/db/catalog/index_catalog.cpp @@ -162,9 +162,7 @@ namespace mongo { requirePowerOf2 = true; if ( requirePowerOf2 ) { - if ( _details->setUserFlag(NamespaceDetails::Flag_UsePowerOf2Sizes) ) { - _details->syncUserFlags( _collection->ns().ns() ); - } + _collection->setUserFlag(NamespaceDetails::Flag_UsePowerOf2Sizes); } } diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 264a581dce9..e80d07936ea 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -1217,8 +1217,6 @@ namespace mongo { return false; } - NamespaceDetails* nsd = coll->detailsWritable(); - bool ok = true; BSONForEach( e, jsobj ) { @@ -1229,16 +1227,17 @@ namespace mongo { // no-op } else if ( str::equals( "usePowerOf2Sizes", e.fieldName() ) ) { - bool oldPowerOf2 = nsd->isUserFlagSet(NamespaceDetails::Flag_UsePowerOf2Sizes); + bool oldPowerOf2 = coll->isUserFlagSet(NamespaceDetails::Flag_UsePowerOf2Sizes); bool newPowerOf2 = e.trueValue(); if ( oldPowerOf2 != newPowerOf2 ) { // change userFlags result.appendBool( "usePowerOf2Sizes_old", oldPowerOf2 ); - newPowerOf2 ? nsd->setUserFlag( NamespaceDetails::Flag_UsePowerOf2Sizes ) : - nsd->clearUserFlag( NamespaceDetails::Flag_UsePowerOf2Sizes ); - nsd->syncUserFlags( ns ); // must keep system.namespaces up-to-date + if ( newPowerOf2 ) + coll->setUserFlag( NamespaceDetails::Flag_UsePowerOf2Sizes ); + else + coll->clearUserFlag( NamespaceDetails::Flag_UsePowerOf2Sizes ); result.appendBool( "usePowerOf2Sizes_new", newPowerOf2 ); } diff --git a/src/mongo/db/structure/catalog/namespace_details.cpp b/src/mongo/db/structure/catalog/namespace_details.cpp index e349062112a..66a27cb593a 100644 --- a/src/mongo/db/structure/catalog/namespace_details.cpp +++ b/src/mongo/db/structure/catalog/namespace_details.cpp @@ -38,7 +38,6 @@ #include "mongo/db/clientcursor.h" #include "mongo/db/commands/server_status.h" #include "mongo/db/db.h" -#include "mongo/db/dbhelpers.h" #include "mongo/db/index_legacy.h" #include "mongo/db/json.h" #include "mongo/db/ops/delete.h" @@ -383,35 +382,6 @@ namespace mongo { *getDur().writing( &_deletedList[bucket] ) = loc; } - /** - * // TODO: this should move to Collection - * keeping things in sync this way is a bit of a hack - * and the fact that we have to pass in ns again - * should be changed, just not sure to what - */ - void NamespaceDetails::syncUserFlags( const string& ns ) { - Lock::assertWriteLocked( ns ); - - string system_namespaces = nsToDatabaseSubstring(ns).toString() + ".system.namespaces"; - Collection* coll = cc().getContext()->db()->getCollection( system_namespaces ); - - DiskLoc oldLocation = Helpers::findOne( coll, BSON( "name" << ns ), false ); - fassert( 17247, !oldLocation.isNull() ); - - BSONObj oldEntry = coll->docFor( oldLocation ); - - BSONObj newEntry = applyUpdateOperators( oldEntry , BSON( "$set" << BSON( "options.flags" << userFlags() ) ) ); - - StatusWith<DiskLoc> loc = coll->updateDocument( oldLocation, newEntry, false, NULL ); - if ( !loc.isOK() ) { - // TODO: should this be an fassert? - error() << "syncUserFlags failed! " - << " ns: " << ns - << " error: " << loc.toString(); - } - - } - bool NamespaceDetails::setUserFlag( int flags ) { if ( ( _userFlags & flags ) == flags ) return false; diff --git a/src/mongo/db/structure/catalog/namespace_details.h b/src/mongo/db/structure/catalog/namespace_details.h index 80bacc669d9..e7579b6e5f5 100644 --- a/src/mongo/db/structure/catalog/namespace_details.h +++ b/src/mongo/db/structure/catalog/namespace_details.h @@ -308,13 +308,10 @@ namespace mongo { } * these methods all return true iff only something was modified */ - bool setUserFlag( int flag ); bool clearUserFlag( int flag ); bool replaceUserFlags( int flags ); - void syncUserFlags( const string& ns ); - /* return which "deleted bucket" for this size object */ static int bucket(int size) { for ( int i = 0; i < Buckets; i++ ) { |