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 15:05:18 -0400
commit08dafe02bf5a127a5e7716f8fc9efb2698afc543 (patch)
treeb6021b619a0e5eb218d99304762e9e57d96f4fb2
parent1a61195c779c6474cdd1a7c1e5c56c82e6bf3ed0 (diff)
downloadmongo-08dafe02bf5a127a5e7716f8fc9efb2698afc543.tar.gz
SERVER-35415 Increase default transaction lock acquisition timeout to 5 milliseconds
(cherry picked from commit 2baf303830538053d3bfedaa99fec0c4b5e83cd8)
-rw-r--r--src/mongo/db/session.cpp8
-rw-r--r--src/mongo/db/session_test.cpp7
2 files changed, 9 insertions, 6 deletions
diff --git a/src/mongo/db/session.cpp b/src/mongo/db/session.cpp
index a47346800af..bb3b04491a1 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 b9b8420cfa0..c1ee65e01a2 100644
--- a/src/mongo/db/session_test.cpp
+++ b/src/mongo/db/session_test.cpp
@@ -574,7 +574,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";
@@ -619,8 +620,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); }