diff options
author | Vesselina Ratcheva <vesselina.ratcheva@10gen.com> | 2020-07-15 20:48:48 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-20 20:06:47 +0000 |
commit | 27eaf9f0ad03c837f7781d2b6037322ee213eb51 (patch) | |
tree | 71cbb14fb2ae243bf50a08d4c38c2d20640951cb | |
parent | 0adaca354fe602e8682da3675d7c8ca535c3602d (diff) | |
download | mongo-27eaf9f0ad03c837f7781d2b6037322ee213eb51.tar.gz |
SERVER-48525 Forbid dropping config.transactions when there are prepared transactions
(cherry picked from commit d520082a3f8568b9303ab7e37c111d436d1dd50b)
-rw-r--r-- | jstests/core/txns/no_writes_to_config_transactions_with_prepared_transaction.js | 8 | ||||
-rw-r--r-- | src/mongo/db/op_observer_impl.cpp | 16 |
2 files changed, 23 insertions, 1 deletions
diff --git a/jstests/core/txns/no_writes_to_config_transactions_with_prepared_transaction.js b/jstests/core/txns/no_writes_to_config_transactions_with_prepared_transaction.js index 79bc3bac28d..4302a131c36 100644 --- a/jstests/core/txns/no_writes_to_config_transactions_with_prepared_transaction.js +++ b/jstests/core/txns/no_writes_to_config_transactions_with_prepared_transaction.js @@ -70,11 +70,17 @@ transactionEntry = config.transactions.findOne(); assert(transactionEntry); jsTestLog("Test that dropping config.transactions fails when there is a prepared transaction" + - " on the session"); + " present"); +jsTestLog("[1] collection drop in the same session"); assert.commandFailedWithCode(assert.throws(function() { sessionConfigDB.transactions.drop(); }), [4852500, 40528]); +jsTestLog("[2] collection drop not in a session"); +assert.commandFailedWithCode(assert.throws(function() { + config.transactions.drop(); + }), + 4852500); jsTestLog("Test that we can prepare a transaction on a different session"); const session2 = db.getMongo().startSession({causalConsistency: false}); diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp index 05b3bb2a35a..1b7bb32b676 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -742,6 +742,22 @@ repl::OpTime OpObserverImpl::onDropCollection(OperationContext* opCtx, if (collectionName.coll() == DurableViewCatalog::viewsCollectionName()) { DurableViewCatalog::onSystemViewsCollectionDrop(opCtx, collectionName); } else if (collectionName == NamespaceString::kSessionTransactionsTableNamespace) { + // Disallow this drop if there are currently prepared transactions. + const auto sessionCatalog = SessionCatalog::get(opCtx); + SessionKiller::Matcher matcherAllSessions( + KillAllSessionsByPatternSet{makeKillAllSessionsByPattern(opCtx)}); + bool noPreparedTxns = true; + sessionCatalog->scanSessions(matcherAllSessions, [&](const ObservableSession& session) { + auto txnParticipant = TransactionParticipant::get(session); + if (txnParticipant.transactionIsPrepared()) { + noPreparedTxns = false; + } + }); + uassert(4852500, + "Unable to drop transactions table (config.transactions) while prepared " + "transactions are present.", + noPreparedTxns); + MongoDSessionCatalog::invalidateAllSessions(opCtx); } else if (collectionName == NamespaceString::kConfigSettingsNamespace) { ReadWriteConcernDefaults::get(opCtx).invalidate(); |