summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2016-11-08 15:28:54 -0500
committerMathias Stearn <redbeard0531@gmail.com>2016-11-14 18:45:25 -0500
commit6271e9904a3a107294434eb61bf62b95c543d7e7 (patch)
treea58f48faa0aa51cab3a60653685b71bd925c28cc
parent8c1a3c4409f423df0d10bebf764ae75a84ad21f1 (diff)
downloadmongo-6271e9904a3a107294434eb61bf62b95c543d7e7.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. (cherry picked from commit f985c0ce3fa7efb0e857747f0a72bdef3326ac55)
-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 b94c465a4e4..de014156efe 100644
--- a/src/mongo/db/catalog/database.cpp
+++ b/src/mongo/db/catalog/database.cpp
@@ -505,12 +505,10 @@ Collection* Database::createCollection(OperationContext* txn,
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 b0ebd0d825f..26933d167db 100644
--- a/src/mongo/dbtests/rollbacktests.cpp
+++ b/src/mongo/dbtests/rollbacktests.cpp
@@ -139,7 +139,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() {
@@ -154,7 +154,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();
@@ -168,7 +169,7 @@ public:
}
};
-template <bool rollback, bool defaultIndexes>
+template <bool rollback, bool defaultIndexes, bool capped>
class DropCollection {
public:
void run() {
@@ -183,7 +184,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));
@@ -710,10 +712,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>();