diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2023-05-16 16:41:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2023-05-16 18:32:05 +0000 |
commit | 6d34f15ca68a6c3e7ec67e5c75cce4d6bbf51aee (patch) | |
tree | 0396966229a982120b228972638c7a162d63a4fd /src/mongo/db/transaction_resources.cpp | |
parent | 7d5b3ce7bbd430a8d9cb231befa9233e372c66cb (diff) | |
download | mongo-6d34f15ca68a6c3e7ec67e5c75cce4d6bbf51aee.tar.gz |
SERVER-77123 Make the readConcern for TransactionResources come from prerequisites
Diffstat (limited to 'src/mongo/db/transaction_resources.cpp')
-rw-r--r-- | src/mongo/db/transaction_resources.cpp | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/src/mongo/db/transaction_resources.cpp b/src/mongo/db/transaction_resources.cpp index 4c286f76c63..24472bfbf12 100644 --- a/src/mongo/db/transaction_resources.cpp +++ b/src/mongo/db/transaction_resources.cpp @@ -35,13 +35,55 @@ const PlacementConcern AcquisitionPrerequisites::kPretendUnsharded = PlacementConcern{boost::none, boost::none}; namespace shard_role_details { +namespace { -TransactionResources::TransactionResources(repl::ReadConcernArgs readConcern) - : readConcern(std::move(readConcern)) {} +/** + * This method ensures that two read concerns are equivalent for the purposes of acquiring a + * transactional snapshot. Equivalence means that they don't acquire snapshot at conflicting levels, + * such as one operation asking for local and a subsequent one for majority. Similarly, we can't + * have two subsequent acquisitions asking for snapshots at two different timestamps. + */ +void assertReadConcernsAreEquivalent(const repl::ReadConcernArgs& rc1, + const repl::ReadConcernArgs& rc2) { + tassert(771230, + str::stream() << "Acquired two different collections on the same transaction with " + "read concerns that are not equivalent (" + << rc1.toString() << " != " << rc2.toString() << ")", + rc1.getLevel() == rc2.getLevel() && + rc1.getArgsAtClusterTime() == rc2.getArgsAtClusterTime()); +} + +} // namespace + +TransactionResources::TransactionResources() = default; + +TransactionResources::~TransactionResources() { + invariant(!locker); + invariant(!yieldedLocker); + invariant(!yieldedRecoveryUnit); + invariant(acquiredCollections.empty()); + invariant(acquiredViews.empty()); +} + +AcquiredCollection& TransactionResources::addAcquiredCollection( + AcquiredCollection&& acquiredCollection) { + if (!readConcern) { + readConcern = acquiredCollection.prerequisites.readConcern; + } + assertReadConcernsAreEquivalent(*readConcern, acquiredCollection.prerequisites.readConcern); + + return acquiredCollections.emplace_back(std::move(acquiredCollection)); +} + +const AcquiredView& TransactionResources::addAcquiredView(AcquiredView&& acquiredView) { + return acquiredViews.emplace_back(std::move(acquiredView)); +} void TransactionResources::releaseAllResourcesOnCommitOrAbort() noexcept { + readConcern.reset(); locker.reset(); - lockSnapshot.reset(); + yieldedLocker.reset(); + yieldedRecoveryUnit.reset(); acquiredCollections.clear(); acquiredViews.clear(); } @@ -57,12 +99,5 @@ void TransactionResources::assertNoAcquiredCollections() const { fassertFailedWithStatus(737660, Status{ErrorCodes::InternalError, ss.str()}); } -TransactionResources::~TransactionResources() { - invariant(!locker); - invariant(!lockSnapshot); - invariant(acquiredCollections.empty()); - invariant(acquiredViews.empty()); -} - } // namespace shard_role_details } // namespace mongo |