diff options
author | Paolo Polato <paolo.polato@mongodb.com> | 2022-08-18 12:36:28 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-08-18 13:55:33 +0000 |
commit | 4a21dc8db7343c74ea17c30df2911601ed430e12 (patch) | |
tree | c7569bc69eb39f3e356d1912f8d208457c908578 | |
parent | 6c381c901f1546d4514d81e17318b12dcb0a264e (diff) | |
download | mongo-4a21dc8db7343c74ea17c30df2911601ed430e12.tar.gz |
SERVER-68642 add config.placementHistory collection to sharding catalog
-rw-r--r-- | src/mongo/db/namespace_string.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.h | 3 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager.cpp | 14 | ||||
-rw-r--r-- | src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp | 15 | ||||
-rw-r--r-- | src/mongo/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_namespace_placement.idl | 57 |
6 files changed, 93 insertions, 0 deletions
diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp index b6c95f10c6b..6478ea29580 100644 --- a/src/mongo/db/namespace_string.cpp +++ b/src/mongo/db/namespace_string.cpp @@ -179,6 +179,9 @@ const NamespaceString NamespaceString::kShardIndexCatalogNamespace(NamespaceStri const NamespaceString NamespaceString::kShardCollectionCatalogNamespace(NamespaceString::kConfigDb, "shard.collections"); +const NamespaceString NamespaceString::kConfigsvrPlacementHistoryNamespace( + NamespaceString::kConfigDb, "placementHistory"); + const NamespaceString NamespaceString::kLockpingsNamespace(NamespaceString::kConfigDb, "lockpings"); const NamespaceString NamespaceString::kDistLocksNamepsace(NamespaceString::kConfigDb, "locks"); diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index 20d2403bb65..166bdf6dd1b 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -239,6 +239,9 @@ public: // Namespace used for storing the collection catalog on the shards. static const NamespaceString kShardCollectionCatalogNamespace; + // Namespace used for storing NamespacePlacementType docs on the CSRS. + static const NamespaceString kConfigsvrPlacementHistoryNamespace; + // TODO SERVER-68551: remove once 7.0 becomes last-lts static const NamespaceString kLockpingsNamespace; diff --git a/src/mongo/db/s/config/sharding_catalog_manager.cpp b/src/mongo/db/s/config/sharding_catalog_manager.cpp index b3fdbfc5c47..753942782ba 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager.cpp @@ -52,6 +52,7 @@ #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog/type_collection.h" #include "mongo/s/catalog/type_config_version.h" +#include "mongo/s/catalog/type_namespace_placement_gen.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog/type_tags.h" #include "mongo/s/client/shard_registry.h" @@ -456,6 +457,19 @@ Status ShardingCatalogManager::_initConfigIndexes(OperationContext* opCtx) { } } + if (feature_flags::gHistoricalPlacementShardingCatalog.isEnabled( + serverGlobalParams.featureCompatibility)) { + result = createIndexOnConfigCollection( + opCtx, + NamespaceString::kConfigsvrPlacementHistoryNamespace, + BSON(NamespacePlacementType::kNssFieldName + << 1 << NamespacePlacementType::kTimestampFieldName << 1), + unique); + if (!result.isOK()) { + return result; + } + } + return Status::OK(); } diff --git a/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp b/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp index 45a59e46b4c..1a54a370f43 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_config_initialization_test.cpp @@ -48,6 +48,7 @@ #include "mongo/s/catalog/type_shard.h" #include "mongo/s/catalog/type_tags.h" #include "mongo/s/client/shard.h" +#include "mongo/s/sharding_feature_flags_gen.h" #include "mongo/util/scopeguard.h" namespace mongo { @@ -303,6 +304,20 @@ TEST_F(ConfigInitializationTest, BuildsNecessaryIndexes) { auto foundTagsIndexes = assertGet(getIndexes(operationContext(), TagsType::ConfigNS)); assertBSONObjsSame(expectedTagsIndexes, foundTagsIndexes); + + if (feature_flags::gHistoricalPlacementShardingCatalog.isEnabled( + serverGlobalParams.featureCompatibility)) { + auto expectedPlacementHistoryIndexes = + std::vector<BSONObj>{BSON("v" << 2 << "key" << BSON("_id" << 1) << "name" + << "_id_"), + BSON("v" << 2 << "unique" << true << "key" + << BSON("nss" << 1 << "timestamp" << 1) << "name" + << "nss_1_timestamp_1")}; + + auto foundlacementHistoryIndexes = assertGet( + getIndexes(operationContext(), NamespaceString::kConfigsvrPlacementHistoryNamespace)); + assertBSONObjsSame(expectedPlacementHistoryIndexes, foundlacementHistoryIndexes); + } } } // unnamed namespace diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index 3f521841d3a..53ab148853c 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -146,6 +146,7 @@ env.Library( 'catalog/type_database.idl', 'catalog/type_index_catalog.idl', 'catalog/type_mongos.cpp', + 'catalog/type_namespace_placement.idl', 'catalog/type_shard.cpp', 'catalog/type_tags.cpp', 'chunk_version.cpp', diff --git a/src/mongo/s/catalog/type_namespace_placement.idl b/src/mongo/s/catalog/type_namespace_placement.idl new file mode 100644 index 00000000000..e6bcc4fab6f --- /dev/null +++ b/src/mongo/s/catalog/type_namespace_placement.idl @@ -0,0 +1,57 @@ +# Copyright(C) 2022 - 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. +# + +global: + cpp_namespace: "mongo" + +imports: + - "mongo/idl/basic_types.idl" + - "mongo/s/sharding_types.idl" + + +structs: + NamespacePlacementType: + description: "Represents the layout and contents of documents contained in the + config.placementHistory collection. + Each document encodes placement information (at shard granularity) on a given + namespace at a specific point in time." + strict: false + fields: + nss: + type: namespacestring + description: "The namespace (database or full collection name) + referenced by this object." + timestamp: + type: timestamp + description: "The point in time at which this version of NamespacePlacementType + for 'nss' has been generated." + shards: + type: array<shard_id> + description: "The list of shard IDs containing one of more chunks of 'nss' + at time 'timestamp' (may be empty)." + |