summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiangyu Yao <xiangyu.yao@mongodb.com>2018-06-07 16:12:49 -0400
committerXiangyu Yao <xiangyu.yao@mongodb.com>2018-06-08 14:57:12 -0400
commit2baf303830538053d3bfedaa99fec0c4b5e83cd8 (patch)
treec5eb4d7b5963a4aff0a2fe096276f08f3aba5737
parente3b54eabd0be75461b521500ee251c152499d5b8 (diff)
downloadmongo-2baf303830538053d3bfedaa99fec0c4b5e83cd8.tar.gz
SERVER-35415 Increase default transaction lock acquisition timeout to 5 milliseconds
-rw-r--r--jstests/noPassthrough/maxTransactionLockRequestTimeoutMillis_serverParameter.js2
-rw-r--r--src/mongo/db/session.cpp8
-rw-r--r--src/mongo/db/session_test.cpp7
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); }