diff options
-rw-r--r-- | jstests/noPassthrough/maxTransactionLockRequestTimeoutMillis_serverParameter.js | 2 | ||||
-rw-r--r-- | src/mongo/db/session.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/session_test.cpp | 7 |
3 files changed, 10 insertions, 7 deletions
diff --git a/jstests/noPassthrough/maxTransactionLockRequestTimeoutMillis_serverParameter.js b/jstests/noPassthrough/maxTransactionLockRequestTimeoutMillis_serverParameter.js index 1d6f032138d..fe24cb47f4d 100644 --- a/jstests/noPassthrough/maxTransactionLockRequestTimeoutMillis_serverParameter.js +++ b/jstests/noPassthrough/maxTransactionLockRequestTimeoutMillis_serverParameter.js @@ -9,7 +9,7 @@ testNumericServerParameter("maxTransactionLockRequestTimeoutMillis", true /*isStartupParameter*/, true /*isRuntimeParameter*/, - 0 /*defaultValue*/, + 5 /*defaultValue*/, 30 /*nonDefaultValidValue*/, false /*hasLowerBound*/, "unused" /*lowerOutOfBounds*/, diff --git a/src/mongo/db/session.cpp b/src/mongo/db/session.cpp index aa7ee6a1f0b..964b0d98076 100644 --- a/src/mongo/db/session.cpp +++ b/src/mongo/db/session.cpp @@ -65,11 +65,9 @@ namespace mongo { // maxTransactionLockRequestTimeoutMillis will override it. If this is set to a negative value, it // is inactive and nothing will be overridden. // -// The default of 0 milliseconds will ensure that transaction operations will immediately give up -// trying to take any lock if it is not immediately available. This prevents deadlocks between -// transactions. Setting a non-zero, positive value will also help obviate deadlocks, but won't -// abort a deadlocked transaction operation to eliminate the deadlock for however long has been set. -MONGO_EXPORT_SERVER_PARAMETER(maxTransactionLockRequestTimeoutMillis, int, 0); +// 5 milliseconds will help avoid deadlocks, but will still allow fast-running metadata operations +// to run without aborting transactions. +MONGO_EXPORT_SERVER_PARAMETER(maxTransactionLockRequestTimeoutMillis, int, 5); Session::CursorExistsFunction Session::_cursorExistsFunction; diff --git a/src/mongo/db/session_test.cpp b/src/mongo/db/session_test.cpp index a7d64b0c52c..ae599a86d4e 100644 --- a/src/mongo/db/session_test.cpp +++ b/src/mongo/db/session_test.cpp @@ -577,7 +577,8 @@ TEST_F(SessionTest, ErrorOnlyWhenStmtIdBeingCheckedIsNotInCache) { ASSERT_THROWS(session.checkStatementExecuted(opCtx(), txnNum, 2), AssertionException); } -// Test that transaction operations will abort if locks cannot be taken immediately. +// Test that transaction lock acquisition times out in `maxTransactionLockRequestTimeoutMillis` +// milliseconds. TEST_F(SessionTest, TransactionThrowsLockTimeoutIfLockIsUnavailable) { const std::string dbName = "TestDB"; @@ -622,8 +623,12 @@ TEST_F(SessionTest, TransactionThrowsLockTimeoutIfLockIsUnavailable) { newSession.beginOrContinueTxn(newOpCtx.get(), newTxnNum, false, true, "testDB", "insert"); newSession.unstashTransactionResources(newOpCtx.get(), "insert"); + Date_t t1 = Date_t::now(); ASSERT_THROWS_CODE( Lock::DBLock(newOpCtx.get(), dbName, MODE_X), AssertionException, ErrorCodes::LockTimeout); + Date_t t2 = Date_t::now(); + int defaultMaxTransactionLockRequestTimeoutMillis = 5; + ASSERT_GTE(t2 - t1, Milliseconds(defaultMaxTransactionLockRequestTimeoutMillis)); // A non-conflicting lock acquisition should work just fine. { Lock::DBLock(newOpCtx.get(), "NewTestDB", MODE_X); } |