summaryrefslogtreecommitdiff
path: root/src/mongo/db/op_observer_impl_test.cpp
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2018-10-09 08:17:38 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2018-10-31 04:50:08 -0400
commit236c6c28a18210586673097ee436c5b613b6c46f (patch)
tree9c26586d5943845b8f3356cbbee41dc75533670d /src/mongo/db/op_observer_impl_test.cpp
parente701da7ff3ec84b2bb3b353fa748c22f7b2a5878 (diff)
downloadmongo-236c6c28a18210586673097ee436c5b613b6c46f.tar.gz
SERVER-37244 Make sessions killable outside of the Session/TransactionParticipant object
Diffstat (limited to 'src/mongo/db/op_observer_impl_test.cpp')
-rw-r--r--src/mongo/db/op_observer_impl_test.cpp108
1 files changed, 76 insertions, 32 deletions
diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp
index abbb9b94754..dd4cbc4b021 100644
--- a/src/mongo/db/op_observer_impl_test.cpp
+++ b/src/mongo/db/op_observer_impl_test.cpp
@@ -345,62 +345,106 @@ public:
}
};
-TEST_F(OpObserverSessionCatalogTest, OnRollbackInvalidatesSessionCatalogIfSessionOpsRolledBack) {
- OpObserverImpl opObserver;
- auto opCtx = cc().makeOperationContext();
+using OpObserverSessionCatalogRollbackTest = OpObserverSessionCatalogTest;
+
+TEST_F(OpObserverSessionCatalogRollbackTest,
+ OnRollbackInvalidatesSessionCatalogIfSessionOpsRolledBack) {
const NamespaceString nss("testDB", "testColl");
// Create a session.
auto sessionCatalog = SessionCatalog::get(getServiceContext());
auto sessionId = makeLogicalSessionIdForTest();
- auto session = sessionCatalog->getOrCreateSession(opCtx.get(), sessionId);
- const auto txnParticipant = TransactionParticipant::getFromNonCheckedOutSession(session.get());
- txnParticipant->refreshFromStorageIfNeeded(opCtx.get());
- // Simulate a write occurring on that session.
const TxnNumber txnNum = 0;
const StmtId stmtId = 1000;
- simulateSessionWrite(opCtx.get(), txnParticipant, nss, txnNum, stmtId);
- // Check that the statement executed.
- ASSERT(txnParticipant->checkStatementExecutedNoOplogEntryFetch(txnNum, stmtId));
+ {
+ auto opCtx = cc().makeOperationContext();
+ opCtx->setLogicalSessionId(sessionId);
+
+ // Create a session and sync it from disk
+ auto session = sessionCatalog->checkOutSession(opCtx.get());
+ const auto txnParticipant =
+ TransactionParticipant::getFromNonCheckedOutSession(session.get());
+ txnParticipant->refreshFromStorageIfNeeded(opCtx.get());
+
+ // Simulate a write occurring on that session
+ simulateSessionWrite(opCtx.get(), txnParticipant, nss, txnNum, stmtId);
+
+ // Check that the statement executed
+ ASSERT(txnParticipant->checkStatementExecutedNoOplogEntryFetch(txnNum, stmtId));
+ }
// The OpObserver should invalidate in-memory session state, so the check after this should
// fail.
- OpObserver::RollbackObserverInfo rbInfo;
- rbInfo.rollbackSessionIds = {UUID::gen()};
- opObserver.onReplicationRollback(opCtx.get(), rbInfo);
- ASSERT_THROWS_CODE(txnParticipant->checkStatementExecutedNoOplogEntryFetch(txnNum, stmtId),
- DBException,
- ErrorCodes::ConflictingOperationInProgress);
+ {
+ auto opCtx = cc().makeOperationContext();
+
+ OpObserverImpl opObserver;
+ OpObserver::RollbackObserverInfo rbInfo;
+ rbInfo.rollbackSessionIds = {UUID::gen()};
+ opObserver.onReplicationRollback(opCtx.get(), rbInfo);
+ }
+
+ {
+ auto opCtx = cc().makeOperationContext();
+ opCtx->setLogicalSessionId(sessionId);
+
+ auto session = sessionCatalog->checkOutSession(opCtx.get());
+ const auto txnParticipant =
+ TransactionParticipant::getFromNonCheckedOutSession(session.get());
+ ASSERT_THROWS_CODE(txnParticipant->checkStatementExecutedNoOplogEntryFetch(txnNum, stmtId),
+ DBException,
+ ErrorCodes::ConflictingOperationInProgress);
+ }
}
-TEST_F(OpObserverSessionCatalogTest,
+TEST_F(OpObserverSessionCatalogRollbackTest,
OnRollbackDoesntInvalidateSessionCatalogIfNoSessionOpsRolledBack) {
- OpObserverImpl opObserver;
- auto opCtx = cc().makeOperationContext();
const NamespaceString nss("testDB", "testColl");
- // Create a session.
auto sessionCatalog = SessionCatalog::get(getServiceContext());
auto sessionId = makeLogicalSessionIdForTest();
- auto session = sessionCatalog->getOrCreateSession(opCtx.get(), sessionId);
- const auto txnParticipant = TransactionParticipant::getFromNonCheckedOutSession(session.get());
- txnParticipant->refreshFromStorageIfNeeded(opCtx.get());
- // Simulate a write occurring on that session.
const TxnNumber txnNum = 0;
const StmtId stmtId = 1000;
- simulateSessionWrite(opCtx.get(), txnParticipant, nss, txnNum, stmtId);
- // Check that the statement executed.
- ASSERT(txnParticipant->checkStatementExecutedNoOplogEntryFetch(txnNum, stmtId));
+ {
+ auto opCtx = cc().makeOperationContext();
+ opCtx->setLogicalSessionId(sessionId);
+
+ // Create a session and sync it from disk
+ auto session = sessionCatalog->checkOutSession(opCtx.get());
+ const auto txnParticipant =
+ TransactionParticipant::getFromNonCheckedOutSession(session.get());
+ txnParticipant->refreshFromStorageIfNeeded(opCtx.get());
- // The OpObserver should not invalidate the in-memory session state, so the check after this
- // should still succeed.
- OpObserver::RollbackObserverInfo rbInfo;
- opObserver.onReplicationRollback(opCtx.get(), rbInfo);
- ASSERT(txnParticipant->checkStatementExecutedNoOplogEntryFetch(txnNum, stmtId));
+ // Simulate a write occurring on that session
+ simulateSessionWrite(opCtx.get(), txnParticipant, nss, txnNum, stmtId);
+
+ // Check that the statement executed
+ ASSERT(txnParticipant->checkStatementExecutedNoOplogEntryFetch(txnNum, stmtId));
+ }
+
+ // Because there are no sessions to rollback, the OpObserver should not invalidate the in-memory
+ // session state, so the check after this should still succeed.
+ {
+ auto opCtx = cc().makeOperationContext();
+
+ OpObserverImpl opObserver;
+ OpObserver::RollbackObserverInfo rbInfo;
+ opObserver.onReplicationRollback(opCtx.get(), rbInfo);
+ }
+
+ {
+ auto opCtx = cc().makeOperationContext();
+ opCtx->setLogicalSessionId(sessionId);
+
+ auto session = sessionCatalog->checkOutSession(opCtx.get());
+ const auto txnParticipant =
+ TransactionParticipant::getFromNonCheckedOutSession(session.get());
+ ASSERT(txnParticipant->checkStatementExecutedNoOplogEntryFetch(txnNum, stmtId));
+ }
}
/**