summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2016-11-08 15:28:54 -0500
committerMathias Stearn <mathias@10gen.com>2016-11-09 15:09:55 -0500
commitf985c0ce3fa7efb0e857747f0a72bdef3326ac55 (patch)
treefcffb1abeb24efe8b7e64c022ddf251dfffa96cb
parent2422b66ef85a139ee5adf55c63e94998954d1a05 (diff)
downloadmongo-f985c0ce3fa7efb0e857747f0a72bdef3326ac55.tar.gz
SERVER-26685 register Database::AddCollectionChange in the correct order
Doing it before creating the RecordStore lead to rollback of Collection creation happening after RecordStore creation. This meant the Collection destructor would call setCappedCallback() on an already destroyed RecordStore.
-rw-r--r--src/mongo/db/catalog/database.cpp4
-rw-r--r--src/mongo/dbtests/rollbacktests.cpp23
2 files changed, 19 insertions, 8 deletions
diff --git a/src/mongo/db/catalog/database.cpp b/src/mongo/db/catalog/database.cpp
index d966119efc7..f6b246395e6 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -561,12 +561,10 @@ Collection* Database::createCollection(OperationContext* txn,
_checkCanCreateCollection(nss, options);
audit::logCreateCollection(&cc(), ns);
- txn->recoveryUnit()->registerChange(new AddCollectionChange(txn, this, ns));
-
Status status = _dbEntry->createCollection(txn, ns, options, true /*allocateDefaultSpace*/);
massertNoTraceStatusOK(status);
-
+ txn->recoveryUnit()->registerChange(new AddCollectionChange(txn, this, ns));
Collection* collection = _getOrCreateCollectionInstance(txn, ns);
invariant(collection);
_collections[ns] = collection;
diff --git a/src/mongo/dbtests/rollbacktests.cpp b/src/mongo/dbtests/rollbacktests.cpp
index 0986db98aa6..b842eb5a9bc 100644
--- a/src/mongo/dbtests/rollbacktests.cpp
+++ b/src/mongo/dbtests/rollbacktests.cpp
@@ -144,7 +144,7 @@ void dropIndex(OperationContext* txn, const NamespaceString& nss, const string&
}
} // namespace
-template <bool rollback, bool defaultIndexes>
+template <bool rollback, bool defaultIndexes, bool capped>
class CreateCollection {
public:
void run() {
@@ -160,7 +160,8 @@ public:
{
WriteUnitOfWork uow(&txn);
ASSERT(!collectionExists(&ctx, ns));
- ASSERT_OK(userCreateNS(&txn, ctx.db(), ns, BSONObj(), defaultIndexes));
+ auto options = capped ? BSON("capped" << true << "size" << 1000) : BSONObj();
+ ASSERT_OK(userCreateNS(&txn, ctx.db(), ns, options, defaultIndexes));
ASSERT(collectionExists(&ctx, ns));
if (!rollback) {
uow.commit();
@@ -174,7 +175,7 @@ public:
}
};
-template <bool rollback, bool defaultIndexes>
+template <bool rollback, bool defaultIndexes, bool capped>
class DropCollection {
public:
void run() {
@@ -190,7 +191,8 @@ public:
{
WriteUnitOfWork uow(&txn);
ASSERT(!collectionExists(&ctx, ns));
- ASSERT_OK(userCreateNS(&txn, ctx.db(), ns, BSONObj(), defaultIndexes));
+ auto options = capped ? BSON("capped" << true << "size" << 1000) : BSONObj();
+ ASSERT_OK(userCreateNS(&txn, ctx.db(), ns, options, defaultIndexes));
uow.commit();
}
ASSERT(collectionExists(&ctx, ns));
@@ -734,10 +736,21 @@ public:
template <template <bool, bool> class T>
void addAll() {
add<T<false, false>>();
- add<T<true, false>>();
add<T<false, true>>();
+ add<T<true, false>>();
add<T<true, true>>();
}
+ template <template <bool, bool, bool> class T>
+ void addAll() {
+ add<T<false, false, false>>();
+ add<T<false, false, true>>();
+ add<T<false, true, false>>();
+ add<T<false, true, true>>();
+ add<T<true, false, false>>();
+ add<T<true, false, true>>();
+ add<T<true, true, false>>();
+ add<T<true, true, true>>();
+ }
void setupTests() {
addAll<CreateCollection>();