From e35e202e414df3f917ff26937f5e8325cce56b1e Mon Sep 17 00:00:00 2001 From: Matthew Russotto Date: Wed, 22 May 2019 14:36:19 -0400 Subject: SERVER-39811 Add a threshold of the total size of buffered oplog entries in a transaction and make it tunable, defaulting to unlimited --- src/mongo/db/transaction_participant_test.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/mongo/db/transaction_participant_test.cpp') diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp index ea04f5b7829..8dbdd4aa6f5 100644 --- a/src/mongo/db/transaction_participant_test.cpp +++ b/src/mongo/db/transaction_participant_test.cpp @@ -1097,6 +1097,33 @@ TEST_F(TxnParticipantTest, TransactionTooLargeWhileBuilding) { ErrorCodes::TransactionTooLarge); } +// Tests that a transaction aborts if it becomes too large based on the server parameter +// 'transactionLimitBytes'. +TEST_F(TxnParticipantTest, TransactionExceedsSizeParameter) { + auto sessionCheckout = checkOutSession(); + auto txnParticipant = TransactionParticipant::get(opCtx()); + + txnParticipant.unstashTransactionResources(opCtx(), "insert"); + auto oldLimit = gTransactionSizeLimitBytes.load(); + ON_BLOCK_EXIT([oldLimit] { gTransactionSizeLimitBytes.store(oldLimit); }); + + // Set a limit of 2.5 MB + gTransactionSizeLimitBytes.store(2 * 1024 * 1024 + 512 * 1024); + + // Two 1MB operations should succeed; three 1MB operations should fail. + constexpr size_t kBigDataSize = 1 * 1024 * 1024; + std::unique_ptr bigData(new uint8_t[kBigDataSize]()); + auto operation = repl::OplogEntry::makeInsertOperation( + kNss, + _uuid, + BSON("_id" << 0 << "data" << BSONBinData(bigData.get(), kBigDataSize, BinDataGeneral))); + txnParticipant.addTransactionOperation(opCtx(), operation); + txnParticipant.addTransactionOperation(opCtx(), operation); + ASSERT_THROWS_CODE(txnParticipant.addTransactionOperation(opCtx(), operation), + AssertionException, + ErrorCodes::TransactionTooLarge); +} + TEST_F(TxnParticipantTest, StashInNestedSessionIsANoop) { auto outerScopedSession = checkOutSession(); Locker* originalLocker = opCtx()->lockState(); -- cgit v1.2.1