summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2018-11-15 06:41:30 -0500
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2018-11-19 10:02:52 -0500
commitc131f5903c8b4039d3fb2732142c987e296bd503 (patch)
tree6c388cf76254bbbde8e7e86a22bc5fb1ab0f3f43 /src/mongo/db
parent0d71197c9fa8a69203fbe0e81e85acb5766c9428 (diff)
downloadmongo-c131f5903c8b4039d3fb2732142c987e296bd503.tar.gz
SERVER-37245 Do not access the SessionCatalog directly if not necessary
The session catalog should not be accessed directly by majority of the consumers on mongod or mongos, instead they should interact with it through the decorations, which properly validate that the session has been assigned to the OperationContext.
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/SConscript12
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp1
-rw-r--r--src/mongo/db/cursor_manager.cpp1
-rw-r--r--src/mongo/db/db.cpp1
-rw-r--r--src/mongo/db/op_observer_impl.cpp109
-rw-r--r--src/mongo/db/op_observer_impl_test.cpp11
-rw-r--r--src/mongo/db/ops/write_ops_exec.cpp1
-rw-r--r--src/mongo/db/pipeline/SConscript1
-rw-r--r--src/mongo/db/repl/do_txn.cpp1
-rw-r--r--src/mongo/db/repl/do_txn_test.cpp2
-rw-r--r--src/mongo/db/repl/oplog.cpp6
-rw-r--r--src/mongo/db/repl/oplog.h1
-rw-r--r--src/mongo/db/repl/replication_recovery_test.cpp4
-rw-r--r--src/mongo/db/repl/rollback_impl.cpp1
-rw-r--r--src/mongo/db/repl/rollback_test_fixture.cpp1
-rw-r--r--src/mongo/db/repl/sync_tail_test.cpp4
-rw-r--r--src/mongo/db/s/SConscript3
-rw-r--r--src/mongo/db/s/session_catalog_migration_destination_test.cpp5
-rw-r--r--src/mongo/db/service_context_d_test_fixture.cpp7
-rw-r--r--src/mongo/db/service_context_test_fixture.cpp3
-rw-r--r--src/mongo/db/service_context_test_fixture.h2
-rw-r--r--src/mongo/db/session_catalog_mongod.cpp6
-rw-r--r--src/mongo/db/session_catalog_mongod.h2
-rw-r--r--src/mongo/db/session_catalog_test.cpp6
-rw-r--r--src/mongo/db/storage/biggie/biggie_kv_engine.cpp10
-rw-r--r--src/mongo/db/storage/biggie/biggie_kv_engine.h13
-rw-r--r--src/mongo/db/transaction_coordinator.cpp4
-rw-r--r--src/mongo/db/transaction_coordinator_service_test.cpp4
-rw-r--r--src/mongo/db/transaction_participant_retryable_writes_test.cpp6
-rw-r--r--src/mongo/db/transaction_participant_test.cpp10
30 files changed, 94 insertions, 144 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 039b249651d..51ceb642fd9 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -1132,7 +1132,8 @@ env.Library(
'update/update_driver',
],
LIBDEPS_PRIVATE=[
- "commands/server_status_core",
+ 'commands/server_status_core',
+ 'kill_sessions',
],
)
@@ -1584,6 +1585,9 @@ env.Library(
'kill_sessions',
'query_exec',
],
+ LIBDEPS_PRIVATE=[
+ 'session_catalog',
+ ],
)
env.Library(
@@ -1796,9 +1800,9 @@ env.CppUnitTest(
'logical_time_validator_test.cpp',
],
LIBDEPS=[
- '$BUILD_DIR/mongo/db/auth/authmocks',
'$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock',
'$BUILD_DIR/mongo/s/config_server_test_fixture',
+ 'auth/authmocks',
'keys_collection_manager',
'logical_time_validator',
],
@@ -1879,11 +1883,11 @@ env.Library(
'service_context_test_fixture',
],
LIBDEPS_PRIVATE=[
- '$BUILD_DIR/mongo/db/commands/mongod',
- '$BUILD_DIR/mongo/db/storage/storage_options',
+ 'commands/mongod',
'service_context_d',
'storage/devnull/storage_devnull',
'storage/ephemeral_for_test/storage_ephemeral_for_test',
+ 'storage/storage_options',
],
)
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index 0029ed9e9d5..eb8d6d895ec 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -66,7 +66,6 @@
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/retryable_writes_stats.h"
#include "mongo/db/s/collection_sharding_state.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/db/stats/top.h"
#include "mongo/db/transaction_participant.h"
#include "mongo/db/write_concern.h"
diff --git a/src/mongo/db/cursor_manager.cpp b/src/mongo/db/cursor_manager.cpp
index 0c72fadb3a3..c9be0fb9f86 100644
--- a/src/mongo/db/cursor_manager.cpp
+++ b/src/mongo/db/cursor_manager.cpp
@@ -52,7 +52,6 @@
#include "mongo/db/query/plan_executor.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/platform/random.h"
#include "mongo/stdx/memory.h"
#include "mongo/util/exit.h"
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 2800b1e6c39..37c555ed167 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -120,7 +120,6 @@
#include "mongo/db/server_parameters.h"
#include "mongo/db/service_context.h"
#include "mongo/db/service_entry_point_mongod.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/db/session_killer.h"
#include "mongo/db/startup_warnings_mongod.h"
#include "mongo/db/stats/counters.h"
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index 810b1e78136..1d41de814a9 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -109,7 +109,6 @@ repl::OpTime logOperation(OperationContext* opCtx,
*/
void onWriteOpCompleted(OperationContext* opCtx,
const NamespaceString& nss,
- Session* session,
std::vector<StmtId> stmtIdsWritten,
const repl::OpTime& lastStmtIdWriteOpTime,
Date_t lastStmtIdWriteDate,
@@ -117,15 +116,16 @@ void onWriteOpCompleted(OperationContext* opCtx,
if (lastStmtIdWriteOpTime.isNull())
return;
- if (session) {
- const auto txnParticipant = TransactionParticipant::get(opCtx);
- txnParticipant->onWriteOpCompletedOnPrimary(opCtx,
- *opCtx->getTxnNumber(),
- std::move(stmtIdsWritten),
- lastStmtIdWriteOpTime,
- lastStmtIdWriteDate,
- txnState);
- }
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
+ if (!txnParticipant)
+ return;
+
+ txnParticipant->onWriteOpCompletedOnPrimary(opCtx,
+ *opCtx->getTxnNumber(),
+ std::move(stmtIdsWritten),
+ lastStmtIdWriteOpTime,
+ lastStmtIdWriteDate,
+ txnState);
}
/**
@@ -172,9 +172,7 @@ struct OpTimeBundle {
/**
* Write oplog entry(ies) for the update operation.
*/
-OpTimeBundle replLogUpdate(OperationContext* opCtx,
- Session* session,
- const OplogUpdateEntryArgs& args) {
+OpTimeBundle replLogUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs& args) {
BSONObj storeObj;
if (args.updateArgs.storeDocOption == CollectionUpdateArgs::StoreDocOption::PreImage) {
invariant(args.updateArgs.preImageDoc);
@@ -186,11 +184,10 @@ OpTimeBundle replLogUpdate(OperationContext* opCtx,
OperationSessionInfo sessionInfo;
repl::OplogLink oplogLink;
- if (session) {
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
+ if (txnParticipant) {
sessionInfo.setSessionId(*opCtx->getLogicalSessionId());
sessionInfo.setTxnNumber(*opCtx->getTxnNumber());
-
- const auto txnParticipant = TransactionParticipant::get(opCtx);
oplogLink.prevOpTime = txnParticipant->getLastWriteOpTime(*opCtx->getTxnNumber());
}
@@ -245,18 +242,16 @@ OpTimeBundle replLogUpdate(OperationContext* opCtx,
OpTimeBundle replLogDelete(OperationContext* opCtx,
const NamespaceString& nss,
OptionalCollectionUUID uuid,
- Session* session,
StmtId stmtId,
bool fromMigrate,
const boost::optional<BSONObj>& deletedDoc) {
OperationSessionInfo sessionInfo;
repl::OplogLink oplogLink;
- if (session) {
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
+ if (txnParticipant) {
sessionInfo.setSessionId(*opCtx->getLogicalSessionId());
sessionInfo.setTxnNumber(*opCtx->getTxnNumber());
-
- const auto txnParticipant = TransactionParticipant::get(opCtx);
oplogLink.prevOpTime = txnParticipant->getLastWriteOpTime(*opCtx->getTxnNumber());
}
@@ -371,7 +366,7 @@ void OpObserverImpl::onInserts(OperationContext* opCtx,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
- auto txnParticipant = TransactionParticipant::get(opCtx);
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
const bool inMultiDocumentTransaction = txnParticipant && opCtx->writesAreReplicated() &&
txnParticipant->inMultiDocumentTransaction();
@@ -393,10 +388,7 @@ void OpObserverImpl::onInserts(OperationContext* opCtx,
}
} else {
lastWriteDate = getWallClockTimeForOpLog(opCtx);
-
- Session* const session = OperationContextSession::get(opCtx);
- opTimeList =
- repl::logInsertOps(opCtx, nss, uuid, session, first, last, fromMigrate, lastWriteDate);
+ opTimeList = repl::logInsertOps(opCtx, nss, uuid, first, last, fromMigrate, lastWriteDate);
if (!opTimeList.empty())
lastOpTime = opTimeList.back();
@@ -411,8 +403,7 @@ void OpObserverImpl::onInserts(OperationContext* opCtx,
std::back_inserter(stmtIdsWritten),
[](const InsertStatement& stmt) { return stmt.stmtId; });
- onWriteOpCompleted(
- opCtx, nss, session, stmtIdsWritten, lastOpTime, lastWriteDate, boost::none);
+ onWriteOpCompleted(opCtx, nss, stmtIdsWritten, lastOpTime, lastWriteDate, boost::none);
}
size_t index = 0;
@@ -460,20 +451,19 @@ void OpObserverImpl::onUpdate(OperationContext* opCtx, const OplogUpdateEntryArg
return;
}
- auto txnParticipant = TransactionParticipant::get(opCtx);
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
const bool inMultiDocumentTransaction = txnParticipant && opCtx->writesAreReplicated() &&
txnParticipant->inMultiDocumentTransaction();
+
OpTimeBundle opTime;
if (inMultiDocumentTransaction) {
auto operation = OplogEntry::makeUpdateOperation(
args.nss, args.uuid, args.updateArgs.update, args.updateArgs.criteria);
txnParticipant->addTransactionOperation(opCtx, operation);
} else {
- Session* const session = OperationContextSession::get(opCtx);
- opTime = replLogUpdate(opCtx, session, args);
+ opTime = replLogUpdate(opCtx, args);
onWriteOpCompleted(opCtx,
args.nss,
- session,
std::vector<StmtId>{args.updateArgs.stmtId},
opTime.writeOpTime,
opTime.wallClockTime,
@@ -523,22 +513,21 @@ void OpObserverImpl::onDelete(OperationContext* opCtx,
bool fromMigrate,
const boost::optional<BSONObj>& deletedDoc) {
auto& documentKey = documentKeyDecoration(opCtx);
-
invariant(!documentKey.isEmpty());
- auto txnParticipant = TransactionParticipant::get(opCtx);
+
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
const bool inMultiDocumentTransaction = txnParticipant && opCtx->writesAreReplicated() &&
txnParticipant->inMultiDocumentTransaction();
+
OpTimeBundle opTime;
if (inMultiDocumentTransaction) {
auto operation =
OplogEntry::makeDeleteOperation(nss, uuid, deletedDoc ? deletedDoc.get() : documentKey);
txnParticipant->addTransactionOperation(opCtx, operation);
} else {
- Session* const session = OperationContextSession::get(opCtx);
- opTime = replLogDelete(opCtx, nss, uuid, session, stmtId, fromMigrate, deletedDoc);
+ opTime = replLogDelete(opCtx, nss, uuid, stmtId, fromMigrate, deletedDoc);
onWriteOpCompleted(opCtx,
nss,
- session,
std::vector<StmtId>{stmtId},
opTime.writeOpTime,
opTime.wallClockTime,
@@ -931,7 +920,6 @@ void OpObserverImpl::onEmptyCapped(OperationContext* opCtx,
namespace {
OpTimeBundle logApplyOpsForTransaction(OperationContext* opCtx,
- Session* const session,
std::vector<repl::ReplOperation> stmts,
const OplogSlot& prepareOplogSlot) {
BSONObjBuilder applyOpsBuilder;
@@ -968,7 +956,7 @@ OpTimeBundle logApplyOpsForTransaction(OperationContext* opCtx,
auto txnState = prepare ? DurableTxnStateEnum::kPrepared : DurableTxnStateEnum::kCommitted;
onWriteOpCompleted(
- opCtx, cmdNss, session, {stmtId}, times.writeOpTime, times.wallClockTime, txnState);
+ opCtx, cmdNss, {stmtId}, times.writeOpTime, times.wallClockTime, txnState);
return times;
} catch (const AssertionException& e) {
// Change the error code to TransactionTooLarge if it is BSONObjectTooLarge.
@@ -981,7 +969,6 @@ OpTimeBundle logApplyOpsForTransaction(OperationContext* opCtx,
}
void logCommitOrAbortForPreparedTransaction(OperationContext* opCtx,
- Session* const session,
const OplogSlot& oplogSlot,
const BSONObj& objectField,
DurableTxnStateEnum durableState) {
@@ -1029,8 +1016,7 @@ void logCommitOrAbortForPreparedTransaction(OperationContext* opCtx,
oplogSlot);
invariant(oplogSlot.opTime.isNull() || oplogSlot.opTime == oplogOpTime);
- onWriteOpCompleted(
- opCtx, cmdNss, session, {stmtId}, oplogOpTime, wallClockTime, durableState);
+ onWriteOpCompleted(opCtx, cmdNss, {stmtId}, oplogOpTime, wallClockTime, durableState);
wuow.commit();
});
}
@@ -1040,27 +1026,23 @@ void logCommitOrAbortForPreparedTransaction(OperationContext* opCtx,
void OpObserverImpl::onTransactionCommit(OperationContext* opCtx,
boost::optional<OplogSlot> commitOplogEntryOpTime,
boost::optional<Timestamp> commitTimestamp) {
+ invariant(opCtx->getTxnNumber());
+
if (!opCtx->writesAreReplicated()) {
return;
}
- invariant(opCtx->getTxnNumber());
- Session* const session = OperationContextSession::get(opCtx);
- invariant(session);
-
- auto txnParticipant = TransactionParticipant::get(opCtx);
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
invariant(txnParticipant);
+
if (commitOplogEntryOpTime) {
invariant(commitTimestamp);
invariant(!commitTimestamp->isNull());
CommitTransactionOplogObject cmdObj;
cmdObj.setCommitTimestamp(*commitTimestamp);
- logCommitOrAbortForPreparedTransaction(opCtx,
- session,
- *commitOplogEntryOpTime,
- cmdObj.toBSON(),
- DurableTxnStateEnum::kCommitted);
+ logCommitOrAbortForPreparedTransaction(
+ opCtx, *commitOplogEntryOpTime, cmdObj.toBSON(), DurableTxnStateEnum::kCommitted);
} else {
invariant(!commitTimestamp);
const auto stmts = txnParticipant->endTransactionAndRetrieveOperations(opCtx);
@@ -1070,18 +1052,15 @@ void OpObserverImpl::onTransactionCommit(OperationContext* opCtx,
if (stmts.empty())
return;
- Session* const session = OperationContextSession::get(opCtx);
- invariant(session);
-
- const auto commitOpTime =
- logApplyOpsForTransaction(opCtx, session, stmts, OplogSlot()).writeOpTime;
+ const auto commitOpTime = logApplyOpsForTransaction(opCtx, stmts, OplogSlot()).writeOpTime;
invariant(!commitOpTime.isNull());
}
}
void OpObserverImpl::onTransactionPrepare(OperationContext* opCtx, const OplogSlot& prepareOpTime) {
invariant(opCtx->getTxnNumber());
- auto txnParticipant = TransactionParticipant::get(opCtx);
+
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
invariant(txnParticipant);
invariant(txnParticipant->inMultiDocumentTransaction());
invariant(!prepareOpTime.opTime.isNull());
@@ -1103,26 +1082,20 @@ void OpObserverImpl::onTransactionPrepare(OperationContext* opCtx, const OplogSl
Lock::GlobalLock globalLock(opCtx, MODE_IX);
WriteUnitOfWork wuow(opCtx);
-
- Session* const session = OperationContextSession::get(opCtx);
- invariant(session);
-
- logApplyOpsForTransaction(opCtx, session, stmts, prepareOpTime);
+ logApplyOpsForTransaction(opCtx, stmts, prepareOpTime);
wuow.commit();
}
}
void OpObserverImpl::onTransactionAbort(OperationContext* opCtx,
boost::optional<OplogSlot> abortOplogEntryOpTime) {
+ invariant(opCtx->getTxnNumber());
+
if (!opCtx->writesAreReplicated()) {
return;
}
- invariant(opCtx->getTxnNumber());
- Session* const session = OperationContextSession::get(opCtx);
- invariant(session);
-
- auto txnParticipant = TransactionParticipant::get(opCtx);
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
invariant(txnParticipant);
if (!abortOplogEntryOpTime) {
@@ -1132,7 +1105,7 @@ void OpObserverImpl::onTransactionAbort(OperationContext* opCtx,
AbortTransactionOplogObject cmdObj;
logCommitOrAbortForPreparedTransaction(
- opCtx, session, *abortOplogEntryOpTime, cmdObj.toBSON(), DurableTxnStateEnum::kAborted);
+ opCtx, *abortOplogEntryOpTime, cmdObj.toBSON(), DurableTxnStateEnum::kAborted);
}
void OpObserverImpl::onReplicationRollback(OperationContext* opCtx,
diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp
index 6bfd5a8ec48..a16813f695c 100644
--- a/src/mongo/db/op_observer_impl_test.cpp
+++ b/src/mongo/db/op_observer_impl_test.cpp
@@ -303,18 +303,11 @@ class OpObserverSessionCatalogRollbackTest : public OpObserverTest {
public:
void setUp() override {
OpObserverTest::setUp();
- auto opCtx = cc().makeOperationContext();
+ auto opCtx = cc().makeOperationContext();
MongoDSessionCatalog::onStepUp(opCtx.get());
}
- void tearDown() override {
- auto sessionCatalog = SessionCatalog::get(getServiceContext());
- sessionCatalog->reset_forTest();
-
- OpObserverTest::tearDown();
- }
-
/**
* Simulate a new write occurring on given session with the given transaction number and
* statement id.
@@ -549,8 +542,6 @@ public:
_sessionCheckout.reset();
_times.reset();
_opCtx.reset();
- auto sessionCatalog = SessionCatalog::get(getServiceContext());
- sessionCatalog->reset_forTest();
OpObserverTest::tearDown();
}
diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp
index f7b37456d2c..5898ad527c3 100644
--- a/src/mongo/db/ops/write_ops_exec.cpp
+++ b/src/mongo/db/ops/write_ops_exec.cpp
@@ -67,7 +67,6 @@
#include "mongo/db/s/collection_sharding_state.h"
#include "mongo/db/s/operation_sharding_state.h"
#include "mongo/db/s/sharding_state.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/stats/top.h"
#include "mongo/db/transaction_participant.h"
diff --git a/src/mongo/db/pipeline/SConscript b/src/mongo/db/pipeline/SConscript
index 2153885e4f0..28f833e2e67 100644
--- a/src/mongo/db/pipeline/SConscript
+++ b/src/mongo/db/pipeline/SConscript
@@ -298,6 +298,7 @@ env.Library(
'mongo_process_common',
],
LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/db/session_catalog',
'$BUILD_DIR/mongo/db/storage/backup_cursor_hooks',
],
)
diff --git a/src/mongo/db/repl/do_txn.cpp b/src/mongo/db/repl/do_txn.cpp
index 169ae5687cc..32f94912579 100644
--- a/src/mongo/db/repl/do_txn.cpp
+++ b/src/mongo/db/repl/do_txn.cpp
@@ -52,7 +52,6 @@
#include "mongo/db/query/collation/collation_spec.h"
#include "mongo/db/repl/replication_coordinator.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/db/transaction_participant.h"
#include "mongo/rpc/get_status_from_command_result.h"
#include "mongo/util/fail_point_service.h"
diff --git a/src/mongo/db/repl/do_txn_test.cpp b/src/mongo/db/repl/do_txn_test.cpp
index 66d3017b415..abede66d1f6 100644
--- a/src/mongo/db/repl/do_txn_test.cpp
+++ b/src/mongo/db/repl/do_txn_test.cpp
@@ -168,8 +168,6 @@ void DoTxnTest::tearDown() {
_storage = {};
_opObserver = nullptr;
- SessionCatalog::get(getServiceContext())->reset_forTest();
-
// Reset default log level in case it was changed.
logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogComponent::kReplication,
logger::LogSeverity::Debug(0));
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 8b0f9d7181e..a2839304314 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -82,7 +82,6 @@
#include "mongo/db/repl/transaction_oplog_application.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/db/stats/counters.h"
#include "mongo/db/storage/storage_engine.h"
#include "mongo/db/storage/storage_options.h"
@@ -505,7 +504,6 @@ OpTime logOp(OperationContext* opCtx,
std::vector<OpTime> logInsertOps(OperationContext* opCtx,
const NamespaceString& nss,
OptionalCollectionUUID uuid,
- Session* session,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate,
@@ -540,11 +538,11 @@ std::vector<OpTime> logInsertOps(OperationContext* opCtx,
OperationSessionInfo sessionInfo;
OplogLink oplogLink;
- if (session) {
+ const auto txnParticipant = TransactionParticipant::get(opCtx);
+ if (txnParticipant) {
sessionInfo.setSessionId(*opCtx->getLogicalSessionId());
sessionInfo.setTxnNumber(*opCtx->getTxnNumber());
- const auto txnParticipant = TransactionParticipant::get(opCtx);
oplogLink.prevOpTime = txnParticipant->getLastWriteOpTime(*opCtx->getTxnNumber());
}
diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h
index 1c5439a62c0..98f4d25a011 100644
--- a/src/mongo/db/repl/oplog.h
+++ b/src/mongo/db/repl/oplog.h
@@ -105,7 +105,6 @@ void createOplog(OperationContext* opCtx);
std::vector<OpTime> logInsertOps(OperationContext* opCtx,
const NamespaceString& nss,
OptionalCollectionUUID uuid,
- Session* session,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate,
diff --git a/src/mongo/db/repl/replication_recovery_test.cpp b/src/mongo/db/repl/replication_recovery_test.cpp
index b056a6a6857..ac80eb73494 100644
--- a/src/mongo/db/repl/replication_recovery_test.cpp
+++ b/src/mongo/db/repl/replication_recovery_test.cpp
@@ -154,6 +154,7 @@ protected:
private:
void setUp() override {
ServiceContextMongoDTest::setUp();
+
_createOpCtx();
_storageInterface = stdx::make_unique<StorageInterfaceRecovery>();
_consistencyMarkers = stdx::make_unique<ReplicationConsistencyMarkersMock>();
@@ -178,11 +179,10 @@ private:
}
void tearDown() override {
- SessionCatalog::get(_opCtx->getServiceContext())->reset_forTest();
-
_opCtx.reset(nullptr);
_consistencyMarkers.reset();
_storageInterface.reset();
+
ServiceContextMongoDTest::tearDown();
}
diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp
index 9392eed0938..d7458856956 100644
--- a/src/mongo/db/repl/rollback_impl.cpp
+++ b/src/mongo/db/repl/rollback_impl.cpp
@@ -55,7 +55,6 @@
#include "mongo/db/s/type_shard_identity.h"
#include "mongo/db/server_parameters.h"
#include "mongo/db/server_recovery.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/s/catalog/type_config_version.h"
#include "mongo/util/log.h"
#include "mongo/util/scopeguard.h"
diff --git a/src/mongo/db/repl/rollback_test_fixture.cpp b/src/mongo/db/repl/rollback_test_fixture.cpp
index f6b2d4884fa..b9228638e07 100644
--- a/src/mongo/db/repl/rollback_test_fixture.cpp
+++ b/src/mongo/db/repl/rollback_test_fixture.cpp
@@ -47,7 +47,6 @@
#include "mongo/db/repl/replication_process.h"
#include "mongo/db/repl/replication_recovery.h"
#include "mongo/db/repl/rs_rollback.h"
-#include "mongo/db/session_catalog.h"
#include "mongo/logger/log_component.h"
#include "mongo/logger/logger.h"
#include "mongo/stdx/memory.h"
diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp
index 14f73d4d0dc..8cff42112f2 100644
--- a/src/mongo/db/repl/sync_tail_test.cpp
+++ b/src/mongo/db/repl/sync_tail_test.cpp
@@ -1641,10 +1641,6 @@ public:
BSONObj result;
ASSERT(client.runCommand(kNs.db().toString(), BSON("create" << kNs.coll()), result));
}
- void tearDown() override {
- SessionCatalog::get(_opCtx->getServiceContext())->reset_forTest();
- SyncTailTest::tearDown();
- }
/**
* Creates an OplogEntry with given parameters and preset defaults for this test suite.
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index 37eb5bf69bc..e348ad6e4ad 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -84,6 +84,9 @@ env.Library(
'sharding_catalog_manager',
'sharding_logging',
],
+ LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/db/session_catalog',
+ ],
)
env.Library(
diff --git a/src/mongo/db/s/session_catalog_migration_destination_test.cpp b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
index 95e806a0afd..0064d5edbc7 100644
--- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp
+++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp
@@ -135,11 +135,6 @@ public:
LogicalSessionCache::set(getServiceContext(), stdx::make_unique<LogicalSessionCacheNoop>());
}
- void tearDown() override {
- SessionCatalog::get(getServiceContext())->reset_forTest();
- ShardServerTestFixture::tearDown();
- }
-
void returnOplog(const std::vector<OplogEntry>& oplogList) {
onCommand([&oplogList](const RemoteCommandRequest& request) -> StatusWith<BSONObj> {
BSONObjBuilder builder;
diff --git a/src/mongo/db/service_context_d_test_fixture.cpp b/src/mongo/db/service_context_d_test_fixture.cpp
index a8be3bf222e..c02348243c3 100644
--- a/src/mongo/db/service_context_d_test_fixture.cpp
+++ b/src/mongo/db/service_context_d_test_fixture.cpp
@@ -36,6 +36,7 @@
#include "mongo/base/checked_cast.h"
#include "mongo/db/catalog/catalog_control.h"
+#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/catalog/uuid_catalog.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/logical_clock.h"
@@ -46,8 +47,6 @@
#include "mongo/util/assert_util.h"
#include "mongo/util/mock_periodic_runner_impl.h"
-#include "mongo/db/catalog/database_holder.h"
-
namespace mongo {
ServiceContextMongoDTest::ServiceContextMongoDTest()
@@ -95,7 +94,9 @@ ServiceContextMongoDTest::~ServiceContextMongoDTest() {
Lock::GlobalLock glk(opCtx.get(), MODE_X);
DatabaseHolder::getDatabaseHolder().closeAll(opCtx.get(), "all databases dropped");
}
- shutdownGlobalStorageEngineCleanly(getGlobalServiceContext());
+
+ shutdownGlobalStorageEngineCleanly(getServiceContext());
+
std::swap(storageGlobalParams.engine, _stashedStorageParams.engine);
std::swap(storageGlobalParams.engineSetByUser, _stashedStorageParams.engineSetByUser);
std::swap(storageGlobalParams.repair, _stashedStorageParams.repair);
diff --git a/src/mongo/db/service_context_test_fixture.cpp b/src/mongo/db/service_context_test_fixture.cpp
index e79c8ab7ea3..859c1b3a32c 100644
--- a/src/mongo/db/service_context_test_fixture.cpp
+++ b/src/mongo/db/service_context_test_fixture.cpp
@@ -55,7 +55,8 @@ ServiceContext* ScopedGlobalServiceContextForTest::getServiceContext() {
return getGlobalServiceContext();
}
-ServiceContextTest::ServiceContextTest() : _threadClient(getGlobalServiceContext()) {}
+
+ServiceContextTest::ServiceContextTest() : _threadClient(getServiceContext()) {}
Client* ServiceContextTest::getClient() {
return Client::getCurrent();
diff --git a/src/mongo/db/service_context_test_fixture.h b/src/mongo/db/service_context_test_fixture.h
index a81962478fd..a538e7c89b3 100644
--- a/src/mongo/db/service_context_test_fixture.h
+++ b/src/mongo/db/service_context_test_fixture.h
@@ -67,6 +67,8 @@ public:
protected:
ServiceContextTest();
virtual ~ServiceContextTest() = default;
+
+private:
ThreadClient _threadClient;
};
diff --git a/src/mongo/db/session_catalog_mongod.cpp b/src/mongo/db/session_catalog_mongod.cpp
index 5ea8173ca05..75ee1f3104e 100644
--- a/src/mongo/db/session_catalog_mongod.cpp
+++ b/src/mongo/db/session_catalog_mongod.cpp
@@ -180,6 +180,9 @@ MongoDOperationContextSession::MongoDOperationContextSession(OperationContext* o
}
}
+MongoDOperationContextSession::~MongoDOperationContextSession() = default;
+
+
MongoDOperationContextSessionWithoutRefresh::MongoDOperationContextSessionWithoutRefresh(
OperationContext* opCtx)
: _operationContextSession(opCtx) {
@@ -190,4 +193,7 @@ MongoDOperationContextSessionWithoutRefresh::MongoDOperationContextSessionWithou
txnParticipant->beginOrContinueTransactionUnconditionally(clientTxnNumber);
}
+MongoDOperationContextSessionWithoutRefresh::~MongoDOperationContextSessionWithoutRefresh() =
+ default;
+
} // namespace mongo
diff --git a/src/mongo/db/session_catalog_mongod.h b/src/mongo/db/session_catalog_mongod.h
index c71e0dce076..ca9e5b0e0ca 100644
--- a/src/mongo/db/session_catalog_mongod.h
+++ b/src/mongo/db/session_catalog_mongod.h
@@ -73,6 +73,7 @@ public:
class MongoDOperationContextSession {
public:
MongoDOperationContextSession(OperationContext* opCtx);
+ ~MongoDOperationContextSession();
private:
OperationContextSession _operationContextSession;
@@ -88,6 +89,7 @@ private:
class MongoDOperationContextSessionWithoutRefresh {
public:
MongoDOperationContextSessionWithoutRefresh(OperationContext* opCtx);
+ ~MongoDOperationContextSessionWithoutRefresh();
private:
OperationContextSession _operationContextSession;
diff --git a/src/mongo/db/session_catalog_test.cpp b/src/mongo/db/session_catalog_test.cpp
index af421398ebd..62a974b308d 100644
--- a/src/mongo/db/session_catalog_test.cpp
+++ b/src/mongo/db/session_catalog_test.cpp
@@ -44,12 +44,6 @@ namespace {
class SessionCatalogTest : public ServiceContextMongoDTest {
protected:
- void setUp() final {
- ServiceContextMongoDTest::setUp();
-
- catalog()->reset_forTest();
- }
-
SessionCatalog* catalog() {
return SessionCatalog::get(getServiceContext());
}
diff --git a/src/mongo/db/storage/biggie/biggie_kv_engine.cpp b/src/mongo/db/storage/biggie/biggie_kv_engine.cpp
index 7ed7b9578c8..6a412f24f03 100644
--- a/src/mongo/db/storage/biggie/biggie_kv_engine.cpp
+++ b/src/mongo/db/storage/biggie/biggie_kv_engine.cpp
@@ -61,11 +61,11 @@ Status KVEngine::createRecordStore(OperationContext* opCtx,
return Status::OK();
}
-std::unique_ptr<::mongo::RecordStore> KVEngine::getRecordStore(OperationContext* opCtx,
- StringData ns,
- StringData ident,
- const CollectionOptions& options) {
- std::unique_ptr<::mongo::RecordStore> recordStore;
+std::unique_ptr<mongo::RecordStore> KVEngine::getRecordStore(OperationContext* opCtx,
+ StringData ns,
+ StringData ident,
+ const CollectionOptions& options) {
+ std::unique_ptr<mongo::RecordStore> recordStore;
if (options.capped) {
recordStore = stdx::make_unique<RecordStore>(
ns,
diff --git a/src/mongo/db/storage/biggie/biggie_kv_engine.h b/src/mongo/db/storage/biggie/biggie_kv_engine.h
index ac15991bf38..cb354a30798 100644
--- a/src/mongo/db/storage/biggie/biggie_kv_engine.h
+++ b/src/mongo/db/storage/biggie/biggie_kv_engine.h
@@ -41,13 +41,14 @@
namespace mongo {
namespace biggie {
+
class JournalListener;
/**
* The biggie storage engine is intended for unit and performance testing.
*/
-class KVEngine : public ::mongo::KVEngine {
+class KVEngine : public mongo::KVEngine {
public:
- KVEngine() : ::mongo::KVEngine() {}
+ KVEngine() : mongo::KVEngine() {}
virtual ~KVEngine() {}
@@ -58,10 +59,10 @@ public:
StringData ident,
const CollectionOptions& options);
- virtual std::unique_ptr<::mongo::RecordStore> getRecordStore(OperationContext* opCtx,
- StringData ns,
- StringData ident,
- const CollectionOptions& options);
+ virtual std::unique_ptr<mongo::RecordStore> getRecordStore(OperationContext* opCtx,
+ StringData ns,
+ StringData ident,
+ const CollectionOptions& options);
virtual Status createSortedDataInterface(OperationContext* opCtx,
StringData ident,
diff --git a/src/mongo/db/transaction_coordinator.cpp b/src/mongo/db/transaction_coordinator.cpp
index cb12b61c719..e8b60811d7b 100644
--- a/src/mongo/db/transaction_coordinator.cpp
+++ b/src/mongo/db/transaction_coordinator.cpp
@@ -32,10 +32,10 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/transaction_coordinator.h"
+
#include "mongo/db/logical_clock.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/session_catalog.h"
-#include "mongo/db/transaction_coordinator.h"
#include "mongo/util/log.h"
namespace mongo {
diff --git a/src/mongo/db/transaction_coordinator_service_test.cpp b/src/mongo/db/transaction_coordinator_service_test.cpp
index 6ca02c9b2be..8eb51f22f68 100644
--- a/src/mongo/db/transaction_coordinator_service_test.cpp
+++ b/src/mongo/db/transaction_coordinator_service_test.cpp
@@ -31,12 +31,12 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/transaction_coordinator_service.h"
+
#include "mongo/client/remote_command_targeter_mock.h"
#include "mongo/db/commands/txn_cmds_gen.h"
#include "mongo/db/commands/txn_two_phase_commit_cmds_gen.h"
#include "mongo/db/operation_context.h"
-#include "mongo/db/session_catalog.h"
-#include "mongo/db/transaction_coordinator_service.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/s/catalog/sharding_catalog_client_mock.h"
#include "mongo/s/catalog/type_shard.h"
diff --git a/src/mongo/db/transaction_participant_retryable_writes_test.cpp b/src/mongo/db/transaction_participant_retryable_writes_test.cpp
index 51bfc5188d2..74db53ed801 100644
--- a/src/mongo/db/transaction_participant_retryable_writes_test.cpp
+++ b/src/mongo/db/transaction_participant_retryable_writes_test.cpp
@@ -155,15 +155,9 @@ protected:
void tearDown() final {
_opObserver = nullptr;
- SessionCatalog::get(opCtx()->getServiceContext())->reset_forTest();
-
MockReplCoordServerFixture::tearDown();
}
- SessionCatalog* catalog() {
- return SessionCatalog::get(opCtx()->getServiceContext());
- }
-
static repl::OpTime logOp(OperationContext* opCtx,
const NamespaceString& nss,
UUID uuid,
diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp
index 1518edff739..0f0eaa0c534 100644
--- a/src/mongo/db/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction_participant_test.cpp
@@ -195,11 +195,9 @@ class TxnParticipantTest : public MockReplCoordServerFixture {
protected:
void setUp() override {
MockReplCoordServerFixture::setUp();
-
- auto service = opCtx()->getServiceContext();
-
MongoDSessionCatalog::onStepUp(opCtx());
+ const auto service = opCtx()->getServiceContext();
OpObserverRegistry* opObserverRegistry =
dynamic_cast<OpObserverRegistry*>(service->getOpObserver());
auto mockObserver = stdx::make_unique<OpObserverMock>();
@@ -214,11 +212,12 @@ protected:
}
void tearDown() override {
+ _opObserver = nullptr;
+
// Clear all sessions to free up any stashed resources.
SessionCatalog::get(opCtx()->getServiceContext())->reset_forTest();
MockReplCoordServerFixture::tearDown();
- _opObserver = nullptr;
}
SessionCatalog* catalog() {
@@ -1668,8 +1667,7 @@ TEST_F(TxnParticipantTest, ThrowDuringPreparedOnTransactionAbortIsFatal) {
* Test fixture for transactions metrics.
*/
class TransactionsMetricsTest : public TxnParticipantTest {
-
-public:
+protected:
using TickSourceMicrosecondMock = TickSourceMock<Microseconds>;
/**