diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2018-03-13 19:50:49 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2018-03-15 18:51:03 -0400 |
commit | b762003b0b692fe78658e675f06495f132af442c (patch) | |
tree | ae6acbc0270ec93adfb8f9654ea830839b42dc6e /src/mongo/db/session_catalog_test.cpp | |
parent | d0dea93d632ce451b66b57b538e66f3e1378b049 (diff) | |
download | mongo-b762003b0b692fe78658e675f06495f132af442c.tar.gz |
SERVER-33591 Cleanup interaction of write concerns and transactions
Diffstat (limited to 'src/mongo/db/session_catalog_test.cpp')
-rw-r--r-- | src/mongo/db/session_catalog_test.cpp | 122 |
1 files changed, 7 insertions, 115 deletions
diff --git a/src/mongo/db/session_catalog_test.cpp b/src/mongo/db/session_catalog_test.cpp index a02203e5554..42fb7d5b321 100644 --- a/src/mongo/db/session_catalog_test.cpp +++ b/src/mongo/db/session_catalog_test.cpp @@ -77,36 +77,6 @@ TEST_F(SessionCatalogTest, OperationContextCheckedOutSession) { auto session = OperationContextSession::get(opCtx()); ASSERT(session); ASSERT_EQ(*opCtx()->getLogicalSessionId(), session->getSessionId()); - session->refreshFromStorageIfNeeded(opCtx()); - session->beginOrContinueTxn(opCtx(), txnNum, boost::none); - - // Set the readConcern level on the operation to snapshot. This ensures that unstash sets up a - // WriteUnitOfWork on the OperationContext. - repl::ReadConcernArgs readConcernArgs; - ASSERT_OK(readConcernArgs.initialize(BSON("find" - << "test" - << repl::ReadConcernArgs::kReadConcernFieldName - << BSON(repl::ReadConcernArgs::kLevelFieldName - << "snapshot")))); - repl::ReadConcernArgs::get(opCtx()) = readConcernArgs; - - // Confirm that unstash can be executed against a top-level checked-out Session. - ocs.unstashTransactionResources(); - - // Stashing requires we are holding locks and either have a stashed cursor or are in a - // multi-statement transaction. - opCtx()->setStashedCursor(); - Lock::GlobalRead lk(opCtx(), Date_t::now()); - ASSERT(lk.isLocked()); - - // Confirm that stash can be executed against a top-level checked-out Session. - ocs.stashTransactionResources(); - - // TODO SERVER-33672: This can be removed when it no longer causes a hang to destroy the - // SessionCatalog when a Session contains stashed transaction resources. - repl::ReadConcernArgs::get(opCtx()) = repl::ReadConcernArgs(); - ocs.unstashTransactionResources(); - opCtx()->getWriteUnitOfWork()->commit(); } TEST_F(SessionCatalogTest, OperationContextNonCheckedOutSession) { @@ -116,11 +86,6 @@ TEST_F(SessionCatalogTest, OperationContextNonCheckedOutSession) { auto session = OperationContextSession::get(opCtx()); ASSERT(!session); - - // Confirm that unstash can be executed against a top-level not-checked-out Session (this is a - // noop). We do not expect stash to be executed against a top-level not-checked-out Session, - // since we will not be in a snapshot read or multi-statement transaction. - ocs.unstashTransactionResources(); } TEST_F(SessionCatalogTest, GetOrCreateNonExistentSession) { @@ -185,99 +150,26 @@ TEST_F(SessionCatalogTest, NestedOperationContextSession) { ASSERT(!OperationContextSession::get(opCtx())); } -TEST_F(SessionCatalogTest, StashInNestedSessionIsANoop) { +TEST_F(SessionCatalogTest, CannotAccessTopLevelSessionInNestedOnes) { opCtx()->setLogicalSessionId(makeLogicalSessionIdForTest()); opCtx()->setTxnNumber(1); { OperationContextSession outerScopedSession(opCtx(), true, boost::none); - Locker* originalLocker = opCtx()->lockState(); - RecoveryUnit* originalRecoveryUnit = opCtx()->recoveryUnit(); - ASSERT(originalLocker); - ASSERT(originalRecoveryUnit); - - // Set the readConcern on the OperationContext. - repl::ReadConcernArgs readConcernArgs; - ASSERT_OK(readConcernArgs.initialize(BSON("find" - << "test" - << repl::ReadConcernArgs::kReadConcernFieldName - << BSON(repl::ReadConcernArgs::kLevelFieldName - << "snapshot")))); - repl::ReadConcernArgs::get(opCtx()) = readConcernArgs; - - // Perform initial unstash, which sets up a WriteUnitOfWork. - outerScopedSession.unstashTransactionResources(); - ASSERT_EQUALS(originalLocker, opCtx()->lockState()); - ASSERT_EQUALS(originalRecoveryUnit, opCtx()->recoveryUnit()); - ASSERT(opCtx()->getWriteUnitOfWork()); - + auto* session = outerScopedSession.get(opCtx(), true); + ASSERT(session); { OperationContextSession innerScopedSession(opCtx(), true, boost::none); - // Indicate that there is a stashed cursor. If we were not in a nested session, this - // would ensure that stashing is not a noop. - opCtx()->setStashedCursor(); - - innerScopedSession.stashTransactionResources(); - - // The stash was a noop, so the locker, RecoveryUnit, and WriteUnitOfWork on the - // OperationContext are unaffected. - ASSERT_EQUALS(originalLocker, opCtx()->lockState()); - ASSERT_EQUALS(originalRecoveryUnit, opCtx()->recoveryUnit()); - ASSERT(opCtx()->getWriteUnitOfWork()); + // Cannot get the top level session since we're a nested one. + const bool topLevelOnly = true; + auto* innerSession = OperationContextSession::get(opCtx(), topLevelOnly); + ASSERT(!innerSession); } } } -TEST_F(SessionCatalogTest, UnstashInNestedSessionIsANoop) { - opCtx()->setLogicalSessionId(makeLogicalSessionIdForTest()); - opCtx()->setTxnNumber(1); - - { - OperationContextSession outerScopedSession(opCtx(), true, boost::none); - - Locker* originalLocker = opCtx()->lockState(); - RecoveryUnit* originalRecoveryUnit = opCtx()->recoveryUnit(); - ASSERT(originalLocker); - ASSERT(originalRecoveryUnit); - - // Set the readConcern on the OperationContext. - repl::ReadConcernArgs readConcernArgs; - ASSERT_OK(readConcernArgs.initialize(BSON("find" - << "test" - << repl::ReadConcernArgs::kReadConcernFieldName - << BSON(repl::ReadConcernArgs::kLevelFieldName - << "snapshot")))); - repl::ReadConcernArgs::get(opCtx()) = readConcernArgs; - - { - OperationContextSession innerScopedSession(opCtx(), true, boost::none); - - innerScopedSession.unstashTransactionResources(); - - // The unstash was a noop, so the OperationContext did not get a WriteUnitOfWork. - ASSERT_EQUALS(originalLocker, opCtx()->lockState()); - ASSERT_EQUALS(originalRecoveryUnit, opCtx()->recoveryUnit()); - ASSERT_FALSE(opCtx()->getWriteUnitOfWork()); - } - } -} - -TEST_F(SessionCatalogTest, OnlyCheckOutSessionWithCheckOutSessionTrue) { - opCtx()->setLogicalSessionId(makeLogicalSessionIdForTest()); - - { - OperationContextSession ocs(opCtx(), true, boost::none); - ASSERT(OperationContextSession::get(opCtx())); - } - - { - OperationContextSession ocs(opCtx(), false, boost::none); - ASSERT(!OperationContextSession::get(opCtx())); - } -} - TEST_F(SessionCatalogTest, ScanSessions) { std::vector<LogicalSessionId> lsids; auto workerFn = [&](OperationContext* opCtx, Session* session) { |