diff options
author | Dianna Hohensee <dianna.hohensee@10gen.com> | 2017-08-01 12:23:50 -0400 |
---|---|---|
committer | Dianna Hohensee <dianna.hohensee@10gen.com> | 2017-08-09 08:50:44 -0400 |
commit | aa102021070c10f802b9be8877870400cc27ed07 (patch) | |
tree | 8ea72176a012413adfdd337c38a563c1524d0334 /src/mongo/db | |
parent | 9f2e54384d90ab0c533c6d311337d6bcc8fb5679 (diff) | |
download | mongo-aa102021070c10f802b9be8877870400cc27ed07.tar.gz |
SERVER-29694 Read-only shards should not try to persist the collection routing information locally
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/s/read_only_catalog_cache_loader.cpp | 70 | ||||
-rw-r--r-- | src/mongo/db/s/read_only_catalog_cache_loader.h | 66 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_initialization_mongod.cpp | 12 |
4 files changed, 146 insertions, 3 deletions
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index d3c7c682c0b..1a9c825aee3 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -74,6 +74,7 @@ env.Library( 'move_timing_helper.cpp', 'namespace_metadata_change_notifications.cpp', 'operation_sharding_state.cpp', + 'read_only_catalog_cache_loader.cpp', 'shard_identity_rollback_notifier.cpp', 'shard_metadata_util.cpp', 'shard_server_catalog_cache_loader.cpp', diff --git a/src/mongo/db/s/read_only_catalog_cache_loader.cpp b/src/mongo/db/s/read_only_catalog_cache_loader.cpp new file mode 100644 index 00000000000..007a6203489 --- /dev/null +++ b/src/mongo/db/s/read_only_catalog_cache_loader.cpp @@ -0,0 +1,70 @@ +/** + * Copyright (C) 2017 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. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/s/read_only_catalog_cache_loader.h" + +#include "mongo/db/operation_context.h" + +namespace mongo { + +using CollectionAndChangedChunks = CatalogCacheLoader::CollectionAndChangedChunks; + +void ReadOnlyCatalogCacheLoader::initializeReplicaSetRole(bool isPrimary) { + return; +} + +void ReadOnlyCatalogCacheLoader::onStepDown() { + return; +} + +void ReadOnlyCatalogCacheLoader::onStepUp() { + return; +} + +void ReadOnlyCatalogCacheLoader::notifyOfCollectionVersionUpdate(OperationContext* opCtx, + const NamespaceString& nss, + const ChunkVersion& version) { + return; +} + +Status ReadOnlyCatalogCacheLoader::waitForCollectionVersion(OperationContext* opCtx, + const NamespaceString& nss, + const ChunkVersion& version) { + return Status::OK(); +} + +std::shared_ptr<Notification<void>> ReadOnlyCatalogCacheLoader::getChunksSince( + const NamespaceString& nss, + ChunkVersion version, + stdx::function<void(OperationContext*, StatusWith<CollectionAndChangedChunks>)> callbackFn) { + return _configServerLoader.getChunksSince(nss, version, callbackFn); +} + +} // namespace mongo diff --git a/src/mongo/db/s/read_only_catalog_cache_loader.h b/src/mongo/db/s/read_only_catalog_cache_loader.h new file mode 100644 index 00000000000..1615ba55c16 --- /dev/null +++ b/src/mongo/db/s/read_only_catalog_cache_loader.h @@ -0,0 +1,66 @@ +/** + * Copyright (C) 2017 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 + +#include "mongo/s/catalog_cache_loader.h" +#include "mongo/s/config_server_catalog_cache_loader.h" + +namespace mongo { + +/** + * Contains a ConfigServerCatalogCacheLoader for remote metadata loading. Inactive functions simply + * return, rather than invariant, so this class can be plugged into the shard server for read-only + * mode, where persistence should not be attempted. + */ +class ReadOnlyCatalogCacheLoader final : public CatalogCacheLoader { +public: + /** + * These functions do nothing and simply return. + */ + void initializeReplicaSetRole(bool isPrimary) override; + void onStepDown() override; + void onStepUp() override; + void notifyOfCollectionVersionUpdate(OperationContext* opCtx, + const NamespaceString& nss, + const ChunkVersion& version) override; + Status waitForCollectionVersion(OperationContext* opCtx, + const NamespaceString& nss, + const ChunkVersion& version) override; + + std::shared_ptr<Notification<void>> getChunksSince( + const NamespaceString& nss, + ChunkVersion version, + stdx::function<void(OperationContext*, StatusWith<CollectionAndChangedChunks>)> callbackFn) + override; + +private: + ConfigServerCatalogCacheLoader _configServerLoader; +}; + +} // namespace mongo diff --git a/src/mongo/db/s/sharding_initialization_mongod.cpp b/src/mongo/db/s/sharding_initialization_mongod.cpp index d109854769b..50bff361b30 100644 --- a/src/mongo/db/s/sharding_initialization_mongod.cpp +++ b/src/mongo/db/s/sharding_initialization_mongod.cpp @@ -38,6 +38,7 @@ #include "mongo/client/remote_command_targeter_factory_impl.h" #include "mongo/db/logical_time_metadata_hook.h" #include "mongo/db/operation_context.h" +#include "mongo/db/s/read_only_catalog_cache_loader.h" #include "mongo/db/s/shard_server_catalog_cache_loader.h" #include "mongo/db/s/sharding_egress_metadata_hook_for_mongod.h" #include "mongo/db/server_options.h" @@ -88,9 +89,14 @@ Status initializeGlobalShardingStateForMongod(OperationContext* opCtx, stdx::make_unique<ShardFactory>(std::move(buildersMap), std::move(targeterFactory)); if (serverGlobalParams.clusterRole == ClusterRole::ShardServer) { - CatalogCacheLoader::set(opCtx->getServiceContext(), - stdx::make_unique<ShardServerCatalogCacheLoader>( - stdx::make_unique<ConfigServerCatalogCacheLoader>())); + if (storageGlobalParams.readOnly) { + CatalogCacheLoader::set(opCtx->getServiceContext(), + stdx::make_unique<ReadOnlyCatalogCacheLoader>()); + } else { + CatalogCacheLoader::set(opCtx->getServiceContext(), + stdx::make_unique<ShardServerCatalogCacheLoader>( + stdx::make_unique<ConfigServerCatalogCacheLoader>())); + } } else { CatalogCacheLoader::set(opCtx->getServiceContext(), stdx::make_unique<ConfigServerCatalogCacheLoader>()); |