diff options
author | Blake Oler <blake.oler@mongodb.com> | 2020-08-03 19:32:00 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-05 13:38:16 +0000 |
commit | a0345214d33cbc02ff9f1587d4b74757217cd8d7 (patch) | |
tree | d336cd5069729e0475650956d38bb7af396ec735 | |
parent | 2fdb9c36748c3206914a3c6ca23720ce7cc75317 (diff) | |
download | mongo-a0345214d33cbc02ff9f1587d4b74757217cd8d7.tar.gz |
SERVER-49561 Add resharding fields to config.collections
-rw-r--r-- | src/mongo/db/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/coordinator_document.idl | 2 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/donor_document.idl | 2 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/recipient_document.idl | 2 | ||||
-rw-r--r-- | src/mongo/s/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_collection.cpp | 18 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_collection.h | 30 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_collection_test.cpp | 10 | ||||
-rw-r--r-- | src/mongo/s/resharding/common_types.idl (renamed from src/mongo/db/s/resharding/common_types.idl) | 0 | ||||
-rw-r--r-- | src/mongo/s/resharding/type_collection_fields.idl | 68 | ||||
-rw-r--r-- | src/mongo/util/uuid.h | 1 |
11 files changed, 131 insertions, 5 deletions
diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 1299619916c..12904d41747 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -87,7 +87,6 @@ env.Library( 'start_chunk_clone_request.cpp', env.Idlc('migration_coordinator_document.idl')[0], env.Idlc('range_deletion_task.idl')[0], - env.Idlc('resharding/common_types.idl')[0], env.Idlc('resharding/coordinator_document.idl')[0], env.Idlc('resharding/donor_document.idl')[0], env.Idlc('resharding/recipient_document.idl')[0], diff --git a/src/mongo/db/s/resharding/coordinator_document.idl b/src/mongo/db/s/resharding/coordinator_document.idl index e1c97b1760f..761e55fb6b2 100644 --- a/src/mongo/db/s/resharding/coordinator_document.idl +++ b/src/mongo/db/s/resharding/coordinator_document.idl @@ -33,7 +33,7 @@ global: cpp_namespace: "mongo" imports: - - "mongo/db/s/resharding/common_types.idl" + - "mongo/s/resharding/common_types.idl" structs: DonorShardEntry: diff --git a/src/mongo/db/s/resharding/donor_document.idl b/src/mongo/db/s/resharding/donor_document.idl index 7716c7a77f8..7febc85192b 100644 --- a/src/mongo/db/s/resharding/donor_document.idl +++ b/src/mongo/db/s/resharding/donor_document.idl @@ -33,7 +33,7 @@ global: cpp_namespace: "mongo" imports: - - "mongo/db/s/resharding/common_types.idl" + - "mongo/s/resharding/common_types.idl" structs: ReshardingDonorDocument: diff --git a/src/mongo/db/s/resharding/recipient_document.idl b/src/mongo/db/s/resharding/recipient_document.idl index f3946c5cf1b..3040f2ad681 100644 --- a/src/mongo/db/s/resharding/recipient_document.idl +++ b/src/mongo/db/s/resharding/recipient_document.idl @@ -33,7 +33,7 @@ global: cpp_namespace: "mongo" imports: - - "mongo/db/s/resharding/common_types.idl" + - "mongo/s/resharding/common_types.idl" structs: DonorShardMirroringEntry: diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index 70400e57ed0..89b1572754d 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -181,6 +181,8 @@ env.Library( env.Idlc('request_types/reshard_collection.idl')[0], env.Idlc('resharded_chunk.idl')[0], env.Idlc('request_types/wait_for_fail_point.idl')[0], + env.Idlc('resharding/common_types.idl')[0], + env.Idlc('resharding/type_collection_fields.idl')[0], ], LIBDEPS=[ '$BUILD_DIR/mongo/client/connection_string', diff --git a/src/mongo/s/catalog/type_collection.cpp b/src/mongo/s/catalog/type_collection.cpp index 3ff95150dfc..0141ecdc4a7 100644 --- a/src/mongo/s/catalog/type_collection.cpp +++ b/src/mongo/s/catalog/type_collection.cpp @@ -56,6 +56,7 @@ const BSONField<BSONObj> CollectionType::defaultCollation("defaultCollation"); const BSONField<bool> CollectionType::unique("unique"); const BSONField<UUID> CollectionType::uuid("uuid"); const BSONField<std::string> CollectionType::distributionMode("distributionMode"); +const BSONField<ReshardingFields> CollectionType::reshardingFields("reshardingFields"); StatusWith<CollectionType> CollectionType::fromBSON(const BSONObj& source) { CollectionType coll; @@ -200,6 +201,15 @@ StatusWith<CollectionType> CollectionType::fromBSON(const BSONObj& source) { } } + { + const auto reshardingFieldsElem = source.getField(reshardingFields.name()); + if (reshardingFieldsElem) { + coll._reshardingFields = + ReshardingFields::parse(IDLParserErrorContext("TypeCollectionReshardingFields"), + reshardingFieldsElem.Obj()); + } + } + return StatusWith<CollectionType>(coll); } @@ -283,6 +293,10 @@ BSONObj CollectionType::toBSON() const { } } + if (_reshardingFields) { + builder.append(reshardingFields.name(), _reshardingFields->toBSON()); + } + return builder.obj(); } @@ -308,6 +322,10 @@ void CollectionType::setKeyPattern(const KeyPattern& keyPattern) { _keyPattern = keyPattern; } +void CollectionType::setReshardingFields(const ReshardingFields& reshardingFields) { + _reshardingFields = reshardingFields; +} + bool CollectionType::hasSameOptions(const CollectionType& other) const { // The relevant options must have been set on this CollectionType. invariant(_fullNs && _keyPattern && _unique); diff --git a/src/mongo/s/catalog/type_collection.h b/src/mongo/s/catalog/type_collection.h index dd40380453f..47190ee216a 100644 --- a/src/mongo/s/catalog/type_collection.h +++ b/src/mongo/s/catalog/type_collection.h @@ -35,6 +35,7 @@ #include "mongo/db/jsobj.h" #include "mongo/db/keypattern.h" #include "mongo/db/namespace_string.h" +#include "mongo/s/resharding/type_collection_fields_gen.h" #include "mongo/util/uuid.h" namespace mongo { @@ -43,6 +44,7 @@ class Status; template <typename T> class StatusWith; +using ReshardingFields = TypeCollectionReshardingFields; /** * This class represents the layout and contents of documents contained in the config server's @@ -65,6 +67,24 @@ class StatusWith; * "uuid" : UUID, * "noBalance" : false, * "distributionMode" : "unsharded|sharded", + * // Only populated if the collection is currently undergoing a resharding operation. + * "reshardingFields" : { + * "uuid" : UUID, + * "state" : CoordinatorState<kInitialized>, + * // Only populated if the collection is currently undergoing a resharding operation, + * // and this collection is the original sharded collection. + * "donorFields" : { + * "reshardingKey" : { + * "_notTheID" : 1 + * } + * }, + * // Only populated if this collection is the temporary resharding collection in a + * // resharding operation. + * "recipientFields" : { + * "fetchTimestamp" : Timestamp(3, 4), + * "originalNamespace" : "foo.bar", + * } + * } * } * */ @@ -81,6 +101,7 @@ public: static const BSONField<bool> unique; static const BSONField<UUID> uuid; static const BSONField<std::string> distributionMode; + static const BSONField<ReshardingFields> reshardingFields; /** * Constructs a new CollectionType object from BSON. Also does validation of the contents. @@ -173,6 +194,12 @@ public: return _distributionMode.get_value_or(DistributionMode::kSharded); } + void setReshardingFields(const ReshardingFields& reshardingFields); + + boost::optional<ReshardingFields> getReshardingFields() const { + return _reshardingFields; + } + bool hasSameOptions(const CollectionType& other) const; private: @@ -206,6 +233,9 @@ private: // Optional whether balancing is allowed for this collection. If missing, implies true. boost::optional<bool> _allowBalance; + + // Fields on the collection entry specific to resharding. + boost::optional<ReshardingFields> _reshardingFields; }; } // namespace mongo diff --git a/src/mongo/s/catalog/type_collection_test.cpp b/src/mongo/s/catalog/type_collection_test.cpp index 9b4c9367cb3..92b70442e9c 100644 --- a/src/mongo/s/catalog/type_collection_test.cpp +++ b/src/mongo/s/catalog/type_collection_test.cpp @@ -74,13 +74,19 @@ TEST(CollectionType, Basic) { TEST(CollectionType, AllFieldsPresent) { const OID oid = OID::gen(); const auto uuid = UUID::gen(); + const auto reshardingUuid = UUID::gen(); + + ReshardingFields reshardingFields; + reshardingFields.setUuid(reshardingUuid); + StatusWith<CollectionType> status = CollectionType::fromBSON(BSON( CollectionType::fullNs("db.coll") << CollectionType::epoch(oid) << CollectionType::updatedAt(Date_t::fromMillisSinceEpoch(1)) << CollectionType::keyPattern(BSON("a" << 1)) << CollectionType::defaultCollation(BSON("locale" << "fr_CA")) - << CollectionType::unique(true) << CollectionType::uuid() << uuid)); + << CollectionType::unique(true) << CollectionType::uuid() << uuid + << CollectionType::reshardingFields() << reshardingFields.toBSON())); ASSERT_TRUE(status.isOK()); CollectionType coll = status.getValue(); @@ -97,6 +103,8 @@ TEST(CollectionType, AllFieldsPresent) { ASSERT_EQUALS(coll.getDropped(), false); ASSERT_TRUE(coll.getUUID()); ASSERT_EQUALS(*coll.getUUID(), uuid); + ASSERT(coll.getReshardingFields()->getState() == CoordinatorStateEnum::kUnused); + ASSERT(coll.getReshardingFields()->getUuid() == reshardingUuid); } TEST(CollectionType, EmptyDefaultCollationFailsToParse) { diff --git a/src/mongo/db/s/resharding/common_types.idl b/src/mongo/s/resharding/common_types.idl index 6eed708138e..6eed708138e 100644 --- a/src/mongo/db/s/resharding/common_types.idl +++ b/src/mongo/s/resharding/common_types.idl diff --git a/src/mongo/s/resharding/type_collection_fields.idl b/src/mongo/s/resharding/type_collection_fields.idl new file mode 100644 index 00000000000..460a2111d35 --- /dev/null +++ b/src/mongo/s/resharding/type_collection_fields.idl @@ -0,0 +1,68 @@ +# 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. +# + +# This file defines the format of resharding-related fields stored in a config.collections entry. + +global: + cpp_namespace: "mongo" + +imports: + - "mongo/db/keypattern.idl" + - "mongo/s/resharding/common_types.idl" + +structs: + TypeCollectionDonorFields: + description: "Resharding-related fields specific to donor shards." + fields: + reshardingKey: + type: KeyPattern + + TypeCollectionRecipientFields: + description: "Resharding-related fields specific to recipient shards." + inline_chained_structs: true + chained_structs: + FetchTimestamp: FetchTimestampStruct + fields: + originalNamespace: + type: namespacestring + + TypeCollectionReshardingFields: + description: "Resharding-related fields meant to be stored in a config.collections + document." + fields: + uuid: + type: uuid + state: + type: CoordinatorState + default: kUnused + donorFields: + type: TypeCollectionDonorFields + optional: true + recipientFields: + type: TypeCollectionRecipientFields + optional: true diff --git a/src/mongo/util/uuid.h b/src/mongo/util/uuid.h index 4330eee758e..c5abb1cad7f 100644 --- a/src/mongo/util/uuid.h +++ b/src/mongo/util/uuid.h @@ -95,6 +95,7 @@ class UUID { friend class ShardsvrRenameCollection; friend class TenantMigrationDonorDocument; friend class TenantMigrationRecipientDocument; + friend class TypeCollectionReshardingFields; friend class VoteCommitIndexBuild; |