diff options
author | Geert Bosch <geert.bosch@mongodb.com> | 2014-07-28 10:20:56 -0400 |
---|---|---|
committer | Geert Bosch <geert.bosch@mongodb.com> | 2014-07-28 10:42:00 -0400 |
commit | 553266111d7295aff03868cdfbf22e08985764db (patch) | |
tree | ac831e6a54a3ee23016437d4a7c318dbac9e879e /src/mongo/db/catalog | |
parent | 306355162c240f96e949f2a504df6cddfec47e42 (diff) | |
download | mongo-553266111d7295aff03868cdfbf22e08985764db.tar.gz |
SERVER-13951: Add rollback of collection metadata
This implements rollback of collection creation or dropping, including
associated indexes.
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r-- | src/mongo/db/catalog/database.cpp | 27 | ||||
-rw-r--r-- | src/mongo/db/catalog/database.h | 2 |
2 files changed, 23 insertions, 6 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp index 2fcabd06962..83ba92727c0 100644 --- a/src/mongo/db/catalog/database.cpp +++ b/src/mongo/db/catalog/database.cpp @@ -53,7 +53,7 @@ #include "mongo/db/server_parameters.h" #include "mongo/db/storage_options.h" #include "mongo/db/storage/storage_engine.h" -#include "mongo/db/catalog/collection.h" +#include "mongo/db/storage/recovery_unit.h" #include "mongo/util/log.h" namespace mongo { @@ -67,6 +67,18 @@ namespace mongo { NamespaceString::normal( ns ) ); } + class Database::CollectionCacheChange : public RecoveryUnit::Change { + public: + CollectionCacheChange(Database* db, const StringData& ns) + : _db(db), _ns(ns.toString()) { } + + void rollback() { _db->_clearCollectionCache(_ns); } + void commit() { } + private: + Database* const _db; + std::string _ns; + }; + Database::~Database() { for (CollectionMap::const_iterator i = _collections.begin(); i != _collections.end(); ++i) delete i->second; @@ -299,6 +311,8 @@ namespace mongo { return Status::OK(); } + txn->recoveryUnit()->registerChange( new CollectionCacheChange(this, fullns) ); + { NamespaceString s( fullns ); verify( s.db() == _name ); @@ -470,13 +484,14 @@ namespace mongo { audit::logCreateCollection( currentClient.get(), ns ); - Status status = _dbEntry->createCollection( txn, ns, - options, allocateDefaultSpace ); - massertStatusOK( status ); + txn->recoveryUnit()->registerChange( new CollectionCacheChange(this, ns) ); + Status status = _dbEntry->createCollection(txn, ns, + options, allocateDefaultSpace); + massertStatusOK(status); - Collection* collection = getCollection( txn, ns ); - invariant( collection ); + Collection* collection = getCollection(txn, ns); + invariant(collection); if ( createIdIndex ) { if ( collection->requiresIdIndex() ) { diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h index 3180694e111..c13a12bbdbe 100644 --- a/src/mongo/db/catalog/database.h +++ b/src/mongo/db/catalog/database.h @@ -142,6 +142,8 @@ namespace mongo { void _clearCollectionCache_inlock( const StringData& fullns ); + class CollectionCacheChange; // to allow rollback actions for invalidating above cache + const std::string _name; // "alleyinsider" boost::scoped_ptr<DatabaseCatalogEntry> _dbEntry; |