summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/database.cpp27
-rw-r--r--src/mongo/db/catalog/database.h2
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;