summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarcos José Grillo Ramírez <marcos.grillo@mongodb.com>2020-02-06 11:27:08 +0100
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-02-11 10:32:50 +0000
commitfc5a4d987ca2ee86d18614183de7b0a0e75c5a45 (patch)
tree61849495c07f1ced08331435fd8d943fe8144374 /src
parentb48cb5d8e2a8ccab0f4be401cc2533e5c2b650ae (diff)
downloadmongo-fc5a4d987ca2ee86d18614183de7b0a0e75c5a45.tar.gz
SERVER-45904 Create a standalone collection sharding state factory
create mode 100644 src/mongo/db/s/collection_sharding_state_factory_shard.h create mode 100644 src/mongo/db/s/collection_sharding_state_factory_standalone.cpp create mode 100644 src/mongo/db/s/collection_sharding_state_factory_standalone.h
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/collection_catalog_test.cpp3
-rw-r--r--src/mongo/db/commands/mr.cpp4
-rw-r--r--src/mongo/db/db.cpp47
-rw-r--r--src/mongo/db/repl/rollback_test_fixture.cpp2
-rw-r--r--src/mongo/db/s/SConscript1
-rw-r--r--src/mongo/db/s/collection_sharding_runtime.h12
-rw-r--r--src/mongo/db/s/collection_sharding_state.h16
-rw-r--r--src/mongo/db/s/collection_sharding_state_factory_embedded.cpp4
-rw-r--r--src/mongo/db/s/collection_sharding_state_factory_shard.cpp80
-rw-r--r--src/mongo/db/s/collection_sharding_state_factory_shard.h57
-rw-r--r--src/mongo/db/s/collection_sharding_state_factory_standalone.cpp96
-rw-r--r--src/mongo/db/s/collection_sharding_state_factory_standalone.h45
-rw-r--r--src/mongo/db/s/get_shard_version_command.cpp2
-rw-r--r--src/mongo/db/s/sharding_initialization_mongod_test.cpp16
-rw-r--r--src/mongo/db/service_context_d_test_fixture.cpp15
-rw-r--r--src/mongo/db/service_context_d_test_fixture.h4
-rw-r--r--src/mongo/db/session_catalog_mongod_test.cpp1
-rw-r--r--src/mongo/dbtests/framework.cpp6
-rw-r--r--src/mongo/dbtests/storage_timestamp_tests.cpp1
-rw-r--r--src/mongo/s/sharding_mongod_test_fixture.cpp1
20 files changed, 337 insertions, 76 deletions
diff --git a/src/mongo/db/catalog/collection_catalog_test.cpp b/src/mongo/db/catalog/collection_catalog_test.cpp
index 44409c32807..55142418bad 100644
--- a/src/mongo/db/catalog/collection_catalog_test.cpp
+++ b/src/mongo/db/catalog/collection_catalog_test.cpp
@@ -62,8 +62,11 @@ public:
std::swap(prevUUID, colUUID);
ASSERT_GT(colUUID, prevUUID);
ASSERT_GT(nextUUID, colUUID);
+ }
+ void setUp() override {
ServiceContextMongoDTest::setUp();
+
std::unique_ptr<Collection> collection = std::make_unique<CollectionMock>(nss);
col = collection.get();
// Register dummy collection in catalog.
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 006969061c8..a9a8582f136 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -548,7 +548,7 @@ void State::prepTempCollection() {
str::stream() << "createIndex failed for mr incLong ns " << _config.incLong.ns());
wuow.commit();
- CollectionShardingRuntime::get(_opCtx, _config.incLong)
+ CollectionShardingState::get(_opCtx, _config.incLong)
->setFilteringMetadata(_opCtx, CollectionMetadata());
});
}
@@ -632,7 +632,7 @@ void State::prepTempCollection() {
wuow.commit();
- CollectionShardingRuntime::get(_opCtx, _config.tempNamespace)
+ CollectionShardingState::get(_opCtx, _config.tempNamespace)
->setFilteringMetadata(_opCtx, CollectionMetadata());
});
}
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index 3fb1a95eabe..b5a2fd26c42 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -97,6 +97,7 @@
#include "mongo/db/logical_time_validator.h"
#include "mongo/db/mongod_options.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/db/op_observer_impl.h"
#include "mongo/db/op_observer_registry.h"
#include "mongo/db/operation_context.h"
#include "mongo/db/periodic_runner_job_abort_expired_transactions.h"
@@ -118,6 +119,8 @@
#include "mongo/db/repl/topology_coordinator.h"
#include "mongo/db/repl_set_member_in_standalone_mode.h"
#include "mongo/db/s/balancer/balancer.h"
+#include "mongo/db/s/collection_sharding_state_factory_shard.h"
+#include "mongo/db/s/collection_sharding_state_factory_standalone.h"
#include "mongo/db/s/config/sharding_catalog_manager.h"
#include "mongo/db/s/config_server_op_observer.h"
#include "mongo/db/s/op_observer_sharding_impl.h"
@@ -278,19 +281,6 @@ ExitCode _initAndListen(int listenPort) {
auto serviceContext = getGlobalServiceContext();
serviceContext->setFastClockSource(FastClockSourceFactory::create(Milliseconds(10)));
- auto opObserverRegistry = std::make_unique<OpObserverRegistry>();
- opObserverRegistry->addObserver(std::make_unique<OpObserverShardingImpl>());
- opObserverRegistry->addObserver(std::make_unique<AuthOpObserver>());
-
- if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
- opObserverRegistry->addObserver(std::make_unique<ShardServerOpObserver>());
- } else if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
- opObserverRegistry->addObserver(std::make_unique<ConfigServerOpObserver>());
- }
- setupFreeMonitoringOpObserver(opObserverRegistry.get());
-
-
- serviceContext->setOpObserver(std::move(opObserverRegistry));
DBDirectClientFactory::get(serviceContext).registerImplementation([](OperationContext* opCtx) {
return std::unique_ptr<DBClientBase>(new DBDirectClient(opCtx));
@@ -836,6 +826,17 @@ void startupConfigActions(const std::vector<std::string>& args) {
#endif
}
+void setUpCollectionShardingState(ServiceContext* serviceContext) {
+ if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
+ CollectionShardingStateFactory::set(
+ serviceContext, std::make_unique<CollectionShardingStateFactoryShard>(serviceContext));
+ } else {
+ CollectionShardingStateFactory::set(
+ serviceContext,
+ std::make_unique<CollectionShardingStateFactoryStandalone>(serviceContext));
+ }
+}
+
void setUpCatalog(ServiceContext* serviceContext) {
DatabaseHolder::set(serviceContext, std::make_unique<DatabaseHolderImpl>());
IndexAccessMethodFactory::set(serviceContext, std::make_unique<IndexAccessMethodFactoryImpl>());
@@ -898,6 +899,24 @@ void setUpReplication(ServiceContext* serviceContext) {
IndexBuildsCoordinator::set(serviceContext, std::make_unique<IndexBuildsCoordinatorMongod>());
}
+void setUpObservers(ServiceContext* serviceContext) {
+ auto opObserverRegistry = std::make_unique<OpObserverRegistry>();
+ if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) {
+ opObserverRegistry->addObserver(std::make_unique<OpObserverShardingImpl>());
+ opObserverRegistry->addObserver(std::make_unique<ShardServerOpObserver>());
+ } else if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) {
+ opObserverRegistry->addObserver(std::make_unique<OpObserverImpl>());
+ opObserverRegistry->addObserver(std::make_unique<ConfigServerOpObserver>());
+ } else {
+ opObserverRegistry->addObserver(std::make_unique<OpObserverImpl>());
+ }
+ opObserverRegistry->addObserver(std::make_unique<AuthOpObserver>());
+
+ setupFreeMonitoringOpObserver(opObserverRegistry.get());
+
+ serviceContext->setOpObserver(std::move(opObserverRegistry));
+}
+
#ifdef MONGO_CONFIG_SSL
MONGO_INITIALIZER_GENERAL(setSSLManagerType, MONGO_NO_PREREQUISITES, ("SSLManager"))
(InitializerContext* context) {
@@ -1136,8 +1155,10 @@ int mongoDbMain(int argc, char* argv[], char** envp) {
}
auto service = getGlobalServiceContext();
+ setUpCollectionShardingState(service);
setUpCatalog(service);
setUpReplication(service);
+ setUpObservers(service);
service->setServiceEntryPoint(std::make_unique<ServiceEntryPointMongod>(service));
ErrorExtraInfo::invariantHaveAllParsers();
diff --git a/src/mongo/db/repl/rollback_test_fixture.cpp b/src/mongo/db/repl/rollback_test_fixture.cpp
index 9a1e95f0136..f73902f7a38 100644
--- a/src/mongo/db/repl/rollback_test_fixture.cpp
+++ b/src/mongo/db/repl/rollback_test_fixture.cpp
@@ -89,6 +89,8 @@ public:
} // namespace
void RollbackTest::setUp() {
+ ServiceContextMongoDTest::setUp();
+
_storageInterface = new StorageInterfaceRollback();
auto serviceContext = getServiceContext();
auto consistencyMarkers = std::make_unique<ReplicationConsistencyMarkersMock>();
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript
index f5ef0a3448c..976282cf4c3 100644
--- a/src/mongo/db/s/SConscript
+++ b/src/mongo/db/s/SConscript
@@ -40,6 +40,7 @@ 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',
'implicit_create_collection.cpp',
'metadata_manager.cpp',
diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h
index b817ca582f5..be2ca17cc91 100644
--- a/src/mongo/db/s/collection_sharding_runtime.h
+++ b/src/mongo/db/s/collection_sharding_runtime.h
@@ -103,15 +103,7 @@ public:
std::shared_ptr<Notification<void>> getCriticalSectionSignal(
ShardingMigrationCriticalSection::Operation op) const override;
- /**
- * Updates the collection's filtering metadata based on changes received from the config server
- * and also resolves the pending receives map in case some of these pending receives have
- * committed on the config server or have been abandoned by the donor shard.
- *
- * This method must be called with an exclusive collection lock and it does not acquire any
- * locks itself.
- */
- void setFilteringMetadata(OperationContext* opCtx, CollectionMetadata newMetadata);
+ void setFilteringMetadata(OperationContext* opCtx, CollectionMetadata newMetadata) override;
/**
* Marks the collection's filtering metadata as UNKNOWN, meaning that all attempts to check for
@@ -159,7 +151,7 @@ public:
/**
* BSON output of the pending metadata into a BSONArray
*/
- void toBSONPending(BSONArrayBuilder& bb) const {
+ void toBSONPending(BSONArrayBuilder& bb) const override {
_metadataManager->toBSONPending(bb);
}
diff --git a/src/mongo/db/s/collection_sharding_state.h b/src/mongo/db/s/collection_sharding_state.h
index 981fb4d3ffb..cdbbdf00d4e 100644
--- a/src/mongo/db/s/collection_sharding_state.h
+++ b/src/mongo/db/s/collection_sharding_state.h
@@ -161,6 +161,22 @@ public:
*/
virtual std::shared_ptr<Notification<void>> getCriticalSectionSignal(
ShardingMigrationCriticalSection::Operation op) const = 0;
+
+ /**
+ * BSON output of the pending metadata into a BSONArray
+ * used for reporting/diagnostic purposes only
+ */
+ virtual void toBSONPending(BSONArrayBuilder& bb) const = 0;
+
+ /**
+ * Updates the collection's filtering metadata based on changes received from the config server
+ * and also resolves the pending receives map in case some of these pending receives have
+ * committed on the config server or have been abandoned by the donor shard.
+ *
+ * This method must be called with an exclusive collection lock and it does not acquire any
+ * locks itself.
+ */
+ virtual void setFilteringMetadata(OperationContext* opCtx, CollectionMetadata newMetadata) = 0;
};
/**
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 81a0a033afd..c2c476d8d9c 100644
--- a/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp
+++ b/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp
@@ -81,6 +81,10 @@ public:
ShardingMigrationCriticalSection::Operation) const override {
return nullptr;
}
+
+ void toBSONPending(BSONArrayBuilder&) const override {}
+
+ void setFilteringMetadata(OperationContext*, CollectionMetadata) override {}
};
class CollectionShardingStateFactoryEmbedded final : public CollectionShardingStateFactory {
diff --git a/src/mongo/db/s/collection_sharding_state_factory_shard.cpp b/src/mongo/db/s/collection_sharding_state_factory_shard.cpp
index 14426d05ec6..15a4d035873 100644
--- a/src/mongo/db/s/collection_sharding_state_factory_shard.cpp
+++ b/src/mongo/db/s/collection_sharding_state_factory_shard.cpp
@@ -32,67 +32,49 @@
#include "mongo/platform/basic.h"
#include "mongo/db/s/collection_sharding_runtime.h"
+#include "mongo/db/s/collection_sharding_state_factory_shard.h"
#include "mongo/db/service_context.h"
#include "mongo/executor/network_interface_factory.h"
#include "mongo/executor/network_interface_thread_pool.h"
#include "mongo/executor/thread_pool_task_executor.h"
namespace mongo {
-namespace {
-
-class CollectionShardingStateFactoryShard final : public CollectionShardingStateFactory {
-public:
- CollectionShardingStateFactoryShard(ServiceContext* serviceContext)
- : CollectionShardingStateFactory(serviceContext) {}
-
- ~CollectionShardingStateFactoryShard() {
- join();
- }
-
- void join() override {
- if (_taskExecutor) {
- _taskExecutor->shutdown();
- _taskExecutor->join();
- }
+CollectionShardingStateFactoryShard::CollectionShardingStateFactoryShard(
+ ServiceContext* serviceContext)
+ : CollectionShardingStateFactory(serviceContext) {}
+
+CollectionShardingStateFactoryShard::~CollectionShardingStateFactoryShard() {
+ join();
+}
+
+void CollectionShardingStateFactoryShard::join() {
+ if (_taskExecutor) {
+ _taskExecutor->shutdown();
+ _taskExecutor->join();
}
+}
- std::unique_ptr<CollectionShardingState> make(const NamespaceString& nss) override {
- return std::make_unique<CollectionShardingRuntime>(_serviceContext, nss, _getExecutor());
- }
-
-private:
- std::shared_ptr<executor::TaskExecutor> _getExecutor() {
- stdx::lock_guard<Latch> lg(_mutex);
- if (!_taskExecutor) {
- const std::string kExecName("CollectionRangeDeleter-TaskExecutor");
+std::unique_ptr<CollectionShardingState> CollectionShardingStateFactoryShard::make(
+ const NamespaceString& nss) {
+ return std::make_unique<CollectionShardingRuntime>(_serviceContext, nss, _getExecutor());
+}
- auto net = executor::makeNetworkInterface(kExecName);
- auto pool = std::make_unique<executor::NetworkInterfaceThreadPool>(net.get());
- auto taskExecutor =
- std::make_shared<executor::ThreadPoolTaskExecutor>(std::move(pool), std::move(net));
- taskExecutor->startup();
+std::shared_ptr<executor::TaskExecutor> CollectionShardingStateFactoryShard::_getExecutor() {
+ stdx::lock_guard<Latch> lg(_mutex);
+ if (!_taskExecutor) {
+ const std::string kExecName("CollectionRangeDeleter-TaskExecutor");
- _taskExecutor = std::move(taskExecutor);
- }
+ auto net = executor::makeNetworkInterface(kExecName);
+ auto pool = std::make_unique<executor::NetworkInterfaceThreadPool>(net.get());
+ auto taskExecutor =
+ std::make_shared<executor::ThreadPoolTaskExecutor>(std::move(pool), std::move(net));
+ taskExecutor->startup();
- return _taskExecutor;
+ _taskExecutor = std::move(taskExecutor);
}
- // Serializes the instantiation of the task executor
- Mutex _mutex = MONGO_MAKE_LATCH("CollectionShardingStateFactoryShard::_mutex");
-
- // Required to be a shared_ptr since it is used as an executor for ExecutorFutures.
- std::shared_ptr<executor::TaskExecutor> _taskExecutor{nullptr};
-};
-
-} // namespace
+ return _taskExecutor;
+}
-ServiceContext::ConstructorActionRegisterer collectionShardingStateFactoryRegisterer{
- "CollectionShardingStateFactory",
- [](ServiceContext* service) {
- CollectionShardingStateFactory::set(
- service, std::make_unique<CollectionShardingStateFactoryShard>(service));
- },
- [](ServiceContext* service) { CollectionShardingStateFactory::clear(service); }};
-} // namespace mongo
+} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/s/collection_sharding_state_factory_shard.h b/src/mongo/db/s/collection_sharding_state_factory_shard.h
new file mode 100644
index 00000000000..f24929b4694
--- /dev/null
+++ b/src/mongo/db/s/collection_sharding_state_factory_shard.h
@@ -0,0 +1,57 @@
+/**
+ * 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
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * 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/s/collection_sharding_state.h"
+#include "mongo/executor/task_executor.h"
+
+namespace mongo {
+
+class CollectionShardingStateFactoryShard final : public CollectionShardingStateFactory {
+public:
+ CollectionShardingStateFactoryShard(ServiceContext* serviceContext);
+
+ ~CollectionShardingStateFactoryShard();
+
+ void join() override;
+
+ std::unique_ptr<CollectionShardingState> make(const NamespaceString& nss) override;
+
+private:
+ std::shared_ptr<executor::TaskExecutor> _getExecutor();
+
+ // Serializes the instantiation of the task executor
+ Mutex _mutex = MONGO_MAKE_LATCH("CollectionShardingStateFactoryShard::_mutex");
+
+ // Required to be a shared_ptr since it is used as an executor for ExecutorFutures.
+ std::shared_ptr<executor::TaskExecutor> _taskExecutor = {nullptr};
+};
+
+} // namespace mongo
diff --git a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp
new file mode 100644
index 00000000000..ccde230167a
--- /dev/null
+++ b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp
@@ -0,0 +1,96 @@
+/**
+ * Copyright (C) 2020-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
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * 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_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kSharding
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/db/s/collection_sharding_state_factory_standalone.h"
+
+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 CollectionShardingStateStandalone final : public CollectionShardingState {
+public:
+ ScopedCollectionFilter getOwnershipFilter(OperationContext*, bool) override {
+ return {kUnshardedCollection};
+ }
+ ScopedCollectionMetadata getCurrentMetadata() override {
+ return {kUnshardedCollection};
+ }
+ boost::optional<ScopedCollectionMetadata> getCurrentMetadataIfKnown() noexcept override {
+ return boost::none;
+ }
+ boost::optional<ChunkVersion> getCurrentShardVersionIfKnown() noexcept override {
+ return boost::none;
+ }
+ void checkShardVersionOrThrow(OperationContext*, bool) noexcept override {}
+ Status checkShardVersionNoThrow(OperationContext*, bool) noexcept override {
+ return Status::OK();
+ }
+ void enterCriticalSectionCatchUpPhase(OperationContext*) noexcept override {}
+ void enterCriticalSectionCommitPhase(OperationContext*) noexcept override {}
+ void exitCriticalSection(OperationContext*) noexcept override {}
+ std::shared_ptr<Notification<void>> getCriticalSectionSignal(
+ ShardingMigrationCriticalSection::Operation) const noexcept override {
+ return nullptr;
+ }
+
+ void toBSONPending(BSONArrayBuilder& bb) const noexcept override {}
+
+ void setFilteringMetadata(OperationContext*, CollectionMetadata) noexcept override {}
+};
+
+} // namespace
+
+CollectionShardingStateFactoryStandalone::CollectionShardingStateFactoryStandalone(
+ ServiceContext* serviceContext)
+ : CollectionShardingStateFactory(serviceContext) {}
+
+void CollectionShardingStateFactoryStandalone::join() {}
+
+std::unique_ptr<CollectionShardingState> CollectionShardingStateFactoryStandalone::make(
+ const NamespaceString&) {
+ return std::make_unique<CollectionShardingStateStandalone>();
+}
+
+} // 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
new file mode 100644
index 00000000000..b09d96a8aa1
--- /dev/null
+++ b/src/mongo/db/s/collection_sharding_state_factory_standalone.h
@@ -0,0 +1,45 @@
+/**
+ * Copyright (C) 2020-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
+ * <http://www.mongodb.com/licensing/server-side-public-license>.
+ *
+ * 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/s/collection_sharding_state.h"
+
+namespace mongo {
+
+class CollectionShardingStateFactoryStandalone final : public CollectionShardingStateFactory {
+public:
+ CollectionShardingStateFactoryStandalone(ServiceContext* serviceContext);
+
+ void join() override;
+
+ std::unique_ptr<CollectionShardingState> make(const NamespaceString&) override;
+};
+
+} // namespace mongo \ No newline at end of file
diff --git a/src/mongo/db/s/get_shard_version_command.cpp b/src/mongo/db/s/get_shard_version_command.cpp
index 0fda498a2bf..98d701bfe40 100644
--- a/src/mongo/db/s/get_shard_version_command.cpp
+++ b/src/mongo/db/s/get_shard_version_command.cpp
@@ -108,7 +108,7 @@ public:
AutoGetCollection autoColl(
opCtx, nss, MODE_IS, AutoGetCollection::ViewMode::kViewsPermitted);
- auto* const css = CollectionShardingRuntime::get(opCtx, nss);
+ auto* const css = CollectionShardingState::get(opCtx, nss);
const auto optMetadata = css->getCurrentMetadataIfKnown();
if (!optMetadata) {
diff --git a/src/mongo/db/s/sharding_initialization_mongod_test.cpp b/src/mongo/db/s/sharding_initialization_mongod_test.cpp
index 5a7a7868259..fd195ad0549 100644
--- a/src/mongo/db/s/sharding_initialization_mongod_test.cpp
+++ b/src/mongo/db/s/sharding_initialization_mongod_test.cpp
@@ -35,6 +35,8 @@
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/op_observer_registry.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
+#include "mongo/db/s/collection_sharding_state_factory_shard.h"
+#include "mongo/db/s/collection_sharding_state_factory_standalone.h"
#include "mongo/db/s/config_server_op_observer.h"
#include "mongo/db/s/op_observer_sharding_impl.h"
#include "mongo/db/s/shard_server_catalog_cache_loader.h"
@@ -135,15 +137,27 @@ protected:
class ScopedSetStandaloneMode {
public:
ScopedSetStandaloneMode(ServiceContext* serviceContext) : _serviceContext(serviceContext) {
+ CollectionShardingStateFactory::clear(serviceContext);
+
+ CollectionShardingStateFactory::set(
+ serviceContext,
+ std::make_unique<CollectionShardingStateFactoryStandalone>(serviceContext));
+
serverGlobalParams.clusterRole = ClusterRole::None;
_serviceContext->setOpObserver(std::make_unique<OpObserverRegistry>());
}
~ScopedSetStandaloneMode() {
+ CollectionShardingStateFactory::clear(_serviceContext);
+
+ CollectionShardingStateFactory::set(
+ _serviceContext,
+ std::make_unique<CollectionShardingStateFactoryShard>(_serviceContext));
+
serverGlobalParams.clusterRole = ClusterRole::ShardServer;
auto makeOpObserver = [&] {
auto opObserver = std::make_unique<OpObserverRegistry>();
- opObserver->addObserver(std::make_unique<OpObserverShardingImpl>());
+ opObserver->addObserver(std::make_unique<OpObserverImpl>());
opObserver->addObserver(std::make_unique<ConfigServerOpObserver>());
opObserver->addObserver(std::make_unique<ShardServerOpObserver>());
return opObserver;
diff --git a/src/mongo/db/service_context_d_test_fixture.cpp b/src/mongo/db/service_context_d_test_fixture.cpp
index e82321bd928..d48597710cc 100644
--- a/src/mongo/db/service_context_d_test_fixture.cpp
+++ b/src/mongo/db/service_context_d_test_fixture.cpp
@@ -43,6 +43,7 @@
#include "mongo/db/index_builds_coordinator_mongod.h"
#include "mongo/db/logical_clock.h"
#include "mongo/db/op_observer_registry.h"
+#include "mongo/db/s/collection_sharding_state_factory_shard.h"
#include "mongo/db/service_entry_point_mongod.h"
#include "mongo/db/storage/storage_engine_init.h"
#include "mongo/db/storage/storage_options.h"
@@ -106,4 +107,18 @@ ServiceContextMongoDTest::~ServiceContextMongoDTest() {
std::swap(storageGlobalParams.repair, _stashedStorageParams.repair);
}
+void ServiceContextMongoDTest::setUp() {
+ ServiceContextTest::setUp();
+
+ CollectionShardingStateFactory::set(
+ getServiceContext(),
+ std::make_unique<CollectionShardingStateFactoryShard>(getServiceContext()));
+}
+
+void ServiceContextMongoDTest::tearDown() {
+ CollectionShardingStateFactory::clear(getServiceContext());
+
+ ServiceContextTest::tearDown();
+}
+
} // namespace mongo
diff --git a/src/mongo/db/service_context_d_test_fixture.h b/src/mongo/db/service_context_d_test_fixture.h
index 0d8a19c2913..0b25498a1a9 100644
--- a/src/mongo/db/service_context_d_test_fixture.h
+++ b/src/mongo/db/service_context_d_test_fixture.h
@@ -52,6 +52,10 @@ protected:
ServiceContextMongoDTest(std::string engine, RepairAction repair);
virtual ~ServiceContextMongoDTest();
+ void setUp() override;
+
+ void tearDown() override;
+
private:
struct {
std::string engine;
diff --git a/src/mongo/db/session_catalog_mongod_test.cpp b/src/mongo/db/session_catalog_mongod_test.cpp
index 415e1e4ac07..61a97fb7b7e 100644
--- a/src/mongo/db/session_catalog_mongod_test.cpp
+++ b/src/mongo/db/session_catalog_mongod_test.cpp
@@ -43,6 +43,7 @@ namespace {
class MongoDSessionCatalogTest : public ServiceContextMongoDTest {
protected:
void setUp() override {
+ ServiceContextMongoDTest::setUp();
const auto service = getServiceContext();
auto replCoord = std::make_unique<repl::ReplicationCoordinatorMock>(service);
ASSERT_OK(replCoord->setFollowerMode(repl::MemberState::RS_PRIMARY));
diff --git a/src/mongo/dbtests/framework.cpp b/src/mongo/dbtests/framework.cpp
index 779580bee27..170e66baea7 100644
--- a/src/mongo/dbtests/framework.cpp
+++ b/src/mongo/dbtests/framework.cpp
@@ -46,6 +46,7 @@
#include "mongo/db/index/index_access_method_factory_impl.h"
#include "mongo/db/index_builds_coordinator_mongod.h"
#include "mongo/db/op_observer_registry.h"
+#include "mongo/db/s/collection_sharding_state_factory_shard.h"
#include "mongo/db/s/sharding_state.h"
#include "mongo/db/service_context.h"
#include "mongo/db/storage/storage_engine_init.h"
@@ -86,6 +87,10 @@ int runDbTests(int argc, char** argv) {
Client::initThread("testsuite");
auto globalServiceContext = getGlobalServiceContext();
+ CollectionShardingStateFactory::set(
+ globalServiceContext,
+ std::make_unique<CollectionShardingStateFactoryShard>(globalServiceContext));
+
// DBTests run as if in the database, so allow them to create direct clients.
DBDirectClientFactory::get(globalServiceContext)
@@ -116,6 +121,7 @@ int runDbTests(int argc, char** argv) {
frameworkGlobalParams.runsPerTest);
// So everything shuts down cleanly
+ CollectionShardingStateFactory::clear(globalServiceContext);
exitCleanly((ExitCode)ret);
return ret;
}
diff --git a/src/mongo/dbtests/storage_timestamp_tests.cpp b/src/mongo/dbtests/storage_timestamp_tests.cpp
index b7885f38df3..c4c0d4cc33d 100644
--- a/src/mongo/dbtests/storage_timestamp_tests.cpp
+++ b/src/mongo/dbtests/storage_timestamp_tests.cpp
@@ -71,6 +71,7 @@
#include "mongo/db/repl/replication_recovery_mock.h"
#include "mongo/db/repl/storage_interface_impl.h"
#include "mongo/db/repl/timestamp_block.h"
+#include "mongo/db/s/collection_sharding_state_factory_shard.h"
#include "mongo/db/s/op_observer_sharding_impl.h"
#include "mongo/db/service_context.h"
#include "mongo/db/session.h"
diff --git a/src/mongo/s/sharding_mongod_test_fixture.cpp b/src/mongo/s/sharding_mongod_test_fixture.cpp
index 7d7b8419e58..dbd20638bee 100644
--- a/src/mongo/s/sharding_mongod_test_fixture.cpp
+++ b/src/mongo/s/sharding_mongod_test_fixture.cpp
@@ -55,6 +55,7 @@
#include "mongo/db/repl/replication_process.h"
#include "mongo/db/repl/replication_recovery_mock.h"
#include "mongo/db/repl/storage_interface_mock.h"
+#include "mongo/db/s/collection_sharding_state_factory_shard.h"
#include "mongo/db/s/config_server_op_observer.h"
#include "mongo/db/s/op_observer_sharding_impl.h"
#include "mongo/db/s/shard_server_op_observer.h"