diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/db/commands/count_cmd.cpp | 10 | ||||
-rw-r--r-- | src/mongo/db/pipeline/pipeline_d.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/query/get_executor.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/query/stage_builder.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/s/collection_metadata_filtering_test.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_runtime.h | 3 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_state.h | 10 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_state_factory_embedded.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_state_factory_standalone.cpp | 3 | ||||
-rw-r--r-- | src/mongo/db/s/op_observer_sharding_impl.cpp | 3 |
12 files changed, 46 insertions, 17 deletions
diff --git a/src/mongo/db/commands/count_cmd.cpp b/src/mongo/db/commands/count_cmd.cpp index 300214ad28a..e606aebb70c 100644 --- a/src/mongo/db/commands/count_cmd.cpp +++ b/src/mongo/db/commands/count_cmd.cpp @@ -168,7 +168,10 @@ public: // Prevent chunks from being cleaned up during yields - this allows us to only check the // version on initial entry into count. - auto rangePreserver = CollectionShardingState::get(opCtx, nss)->getOwnershipFilter(opCtx); + auto rangePreserver = + CollectionShardingState::get(opCtx, nss) + ->getOwnershipFilter( + opCtx, CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup); auto expCtx = makeExpressionContextForGetExecutor( opCtx, request.getCollation().value_or(BSONObj()), nss); @@ -228,7 +231,10 @@ public: // Prevent chunks from being cleaned up during yields - this allows us to only check the // version on initial entry into count. - auto rangePreserver = CollectionShardingState::get(opCtx, nss)->getOwnershipFilter(opCtx); + auto rangePreserver = + CollectionShardingState::get(opCtx, nss) + ->getOwnershipFilter( + opCtx, CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup); auto statusWithPlanExecutor = getExecutorCount(makeExpressionContextForGetExecutor( diff --git a/src/mongo/db/pipeline/pipeline_d.cpp b/src/mongo/db/pipeline/pipeline_d.cpp index ef92f11d953..b35e720fcf6 100644 --- a/src/mongo/db/pipeline/pipeline_d.cpp +++ b/src/mongo/db/pipeline/pipeline_d.cpp @@ -135,7 +135,9 @@ StatusWith<unique_ptr<PlanExecutor, PlanExecutor::Deleter>> createRandomCursorEx // If the incoming operation is sharded, use the CSS to infer the filtering metadata for the // collection, otherwise treat it as unsharded auto collectionFilter = - CollectionShardingState::get(opCtx, coll->ns())->getOwnershipFilter(opCtx); + CollectionShardingState::get(opCtx, coll->ns()) + ->getOwnershipFilter( + opCtx, CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup); // Because 'numRecords' includes orphan documents, our initial decision to optimize the $sample // cursor may have been mistaken. For sharded collections, build a TRIAL plan that will switch diff --git a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp index 76dc456a92c..04e916c4d52 100644 --- a/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp +++ b/src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp @@ -140,7 +140,10 @@ BSONObj ShardServerProcessInterface::attachCursorSourceAndExplain( std::unique_ptr<ShardFilterer> ShardServerProcessInterface::getShardFilterer( const boost::intrusive_ptr<ExpressionContext>& expCtx) const { auto collectionFilter = - CollectionShardingState::get(expCtx->opCtx, expCtx->ns)->getOwnershipFilter(expCtx->opCtx); + CollectionShardingState::get(expCtx->opCtx, expCtx->ns) + ->getOwnershipFilter( + expCtx->opCtx, + CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup); return std::make_unique<ShardFiltererImpl>(std::move(collectionFilter)); } diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index b18a1702d1e..a0640b364dc 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -414,7 +414,9 @@ StatusWith<PrepareExecutionResult> prepareExecution(OperationContext* opCtx, root = std::make_unique<ShardFilterStage>( canonicalQuery->getExpCtx().get(), CollectionShardingState::get(opCtx, canonicalQuery->nss()) - ->getOwnershipFilter(opCtx), + ->getOwnershipFilter( + opCtx, + CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup), ws, std::move(root)); } diff --git a/src/mongo/db/query/stage_builder.cpp b/src/mongo/db/query/stage_builder.cpp index 75ed2509be1..3b9dad99a0f 100644 --- a/src/mongo/db/query/stage_builder.cpp +++ b/src/mongo/db/query/stage_builder.cpp @@ -297,7 +297,11 @@ std::unique_ptr<PlanStage> buildStages(OperationContext* opCtx, auto css = CollectionShardingState::get(opCtx, collection->ns()); return std::make_unique<ShardFilterStage>( - expCtx, css->getOwnershipFilter(opCtx), ws, std::move(childStage)); + expCtx, + css->getOwnershipFilter( + opCtx, CollectionShardingState::OrphanCleanupPolicy::kDisallowOrphanCleanup), + ws, + std::move(childStage)); } case STAGE_DISTINCT_SCAN: { const DistinctNode* dn = static_cast<const DistinctNode*>(root); diff --git a/src/mongo/db/s/collection_metadata_filtering_test.cpp b/src/mongo/db/s/collection_metadata_filtering_test.cpp index 572d19d356e..951ff41e089 100644 --- a/src/mongo/db/s/collection_metadata_filtering_test.cpp +++ b/src/mongo/db/s/collection_metadata_filtering_test.cpp @@ -138,7 +138,8 @@ TEST_F(CollectionMetadataFilteringTest, FilterDocumentsInTheFuture) { AutoGetCollection autoColl(operationContext(), kNss, MODE_IS); auto* const css = CollectionShardingState::get(operationContext(), kNss); - testFilterFn(css->getOwnershipFilter(operationContext())); + testFilterFn(css->getOwnershipFilter( + operationContext(), CollectionShardingState::OrphanCleanupPolicy::kAllowOrphanCleanup)); } // Verifies that a different set of documents is visible for a timestamp in the past @@ -161,7 +162,8 @@ TEST_F(CollectionMetadataFilteringTest, FilterDocumentsInThePast) { AutoGetCollection autoColl(operationContext(), kNss, MODE_IS); auto* const css = CollectionShardingState::get(operationContext(), kNss); - testFilterFn(css->getOwnershipFilter(operationContext())); + testFilterFn(css->getOwnershipFilter( + operationContext(), CollectionShardingState::OrphanCleanupPolicy::kAllowOrphanCleanup)); } // Verifies that when accessing too far into the past we get the stale error @@ -192,7 +194,8 @@ TEST_F(CollectionMetadataFilteringTest, FilterDocumentsTooFarInThePastThrowsStal AutoGetCollection autoColl(operationContext(), kNss, MODE_IS); auto* const css = CollectionShardingState::get(operationContext(), kNss); - testFilterFn(css->getOwnershipFilter(operationContext())); + testFilterFn(css->getOwnershipFilter( + operationContext(), CollectionShardingState::OrphanCleanupPolicy::kAllowOrphanCleanup)); } } // namespace diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index a7892bad128..999601e64f0 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -122,7 +122,8 @@ CollectionShardingRuntime* CollectionShardingRuntime::get_UNSAFE(ServiceContext* return checked_cast<CollectionShardingRuntime*>(css); } -ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter(OperationContext* opCtx) { +ScopedCollectionFilter CollectionShardingRuntime::getOwnershipFilter( + OperationContext* opCtx, OrphanCleanupPolicy orphanCleanupPolicy) { const auto optReceivedShardVersion = getOperationReceivedVersion(opCtx, _nss); if (!optReceivedShardVersion) return {kUnshardedCollection}; diff --git a/src/mongo/db/s/collection_sharding_runtime.h b/src/mongo/db/s/collection_sharding_runtime.h index ddbf9683b7f..ebdde2fed05 100644 --- a/src/mongo/db/s/collection_sharding_runtime.h +++ b/src/mongo/db/s/collection_sharding_runtime.h @@ -82,7 +82,8 @@ public: const UUID& collectionUuid, ChunkRange orphanRange); - ScopedCollectionFilter getOwnershipFilter(OperationContext* opCtx) override; + ScopedCollectionFilter getOwnershipFilter(OperationContext* opCtx, + OrphanCleanupPolicy orphanCleanupPolicy) override; ScopedCollectionDescription getCollectionDescription() override; diff --git a/src/mongo/db/s/collection_sharding_state.h b/src/mongo/db/s/collection_sharding_state.h index 2b46af3274c..b61a7c2d845 100644 --- a/src/mongo/db/s/collection_sharding_state.h +++ b/src/mongo/db/s/collection_sharding_state.h @@ -100,8 +100,9 @@ public: * the operation is not associated with a shard version (refer to * OperationShardingState::isOperationVersioned for more info on that), returns an UNSHARDED * metadata object. - * - * The intended users of this method are callers which need to perform filtering. Use + * If 'kDisallowOrphanCleanup' is passed as 'OrphanCleanupPolicy', the range deleter won't + * delete any orphan chunk associated with this ScopedCollectionFilter until the object is + * destroyed. The intended users of this method are callers which need to perform filtering. Use * 'getCurrentMetadata' for other cases, like obtaining information about sharding-related * properties of the collection are necessary that won't change under collection IX/IS lock * (e.g., isSharded or the shard key). @@ -109,7 +110,10 @@ public: * The returned object is safe to access even after the collection lock has been dropped. */ - virtual ScopedCollectionFilter getOwnershipFilter(OperationContext* opCtx) = 0; + enum class OrphanCleanupPolicy { kDisallowOrphanCleanup, kAllowOrphanCleanup }; + + virtual ScopedCollectionFilter getOwnershipFilter(OperationContext* opCtx, + OrphanCleanupPolicy orphanCleanupPolicy) = 0; /** * See the comments for 'getOwnershipFilter' above for more information on this method. diff --git a/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp b/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp index c46090d2034..f7d8a860594 100644 --- a/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp +++ b/src/mongo/db/s/collection_sharding_state_factory_embedded.cpp @@ -53,7 +53,8 @@ const auto kUnshardedCollection = std::make_shared<UnshardedCollection>(); class CollectionShardingStateStandalone final : public CollectionShardingState { public: - ScopedCollectionFilter getOwnershipFilter(OperationContext*) override { + ScopedCollectionFilter getOwnershipFilter(OperationContext*, + OrphanCleanupPolicy orphanCleanupPolicy) override { return {kUnshardedCollection}; } diff --git a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp index c2ca5dd0c47..6f0d1ffe00d 100644 --- a/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp +++ b/src/mongo/db/s/collection_sharding_state_factory_standalone.cpp @@ -51,7 +51,8 @@ const auto kUnshardedCollection = std::make_shared<UnshardedCollection>(); class CollectionShardingStateStandalone final : public CollectionShardingState { public: - ScopedCollectionFilter getOwnershipFilter(OperationContext*) override { + ScopedCollectionFilter getOwnershipFilter(OperationContext*, + OrphanCleanupPolicy orphanCleanupPolicy) override { return {kUnshardedCollection}; } ScopedCollectionDescription getCollectionDescription() override { diff --git a/src/mongo/db/s/op_observer_sharding_impl.cpp b/src/mongo/db/s/op_observer_sharding_impl.cpp index 9e201306ee6..b65d2aba4e2 100644 --- a/src/mongo/db/s/op_observer_sharding_impl.cpp +++ b/src/mongo/db/s/op_observer_sharding_impl.cpp @@ -55,7 +55,8 @@ void assertIntersectingChunkHasNotMoved(OperationContext* opCtx, if (!repl::ReadConcernArgs::get(opCtx).getArgsAtClusterTime()) return; - const auto collectionFilter = csr->getOwnershipFilter(opCtx); + const auto collectionFilter = csr->getOwnershipFilter( + opCtx, CollectionShardingState::OrphanCleanupPolicy::kAllowOrphanCleanup); if (!collectionFilter.isSharded()) return; |