diff options
author | Eliot Horowitz <eliot@10gen.com> | 2014-04-28 17:42:55 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2014-04-28 17:51:33 -0400 |
commit | ac3c2c29726cc6f576ffa1343151072b9fae24f1 (patch) | |
tree | e80fbd9dccb519dc0db984738419280e5593335e /src/mongo/db/catalog | |
parent | 24aeb8515961f9dc493addee39ee2d2c78254d90 (diff) | |
download | mongo-ac3c2c29726cc6f576ffa1343151072b9fae24f1.tar.gz |
SERVER-13680: bring some user flags under Collection for now
Diffstat (limited to 'src/mongo/db/catalog')
-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 |
4 files changed, 65 insertions, 8 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); } } |