diff options
author | Henrik Edin <henrik.edin@mongodb.com> | 2018-09-19 15:01:04 -0400 |
---|---|---|
committer | Henrik Edin <henrik.edin@mongodb.com> | 2018-09-26 09:46:29 -0400 |
commit | 29ed53c6e1880b89adacdb292227dec57fb78fdc (patch) | |
tree | 7cbf32bd7aec50b1f6eaf950d6fa5b27054a194a | |
parent | aa952ac3b0d54d651f1cd8f618baee4fe0e10efa (diff) | |
download | mongo-29ed53c6e1880b89adacdb292227dec57fb78fdc.tar.gz |
SERVER-36084 Remove sharding runtime from ServiceEntryPointCommon and embedded build
-rw-r--r-- | src/mongo/db/SConscript | 8 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_state_factory_embedded.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/s/scoped_operation_completion_sharding_actions.h | 3 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_common.cpp | 50 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_common.h | 10 | ||||
-rw-r--r-- | src/mongo/db/service_entry_point_mongod.cpp | 41 | ||||
-rw-r--r-- | src/mongo/embedded/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/embedded/service_entry_point_embedded.cpp | 11 | ||||
-rw-r--r-- | src/mongo/platform/compiler.h | 7 | ||||
-rw-r--r-- | src/mongo/platform/compiler_gcc.h | 3 | ||||
-rw-r--r-- | src/mongo/platform/compiler_msvc.h | 1 | ||||
-rw-r--r-- | src/mongo/util/polymorphic_scoped.h | 40 |
12 files changed, 132 insertions, 63 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index 3258448fe23..24954cd9fd7 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -750,6 +750,7 @@ env.Library( '$BUILD_DIR/mongo/db/auth/auth', '$BUILD_DIR/mongo/db/concurrency/lock_manager', '$BUILD_DIR/mongo/db/ops/write_ops_parsers', + '$BUILD_DIR/mongo/db/s/sharding_runtime_d', '$BUILD_DIR/mongo/db/storage/storage_engine_common', '$BUILD_DIR/mongo/db/storage/storage_options', '$BUILD_DIR/mongo/db/storage/storage_engine_lock_file', @@ -806,14 +807,19 @@ env.Library( ], LIBDEPS_PRIVATE=[ 'handle_request_response', + 'introspect', + 'lasterror', + 'query_exec', 'snapshot_window_util', + '$BUILD_DIR/mongo/db/audit', '$BUILD_DIR/mongo/db/auth/auth', '$BUILD_DIR/mongo/db/auth/authprivilege', '$BUILD_DIR/mongo/db/command_can_run_here', '$BUILD_DIR/mongo/db/ops/write_ops_exec', '$BUILD_DIR/mongo/db/rw_concern_d', - '$BUILD_DIR/mongo/db/s/sharding_runtime_d', + '$BUILD_DIR/mongo/db/s/sharding_api_d', '$BUILD_DIR/mongo/db/stats/counters', + '$BUILD_DIR/mongo/db/stats/top', '$BUILD_DIR/mongo/db/storage/storage_engine_lock_file', '$BUILD_DIR/mongo/db/storage/storage_engine_metadata', ], diff --git a/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp b/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp index afd03a16e1f..1660633244e 100644 --- a/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp +++ b/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp @@ -36,20 +36,6 @@ namespace mongo { namespace { -class UnshardedCollection : public ScopedCollectionMetadata::Impl { -public: - UnshardedCollection() = default; - - const CollectionMetadata& get() override { - return _metadata; - } - -private: - CollectionMetadata _metadata; -}; - -const auto kUnshardedCollection = std::make_shared<UnshardedCollection>(); - class CollectionShardingStateFactoryEmbedded final : public CollectionShardingStateFactory { public: CollectionShardingStateFactoryEmbedded(ServiceContext* serviceContext) @@ -61,8 +47,9 @@ public: CollectionShardingStateStandalone(NamespaceString nss) : CollectionShardingState(nss) {} private: - ScopedCollectionMetadata _getMetadata(OperationContext* opCtx) override { - return {kUnshardedCollection}; + boost::optional<ScopedCollectionMetadata> _getMetadata( + const boost::optional<mongo::LogicalTime>& atClusterTime) override { + return boost::none; } }; diff --git a/src/mongo/db/s/scoped_operation_completion_sharding_actions.h b/src/mongo/db/s/scoped_operation_completion_sharding_actions.h index 5d861520454..353f8f1d21c 100644 --- a/src/mongo/db/s/scoped_operation_completion_sharding_actions.h +++ b/src/mongo/db/s/scoped_operation_completion_sharding_actions.h @@ -29,6 +29,7 @@ #pragma once #include "mongo/base/disallow_copying.h" +#include "mongo/util/polymorphic_scoped.h" namespace mongo { @@ -39,7 +40,7 @@ namespace mongo { */ class OperationContext; -class ScopedOperationCompletionShardingActions { +class ScopedOperationCompletionShardingActions : public PolymorphicScoped { MONGO_DISALLOW_COPYING(ScopedOperationCompletionShardingActions); public: diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index 75d7f8b3071..8043df51d68 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -65,12 +65,8 @@ #include "mongo/db/repl/read_concern_args.h" #include "mongo/db/repl/repl_client_info.h" #include "mongo/db/repl/replication_coordinator.h" -#include "mongo/db/s/implicit_create_collection.h" #include "mongo/db/s/operation_sharding_state.h" -#include "mongo/db/s/scoped_operation_completion_sharding_actions.h" -#include "mongo/db/s/shard_filtering_metadata_refresh.h" #include "mongo/db/s/sharded_connection_info.h" -#include "mongo/db/s/sharding_config_optime_gossip.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/service_entry_point_common.h" #include "mongo/db/snapshot_window_util.h" @@ -89,9 +85,7 @@ #include "mongo/rpc/metadata/tracking_metadata.h" #include "mongo/rpc/op_msg.h" #include "mongo/rpc/reply_builder_interface.h" -#include "mongo/s/cannot_implicitly_create_collection_info.h" #include "mongo/s/grid.h" -#include "mongo/s/stale_exception.h" #include "mongo/util/fail_point_service.h" #include "mongo/util/log.h" #include "mongo/util/scopeguard.h" @@ -839,12 +833,11 @@ void execCommandDatabase(OperationContext* opCtx, uassertStatusOK(shardingState->canAcceptShardedCommands()); } - // Handle config optime information that may have been sent along with the command. - rpc::advanceConfigOptimeFromRequestMetadata(opCtx); + behaviors.advanceConfigOptimeFromRequestMetadata(opCtx); } oss.setAllowImplicitCollectionCreation(allowImplicitCollectionCreationField); - ScopedOperationCompletionShardingActions operationCompletionShardingActions(opCtx); + auto scoped = behaviors.scopedOperationCompletionShardingActions(opCtx); // This may trigger the maxTimeAlwaysTimeOut failpoint. auto status = opCtx->checkForInterruptNoAssert(); @@ -891,27 +884,7 @@ void execCommandDatabase(OperationContext* opCtx, throw; } } catch (const DBException& e) { - // If we got a stale config, wait in case the operation is stuck in a critical section - if (auto sce = e.extraInfo<StaleConfigInfo>()) { - if (!opCtx->getClient()->isInDirectClient()) { - // We already have the StaleConfig exception, so just swallow any errors due to - // refresh - onShardVersionMismatchNoExcept(opCtx, sce->getNss(), sce->getVersionReceived()) - .ignore(); - } - } else if (auto sce = e.extraInfo<StaleDbRoutingVersion>()) { - if (!opCtx->getClient()->isInDirectClient()) { - onDbVersionMismatchNoExcept( - opCtx, sce->getDb(), sce->getVersionReceived(), sce->getVersionWanted()) - .ignore(); - } - } else if (auto cannotImplicitCreateCollInfo = - e.extraInfo<CannotImplicitlyCreateCollectionInfo>()) { - if (ShardingState::get(opCtx)->enabled()) { - onCannotImplicitlyCreateCollection(opCtx, cannotImplicitCreateCollInfo->getNss()) - .ignore(); - } - } else if (e.code() == ErrorCodes::SnapshotTooOld) { + if (e.code() == ErrorCodes::SnapshotTooOld) { // SnapshotTooOld errors indicate that PIT ops are failing to find an available snapshot // at their specified atClusterTime. Therefore, we'll try to increase the snapshot // history window that the storage engine maintains in order to increase the likelihood @@ -920,6 +893,8 @@ void execCommandDatabase(OperationContext* opCtx, if (engine && engine->supportsReadConcernSnapshot()) { SnapshotWindowUtil::increaseTargetSnapshotWindowSize(opCtx); } + } else { + behaviors.handleException(e, opCtx); } // Append the error labels for transient transaction errors. @@ -1059,7 +1034,8 @@ DbResponse receivedCommands(OperationContext* opCtx, DbResponse receivedQuery(OperationContext* opCtx, const NamespaceString& nss, Client& c, - const Message& m) { + const Message& m, + const ServiceEntryPointCommon::Hooks& behaviors) { invariant(!nss.isCommand()); globalOpCounters.gotQuery(); @@ -1077,15 +1053,7 @@ DbResponse receivedQuery(OperationContext* opCtx, dbResponse.exhaustNS = runQuery(opCtx, q, nss, dbResponse.response); } catch (const AssertionException& e) { - // If we got a stale config, wait in case the operation is stuck in a critical section - if (auto sce = e.extraInfo<StaleConfigInfo>()) { - if (!opCtx->getClient()->isInDirectClient()) { - // We already have the StaleConfig exception, so just swallow any errors due to - // refresh - onShardVersionMismatchNoExcept(opCtx, sce->getNss(), sce->getVersionReceived()) - .ignore(); - } - } + behaviors.handleException(e, opCtx); dbResponse.response.reset(); generateLegacyQueryErrorResponse(e, q, &op, &dbResponse.response); @@ -1316,7 +1284,7 @@ DbResponse ServiceEntryPointCommon::handleRequest(OperationContext* opCtx, dbresponse = receivedCommands(opCtx, m, behaviors); } else if (op == dbQuery) { invariant(!isCommand); - dbresponse = receivedQuery(opCtx, nsString, c, m); + dbresponse = receivedQuery(opCtx, nsString, c, m, behaviors); } else if (op == dbGetMore) { dbresponse = receivedGetMore(opCtx, m, currentOp, &forceLog); } else { diff --git a/src/mongo/db/service_entry_point_common.h b/src/mongo/db/service_entry_point_common.h index 1ec084d18b4..42162774baf 100644 --- a/src/mongo/db/service_entry_point_common.h +++ b/src/mongo/db/service_entry_point_common.h @@ -28,14 +28,13 @@ #pragma once -#include "mongo/transport/service_entry_point_impl.h" - #include "mongo/base/status.h" #include "mongo/db/commands.h" #include "mongo/db/dbmessage.h" #include "mongo/db/operation_context.h" #include "mongo/rpc/message.h" #include "mongo/util/fail_point_service.h" +#include "mongo/util/polymorphic_scoped.h" namespace mongo { @@ -72,6 +71,13 @@ struct ServiceEntryPointCommon { virtual void uassertCommandDoesNotSpecifyWriteConcern(const BSONObj& cmdObj) const = 0; virtual void attachCurOpErrInfo(OperationContext* opCtx, const BSONObj& replyObj) const = 0; + + virtual void handleException(const DBException& e, OperationContext* opCtx) const = 0; + + virtual void advanceConfigOptimeFromRequestMetadata(OperationContext* opCtx) const = 0; + + MONGO_WARN_UNUSED_RESULT_FUNCTION virtual std::unique_ptr<PolymorphicScoped> + scopedOperationCompletionShardingActions(OperationContext* opCtx) const = 0; }; static DbResponse handleRequest(OperationContext* opCtx, const Message& m, const Hooks& hooks); diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp index 488bdcba0bc..c0281fe7460 100644 --- a/src/mongo/db/service_entry_point_mongod.cpp +++ b/src/mongo/db/service_entry_point_mongod.cpp @@ -37,9 +37,16 @@ #include "mongo/db/curop.h" #include "mongo/db/read_concern.h" #include "mongo/db/repl/repl_client_info.h" +#include "mongo/db/s/implicit_create_collection.h" +#include "mongo/db/s/scoped_operation_completion_sharding_actions.h" +#include "mongo/db/s/shard_filtering_metadata_refresh.h" +#include "mongo/db/s/sharding_config_optime_gossip.h" +#include "mongo/db/s/sharding_state.h" #include "mongo/db/service_entry_point_common.h" #include "mongo/logger/redaction.h" #include "mongo/rpc/get_status_from_command_result.h" +#include "mongo/s/cannot_implicitly_create_collection_info.h" +#include "mongo/s/stale_exception.h" #include "mongo/util/log.h" namespace mongo { @@ -117,6 +124,40 @@ public: void attachCurOpErrInfo(OperationContext* opCtx, const BSONObj& replyObj) const override { CurOp::get(opCtx)->debug().errInfo = getStatusFromCommandResult(replyObj); } + + void handleException(const DBException& e, OperationContext* opCtx) const override { + // If we got a stale config, wait in case the operation is stuck in a critical section + if (auto sce = e.extraInfo<StaleConfigInfo>()) { + if (!opCtx->getClient()->isInDirectClient()) { + // We already have the StaleConfig exception, so just swallow any errors due to + // refresh + onShardVersionMismatchNoExcept(opCtx, sce->getNss(), sce->getVersionReceived()) + .ignore(); + } + } else if (auto sce = e.extraInfo<StaleDbRoutingVersion>()) { + if (!opCtx->getClient()->isInDirectClient()) { + onDbVersionMismatchNoExcept( + opCtx, sce->getDb(), sce->getVersionReceived(), sce->getVersionWanted()) + .ignore(); + } + } else if (auto cannotImplicitCreateCollInfo = + e.extraInfo<CannotImplicitlyCreateCollectionInfo>()) { + if (ShardingState::get(opCtx)->enabled()) { + onCannotImplicitlyCreateCollection(opCtx, cannotImplicitCreateCollInfo->getNss()) + .ignore(); + } + } + } + + void advanceConfigOptimeFromRequestMetadata(OperationContext* opCtx) const override { + // Handle config optime information that may have been sent along with the command. + rpc::advanceConfigOptimeFromRequestMetadata(opCtx); + } + + std::unique_ptr<PolymorphicScoped> scopedOperationCompletionShardingActions( + OperationContext* opCtx) const override { + return std::make_unique<ScopedOperationCompletionShardingActions>(opCtx); + } }; DbResponse ServiceEntryPointMongod::handleRequest(OperationContext* opCtx, const Message& m) { diff --git a/src/mongo/embedded/SConscript b/src/mongo/embedded/SConscript index 45f8e5e7827..f938a549790 100644 --- a/src/mongo/embedded/SConscript +++ b/src/mongo/embedded/SConscript @@ -58,7 +58,7 @@ env.Library( '$BUILD_DIR/mongo/db/repl/storage_interface_impl', '$BUILD_DIR/mongo/db/rw_concern_d', '$BUILD_DIR/mongo/db/s/sharding_api_d', - '$BUILD_DIR/mongo/db/s/sharding_runtime_d', + '$BUILD_DIR/mongo/db/s/sharding_runtime_d_embedded', '$BUILD_DIR/mongo/db/server_options', '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/service_entry_point_common', diff --git a/src/mongo/embedded/service_entry_point_embedded.cpp b/src/mongo/embedded/service_entry_point_embedded.cpp index ced60eb8af8..a1977b7250a 100644 --- a/src/mongo/embedded/service_entry_point_embedded.cpp +++ b/src/mongo/embedded/service_entry_point_embedded.cpp @@ -39,7 +39,7 @@ namespace mongo { -class ServiceEntryPointEmbedded::Hooks : public ServiceEntryPointCommon::Hooks { +class ServiceEntryPointEmbedded::Hooks final : public ServiceEntryPointCommon::Hooks { public: bool lockedForWriting() const override { return false; @@ -78,6 +78,15 @@ public: } void attachCurOpErrInfo(OperationContext*, const BSONObj&) const override {} + + void handleException(const DBException& e, OperationContext* opCtx) const override {} + + void advanceConfigOptimeFromRequestMetadata(OperationContext* opCtx) const override {} + + std::unique_ptr<PolymorphicScoped> scopedOperationCompletionShardingActions( + OperationContext* opCtx) const override { + return nullptr; + } }; DbResponse ServiceEntryPointEmbedded::handleRequest(OperationContext* opCtx, const Message& m) { diff --git a/src/mongo/platform/compiler.h b/src/mongo/platform/compiler.h index af3e0b20dc3..713cb11379d 100644 --- a/src/mongo/platform/compiler.h +++ b/src/mongo/platform/compiler.h @@ -150,6 +150,13 @@ * Tells the compiler that a class defines a type for which checking results is necessary. Types * thus defined turn functions returning them into "must check results" style functions. Preview * of the `[[nodiscard]]` C++17 attribute. + * + * + * MONGO_WARN_UNUSED_RESULT_FUNCTION + * + * Tells the compiler that a function returns a value for which consuming the result is + * necessary. Functions thus defined are "must check results" style functions. Preview of the + * `[[nodiscard]]` C++17 attribute. */ diff --git a/src/mongo/platform/compiler_gcc.h b/src/mongo/platform/compiler_gcc.h index a58a72a2d11..913dace45a0 100644 --- a/src/mongo/platform/compiler_gcc.h +++ b/src/mongo/platform/compiler_gcc.h @@ -45,6 +45,7 @@ // MONGO_WARN_UNUSED_RESULT is only supported in the semantics we want for classes in Clang, not in // GCC < 7. #define MONGO_WARN_UNUSED_RESULT_CLASS [[gnu::warn_unused_result]] +#define MONGO_WARN_UNUSED_RESULT_FUNCTION [[gnu::warn_unused_result]] #else #define MONGO_COMPILER_COLD_FUNCTION __attribute__((__cold__)) #define MONGO_COMPILER_NORETURN __attribute__((__noreturn__, __cold__)) @@ -52,8 +53,10 @@ // GCC 7 added support for [[nodiscard]] with the semantics we want. #if defined(__has_cpp_attribute) && __has_cpp_attribute(nodiscard) #define MONGO_WARN_UNUSED_RESULT_CLASS [[nodiscard]] +#define MONGO_WARN_UNUSED_RESULT_FUNCTION [[nodiscard]] #else #define MONGO_WARN_UNUSED_RESULT_CLASS +#define MONGO_WARN_UNUSED_RESULT_FUNCTION [[gnu::warn_unused_result]] #endif #endif diff --git a/src/mongo/platform/compiler_msvc.h b/src/mongo/platform/compiler_msvc.h index e9e2bfa86ef..9c872256d4d 100644 --- a/src/mongo/platform/compiler_msvc.h +++ b/src/mongo/platform/compiler_msvc.h @@ -51,6 +51,7 @@ #define MONGO_COMPILER_API_IMPORT __declspec(dllimport) #define MONGO_WARN_UNUSED_RESULT_CLASS +#define MONGO_WARN_UNUSED_RESULT_FUNCTION #ifdef _M_IX86 // 32-bit x86 supports multiple of calling conventions. We build supporting the cdecl convention diff --git a/src/mongo/util/polymorphic_scoped.h b/src/mongo/util/polymorphic_scoped.h new file mode 100644 index 00000000000..bb6ffb1c198 --- /dev/null +++ b/src/mongo/util/polymorphic_scoped.h @@ -0,0 +1,40 @@ +/** + * Copyright (C) 2018 MongoDB Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * 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 + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * 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 GNU Affero General 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 { +/** +* Base class to implement interfaces with RAII-style objects +*/ +class PolymorphicScoped { +public: + virtual ~PolymorphicScoped() = default; +}; + +} // namespace mongo |