diff options
Diffstat (limited to 'src/mongo/db/storage/kv/kv_catalog.h')
-rw-r--r-- | src/mongo/db/storage/kv/kv_catalog.h | 164 |
1 files changed, 76 insertions, 88 deletions
diff --git a/src/mongo/db/storage/kv/kv_catalog.h b/src/mongo/db/storage/kv/kv_catalog.h index d253b9a1828..577fdba1faf 100644 --- a/src/mongo/db/storage/kv/kv_catalog.h +++ b/src/mongo/db/storage/kv/kv_catalog.h @@ -41,93 +41,81 @@ namespace mongo { - class OperationContext; - class RecordStore; - - class KVCatalog { - public: - /** - * @param rs - does NOT take ownership - */ - KVCatalog( RecordStore* rs, - bool isRsThreadSafe, - bool directoryPerDb, - bool directoryForIndexes ); - ~KVCatalog(); - - void init( OperationContext* opCtx ); - - void getAllCollections( std::vector<std::string>* out ) const; - - /** - * @return error or ident for instance - */ - Status newCollection( OperationContext* opCtx, - StringData ns, - const CollectionOptions& options ); - - std::string getCollectionIdent( StringData ns ) const; - - std::string getIndexIdent( OperationContext* opCtx, - StringData ns, - StringData idName ) const; - - const BSONCollectionCatalogEntry::MetaData getMetaData( OperationContext* opCtx, - StringData ns ); - void putMetaData( OperationContext* opCtx, - StringData ns, - BSONCollectionCatalogEntry::MetaData& md ); - - Status renameCollection( OperationContext* opCtx, - StringData fromNS, - StringData toNS, - bool stayTemp ); - - Status dropCollection( OperationContext* opCtx, - StringData ns ); - - std::vector<std::string> getAllIdentsForDB( StringData db ) const; - std::vector<std::string> getAllIdents( OperationContext* opCtx ) const; - - bool isUserDataIdent( StringData ident ) const; - private: - class AddIdentChange; - class RemoveIdentChange; - - BSONObj _findEntry( OperationContext* opCtx, - StringData ns, - RecordId* out=NULL ) const; - - /** - * Generates a new unique identifier for a new "thing". - * @param ns - the containing ns - * @param kind - what this "thing" is, likely collection or index - */ - std::string _newUniqueIdent(StringData ns, const char* kind); - - // Helpers only used by constructor and init(). Don't call from elsewhere. - static std::string _newRand(); - bool _hasEntryCollidingWithRand() const; - - RecordStore* _rs; // not owned - const bool _isRsThreadSafe; - const bool _directoryPerDb; - const bool _directoryForIndexes; - - // These two are only used for ident generation inside _newUniqueIdent. - std::string _rand; // effectively const after init() returns - AtomicUInt64 _next; - - struct Entry { - Entry(){} - Entry( std::string i, RecordId l ) - : ident(i), storedLoc( l ) {} - std::string ident; - RecordId storedLoc; - }; - typedef std::map<std::string,Entry> NSToIdentMap; - NSToIdentMap _idents; - mutable stdx::mutex _identsLock; - }; +class OperationContext; +class RecordStore; + +class KVCatalog { +public: + /** + * @param rs - does NOT take ownership + */ + KVCatalog(RecordStore* rs, bool isRsThreadSafe, bool directoryPerDb, bool directoryForIndexes); + ~KVCatalog(); + + void init(OperationContext* opCtx); + + void getAllCollections(std::vector<std::string>* out) const; + + /** + * @return error or ident for instance + */ + Status newCollection(OperationContext* opCtx, StringData ns, const CollectionOptions& options); + + std::string getCollectionIdent(StringData ns) const; + + std::string getIndexIdent(OperationContext* opCtx, StringData ns, StringData idName) const; + + const BSONCollectionCatalogEntry::MetaData getMetaData(OperationContext* opCtx, StringData ns); + void putMetaData(OperationContext* opCtx, + StringData ns, + BSONCollectionCatalogEntry::MetaData& md); + + Status renameCollection(OperationContext* opCtx, + StringData fromNS, + StringData toNS, + bool stayTemp); + + Status dropCollection(OperationContext* opCtx, StringData ns); + std::vector<std::string> getAllIdentsForDB(StringData db) const; + std::vector<std::string> getAllIdents(OperationContext* opCtx) const; + + bool isUserDataIdent(StringData ident) const; + +private: + class AddIdentChange; + class RemoveIdentChange; + + BSONObj _findEntry(OperationContext* opCtx, StringData ns, RecordId* out = NULL) const; + + /** + * Generates a new unique identifier for a new "thing". + * @param ns - the containing ns + * @param kind - what this "thing" is, likely collection or index + */ + std::string _newUniqueIdent(StringData ns, const char* kind); + + // Helpers only used by constructor and init(). Don't call from elsewhere. + static std::string _newRand(); + bool _hasEntryCollidingWithRand() const; + + RecordStore* _rs; // not owned + const bool _isRsThreadSafe; + const bool _directoryPerDb; + const bool _directoryForIndexes; + + // These two are only used for ident generation inside _newUniqueIdent. + std::string _rand; // effectively const after init() returns + AtomicUInt64 _next; + + struct Entry { + Entry() {} + Entry(std::string i, RecordId l) : ident(i), storedLoc(l) {} + std::string ident; + RecordId storedLoc; + }; + typedef std::map<std::string, Entry> NSToIdentMap; + NSToIdentMap _idents; + mutable stdx::mutex _identsLock; +}; } |