From c7effc761dafc335f1e4e0a37f3039826435be28 Mon Sep 17 00:00:00 2001 From: Kaloian Manassiev Date: Tue, 19 Jan 2021 04:24:03 -0500 Subject: SERVER-53869 Remove references to `getGlobalServiceContext()` from the catalog ... also removes some unnecessary references to the `sharding_runtime_d` library from the op_msg_fuzzer test --- src/mongo/db/SConscript | 3 +- src/mongo/db/catalog/collection_impl.cpp | 5 +- src/mongo/db/catalog/collection_impl.h | 1 + src/mongo/db/catalog/index_catalog_impl.cpp | 1 - src/mongo/db/op_msg_fuzzer_fixture.cpp | 4 +- src/mongo/db/repl/oplog.cpp | 4 +- src/mongo/db/repl/oplog.h | 2 +- src/mongo/db/s/SConscript | 12 +-- .../collection_sharding_state_factory_embedded.cpp | 94 ---------------------- .../collection_sharding_state_factory_standalone.h | 2 +- src/mongo/dbtests/SConscript | 2 - src/mongo/embedded/SConscript | 1 - src/mongo/embedded/embedded.cpp | 11 ++- 13 files changed, 23 insertions(+), 119 deletions(-) delete mode 100644 src/mongo/db/s/collection_sharding_state_factory_embedded.cpp (limited to 'src/mongo') diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript index c927c09ea41..6e0d57272b1 100644 --- a/src/mongo/db/SConscript +++ b/src/mongo/db/SConscript @@ -2246,7 +2246,6 @@ env.Library( '$BUILD_DIR/mongo/db/index/index_access_methods', '$BUILD_DIR/mongo/db/repl/replmocks', '$BUILD_DIR/mongo/db/s/sharding_api_d', - '$BUILD_DIR/mongo/db/service_context', '$BUILD_DIR/mongo/db/service_context_d', '$BUILD_DIR/mongo/transport/service_entry_point', '$BUILD_DIR/mongo/transport/transport_layer_mock', @@ -2431,7 +2430,7 @@ env.CppLibfuzzerTest( ], LIBDEPS=[ '$BUILD_DIR/mongo/base', - '$BUILD_DIR/mongo/db/op_msg_fuzzer_fixture', + 'op_msg_fuzzer_fixture', ], ) diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp index 6a09c8e16f2..6c6203fa299 100644 --- a/src/mongo/db/catalog/collection_impl.cpp +++ b/src/mongo/db/catalog/collection_impl.cpp @@ -258,7 +258,8 @@ CollectionImpl::CollectionImpl(OperationContext* opCtx, RecordId catalogId, UUID uuid, std::unique_ptr recordStore) - : _ns(nss), + : _service(opCtx->getServiceContext()), + _ns(nss), _catalogId(catalogId), _uuid(uuid), _shared(std::make_shared(this, std::move(recordStore))), @@ -270,7 +271,7 @@ CollectionImpl::~CollectionImpl() { void CollectionImpl::onDeregisterFromCatalog() { if (ns().isOplog()) { - repl::clearLocalOplogPtr(); + repl::clearLocalOplogPtr(_service); } } diff --git a/src/mongo/db/catalog/collection_impl.h b/src/mongo/db/catalog/collection_impl.h index 54ce4109029..28cf28ce270 100644 --- a/src/mongo/db/catalog/collection_impl.h +++ b/src/mongo/db/catalog/collection_impl.h @@ -449,6 +449,7 @@ private: AtomicWord _committed{true}; }; + ServiceContext* const _service; NamespaceString _ns; RecordId _catalogId; diff --git a/src/mongo/db/catalog/index_catalog_impl.cpp b/src/mongo/db/catalog/index_catalog_impl.cpp index 3f7eb16770d..b0de98a8517 100644 --- a/src/mongo/db/catalog/index_catalog_impl.cpp +++ b/src/mongo/db/catalog/index_catalog_impl.cpp @@ -107,7 +107,6 @@ void IndexCatalogImpl::setCollection(Collection* collection) { _collection = collection; } - Status IndexCatalogImpl::init(OperationContext* opCtx) { vector indexNames; auto durableCatalog = DurableCatalog::get(opCtx); diff --git a/src/mongo/db/op_msg_fuzzer_fixture.cpp b/src/mongo/db/op_msg_fuzzer_fixture.cpp index d4fcd942a05..758d3ea4f70 100644 --- a/src/mongo/db/op_msg_fuzzer_fixture.cpp +++ b/src/mongo/db/op_msg_fuzzer_fixture.cpp @@ -51,6 +51,7 @@ #include "mongo/transport/service_entry_point_impl.h" namespace mongo { + OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers) { if (!skipGlobalInitializers) { auto ret = runGlobalInitializers(std::vector{}); @@ -89,7 +90,7 @@ OpMsgFuzzerFixture::OpMsgFuzzerFixture(bool skipGlobalInitializers) { auto replCoord = std::make_unique(_serviceContext); invariant(replCoord->setFollowerMode(repl::MemberState::RS_PRIMARY)); - repl::ReplicationCoordinator::set(getGlobalServiceContext(), std::move(replCoord)); + repl::ReplicationCoordinator::set(_serviceContext, std::move(replCoord)); } int OpMsgFuzzerFixture::testOneInput(const char* Data, size_t Size) { @@ -115,4 +116,5 @@ int OpMsgFuzzerFixture::testOneInput(const char* Data, size_t Size) { return 0; } + } // namespace mongo diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 09e1820ccf9..f89fb9d8412 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -1807,8 +1807,8 @@ void initTimestampFromOplog(OperationContext* opCtx, const NamespaceString& oplo } } -void clearLocalOplogPtr() { - LocalOplogInfo::get(getGlobalServiceContext())->resetCollection(); +void clearLocalOplogPtr(ServiceContext* service) { + LocalOplogInfo::get(service)->resetCollection(); } void acquireOplogCollectionForLogging(OperationContext* opCtx) { diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h index 735cf631e14..e1fe8ed904d 100644 --- a/src/mongo/db/repl/oplog.h +++ b/src/mongo/db/repl/oplog.h @@ -136,7 +136,7 @@ std::vector logInsertOps(OperationContext* opCtx, OpTime logOp(OperationContext* opCtx, MutableOplogEntry* oplogEntry); // Flush out the cached pointer to the oplog. -void clearLocalOplogPtr(); +void clearLocalOplogPtr(ServiceContext* service); /** * Establish the cached pointer to the local oplog. diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 986b67a99c6..cb48e076e87 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -12,6 +12,7 @@ env.Library( target='sharding_api_d', source=[ 'collection_metadata.cpp', + 'collection_sharding_state_factory_standalone.cpp', 'collection_sharding_state.cpp', 'database_sharding_state.cpp', 'operation_sharding_state.cpp', @@ -49,7 +50,6 @@ env.Library( 'chunk_splitter.cpp', 'collection_sharding_runtime.cpp', 'collection_sharding_state_factory_shard.cpp', - 'collection_sharding_state_factory_standalone.cpp', 'config_server_op_observer.cpp', 'metadata_manager.cpp', 'migration_chunk_cloner_source_legacy.cpp', @@ -178,16 +178,6 @@ env.Library( ], ) -env.Library( - target='sharding_runtime_d_embedded', - source=[ - 'collection_sharding_state_factory_embedded.cpp', - ], - LIBDEPS=[ - 'sharding_api_d', - ], -) - env.Library( target='transaction_coordinator', source=[ diff --git a/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp b/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp deleted file mode 100644 index e4be7a1862a..00000000000 --- a/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp +++ /dev/null @@ -1,94 +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. - */ - -#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kSharding - -#include "mongo/platform/basic.h" - -#include "mongo/db/s/collection_sharding_state.h" -#include "mongo/db/service_context.h" - -namespace mongo { -namespace { - -class UnshardedCollection : public ScopedCollectionDescription::Impl { -public: - UnshardedCollection() = default; - - const CollectionMetadata& get() override { - return _metadata; - } - -private: - CollectionMetadata _metadata; -}; - -const auto kUnshardedCollection = std::make_shared(); - -class CollectionShardingStateEmbedded final : public CollectionShardingState { -public: - ScopedCollectionDescription getCollectionDescription(OperationContext* opCtx) override { - return {kUnshardedCollection}; - } - ScopedCollectionFilter getOwnershipFilter(OperationContext*, - OrphanCleanupPolicy orphanCleanupPolicy) override { - return {kUnshardedCollection}; - } - void checkShardVersionOrThrow(OperationContext*) override {} - - void appendShardVersion(BSONObjBuilder* builder) override {} - - size_t numberOfRangesScheduledForDeletion() const override { - return 0; - } -}; - -class CollectionShardingStateFactoryEmbedded final : public CollectionShardingStateFactory { -public: - CollectionShardingStateFactoryEmbedded(ServiceContext* serviceContext) - : CollectionShardingStateFactory(serviceContext) {} - - void join() override {} - - std::unique_ptr make(const NamespaceString&) override { - return std::make_unique(); - } -}; - -} // namespace - -ServiceContext::ConstructorActionRegisterer collectionShardingStateFactoryRegisterer{ - "CollectionShardingStateFactory", - [](ServiceContext* service) { - CollectionShardingStateFactory::set( - service, std::make_unique(service)); - }, - [](ServiceContext* service) { CollectionShardingStateFactory::clear(service); }}; - -} // namespace mongo diff --git a/src/mongo/db/s/collection_sharding_state_factory_standalone.h b/src/mongo/db/s/collection_sharding_state_factory_standalone.h index b09d96a8aa1..c860aa57a11 100644 --- a/src/mongo/db/s/collection_sharding_state_factory_standalone.h +++ b/src/mongo/db/s/collection_sharding_state_factory_standalone.h @@ -42,4 +42,4 @@ public: std::unique_ptr make(const NamespaceString&) override; }; -} // namespace mongo \ No newline at end of file +} // namespace mongo diff --git a/src/mongo/dbtests/SConscript b/src/mongo/dbtests/SConscript index 09d63233bdf..d8752a237b2 100644 --- a/src/mongo/dbtests/SConscript +++ b/src/mongo/dbtests/SConscript @@ -35,7 +35,6 @@ env.Library( '$BUILD_DIR/mongo/db/index/index_access_methods', '$BUILD_DIR/mongo/db/index_builds_coordinator_mongod', '$BUILD_DIR/mongo/db/op_observer', - '$BUILD_DIR/mongo/db/s/sharding_runtime_d', '$BUILD_DIR/mongo/db/service_context_d', '$BUILD_DIR/mongo/db/storage/storage_control', '$BUILD_DIR/mongo/scripting/scripting_common', @@ -166,7 +165,6 @@ if not has_option('noshell') and usemozjs: "$BUILD_DIR/mongo/db/repl/storage_interface_impl", "$BUILD_DIR/mongo/db/repl/timestamp_block", "$BUILD_DIR/mongo/db/s/resharding_util", - "$BUILD_DIR/mongo/db/s/sharding_runtime_d", "$BUILD_DIR/mongo/db/server_options_core", "$BUILD_DIR/mongo/db/sessions_collection_standalone", "$BUILD_DIR/mongo/db/storage/durable_catalog_impl", diff --git a/src/mongo/embedded/SConscript b/src/mongo/embedded/SConscript index c2161766407..ac924ca6a0f 100644 --- a/src/mongo/embedded/SConscript +++ b/src/mongo/embedded/SConscript @@ -97,7 +97,6 @@ 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_embedded', '$BUILD_DIR/mongo/db/server_options', '$BUILD_DIR/mongo/db/server_options_base', '$BUILD_DIR/mongo/db/service_context', diff --git a/src/mongo/embedded/embedded.cpp b/src/mongo/embedded/embedded.cpp index d8301a76ead..0464c2b895e 100644 --- a/src/mongo/embedded/embedded.cpp +++ b/src/mongo/embedded/embedded.cpp @@ -53,6 +53,7 @@ #include "mongo/db/op_observer_impl.h" #include "mongo/db/op_observer_registry.h" #include "mongo/db/repl/storage_interface_impl.h" +#include "mongo/db/s/collection_sharding_state_factory_standalone.h" #include "mongo/db/service_liaison_mongod.h" #include "mongo/db/session_killer.h" #include "mongo/db/sessions_collection_standalone.h" @@ -135,13 +136,21 @@ GlobalInitializerRegisterer filterAllowedIndexFieldNamesEmbeddedInitializer( DeinitializerFunction(nullptr), {}, {"FilterAllowedIndexFieldNames"}); + +ServiceContext::ConstructorActionRegisterer collectionShardingStateFactoryRegisterer{ + "CollectionShardingStateFactory", + [](ServiceContext* service) { + CollectionShardingStateFactory::set( + service, std::make_unique(service)); + }, + [](ServiceContext* service) { CollectionShardingStateFactory::clear(service); }}; + } // namespace using logv2::LogComponent; using std::endl; void shutdown(ServiceContext* srvContext) { - { ThreadClient tc(srvContext); auto const client = Client::getCurrent(); -- cgit v1.2.1