diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2020-08-14 10:40:41 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-17 15:09:49 +0000 |
commit | faf14d0009c5a39cf8acdffcf6473262e1759381 (patch) | |
tree | 07e0735b1bf919b9744973843560919f556b5bcd /src/mongo/db/s | |
parent | ea3f3e8f52087187992beb371ffd778a298f950c (diff) | |
download | mongo-faf14d0009c5a39cf8acdffcf6473262e1759381.tar.gz |
SERVER-50329 Make ChunkManager be passed by value everywhere
... instead of shared_ptr.
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r-- | src/mongo/db/s/balancer/balancer.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp | 30 | ||||
-rw-r--r-- | src/mongo/db/s/collection_metadata.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/s/collection_metadata.h | 12 | ||||
-rw-r--r-- | src/mongo/db/s/collection_metadata_filtering_test.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/s/collection_metadata_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime_test.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/s/metadata_manager.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/s/metadata_manager_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/s/op_observer_sharding_test.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/s/range_deletion_util_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/s/shard_filtering_metadata_refresh.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/s/shard_key_util.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/shard_key_util.h | 2 |
15 files changed, 48 insertions, 56 deletions
diff --git a/src/mongo/db/s/balancer/balancer.cpp b/src/mongo/db/s/balancer/balancer.cpp index d7b6dc884bc..d91670c60d8 100644 --- a/src/mongo/db/s/balancer/balancer.cpp +++ b/src/mongo/db/s/balancer/balancer.cpp @@ -703,8 +703,7 @@ void Balancer::_splitOrMarkJumbo(OperationContext* opCtx, const BSONObj& minKey) { auto routingInfo = uassertStatusOK( Grid::get(opCtx)->catalogCache()->getShardedCollectionRoutingInfoWithRefresh(opCtx, nss)); - const auto cm = routingInfo.cm().get(); - + const auto cm = routingInfo.cm(); auto chunk = cm->findIntersectingChunkWithSimpleCollation(minKey); try { diff --git a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp index 61cf7e2525c..e41e0f977f1 100644 --- a/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp +++ b/src/mongo/db/s/balancer/balancer_chunk_selection_policy_impl.cpp @@ -65,7 +65,7 @@ namespace { * distribution and chunk placement information which is needed by the balancer policy. */ StatusWith<DistributionStatus> createCollectionDistributionStatus( - OperationContext* opCtx, const ShardStatisticsVector& allShards, ChunkManager* chunkMgr) { + OperationContext* opCtx, const ShardStatisticsVector& allShards, const ChunkManager& chunkMgr) { ShardToChunksMap shardToChunksMap; // Makes sure there is an entry in shardToChunksMap for every shard, so empty shards will also @@ -74,9 +74,9 @@ StatusWith<DistributionStatus> createCollectionDistributionStatus( shardToChunksMap[stat.shardId]; } - chunkMgr->forEachChunk([&](const auto& chunkEntry) { + chunkMgr.forEachChunk([&](const auto& chunkEntry) { ChunkType chunk; - chunk.setNS(chunkMgr->getns()); + chunk.setNS(chunkMgr.getns()); chunk.setMin(chunkEntry.getMin()); chunk.setMax(chunkEntry.getMax()); chunk.setJumbo(chunkEntry.isJumbo()); @@ -89,17 +89,17 @@ StatusWith<DistributionStatus> createCollectionDistributionStatus( }); const auto swCollectionTags = - Grid::get(opCtx)->catalogClient()->getTagsForCollection(opCtx, chunkMgr->getns()); + Grid::get(opCtx)->catalogClient()->getTagsForCollection(opCtx, chunkMgr.getns()); if (!swCollectionTags.isOK()) { return swCollectionTags.getStatus().withContext( - str::stream() << "Unable to load tags for collection " << chunkMgr->getns().ns()); + str::stream() << "Unable to load tags for collection " << chunkMgr.getns()); } const auto& collectionTags = swCollectionTags.getValue(); - DistributionStatus distribution(chunkMgr->getns(), std::move(shardToChunksMap)); + DistributionStatus distribution(chunkMgr.getns(), std::move(shardToChunksMap)); // Cache the collection tags - const auto& keyPattern = chunkMgr->getShardKeyPattern().getKeyPattern(); + const auto& keyPattern = chunkMgr.getShardKeyPattern().getKeyPattern(); for (const auto& tag : collectionTags) { auto status = distribution.addRangeToZone( @@ -465,9 +465,9 @@ BalancerChunkSelectionPolicyImpl::selectSpecificChunkToMove(OperationContext* op return routingInfoStatus.getStatus(); } - const auto cm = routingInfoStatus.getValue().cm().get(); + const auto cm = routingInfoStatus.getValue().cm(); - const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, cm); + const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, *cm); if (!collInfoStatus.isOK()) { return collInfoStatus.getStatus(); } @@ -494,9 +494,9 @@ Status BalancerChunkSelectionPolicyImpl::checkMoveAllowed(OperationContext* opCt return routingInfoStatus.getStatus(); } - const auto cm = routingInfoStatus.getValue().cm().get(); + const auto cm = routingInfoStatus.getValue().cm(); - const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, cm); + const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, *cm); if (!collInfoStatus.isOK()) { return collInfoStatus.getStatus(); } @@ -527,9 +527,9 @@ StatusWith<SplitInfoVector> BalancerChunkSelectionPolicyImpl::_getSplitCandidate return routingInfoStatus.getStatus(); } - const auto cm = routingInfoStatus.getValue().cm().get(); + const auto cm = routingInfoStatus.getValue().cm(); - const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, cm); + const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, *cm); if (!collInfoStatus.isOK()) { return collInfoStatus.getStatus(); } @@ -565,11 +565,11 @@ StatusWith<MigrateInfoVector> BalancerChunkSelectionPolicyImpl::_getMigrateCandi return routingInfoStatus.getStatus(); } - const auto cm = routingInfoStatus.getValue().cm().get(); + const auto cm = routingInfoStatus.getValue().cm(); const auto& shardKeyPattern = cm->getShardKeyPattern().getKeyPattern(); - const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, cm); + const auto collInfoStatus = createCollectionDistributionStatus(opCtx, shardStats, *cm); if (!collInfoStatus.isOK()) { return collInfoStatus.getStatus(); } diff --git a/src/mongo/db/s/collection_metadata.cpp b/src/mongo/db/s/collection_metadata.cpp index 984fa6a1059..ccb0a5a4050 100644 --- a/src/mongo/db/s/collection_metadata.cpp +++ b/src/mongo/db/s/collection_metadata.cpp @@ -33,8 +33,6 @@ #include "mongo/db/s/collection_metadata.h" -#include <memory> - #include "mongo/bson/simple_bsonobj_comparator.h" #include "mongo/bson/util/builder.h" #include "mongo/db/bson/dotted_path_support.h" @@ -43,7 +41,7 @@ namespace mongo { -CollectionMetadata::CollectionMetadata(std::shared_ptr<ChunkManager> cm, const ShardId& thisShardId) +CollectionMetadata::CollectionMetadata(ChunkManager cm, const ShardId& thisShardId) : _cm(std::move(cm)), _thisShardId(thisShardId) {} BSONObj CollectionMetadata::extractDocumentKey(const BSONObj& doc) const { diff --git a/src/mongo/db/s/collection_metadata.h b/src/mongo/db/s/collection_metadata.h index 792dbb208b0..5ac597eaa95 100644 --- a/src/mongo/db/s/collection_metadata.h +++ b/src/mongo/db/s/collection_metadata.h @@ -60,7 +60,7 @@ public: * "thisShardId" is the shard identity of this shard for purposes of answering questions like * "does this key belong to this shard"? */ - CollectionMetadata(std::shared_ptr<ChunkManager> cm, const ShardId& thisShardId); + CollectionMetadata(ChunkManager cm, const ShardId& thisShardId); /** * Returns whether this metadata object represents a sharded or unsharded collection. @@ -158,9 +158,9 @@ public: // Methods used for orphan filtering and general introspection of the chunks owned by the shard // - ChunkManager* getChunkManager() const { + const ChunkManager* getChunkManager() const { invariant(isSharded()); - return _cm.get(); + return _cm.get_ptr(); } /** @@ -225,11 +225,11 @@ public: void toBSONChunks(BSONArrayBuilder* builder) const; private: - // The full routing table for the collection or nullptr if the collection is not sharded - std::shared_ptr<ChunkManager> _cm; + // The full routing table for the collection or boost::none if the collection is not sharded + boost::optional<ChunkManager> _cm; // The identity of this shard, for the purpose of answering "key belongs to me" queries. If the - // collection is not sharded (_cm is nullptr), then this value will be empty. + // collection is not sharded (_cm is boost::none), then this value will be empty. ShardId _thisShardId; }; diff --git a/src/mongo/db/s/collection_metadata_filtering_test.cpp b/src/mongo/db/s/collection_metadata_filtering_test.cpp index ebb0d564bea..c275530b384 100644 --- a/src/mongo/db/s/collection_metadata_filtering_test.cpp +++ b/src/mongo/db/s/collection_metadata_filtering_test.cpp @@ -96,8 +96,8 @@ protected: return std::vector<ChunkType>{chunk1, chunk2, chunk3, chunk4}; }()); - auto cm = std::make_shared<ChunkManager>(rt, boost::none); - ASSERT_EQ(4, cm->numChunks()); + ChunkManager cm(rt, boost::none); + ASSERT_EQ(4, cm.numChunks()); { AutoGetCollection autoColl(operationContext(), kNss, MODE_X); @@ -109,7 +109,7 @@ protected: getServiceContext(), kNss, executor(), CollectionMetadata(cm, ShardId("0"))); auto& oss = OperationShardingState::get(operationContext()); - const auto version = cm->getVersion(ShardId("0")); + const auto version = cm.getVersion(ShardId("0")); BSONObjBuilder builder; version.appendToCommand(&builder); oss.initializeClientRoutingVersionsFromCommand(kNss, builder.obj()); diff --git a/src/mongo/db/s/collection_metadata_test.cpp b/src/mongo/db/s/collection_metadata_test.cpp index 035bd4777f8..eaa5d5bcf79 100644 --- a/src/mongo/db/s/collection_metadata_test.cpp +++ b/src/mongo/db/s/collection_metadata_test.cpp @@ -82,8 +82,7 @@ std::unique_ptr<CollectionMetadata> makeCollectionMetadataImpl( UUID uuid(UUID::gen()); auto rt = RoutingTableHistory::makeNew(kNss, uuid, shardKeyPattern, nullptr, false, epoch, allChunks); - std::shared_ptr<ChunkManager> cm = std::make_shared<ChunkManager>(rt, kChunkManager); - return std::make_unique<CollectionMetadata>(cm, kThisShard); + return std::make_unique<CollectionMetadata>(ChunkManager(rt, kChunkManager), kThisShard); } struct ConstructedRangeMap : public RangeMap { diff --git a/src/mongo/db/s/collection_sharding_runtime_test.cpp b/src/mongo/db/s/collection_sharding_runtime_test.cpp index 71ea4afab44..58415ae97eb 100644 --- a/src/mongo/db/s/collection_sharding_runtime_test.cpp +++ b/src/mongo/db/s/collection_sharding_runtime_test.cpp @@ -51,12 +51,13 @@ CollectionMetadata makeShardedMetadata(OperationContext* opCtx, UUID uuid = UUID const OID epoch = OID::gen(); auto range = ChunkRange(BSON(kShardKey << MINKEY), BSON(kShardKey << MAXKEY)); auto chunk = ChunkType(kTestNss, std::move(range), ChunkVersion(1, 0, epoch), ShardId("other")); - auto rt = RoutingTableHistory::makeNew( - kTestNss, uuid, kShardKeyPattern, nullptr, false, epoch, {std::move(chunk)}); - std::shared_ptr<ChunkManager> cm = std::make_shared<ChunkManager>(rt, boost::none); + ChunkManager cm( + RoutingTableHistory::makeNew( + kTestNss, uuid, kShardKeyPattern, nullptr, false, epoch, {std::move(chunk)}), + boost::none); if (!OperationShardingState::isOperationVersioned(opCtx)) { - const auto version = cm->getVersion(ShardId("0")); + const auto version = cm.getVersion(ShardId("0")); BSONObjBuilder builder; version.appendToCommand(&builder); diff --git a/src/mongo/db/s/metadata_manager.cpp b/src/mongo/db/s/metadata_manager.cpp index feb943e2462..7f83dfaca1d 100644 --- a/src/mongo/db/s/metadata_manager.cpp +++ b/src/mongo/db/s/metadata_manager.cpp @@ -137,8 +137,8 @@ std::shared_ptr<ScopedCollectionDescription::Impl> MetadataManager::getActiveMet } auto chunkManager = activeMetadata->getChunkManager(); - auto chunkManagerAtClusterTime = std::make_shared<ChunkManager>( - chunkManager->getRoutingHistory(), atClusterTime->asTimestamp()); + ChunkManager chunkManagerAtClusterTime = + ChunkManager(chunkManager->getRoutingHistory(), atClusterTime->asTimestamp()); class MetadataAtTimestamp : public ScopedCollectionDescription::Impl { public: diff --git a/src/mongo/db/s/metadata_manager_test.cpp b/src/mongo/db/s/metadata_manager_test.cpp index e2693e9de1a..6ec878a9bc1 100644 --- a/src/mongo/db/s/metadata_manager_test.cpp +++ b/src/mongo/db/s/metadata_manager_test.cpp @@ -87,9 +87,7 @@ protected: epoch, {ChunkType{kNss, range, ChunkVersion(1, 0, epoch), kOtherShard}}); - std::shared_ptr<ChunkManager> cm = std::make_shared<ChunkManager>(rt, boost::none); - - return CollectionMetadata(cm, kThisShard); + return CollectionMetadata(ChunkManager(rt, boost::none), kThisShard); } /** @@ -131,7 +129,7 @@ protected: auto rt = cm->getRoutingHistory()->makeUpdated(splitChunks); - return CollectionMetadata(std::make_shared<ChunkManager>(rt, boost::none), kThisShard); + return CollectionMetadata(ChunkManager(rt, boost::none), kThisShard); } static CollectionMetadata cloneMetadataMinusChunk(const CollectionMetadata& metadata, @@ -152,7 +150,7 @@ protected: auto rt = cm->getRoutingHistory()->makeUpdated( {ChunkType(kNss, ChunkRange(minKey, maxKey), chunkVersion, kOtherShard)}); - return CollectionMetadata(std::make_shared<ChunkManager>(rt, boost::none), kThisShard); + return CollectionMetadata(ChunkManager(rt, boost::none), kThisShard); } std::shared_ptr<MetadataManager> _manager; diff --git a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp index 446b5984c68..7d8b0d1c6f3 100644 --- a/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp +++ b/src/mongo/db/s/migration_chunk_cloner_source_legacy_test.cpp @@ -159,13 +159,12 @@ protected: ChunkVersion(1, 0, epoch), ShardId("dummyShardId")}}); - std::shared_ptr<ChunkManager> cm = std::make_shared<ChunkManager>(rt, boost::none); - AutoGetDb autoDb(operationContext(), kNss.db(), MODE_IX); Lock::CollectionLock collLock(operationContext(), kNss, MODE_IX); CollectionShardingRuntime::get(operationContext(), kNss) - ->setFilteringMetadata(operationContext(), - CollectionMetadata(cm, ShardId("dummyShardId"))); + ->setFilteringMetadata( + operationContext(), + CollectionMetadata(ChunkManager(rt, boost::none), ShardId("dummyShardId"))); }(); _client->createIndex(kNss.ns(), kShardKeyPattern); diff --git a/src/mongo/db/s/op_observer_sharding_test.cpp b/src/mongo/db/s/op_observer_sharding_test.cpp index 4c328b6936f..0d8597e9e98 100644 --- a/src/mongo/db/s/op_observer_sharding_test.cpp +++ b/src/mongo/db/s/op_observer_sharding_test.cpp @@ -65,9 +65,8 @@ CollectionMetadata makeAMetadata(BSONObj const& keyPattern) { auto chunk = ChunkType(kTestNss, std::move(range), ChunkVersion(1, 0, epoch), ShardId("other")); auto rt = RoutingTableHistory::makeNew( kTestNss, UUID::gen(), KeyPattern(keyPattern), nullptr, false, epoch, {std::move(chunk)}); - std::shared_ptr<ChunkManager> cm = std::make_shared<ChunkManager>(rt, Timestamp(100, 0)); - return CollectionMetadata(std::move(cm), ShardId("this")); + return CollectionMetadata(ChunkManager(rt, Timestamp(100, 0)), ShardId("this")); } class DeleteStateTest : public ShardServerTestFixture {}; diff --git a/src/mongo/db/s/range_deletion_util_test.cpp b/src/mongo/db/s/range_deletion_util_test.cpp index b4a80b9a25d..a8bdd46cf56 100644 --- a/src/mongo/db/s/range_deletion_util_test.cpp +++ b/src/mongo/db/s/range_deletion_util_test.cpp @@ -101,13 +101,12 @@ public: ChunkVersion(1, 0, epoch), ShardId("dummyShardId")}}); - std::shared_ptr<ChunkManager> cm = std::make_shared<ChunkManager>(rt, boost::none); - AutoGetDb autoDb(operationContext(), kNss.db(), MODE_IX); Lock::CollectionLock collLock(operationContext(), kNss, MODE_IX); CollectionShardingRuntime::get(operationContext(), kNss) - ->setFilteringMetadata(operationContext(), - CollectionMetadata(cm, ShardId("dummyShardId"))); + ->setFilteringMetadata( + operationContext(), + CollectionMetadata(ChunkManager(rt, boost::none), ShardId("dummyShardId"))); } UUID uuid() const { diff --git a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp index ac01d337e6c..d7115e5b294 100644 --- a/src/mongo/db/s/shard_filtering_metadata_refresh.cpp +++ b/src/mongo/db/s/shard_filtering_metadata_refresh.cpp @@ -328,7 +328,7 @@ CollectionMetadata forceGetCurrentMetadata(OperationContext* opCtx, const Namesp return CollectionMetadata(); } - return CollectionMetadata(routingInfo.cm(), shardingState->shardId()); + return CollectionMetadata(*routingInfo.cm(), shardingState->shardId()); } ChunkVersion forceShardFilteringMetadataRefresh(OperationContext* opCtx, @@ -421,7 +421,7 @@ ChunkVersion forceShardFilteringMetadataRefresh(OperationContext* opCtx, } } - CollectionMetadata metadata(std::move(cm), shardingState->shardId()); + CollectionMetadata metadata(*cm, shardingState->shardId()); const auto newShardVersion = metadata.getShardVersion(); csr->setFilteringMetadata(opCtx, std::move(metadata)); diff --git a/src/mongo/db/s/shard_key_util.cpp b/src/mongo/db/s/shard_key_util.cpp index 7bbeed2614d..2cae3071624 100644 --- a/src/mongo/db/s/shard_key_util.cpp +++ b/src/mongo/db/s/shard_key_util.cpp @@ -240,7 +240,7 @@ ValidationBehaviorsRefineShardKey::ValidationBehaviorsRefineShardKey(OperationCo const auto minKeyShardId = routingInfo.cm()->getMinKeyShardIdWithSimpleCollation(); _indexShard = uassertStatusOK(Grid::get(opCtx)->shardRegistry()->getShard(opCtx, minKeyShardId)); - _cm = routingInfo.cm(); + _cm.emplace(*routingInfo.cm()); } std::vector<BSONObj> ValidationBehaviorsRefineShardKey::loadIndexes( diff --git a/src/mongo/db/s/shard_key_util.h b/src/mongo/db/s/shard_key_util.h index 494ef5bce04..d6e1802549c 100644 --- a/src/mongo/db/s/shard_key_util.h +++ b/src/mongo/db/s/shard_key_util.h @@ -105,7 +105,7 @@ public: private: OperationContext* _opCtx; std::shared_ptr<Shard> _indexShard; - std::shared_ptr<ChunkManager> _cm; + boost::optional<ChunkManager> _cm; }; /** |