diff options
author | Jack Mulrow <jack.mulrow@mongodb.com> | 2022-05-18 23:18:40 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-19 00:31:41 +0000 |
commit | 533ef33817696b85bac9091c4257a9204da6db95 (patch) | |
tree | bbe59e8a60a9abe642d61f5bd7adbcd5fa75c9d6 /src/mongo/db/transaction_participant.cpp | |
parent | 788627e58f5d488a833b73739d0dc8d9ff96d5e7 (diff) | |
download | mongo-533ef33817696b85bac9091c4257a9204da6db95.tar.gz |
SERVER-66560 Check feature flag before fetching child transaction history
(cherry picked from commit 2fdcda013f2cecafb496d58a362fec750b284e82)
Diffstat (limited to 'src/mongo/db/transaction_participant.cpp')
-rw-r--r-- | src/mongo/db/transaction_participant.cpp | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp index e7a49152983..abbfce99298 100644 --- a/src/mongo/db/transaction_participant.cpp +++ b/src/mongo/db/transaction_participant.cpp @@ -2757,7 +2757,9 @@ void TransactionParticipant::Participant::_refreshSelfFromStorageIfNeeded(Operat } } - if (!_isInternalSession()) { + if (feature_flags::gFeatureFlagInternalTransactions.isEnabled( + serverGlobalParams.featureCompatibility) && + !_isInternalSession()) { const auto txnNumber = fetchHighestTxnNumberWithInternalSessions(opCtx, _sessionId()); if (txnNumber > o().activeTxnNumberAndRetryCounter.getTxnNumber()) { _setNewTxnNumberAndRetryCounter(opCtx, {txnNumber, kUninitializedTxnRetryCounter}); @@ -2790,46 +2792,51 @@ void TransactionParticipant::Participant::_refreshActiveTransactionParticipantsF // Add parent Participant. retryableWriteTxnParticipantCatalog.addParticipant(parentTxnParticipant); - // Add child participants. - std::vector<TransactionParticipant::Participant> childTxnParticipants; - - // Make sure that every child session has a corresponding Session/TransactionParticipant. - performReadWithNoTimestampDBDirectClient(opCtx, [&](DBDirectClient* client) { - FindCommandRequest findRequest{NamespaceString::kSessionTransactionsTableNamespace}; - findRequest.setFilter(BSON(SessionTxnRecord::kParentSessionIdFieldName - << parentTxnParticipant._sessionId().toBSON() - << (SessionTxnRecord::kSessionIdFieldName + "." + - LogicalSessionId::kTxnNumberFieldName) - << BSON("$gte" << *activeRetryableWriteTxnNumber))); - findRequest.setProjection(BSON("_id" << 1)); - - auto cursor = client->find(findRequest); - - while (cursor->more()) { - const auto doc = cursor->next(); - const auto childLsid = LogicalSessionId::parse( - IDLParserErrorContext("LogicalSessionId"), doc.getObjectField("_id")); - uassert(6202001, - str::stream() - << "Refresh expected the highest transaction number in the session " - << parentTxnParticipant._sessionId() << " to be " - << *activeRetryableWriteTxnNumber << " found a " - << NamespaceString::kSessionTransactionsTableNamespace - << " entry for an internal transaction for retryable writes with " - << "transaction number " << *childLsid.getTxnNumber(), - *childLsid.getTxnNumber() == *activeRetryableWriteTxnNumber); - auto sessionCatalog = SessionCatalog::get(opCtx); - sessionCatalog->createSessionIfDoesNotExist(childLsid); - sessionCatalog->scanSession(childLsid, [&](const ObservableSession& osession) { - auto childTxnParticipant = TransactionParticipant::get(opCtx, osession.get()); - childTxnParticipants.push_back(childTxnParticipant); - }); - } - }); + if (feature_flags::gFeatureFlagInternalTransactions.isEnabled( + serverGlobalParams.featureCompatibility)) { + // Add child participants. + std::vector<TransactionParticipant::Participant> childTxnParticipants; + + // Make sure that every child session has a corresponding + // Session/TransactionParticipant. + performReadWithNoTimestampDBDirectClient(opCtx, [&](DBDirectClient* client) { + FindCommandRequest findRequest{NamespaceString::kSessionTransactionsTableNamespace}; + findRequest.setFilter(BSON(SessionTxnRecord::kParentSessionIdFieldName + << parentTxnParticipant._sessionId().toBSON() + << (SessionTxnRecord::kSessionIdFieldName + "." + + LogicalSessionId::kTxnNumberFieldName) + << BSON("$gte" << *activeRetryableWriteTxnNumber))); + findRequest.setProjection(BSON("_id" << 1)); + + auto cursor = client->find(findRequest); + + while (cursor->more()) { + const auto doc = cursor->next(); + const auto childLsid = LogicalSessionId::parse( + IDLParserErrorContext("LogicalSessionId"), doc.getObjectField("_id")); + uassert(6202001, + str::stream() + << "Refresh expected the highest transaction number in the session " + << parentTxnParticipant._sessionId() << " to be " + << *activeRetryableWriteTxnNumber << " found a " + << NamespaceString::kSessionTransactionsTableNamespace + << " entry for an internal transaction for retryable writes with " + << "transaction number " << *childLsid.getTxnNumber(), + *childLsid.getTxnNumber() == *activeRetryableWriteTxnNumber); + auto sessionCatalog = SessionCatalog::get(opCtx); + sessionCatalog->createSessionIfDoesNotExist(childLsid); + sessionCatalog->scanSession(childLsid, [&](const ObservableSession& osession) { + auto childTxnParticipant = + TransactionParticipant::get(opCtx, osession.get()); + childTxnParticipants.push_back(childTxnParticipant); + }); + } + }); - for (auto& childTxnParticipant : childTxnParticipants) { - childTxnParticipant._refreshSelfFromStorageIfNeeded(opCtx, fetchOplogEntries); - retryableWriteTxnParticipantCatalog.addParticipant(childTxnParticipant); + for (auto& childTxnParticipant : childTxnParticipants) { + childTxnParticipant._refreshSelfFromStorageIfNeeded(opCtx, fetchOplogEntries); + retryableWriteTxnParticipantCatalog.addParticipant(childTxnParticipant); + } } } else { retryableWriteTxnParticipantCatalog.reset(); |