From 279531ef0dbaf8f6df0e25341425eb57d75a21ea Mon Sep 17 00:00:00 2001 From: Kaloian Manassiev Date: Mon, 15 May 2023 11:09:32 +0000 Subject: SERVER-77124 Move TransactionResources under shard_role_api --- src/mongo/db/SConscript | 26 ++-- src/mongo/db/commands/SConscript | 5 +- src/mongo/db/initialize_operation_session_info.cpp | 170 ++++++++++++++++++++ src/mongo/db/initialize_operation_session_info.h | 58 +++++++ .../session_catalog_migration_destination_test.cpp | 2 +- src/mongo/db/service_entry_point_common.cpp | 3 +- src/mongo/db/session/SConscript | 1 - .../session/initialize_operation_session_info.cpp | 172 --------------------- .../db/session/initialize_operation_session_info.h | 58 ------- src/mongo/db/session/logical_session_id_test.cpp | 7 +- src/mongo/embedded/SConscript | 1 - src/mongo/s/SConscript | 9 +- src/mongo/s/commands/strategy.cpp | 2 +- 13 files changed, 251 insertions(+), 263 deletions(-) create mode 100644 src/mongo/db/initialize_operation_session_info.cpp create mode 100644 src/mongo/db/initialize_operation_session_info.h delete mode 100644 src/mongo/db/session/initialize_operation_session_info.cpp delete mode 100644 src/mongo/db/session/initialize_operation_session_info.h (limited to 'src') diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 58a090cdced..d0e8b323673 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -875,12 +875,15 @@ env.Library( 's/transaction_coordinator_curop.cpp', 's/transaction_coordinator_factory.cpp', 's/transaction_coordinator_worker_curop_repository.cpp', + 'transaction_resources.cpp', ], LIBDEPS=[ '$BUILD_DIR/mongo/s/grid', 'concurrency/lock_manager', 'index/index_access_method', + 'rw_concern_d', 'shard_role_api_stor_ex', + 'views/views', ], LIBDEPS_PRIVATE=[ 'server_base', @@ -891,13 +894,12 @@ env.Library( env.Library( target='shard_role', source=[ - 'catalog_raii.cpp', 'catalog/catalog_helper.cpp', 'catalog/collection_uuid_mismatch.cpp', 'catalog/collection_yield_restore.cpp', + 'catalog_raii.cpp', 'db_raii.cpp', 'shard_role.cpp', - 'transaction_resources.cpp', ], LIBDEPS=[ 'catalog/collection_catalog', @@ -905,7 +907,6 @@ env.Library( 'shard_role_api', 'stats/top', 'storage/write_unit_of_work', - 'views/views', ], LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/catalog/collection_uuid_mismatch_info', @@ -1830,23 +1831,24 @@ env.Library( 'error_labels.cpp', ], LIBDEPS=[ - '$BUILD_DIR/mongo/db/pipeline/lite_parsed_document_source', - '$BUILD_DIR/mongo/db/query/op_metrics', - '$BUILD_DIR/mongo/db/session/logical_session_id', 'commands', + 'pipeline/lite_parsed_document_source', + 'query/op_metrics', + 'session/logical_session_id', ], ) env.Library( target='shared_request_handling', source=[ + 'initialize_operation_session_info.cpp', 'transaction_validation.cpp', ], LIBDEPS=[ - '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface', 'api_parameters', 'error_labels', - 'session/logical_session_cache_impl', + 'repl/repl_coordinator_interface', + 'session/logical_session_cache', ], ) @@ -2271,11 +2273,11 @@ env.Library( ) env.Library( - target="mongod_initializers", + target='mongod_initializers', source=[ # NOTE: If you add an additional source file here, please delete # the file db/mongod_initializers.cpp. - "mongod_initializers.cpp", + 'mongod_initializers.cpp', ], LIBDEPS_PRIVATE=[ # NOTE: If you need to add a static or mongo initializer to mongod startup, @@ -2357,7 +2359,6 @@ env.Library( 'serverless/shard_split_commands', 'service_liaison_mongod', 'session/kill_sessions_local', - 'session/logical_session_cache_impl', 'session/sessions_collection_rs', 'session/sessions_collection_standalone', 'shard_role', @@ -2413,6 +2414,7 @@ env.Library( '$BUILD_DIR/mongo/db/pipeline/change_stream_expired_pre_image_remover', '$BUILD_DIR/mongo/db/query/stats/query_stats', '$BUILD_DIR/mongo/db/s/query_analysis_writer', + '$BUILD_DIR/mongo/db/session/logical_session_cache_impl', '$BUILD_DIR/mongo/db/set_change_stream_state_coordinator', '$BUILD_DIR/mongo/idl/cluster_server_parameter', '$BUILD_DIR/mongo/idl/cluster_server_parameter_initializer', @@ -2691,9 +2693,7 @@ if wiredtiger: '$BUILD_DIR/mongo/db/repl/storage_interface_impl', '$BUILD_DIR/mongo/db/repl/tenant_migration_access_blocker', '$BUILD_DIR/mongo/db/s/shard_server_test_fixture', - '$BUILD_DIR/mongo/db/session/logical_session_cache', '$BUILD_DIR/mongo/db/session/logical_session_cache_impl', - '$BUILD_DIR/mongo/db/session/logical_session_id', '$BUILD_DIR/mongo/db/session/logical_session_id_helpers', '$BUILD_DIR/mongo/db/session/session_catalog', '$BUILD_DIR/mongo/db/session/session_catalog_mongod', diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript index 78933f289ea..a1b52019334 100644 --- a/src/mongo/db/commands/SConscript +++ b/src/mongo/db/commands/SConscript @@ -84,8 +84,6 @@ env.Library( '$BUILD_DIR/mongo/db/server_base', '$BUILD_DIR/mongo/db/session/kill_sessions', '$BUILD_DIR/mongo/db/session/logical_session_cache', - '$BUILD_DIR/mongo/db/session/logical_session_cache_impl', - '$BUILD_DIR/mongo/db/session/logical_session_id', '$BUILD_DIR/mongo/db/session/logical_session_id_helpers', '$BUILD_DIR/mongo/db/stats/counters', '$BUILD_DIR/mongo/db/transaction/transaction_api', @@ -136,8 +134,7 @@ env.Library( '$BUILD_DIR/mongo/db/repl/isself', '$BUILD_DIR/mongo/db/repl/repl_coordinator_interface', '$BUILD_DIR/mongo/db/server_base', - '$BUILD_DIR/mongo/db/session/logical_session_cache_impl', - '$BUILD_DIR/mongo/db/session/logical_session_id', + '$BUILD_DIR/mongo/db/session/logical_session_cache', '$BUILD_DIR/mongo/db/session/logical_session_id_helpers', '$BUILD_DIR/mongo/db/session/session_catalog', '$BUILD_DIR/mongo/db/shared_request_handling', diff --git a/src/mongo/db/initialize_operation_session_info.cpp b/src/mongo/db/initialize_operation_session_info.cpp new file mode 100644 index 00000000000..9ed86b4475d --- /dev/null +++ b/src/mongo/db/initialize_operation_session_info.cpp @@ -0,0 +1,170 @@ +/** + * Copyright (C) 2018-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. + */ + +#include "mongo/db/initialize_operation_session_info.h" + +#include "mongo/db/auth/authorization_session.h" +#include "mongo/db/operation_context.h" +#include "mongo/db/session/logical_session_cache.h" +#include "mongo/db/session/logical_session_id_helpers.h" + +namespace mongo { + +OperationSessionInfoFromClient initializeOperationSessionInfo(OperationContext* opCtx, + const BSONObj& requestBody, + bool requiresAuth, + bool attachToOpCtx, + bool isReplSetMemberOrMongos) { + auto osi = OperationSessionInfoFromClient::parse(IDLParserContext{"OperationSessionInfo"}, + requestBody); + auto isAuthorizedForInternalClusterAction = + AuthorizationSession::get(opCtx->getClient()) + ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(), + ActionType::internal); + + if (opCtx->getClient()->isInDirectClient()) { + uassert(50891, + "Invalid to set operation session info in a direct client", + !osi.getSessionId() && !osi.getTxnNumber() && !osi.getAutocommit() && + !osi.getStartTransaction()); + } + + if (!requiresAuth) { + uassert(ErrorCodes::OperationNotSupportedInTransaction, + "This command is not supported in transactions", + !osi.getAutocommit()); + uassert( + 50889, "It is illegal to provide a txnNumber for this command", !osi.getTxnNumber()); + } + + if (auto authSession = AuthorizationSession::get(opCtx->getClient())) { + // If we're using the localhost bypass, and the client hasn't authenticated, + // logical sessions are disabled. A client may authenticate as the __sytem user, + // or as an externally authorized user. + if (authSession->isUsingLocalhostBypass() && !authSession->isAuthenticated()) { + return {}; + } + + // Do not initialize lsid when auth is enabled and no user is logged in since + // there is no sensible uid that can be assigned to it. + if (AuthorizationManager::get(opCtx->getServiceContext())->isAuthEnabled() && + !authSession->isAuthenticated() && !requiresAuth) { + return {}; + } + } + + if (osi.getSessionId()) { + stdx::lock_guard lk(*opCtx->getClient()); + + auto lsc = LogicalSessionCache::get(opCtx->getServiceContext()); + if (!lsc) { + // Ignore session information if the logical session cache has not been set up, e.g. on + // the embedded version of mongod. + return {}; + } + + // If osi lsid includes the uid, makeLogicalSessionId will also verify that the hash + // matches with the current user logged in. + auto lsid = makeLogicalSessionId(osi.getSessionId().value(), opCtx); + + if (!attachToOpCtx) { + return {}; + } + + if (isChildSession(lsid)) { + uassert(ErrorCodes::InvalidOptions, + "Internal sessions are only allowed for internal clients", + isAuthorizedForInternalClusterAction); + uassert(ErrorCodes::InvalidOptions, + "Internal sessions are not supported outside of transactions", + osi.getTxnNumber() && osi.getAutocommit() && !osi.getAutocommit().value()); + } + + opCtx->setLogicalSessionId(std::move(lsid)); + uassertStatusOK(lsc->vivify(opCtx, opCtx->getLogicalSessionId().value())); + } else { + uassert(ErrorCodes::InvalidOptions, + "Transaction number requires a session ID to also be specified", + !osi.getTxnNumber()); + } + + if (osi.getTxnNumber()) { + invariant(osi.getSessionId()); + stdx::lock_guard lk(*opCtx->getClient()); + + uassert(ErrorCodes::IllegalOperation, + "Transaction numbers are only allowed on a replica set member or mongos", + isReplSetMemberOrMongos); + uassert(ErrorCodes::InvalidOptions, + "Transaction number cannot be negative", + *osi.getTxnNumber() >= 0); + + opCtx->setTxnNumber(*osi.getTxnNumber()); + + if (auto txnRetryCounter = osi.getTxnRetryCounter()) { + uassert(ErrorCodes::InvalidOptions, + "txnRetryCounter is only allowed for internal clients", + isAuthorizedForInternalClusterAction); + uassert(ErrorCodes::InvalidOptions, + str::stream() << "Cannot specify txnRetryCounter for a retryable write", + osi.getAutocommit().has_value()); + uassert(ErrorCodes::InvalidOptions, + "txnRetryCounter cannot be negative", + txnRetryCounter >= 0); + opCtx->setTxnRetryCounter(*txnRetryCounter); + } + } else { + uassert(ErrorCodes::InvalidOptions, + "'autocommit' field requires a transaction number to also be specified", + !osi.getAutocommit()); + } + + if (osi.getAutocommit()) { + invariant(osi.getTxnNumber()); + uassert(ErrorCodes::InvalidOptions, + "Specifying autocommit=true is not allowed.", + !osi.getAutocommit().value()); + opCtx->setInMultiDocumentTransaction(); + } else { + uassert(ErrorCodes::InvalidOptions, + "'startTransaction' field requires 'autocommit' field to also be specified", + !osi.getStartTransaction()); + } + + if (osi.getStartTransaction()) { + invariant(osi.getAutocommit()); + uassert(ErrorCodes::InvalidOptions, + "Specifying startTransaction=false is not allowed.", + osi.getStartTransaction().value()); + } + + return osi; +} + +} // namespace mongo diff --git a/src/mongo/db/initialize_operation_session_info.h b/src/mongo/db/initialize_operation_session_info.h new file mode 100644 index 00000000000..b2c1fcde67d --- /dev/null +++ b/src/mongo/db/initialize_operation_session_info.h @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2018-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 + +#include "mongo/db/session/logical_session_id.h" + +namespace mongo { + +/** + * Parses the session information from the body of a request and stores the sessionId and txnNumber + * on the current operation context. Must only be called once per operation and should be done right + * in the beginning. Note that the session info will be stored in the operation context and returned + * only if the current request supports it. For example, if attachToOpCtx is false or this is called + * within the context of DBDirectClient. + * + * Throws if the sessionId/txnNumber combination is not properly formatted. + * + * requiresAuth specifies if the command we're initializing operationSessionInfo for requires + * authorization or not. This can be determined by invoking ->requiresAuth() on the parsed command. + * If it does not require authorization, return boost::none. + * + * isReplSetMemberOrMongos needs to be true if the command contains a transaction number, otherwise + * this function will throw. + */ +OperationSessionInfoFromClient initializeOperationSessionInfo(OperationContext* opCtx, + const BSONObj& requestBody, + bool requiresAuth, + bool attachToOpCtx, + bool isReplSetMemberOrMongos); + +} // namespace mongo 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 09bbd62441b..28987a18a9d 100644 --- a/src/mongo/db/s/session_catalog_migration_destination_test.cpp +++ b/src/mongo/db/s/session_catalog_migration_destination_test.cpp @@ -36,6 +36,7 @@ #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" +#include "mongo/db/initialize_operation_session_info.h" #include "mongo/db/ops/write_ops_exec.h" #include "mongo/db/ops/write_ops_gen.h" #include "mongo/db/repl/oplog_entry.h" @@ -47,7 +48,6 @@ #include "mongo/db/s/shard_server_test_fixture.h" #include "mongo/db/s/sharding_statistics.h" #include "mongo/db/server_options.h" -#include "mongo/db/session/initialize_operation_session_info.h" #include "mongo/db/session/logical_session_cache_noop.h" #include "mongo/db/session/logical_session_id.h" #include "mongo/db/session/session_catalog_mongod.h" diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index a23da80ed18..11a859255fb 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -54,6 +54,7 @@ #include "mongo/db/dbdirectclient.h" #include "mongo/db/error_labels.h" #include "mongo/db/initialize_api_parameters.h" +#include "mongo/db/initialize_operation_session_info.h" #include "mongo/db/introspect.h" #include "mongo/db/jsobj.h" #include "mongo/db/logical_time_validator.h" @@ -81,8 +82,6 @@ #include "mongo/db/s/transaction_coordinator_factory.h" #include "mongo/db/server_feature_flags_gen.h" #include "mongo/db/service_entry_point_common.h" -#include "mongo/db/session/initialize_operation_session_info.h" -#include "mongo/db/session/logical_session_id.h" #include "mongo/db/session/logical_session_id_helpers.h" #include "mongo/db/session/session_catalog_mongod.h" #include "mongo/db/stats/api_version_metrics.h" diff --git a/src/mongo/db/session/SConscript b/src/mongo/db/session/SConscript index 8e7d243c93b..858ac084f1f 100644 --- a/src/mongo/db/session/SConscript +++ b/src/mongo/db/session/SConscript @@ -122,7 +122,6 @@ env.Library( env.Library( target='logical_session_cache_impl', source=[ - 'initialize_operation_session_info.cpp', 'logical_session_cache_impl.cpp', ], LIBDEPS=[ diff --git a/src/mongo/db/session/initialize_operation_session_info.cpp b/src/mongo/db/session/initialize_operation_session_info.cpp deleted file mode 100644 index 523534b0bc6..00000000000 --- a/src/mongo/db/session/initialize_operation_session_info.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/** - * Copyright (C) 2018-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. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/db/session/initialize_operation_session_info.h" - -#include "mongo/db/auth/authorization_session.h" -#include "mongo/db/operation_context.h" -#include "mongo/db/session/logical_session_cache.h" -#include "mongo/db/session/logical_session_id_helpers.h" - -namespace mongo { - -OperationSessionInfoFromClient initializeOperationSessionInfo(OperationContext* opCtx, - const BSONObj& requestBody, - bool requiresAuth, - bool attachToOpCtx, - bool isReplSetMemberOrMongos) { - auto osi = OperationSessionInfoFromClient::parse(IDLParserContext{"OperationSessionInfo"}, - requestBody); - auto isAuthorizedForInternalClusterAction = - AuthorizationSession::get(opCtx->getClient()) - ->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(), - ActionType::internal); - - if (opCtx->getClient()->isInDirectClient()) { - uassert(50891, - "Invalid to set operation session info in a direct client", - !osi.getSessionId() && !osi.getTxnNumber() && !osi.getAutocommit() && - !osi.getStartTransaction()); - } - - if (!requiresAuth) { - uassert(ErrorCodes::OperationNotSupportedInTransaction, - "This command is not supported in transactions", - !osi.getAutocommit()); - uassert( - 50889, "It is illegal to provide a txnNumber for this command", !osi.getTxnNumber()); - } - - if (auto authSession = AuthorizationSession::get(opCtx->getClient())) { - // If we're using the localhost bypass, and the client hasn't authenticated, - // logical sessions are disabled. A client may authenticate as the __sytem user, - // or as an externally authorized user. - if (authSession->isUsingLocalhostBypass() && !authSession->isAuthenticated()) { - return {}; - } - - // Do not initialize lsid when auth is enabled and no user is logged in since - // there is no sensible uid that can be assigned to it. - if (AuthorizationManager::get(opCtx->getServiceContext())->isAuthEnabled() && - !authSession->isAuthenticated() && !requiresAuth) { - return {}; - } - } - - if (osi.getSessionId()) { - stdx::lock_guard lk(*opCtx->getClient()); - - auto lsc = LogicalSessionCache::get(opCtx->getServiceContext()); - if (!lsc) { - // Ignore session information if the logical session cache has not been set up, e.g. on - // the embedded version of mongod. - return {}; - } - - // If osi lsid includes the uid, makeLogicalSessionId will also verify that the hash - // matches with the current user logged in. - auto lsid = makeLogicalSessionId(osi.getSessionId().value(), opCtx); - - if (!attachToOpCtx) { - return {}; - } - - if (isChildSession(lsid)) { - uassert(ErrorCodes::InvalidOptions, - "Internal sessions are only allowed for internal clients", - isAuthorizedForInternalClusterAction); - uassert(ErrorCodes::InvalidOptions, - "Internal sessions are not supported outside of transactions", - osi.getTxnNumber() && osi.getAutocommit() && !osi.getAutocommit().value()); - } - - opCtx->setLogicalSessionId(std::move(lsid)); - uassertStatusOK(lsc->vivify(opCtx, opCtx->getLogicalSessionId().value())); - } else { - uassert(ErrorCodes::InvalidOptions, - "Transaction number requires a session ID to also be specified", - !osi.getTxnNumber()); - } - - if (osi.getTxnNumber()) { - invariant(osi.getSessionId()); - stdx::lock_guard lk(*opCtx->getClient()); - - uassert(ErrorCodes::IllegalOperation, - "Transaction numbers are only allowed on a replica set member or mongos", - isReplSetMemberOrMongos); - uassert(ErrorCodes::InvalidOptions, - "Transaction number cannot be negative", - *osi.getTxnNumber() >= 0); - - opCtx->setTxnNumber(*osi.getTxnNumber()); - - if (auto txnRetryCounter = osi.getTxnRetryCounter()) { - uassert(ErrorCodes::InvalidOptions, - "txnRetryCounter is only allowed for internal clients", - isAuthorizedForInternalClusterAction); - uassert(ErrorCodes::InvalidOptions, - str::stream() << "Cannot specify txnRetryCounter for a retryable write", - osi.getAutocommit().has_value()); - uassert(ErrorCodes::InvalidOptions, - "txnRetryCounter cannot be negative", - txnRetryCounter >= 0); - opCtx->setTxnRetryCounter(*txnRetryCounter); - } - } else { - uassert(ErrorCodes::InvalidOptions, - "'autocommit' field requires a transaction number to also be specified", - !osi.getAutocommit()); - } - - if (osi.getAutocommit()) { - invariant(osi.getTxnNumber()); - uassert(ErrorCodes::InvalidOptions, - "Specifying autocommit=true is not allowed.", - !osi.getAutocommit().value()); - opCtx->setInMultiDocumentTransaction(); - } else { - uassert(ErrorCodes::InvalidOptions, - "'startTransaction' field requires 'autocommit' field to also be specified", - !osi.getStartTransaction()); - } - - if (osi.getStartTransaction()) { - invariant(osi.getAutocommit()); - uassert(ErrorCodes::InvalidOptions, - "Specifying startTransaction=false is not allowed.", - osi.getStartTransaction().value()); - } - - return osi; -} - -} // namespace mongo diff --git a/src/mongo/db/session/initialize_operation_session_info.h b/src/mongo/db/session/initialize_operation_session_info.h deleted file mode 100644 index b2c1fcde67d..00000000000 --- a/src/mongo/db/session/initialize_operation_session_info.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (C) 2018-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 - -#include "mongo/db/session/logical_session_id.h" - -namespace mongo { - -/** - * Parses the session information from the body of a request and stores the sessionId and txnNumber - * on the current operation context. Must only be called once per operation and should be done right - * in the beginning. Note that the session info will be stored in the operation context and returned - * only if the current request supports it. For example, if attachToOpCtx is false or this is called - * within the context of DBDirectClient. - * - * Throws if the sessionId/txnNumber combination is not properly formatted. - * - * requiresAuth specifies if the command we're initializing operationSessionInfo for requires - * authorization or not. This can be determined by invoking ->requiresAuth() on the parsed command. - * If it does not require authorization, return boost::none. - * - * isReplSetMemberOrMongos needs to be true if the command contains a transaction number, otherwise - * this function will throw. - */ -OperationSessionInfoFromClient initializeOperationSessionInfo(OperationContext* opCtx, - const BSONObj& requestBody, - bool requiresAuth, - bool attachToOpCtx, - bool isReplSetMemberOrMongos); - -} // namespace mongo diff --git a/src/mongo/db/session/logical_session_id_test.cpp b/src/mongo/db/session/logical_session_id_test.cpp index f66be646367..f64d5fe2266 100644 --- a/src/mongo/db/session/logical_session_id_test.cpp +++ b/src/mongo/db/session/logical_session_id_test.cpp @@ -27,12 +27,8 @@ * it in the license file. */ -#include "mongo/platform/basic.h" - #include -#include "mongo/db/session/logical_session_id.h" - #include "mongo/crypto/mechanism_scram.h" #include "mongo/crypto/sha1_block.h" #include "mongo/crypto/sha256_block.h" @@ -45,13 +41,12 @@ #include "mongo/db/auth/authz_session_external_state_mock.h" #include "mongo/db/auth/sasl_options.h" #include "mongo/db/auth/user.h" +#include "mongo/db/initialize_operation_session_info.h" #include "mongo/db/jsobj.h" #include "mongo/db/operation_context.h" #include "mongo/db/service_context.h" #include "mongo/db/service_context_test_fixture.h" #include "mongo/db/service_liaison_mock.h" -#include "mongo/db/session/initialize_operation_session_info.h" -#include "mongo/db/session/logical_session_cache.h" #include "mongo/db/session/logical_session_cache_impl.h" #include "mongo/db/session/logical_session_id_helpers.h" #include "mongo/db/session/sessions_collection_mock.h" diff --git a/src/mongo/embedded/SConscript b/src/mongo/embedded/SConscript index df799736c3b..e09e48bccd1 100644 --- a/src/mongo/embedded/SConscript +++ b/src/mongo/embedded/SConscript @@ -101,7 +101,6 @@ env.Library( '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/service_entry_point_common', '$BUILD_DIR/mongo/db/service_liaison_mongod', - '$BUILD_DIR/mongo/db/session/logical_session_cache', '$BUILD_DIR/mongo/db/session/logical_session_cache_impl', '$BUILD_DIR/mongo/db/session/sessions_collection_standalone', '$BUILD_DIR/mongo/db/startup_recovery', diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index 2ef620fa6eb..cc3596046fd 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -410,9 +410,11 @@ env.Library( source=[ 'sessions_collection_sharded.cpp', ], - LIBDEPS_PRIVATE=[ - '$BUILD_DIR/mongo/db/session/logical_session_id', + LIBDEPS=[ '$BUILD_DIR/mongo/db/session/sessions_collection', + ], + LIBDEPS_PRIVATE=[ + '$BUILD_DIR/mongo/db/server_base', 'sharding_api', ], ) @@ -472,8 +474,6 @@ env.Library( '$BUILD_DIR/mongo/db/server_options', '$BUILD_DIR/mongo/db/server_options_base', '$BUILD_DIR/mongo/db/service_liaison_mongos', - '$BUILD_DIR/mongo/db/session/logical_session_cache', - '$BUILD_DIR/mongo/db/session/logical_session_cache_impl', '$BUILD_DIR/mongo/db/session/session_catalog', '$BUILD_DIR/mongo/db/startup_warnings_common', '$BUILD_DIR/mongo/db/stats/counters', @@ -540,6 +540,7 @@ env.Library( '$BUILD_DIR/mongo/db/read_write_concern_defaults', '$BUILD_DIR/mongo/db/serverinit', '$BUILD_DIR/mongo/db/service_liaison_mongos', + '$BUILD_DIR/mongo/db/session/logical_session_cache_impl', '$BUILD_DIR/mongo/db/session/session_catalog', '$BUILD_DIR/mongo/db/startup_warnings_common', '$BUILD_DIR/mongo/idl/cluster_server_parameter_refresher', diff --git a/src/mongo/s/commands/strategy.cpp b/src/mongo/s/commands/strategy.cpp index 5534cc42dca..5d7b80d0cda 100644 --- a/src/mongo/s/commands/strategy.cpp +++ b/src/mongo/s/commands/strategy.cpp @@ -47,6 +47,7 @@ #include "mongo/db/curop.h" #include "mongo/db/error_labels.h" #include "mongo/db/initialize_api_parameters.h" +#include "mongo/db/initialize_operation_session_info.h" #include "mongo/db/logical_time_validator.h" #include "mongo/db/matcher/extensions_callback_noop.h" #include "mongo/db/namespace_string.h" @@ -58,7 +59,6 @@ #include "mongo/db/query/query_request_helper.h" #include "mongo/db/read_write_concern_defaults.h" #include "mongo/db/repl/repl_server_parameters_gen.h" -#include "mongo/db/session/initialize_operation_session_info.h" #include "mongo/db/session/logical_session_id_helpers.h" #include "mongo/db/stats/api_version_metrics.h" #include "mongo/db/stats/counters.h" -- cgit v1.2.1