From 70d80045e3b605a8534f7669aae3089970b73184 Mon Sep 17 00:00:00 2001 From: Paolo Polato Date: Thu, 9 Feb 2023 08:53:32 +0000 Subject: SERVER-73752 Remove active shards check from ShardingCatalogClient::getShardsThatOwnData() methods --- .../sharding_catalog_client_aggregations_test.cpp | 34 ---- .../s/catalog/sharding_catalog_client_impl.cpp | 215 ++++++++------------- 2 files changed, 79 insertions(+), 170 deletions(-) diff --git a/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp b/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp index a26efde5588..abd0a8d9c60 100644 --- a/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp +++ b/src/mongo/db/s/sharding_catalog_client_aggregations_test.cpp @@ -1004,40 +1004,6 @@ TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_RegexSta assertSameHistoricalPlacement(historicalPlacement, {"shard1", "shard2", "shard3"}); } -// ######################## PlacementHistory: SnapshotTooOld ##################### -TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_SnapshotTooOld) { - RAIIServerParameterControllerForTest featureFlagHistoricalPlacementShardingCatalog{ - "featureFlagHistoricalPlacementShardingCatalog", true}; - /*Quering the placementHistory must throw SnapshotTooOld when the returned list of shards - contains at least one shard no longer active*/ - auto opCtx = operationContext(); - - setupConfigPlacementHistory( - opCtx, - {{Timestamp(1, 0), "db", {"shard1"}}, - {Timestamp(2, 0), "db.collection1", {"shard1", "shard2", "shard3"}}, - {Timestamp(3, 0), "db.collection2", {"shard1", "shard2", "shard3"}}}); - - setupConfigShard(opCtx, 2 /*nShards*/); - - ASSERT_THROWS_CODE( - catalogClient()->getShardsThatOwnDataForDbAtClusterTime( - opCtx, NamespaceString::createNamespaceString_forTest("db"), Timestamp(4, 0)), - DBException, - ErrorCodes::SnapshotTooOld); - - ASSERT_THROWS_CODE(catalogClient()->getShardsThatOwnDataForCollAtClusterTime( - opCtx, - NamespaceString::createNamespaceString_forTest("db.collection1"), - Timestamp(4, 0)), - DBException, - ErrorCodes::SnapshotTooOld); - - ASSERT_THROWS_CODE(catalogClient()->getShardsThatOwnDataAtClusterTime(opCtx, Timestamp(4, 0)), - DBException, - ErrorCodes::SnapshotTooOld); -} - // ######################## PlacementHistory: EmptyHistory ##################### TEST_F(CatalogClientAggregationsTest, GetShardsThatOwnDataAtClusterTime_EmptyHistory) { RAIIServerParameterControllerForTest featureFlagHistoricalPlacementShardingCatalog{ diff --git a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp index 78c89f29d1f..b2a052fee22 100644 --- a/src/mongo/s/catalog/sharding_catalog_client_impl.cpp +++ b/src/mongo/s/catalog/sharding_catalog_client_impl.cpp @@ -1344,10 +1344,6 @@ HistoricalPlacement ShardingCatalogClientImpl::getHistoricalPlacement( Stage 6. Flatten the array of arrays into a set (this will also remove duplicates) Stage 7. Access to the list of shards currently active in the cluster - Stage 8. Count the number of shards obtained on stage 6 that also appear in the list of - active shards - Stage 9. Do not return the list of active shards (used only for the count) - - one pipeline "approximatePlacementData" retreiving the last "marker" which is a special entry where the nss is empty and the list of shard can be either empty or not. - In case the list is not empty: it means the clusterTime requested was during an fcv @@ -1357,108 +1353,89 @@ HistoricalPlacement ShardingCatalogClientImpl::getHistoricalPlacement( - The pipeline selects only the fcv markers, sorts by decreasing timestamp and gets the first element. - regex=^db(\.collection)?$ // matches db or db.collection - { + regex=^db(\.collection)?$ // matches db or db.collection + db.placementHistory.aggregate([ + { "$facet": { - "exactPlacementData": [ - { - "$match": { - "timestamp": { - "$lte": - }, - "nss": { - $regex: regex - } - } - }, - { - "$sort": { - "timestamp": -1 - } - }, - { - "$group": { - _id: "$nss", - shards: { - $first: "$shards" - } - } + "exactPlacementData": [ + { + "$match": { + "timestamp": { + "$lte": }, - { - "$match": { - shards: { - $not: { - $size: 0 - } - } + "nss": { + $regex: regex } - }, - { - "$group": { - _id: "", - shards: { - $push: "$shards" - } + } + }, + { + "$sort": { + "timestamp": -1 + } + }, + { + "$group": { + _id: "$nss", + shards: { + $first: "$shards" } - }, - { - $project: { - "shards": { - $reduce: { - input: "$shards", - initialValue: [], - in: { - "$setUnion": [ - "$$this", - "$$value" - ] - } - } - } + } + }, + { + "$match": { + shards: { + $not: { + $size: 0 + } } - }, - { - $lookup: { - from: "shards", - localField: "shards", - foreignField: "_id", - as: "activeShards" + } + }, + { + "$group": { + _id: "", + shards: { + $push: "$shards" } - }, - { - "$set": { - "numActiveShards": { - "$size": "$activeShards" + } + }, + { + $project: { + "shards": { + $reduce: { + input: "$shards", + initialValue: [], + in: { + "$setUnion": [ + "$$this", + "$$value" + ] } + } } + } + } + ], + "approximatePlacementData": [ + { + "$match": { + "timestamp": { + "$lte": }, - { - "$project": { - "activeShards": 0, - "_id": 0 - } - } - ], - "approximatePlacementData": [ - { - "$match": { - "timestamp": { - "$lte": Timestamp(3, 0) - }, - "nss": - } - }, - { - "$sort": { - "timestamp": -1 - } - }, - { - "$limit": 1 - } - } - ] + "nss": kConfigsvrPlacementHistoryFcvMarkerNamespace + } + }, + { + "$sort": { + "timestamp": -1 + } + }, + { + "$limit": 1 + } + ] } + } + ]) */ @@ -1527,28 +1504,6 @@ HistoricalPlacement ShardingCatalogClientImpl::getHistoricalPlacement( auto projectStageFlatten = DocumentSourceProject::createFromBson( Document{{"$project", std::move(projectStageBson)}}.toBson().firstElement(), expCtx); - - // Stage 7. Lookup active shards with left outer join on config.shards - Document lookupStageDoc = { - {"from", NamespaceString::kConfigsvrShardsNamespace.coll().toString()}, - {"localField", StringData("shards")}, - {"foreignField", StringData("_id")}, - {"as", StringData("activeShards")}}; - - auto lookupStage = DocumentSourceLookUp::createFromBson( - Document{{"$lookup", std::move(lookupStageDoc)}}.toBson().firstElement(), expCtx); - - // Stage 8. Count number of active shards - auto setStageDoc = Document( - {{"$set", Document{{"numActiveShards", Document{{"$size", "$activeShards"_sd}}}}}}); - auto setStage = - DocumentSourceAddFields::createFromBson(setStageDoc.toBson().firstElement(), expCtx); - - // Stage 9. Disable activeShards field to avoid sending it to the client - auto projectStageDoc = Document{{"activeShards", 0}}; - auto projectStageHideActiveShards = DocumentSourceProject::createFromBson( - Document{{"$project", projectStageDoc.toBson()}}.toBson().firstElement(), expCtx); - Pipeline::SourceContainer stages; stages.emplace_back(std::move(matchStage)); stages.emplace_back(std::move(sortStage)); @@ -1556,20 +1511,17 @@ HistoricalPlacement ShardingCatalogClientImpl::getHistoricalPlacement( stages.emplace_back(std::move(noShardsFilter)); stages.emplace_back(std::move(groupStageConcat)); stages.emplace_back(std::move(projectStageFlatten)); - stages.emplace_back(std::move(lookupStage)); - stages.emplace_back(std::move(setStage)); - stages.emplace_back(std::move(projectStageHideActiveShards)); auto exactDataPipeline = Pipeline::create(stages, expCtx); // Build the pipeline for the approximate data. - auto MatchFcvMarkerStage = DocumentSourceMatch::create( + auto matchFcvMarkerStage = DocumentSourceMatch::create( BSON("timestamp" << BSON("$lte" << atClusterTime) << "nss" << kMarkerNss), expCtx); - auto SortFcvMarkerStage = DocumentSourceSort::create(expCtx, BSON("timestamp" << -1)); - auto LimitFcvMarkerStage = DocumentSourceLimit::create(expCtx, 1); + auto sortFcvMarkerStage = DocumentSourceSort::create(expCtx, BSON("timestamp" << -1)); + auto limitFcvMarkerStage = DocumentSourceLimit::create(expCtx, 1); Pipeline::SourceContainer stages2; - stages2.emplace_back(std::move(MatchFcvMarkerStage)); - stages2.emplace_back(std::move(SortFcvMarkerStage)); - stages2.emplace_back(std::move(LimitFcvMarkerStage)); + stages2.emplace_back(std::move(matchFcvMarkerStage)); + stages2.emplace_back(std::move(sortFcvMarkerStage)); + stages2.emplace_back(std::move(limitFcvMarkerStage)); auto approximateDataPipeline = Pipeline::create(stages2, expCtx); @@ -1631,15 +1583,6 @@ HistoricalPlacement ShardingCatalogClientImpl::getHistoricalPlacement( return HistoricalPlacement{{}, true}; } - // check that the shards in the exact data are all active shards - const int numActiveShards = - aggrResult.front()["exactPlacementData"].Array()[0]["numActiveShards"].Int(); - - uassert(ErrorCodes::SnapshotTooOld, - "Part of the history may no longer be retrieved because of one or more removed " - "shards.", - numActiveShards == static_cast(exactShards.size())); - return HistoricalPlacement{exactShards, true}; } -- cgit v1.2.1