From 4382b9e9231ba5360e374e97df382f34602ccaa4 Mon Sep 17 00:00:00 2001 From: Tommaso Tocci Date: Wed, 11 Mar 2020 12:49:46 +0100 Subject: SERVER-47103 Add OrphanCleanupPolicy parameter to getOwnershipFilter --- src/mongo/db/s/collection_metadata_filtering_test.cpp | 9 ++++++--- src/mongo/db/s/collection_sharding_runtime.cpp | 3 ++- src/mongo/db/s/collection_sharding_runtime.h | 3 ++- src/mongo/db/s/collection_sharding_state.h | 10 +++++++--- src/mongo/db/s/collection_sharding_state_factory_embedded.cpp | 3 ++- .../db/s/collection_sharding_state_factory_standalone.cpp | 3 ++- src/mongo/db/s/op_observer_sharding_impl.cpp | 3 ++- 7 files changed, 23 insertions(+), 11 deletions(-) (limited to 'src/mongo/db/s') 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(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(); 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(); 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; -- cgit v1.2.1