diff options
author | Randolph Tan <randolph@10gen.com> | 2021-05-20 17:40:52 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-06-01 16:01:24 +0000 |
commit | 416886e39cb3aa49dccbb1b26e9fb40583c608c4 (patch) | |
tree | 02f6bee0d9c951be731f1f61b069ec213a4148cf | |
parent | 99b0e4697844265cc430c4045aba2c89882b34d0 (diff) | |
download | mongo-416886e39cb3aa49dccbb1b26e9fb40583c608c4.tar.gz |
SERVER-56890 Use a well typed struct rather than object_owned for presetReshardedChunks in resharding coordinator doc
-rw-r--r-- | src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/s/config/initial_split_policy.h | 1 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/coordinator_document.idl | 2 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/resharding_coordinator_service.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/resharding_coordinator_test.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/s/resharding/resharding_util_test.cpp | 62 | ||||
-rw-r--r-- | src/mongo/db/s/resharding_util.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/s/resharding_util.h | 4 | ||||
-rw-r--r-- | src/mongo/s/SConscript | 1 | ||||
-rw-r--r-- | src/mongo/s/request_types/reshard_collection.idl | 4 | ||||
-rw-r--r-- | src/mongo/s/request_types/sharded_ddl_commands.idl | 2 | ||||
-rw-r--r-- | src/mongo/s/resharded_chunk.idl | 51 | ||||
-rw-r--r-- | src/mongo/s/resharding/common_types.idl | 13 |
13 files changed, 47 insertions, 117 deletions
diff --git a/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp b/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp index cd06fc52a96..5586c71a25d 100644 --- a/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp +++ b/src/mongo/db/s/config/configsvr_reshard_collection_cmd.cpp @@ -95,7 +95,7 @@ public: request().getZones()); } - if (request().get_presetReshardedChunks()) { + if (const auto& presetChunks = request().get_presetReshardedChunks()) { uassert(ErrorCodes::BadValue, "Test commands must be enabled when a value is provided for field: " "_presetReshardedChunks", @@ -105,9 +105,8 @@ public: "Must specify only one of _presetReshardedChunks or numInitialChunks", !(bool(request().getNumInitialChunks()))); - validateReshardedChunks(request().get_presetReshardedChunks().get(), - opCtx, - ShardKeyPattern(request().getKey()).getKeyPattern()); + validateReshardedChunks( + *presetChunks, opCtx, ShardKeyPattern(request().getKey()).getKeyPattern()); } auto instance = ([&] { diff --git a/src/mongo/db/s/config/initial_split_policy.h b/src/mongo/db/s/config/initial_split_policy.h index bcc918ce473..6ba5baa449a 100644 --- a/src/mongo/db/s/config/initial_split_policy.h +++ b/src/mongo/db/s/config/initial_split_policy.h @@ -38,7 +38,6 @@ #include "mongo/db/s/sharding_ddl_50_upgrade_downgrade.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog/type_tags.h" -#include "mongo/s/resharded_chunk_gen.h" #include "mongo/s/shard_id.h" #include "mongo/s/shard_key_pattern.h" #include "mongo/util/string_map.h" diff --git a/src/mongo/db/s/resharding/coordinator_document.idl b/src/mongo/db/s/resharding/coordinator_document.idl index 50b66449d20..543c3216222 100644 --- a/src/mongo/db/s/resharding/coordinator_document.idl +++ b/src/mongo/db/s/resharding/coordinator_document.idl @@ -97,7 +97,7 @@ structs: description: "The number of chunks the new collection should have after resharding." optional: true presetReshardedChunks: - type: array<object_owned> + type: array<ReshardedChunk> description: >- Mapping of chunk ranges to be used as the initial split output. This is only for testing purposes. diff --git a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp index 43f25b7665a..288cc3c52c8 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_service.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_service.cpp @@ -749,12 +749,9 @@ ReshardingCoordinatorExternalStateImpl::calculateParticipantShardsAndChunks( // Use the provided shardIds from presetReshardedChunks to construct the // recipient list. - for (const BSONObj& obj : *chunks) { - recipientShardIds.emplace( - obj.getStringField(ReshardedChunk::kRecipientShardIdFieldName)); + for (const auto& reshardedChunk : *chunks) { + recipientShardIds.emplace(reshardedChunk.getRecipientShardId()); - auto reshardedChunk = - ReshardedChunk::parse(IDLParserErrorContext("ReshardedChunk"), obj); if (version.getTimestamp()) { initialChunks.emplace_back( coordinatorDoc.getReshardingUUID(), diff --git a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp index c557e0bb101..253c97032cb 100644 --- a/src/mongo/db/s/resharding/resharding_coordinator_test.cpp +++ b/src/mongo/db/s/resharding/resharding_coordinator_test.cpp @@ -741,10 +741,9 @@ TEST_F(ReshardingCoordinatorPersistenceTest, WriteInitialInfoSucceeds) { reshardingZoneTypes.push_back(zoneType); } - std::vector<BSONObj> presetBSONChunks; + std::vector<ReshardedChunk> presetBSONChunks; for (const auto& chunk : initialChunks) { - ReshardedChunk reshardChunk(chunk.getShard(), chunk.getMin(), chunk.getMax()); - presetBSONChunks.push_back(reshardChunk.toBSON()); + presetBSONChunks.emplace_back(chunk.getShard(), chunk.getMin(), chunk.getMax()); } // Persist the updates on disk diff --git a/src/mongo/db/s/resharding/resharding_util_test.cpp b/src/mongo/db/s/resharding/resharding_util_test.cpp index f6155fc931b..f73b88dd768 100644 --- a/src/mongo/db/s/resharding/resharding_util_test.cpp +++ b/src/mongo/db/s/resharding/resharding_util_test.cpp @@ -80,14 +80,6 @@ protected: return _nss; } - BSONObj makeReshardedChunk(const ChunkRange range, std::string shardId) { - BSONObjBuilder reshardedchunkBuilder; - reshardedchunkBuilder.append(ReshardedChunk::kRecipientShardIdFieldName, shardId); - reshardedchunkBuilder.append(ReshardedChunk::kMinFieldName, range.getMin()); - reshardedchunkBuilder.append(ReshardedChunk::kMaxFieldName, range.getMax()); - return reshardedchunkBuilder.obj(); - } - ReshardingZoneType makeZone(const ChunkRange range, std::string zoneName) { return ReshardingZoneType(zoneName, range.getMin(), range.getMax()); } @@ -133,64 +125,48 @@ TEST(ReshardingUtilTest, HighestMinFetchTimestampSucceedsWithDonorStateGTkDonati // Validate resharded chunks tests. TEST_F(ReshardingUtilTest, SuccessfulValidateReshardedChunkCase) { - std::vector<mongo::BSONObj> chunks; - const std::vector<ChunkRange> chunkRanges = { - ChunkRange(keyPattern().globalMin(), BSON(shardKey() << 0)), - ChunkRange(BSON(shardKey() << 0), keyPattern().globalMax()), - }; - chunks.push_back(makeReshardedChunk(chunkRanges[0], "a")); - chunks.push_back(makeReshardedChunk(chunkRanges[1], "b")); + std::vector<ReshardedChunk> chunks; + chunks.emplace_back(ShardId("a"), keyPattern().globalMin(), BSON(shardKey() << 0)); + chunks.emplace_back(ShardId("b"), BSON(shardKey() << 0), keyPattern().globalMax()); validateReshardedChunks(chunks, operationContext(), keyPattern()); } TEST_F(ReshardingUtilTest, FailWhenHoleInChunkRange) { - std::vector<mongo::BSONObj> chunks; - const std::vector<ChunkRange> chunkRanges = { - ChunkRange(keyPattern().globalMin(), BSON(shardKey() << 0)), - ChunkRange(BSON(shardKey() << 20), keyPattern().globalMax()), - }; - chunks.push_back(makeReshardedChunk(chunkRanges[0], "a")); - chunks.push_back(makeReshardedChunk(chunkRanges[1], "b")); + std::vector<ReshardedChunk> chunks; + chunks.emplace_back(ShardId("a"), keyPattern().globalMin(), BSON(shardKey() << 0)); + chunks.emplace_back(ShardId("b"), BSON(shardKey() << 20), keyPattern().globalMax()); + ASSERT_THROWS_CODE(validateReshardedChunks(chunks, operationContext(), keyPattern()), DBException, ErrorCodes::BadValue); } TEST_F(ReshardingUtilTest, FailWhenOverlapInChunkRange) { - const std::vector<ChunkRange> overlapChunkRanges = { - ChunkRange(keyPattern().globalMin(), BSON(shardKey() << 10)), - ChunkRange(BSON(shardKey() << 5), keyPattern().globalMax()), - }; - std::vector<mongo::BSONObj> chunks; - chunks.push_back(makeReshardedChunk(overlapChunkRanges[0], "a")); - chunks.push_back(makeReshardedChunk(overlapChunkRanges[1], "b")); + std::vector<ReshardedChunk> chunks; + chunks.emplace_back(ShardId("a"), keyPattern().globalMin(), BSON(shardKey() << 10)); + chunks.emplace_back(ShardId("b"), BSON(shardKey() << 5), keyPattern().globalMax()); + ASSERT_THROWS_CODE(validateReshardedChunks(chunks, operationContext(), keyPattern()), DBException, ErrorCodes::BadValue); } TEST_F(ReshardingUtilTest, FailWhenChunkRangeDoesNotStartAtGlobalMin) { - std::vector<mongo::BSONObj> chunks; - const std::vector<ChunkRange> chunkRanges = { - ChunkRange(BSON(shardKey() << 10), BSON(shardKey() << 20)), - ChunkRange(BSON(shardKey() << 20), keyPattern().globalMax()), - }; - chunks.push_back(makeReshardedChunk(chunkRanges[0], "a")); - chunks.push_back(makeReshardedChunk(chunkRanges[1], "b")); + std::vector<ReshardedChunk> chunks; + + chunks.emplace_back(ShardId("a"), BSON(shardKey() << 10), BSON(shardKey() << 20)); + chunks.emplace_back(ShardId("b"), BSON(shardKey() << 20), keyPattern().globalMax()); + ASSERT_THROWS_CODE(validateReshardedChunks(chunks, operationContext(), keyPattern()), DBException, ErrorCodes::BadValue); } TEST_F(ReshardingUtilTest, FailWhenChunkRangeDoesNotEndAtGlobalMax) { - std::vector<mongo::BSONObj> chunks; - const std::vector<ChunkRange> chunkRanges = { - ChunkRange(keyPattern().globalMin(), BSON(shardKey() << 0)), - ChunkRange(BSON(shardKey() << 0), BSON(shardKey() << 10)), - }; - chunks.push_back(makeReshardedChunk(chunkRanges[0], "a")); - chunks.push_back(makeReshardedChunk(chunkRanges[1], "b")); + std::vector<ReshardedChunk> chunks; + chunks.emplace_back(ShardId("a"), keyPattern().globalMin(), BSON(shardKey() << 0)); + chunks.emplace_back(ShardId("b"), BSON(shardKey() << 0), BSON(shardKey() << 10)); ASSERT_THROWS_CODE(validateReshardedChunks(chunks, operationContext(), keyPattern()), DBException, diff --git a/src/mongo/db/s/resharding_util.cpp b/src/mongo/db/s/resharding_util.cpp index 03327180339..c53b2cffcaa 100644 --- a/src/mongo/db/s/resharding_util.cpp +++ b/src/mongo/db/s/resharding_util.cpp @@ -168,12 +168,11 @@ void checkForHolesAndOverlapsInChunks(std::vector<ReshardedChunk>& chunks, } } -void validateReshardedChunks(const std::vector<mongo::BSONObj>& chunks, +void validateReshardedChunks(const std::vector<ReshardedChunk>& chunks, OperationContext* opCtx, const KeyPattern& keyPattern) { std::vector<ReshardedChunk> validChunks; - for (const BSONObj& obj : chunks) { - auto chunk = ReshardedChunk::parse(IDLParserErrorContext("reshardedChunks"), obj); + for (const auto& chunk : chunks) { uassertStatusOK( Grid::get(opCtx)->shardRegistry()->getShard(opCtx, chunk.getRecipientShardId())); validChunks.push_back(chunk); diff --git a/src/mongo/db/s/resharding_util.h b/src/mongo/db/s/resharding_util.h index 095a7c22349..0a4f792db5f 100644 --- a/src/mongo/db/s/resharding_util.h +++ b/src/mongo/db/s/resharding_util.h @@ -44,7 +44,7 @@ #include "mongo/executor/task_executor.h" #include "mongo/s/catalog/type_tags.h" #include "mongo/s/chunk_manager.h" -#include "mongo/s/resharded_chunk_gen.h" +#include "mongo/s/resharding/common_types_gen.h" #include "mongo/s/shard_id.h" #include "mongo/s/write_ops/batched_command_request.h" @@ -236,7 +236,7 @@ void checkForHolesAndOverlapsInChunks(std::vector<ReshardedChunk>& chunks, * ReshardedChunk and asserts that each chunk's shardId is associated with an existing entry in * the shardRegistry. Then, asserts that there is not a hole or overlap in the chunks. */ -void validateReshardedChunks(const std::vector<mongo::BSONObj>& chunks, +void validateReshardedChunks(const std::vector<ReshardedChunk>& chunks, OperationContext* opCtx, const KeyPattern& keyPattern); diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index 43989441b00..eaa47847456 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -178,7 +178,6 @@ env.Library( 'request_types/split_chunk_request_type.cpp', 'request_types/update_zone_key_range_request_type.cpp', 'request_types/wait_for_fail_point.idl', - 'resharded_chunk.idl', 'resharding/common_types.idl', 'resharding/resharding_feature_flag.idl', 'resharding/resume_token.idl', diff --git a/src/mongo/s/request_types/reshard_collection.idl b/src/mongo/s/request_types/reshard_collection.idl index 09afc405794..2b8abe56d44 100644 --- a/src/mongo/s/request_types/reshard_collection.idl +++ b/src/mongo/s/request_types/reshard_collection.idl @@ -65,7 +65,7 @@ commands: description: "The zones for the new shard key." optional: true _presetReshardedChunks: - type: array<object> + type: array<ReshardedChunk> description: "Mapping of chunk ranges. This is only for testing purposes." optional: true @@ -99,7 +99,7 @@ commands: description: "The zones associated with the new shard key." optional: true _presetReshardedChunks: - type: array<object> + type: array<ReshardedChunk> description: >- "Mapping of chunk ranges to be used as the initial split output. This is only for testing purposes." diff --git a/src/mongo/s/request_types/sharded_ddl_commands.idl b/src/mongo/s/request_types/sharded_ddl_commands.idl index ebe22f7079f..81d2950189c 100644 --- a/src/mongo/s/request_types/sharded_ddl_commands.idl +++ b/src/mongo/s/request_types/sharded_ddl_commands.idl @@ -230,7 +230,7 @@ commands: description: "The zones associated with the new shard key." optional: true _presetReshardedChunks: - type: array<object> + type: array<ReshardedChunk> description: >- "Mapping of chunk ranges to be used as the initial split output. This is only for testing purposes." diff --git a/src/mongo/s/resharded_chunk.idl b/src/mongo/s/resharded_chunk.idl deleted file mode 100644 index 9cc42613d36..00000000000 --- a/src/mongo/s/resharded_chunk.idl +++ /dev/null @@ -1,51 +0,0 @@ -# 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. -# - -# ReshardedChunk IDL File - -global: - cpp_namespace: "mongo" - -imports: - - "mongo/idl/basic_types.idl" - - "mongo/s/sharding_types.idl" - -structs: - ReshardedChunk: - description: "ReshardedChunk" - fields: - recipientShardId: - type: shard_id - description: "The id of the recipient shard." - min: - type: object_owned - description: "The min key of the chunk range." - max: - type: object_owned - description: "The max key of the chunk range." - diff --git a/src/mongo/s/resharding/common_types.idl b/src/mongo/s/resharding/common_types.idl index 55782b11049..86cf678e49b 100644 --- a/src/mongo/s/resharding/common_types.idl +++ b/src/mongo/s/resharding/common_types.idl @@ -235,3 +235,16 @@ structs: max: type: object_owned description: "The max key of the chunk range assigned to the zone." + + ReshardedChunk: + description: "ReshardedChunk" + fields: + recipientShardId: + type: shard_id + description: "The id of the recipient shard." + min: + type: object_owned + description: "The min key of the chunk range." + max: + type: object_owned + description: "The max key of the chunk range." |