From ec8694abf458ceb1494ed97a29b199afc3e73708 Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Thu, 25 Aug 2022 06:39:31 -0400 Subject: SERVER-68215 MongoDSessionCatalog constructor accepts MongoDSessionCatalogTransactionInterface --- src/mongo/db/session/session_catalog_mongod.cpp | 4 +- src/mongo/db/session/session_catalog_mongod.h | 6 ++- .../db/session/session_catalog_mongod_test.cpp | 4 +- .../session_catalog_mongod_transaction_interface.h | 44 ++++++++++++++++++++++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/mongo/db/session/session_catalog_mongod_transaction_interface.h (limited to 'src/mongo/db/session') diff --git a/src/mongo/db/session/session_catalog_mongod.cpp b/src/mongo/db/session/session_catalog_mongod.cpp index 2822274690b..2b9a24e9dcf 100644 --- a/src/mongo/db/session/session_catalog_mongod.cpp +++ b/src/mongo/db/session/session_catalog_mongod.cpp @@ -521,7 +521,9 @@ BSONObj MongoDSessionCatalog::getConfigTxnPartialIndexSpec() { return index.toBSON(); } -MongoDSessionCatalog::MongoDSessionCatalog() {} +MongoDSessionCatalog::MongoDSessionCatalog( + std::unique_ptr ti) + : _ti(std::move(ti)) {} void MongoDSessionCatalog::onStepUp(OperationContext* opCtx) { // Invalidate sessions that could have a retryable write on it, so that we can refresh from disk diff --git a/src/mongo/db/session/session_catalog_mongod.h b/src/mongo/db/session/session_catalog_mongod.h index ce5de294b51..10ae6fea506 100644 --- a/src/mongo/db/session/session_catalog_mongod.h +++ b/src/mongo/db/session/session_catalog_mongod.h @@ -30,6 +30,7 @@ #pragma once #include "mongo/db/session/session_catalog.h" +#include "mongo/db/session/session_catalog_mongod_transaction_interface.h" namespace mongo { @@ -66,7 +67,7 @@ public: */ static BSONObj getConfigTxnPartialIndexSpec(); - MongoDSessionCatalog(); + explicit MongoDSessionCatalog(std::unique_ptr ti); /** * Invoked when the node enters the primary state. Ensures that the transactions collection is @@ -180,6 +181,9 @@ public: void checkInUnscopedSession(OperationContext* opCtx, OperationContextSession::CheckInReason reason); void checkOutUnscopedSession(OperationContext* opCtx); + +private: + std::unique_ptr _ti; }; /** diff --git a/src/mongo/db/session/session_catalog_mongod_test.cpp b/src/mongo/db/session/session_catalog_mongod_test.cpp index 5e988142e97..87758d0bb63 100644 --- a/src/mongo/db/session/session_catalog_mongod_test.cpp +++ b/src/mongo/db/session/session_catalog_mongod_test.cpp @@ -35,6 +35,7 @@ #include "mongo/db/session/session_catalog_mongod.h" #include "mongo/db/session/session_txn_record_gen.h" #include "mongo/db/session/sessions_collection_mock.h" +#include "mongo/db/transaction/session_catalog_mongod_transaction_interface_impl.h" #include "mongo/util/clock_source_mock.h" namespace mongo { @@ -84,7 +85,8 @@ TEST_F(MongoDSessionCatalogTest, ReapSomeExpiredSomeNot) { _collectionMock->add(LogicalSessionRecord(makeLogicalSessionIdForTest(), clock()->now())); _collectionMock->add(LogicalSessionRecord(makeLogicalSessionIdForTest(), clock()->now())); - auto mongoDSessionCatalog = MongoDSessionCatalog{}; + auto mongoDSessionCatalog = + MongoDSessionCatalog(std::make_unique()); auto numReaped = mongoDSessionCatalog.reapSessionsOlderThan( _opCtx, *_collection, clock()->now() - Minutes{30}); diff --git a/src/mongo/db/session/session_catalog_mongod_transaction_interface.h b/src/mongo/db/session/session_catalog_mongod_transaction_interface.h new file mode 100644 index 00000000000..4a6af53d049 --- /dev/null +++ b/src/mongo/db/session/session_catalog_mongod_transaction_interface.h @@ -0,0 +1,44 @@ +/** + * Copyright (C) 2022-present MongoDB, Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the Server Side Public License, version 1, + * as published by MongoDB, Inc. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * Server Side Public License for more details. + * + * You should have received a copy of the Server Side Public License + * along with this program. If not, see + * . + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the Server Side Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#pragma once + +namespace mongo { + +/** + * This interface provides methods for the MongoDSessionCatalog implementation to access + * multi-document transaction features, specifically functionality provided by the + * TransactionParticipant class in the db/transaction library. + */ +class MongoDSessionCatalogTransactionInterface { +public: + virtual ~MongoDSessionCatalogTransactionInterface() = default; +}; + +} // namespace mongo -- cgit v1.2.1