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-07 00:14:08 +0000 |
commit | d61f0526692d5717c1375666637164c4f0744b43 (patch) | |
tree | 09200388681a6a1f591c940a0a4c77c02f34d13f | |
parent | caef6619556ddeb20adf8e2bad651b96d2b3ea70 (diff) | |
download | mongo-d61f0526692d5717c1375666637164c4f0744b43.tar.gz |
SERVER-48525 Forbid dropping config.transactions when there are prepared transactions
(cherry picked from commit d520082a3f8568b9303ab7e37c111d436d1dd50b)
-rw-r--r-- | etc/backports_required_for_multiversion_tests.yml | 2 | ||||
-rw-r--r-- | jstests/core/txns/no_writes_to_config_transactions_with_prepared_transaction.js | 10 | ||||
-rw-r--r-- | src/mongo/db/op_observer_impl.cpp | 16 |
3 files changed, 26 insertions, 2 deletions
diff --git a/etc/backports_required_for_multiversion_tests.yml b/etc/backports_required_for_multiversion_tests.yml index e70f05258e7..d6dc2598520 100644 --- a/etc/backports_required_for_multiversion_tests.yml +++ b/etc/backports_required_for_multiversion_tests.yml @@ -37,6 +37,8 @@ replica_sets_jscore_multiversion_passthrough: test_file: jstests/core/wildcard_index_partial_index.js - ticket: SERVER-48993 test_file: jstests/core/explode_for_sort_collation.js +- ticket: SERVER-48525 + test_file: jstests/core/txns/no_writes_to_config_transactions_with_prepared_transaction.js replica_sets_multiversion: - ticket: SERVER-42825 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 067bf1482fa..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(); }), - 40528); + [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 d4715bb3b96..d5217c1e535 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -807,6 +807,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); } |