diff options
-rw-r--r-- | src/mongo/db/s/migration_source_manager.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/s/migration_source_manager.h | 9 | ||||
-rw-r--r-- | src/mongo/db/s/op_observer_sharding_impl.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/s/op_observer_sharding_impl.h | 7 | ||||
-rw-r--r-- | src/mongo/db/s/op_observer_sharding_test.cpp | 9 |
5 files changed, 26 insertions, 22 deletions
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 3b98d03285b..a0368f6c262 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -143,6 +143,17 @@ std::shared_ptr<MigrationChunkClonerSource> MigrationSourceManager::getCurrentCl return msm->_cloneDriver; } +// static +bool MigrationSourceManager::isMigrating(OperationContext* opCtx, + NamespaceString const& nss, + BSONObj const& docToDelete) { + const auto scopedCsr = + CollectionShardingRuntime::assertCollectionLockedAndAcquireShared(opCtx, nss); + auto cloner = MigrationSourceManager::getCurrentCloner(*scopedCsr); + + return cloner && cloner->isDocumentInMigratingChunk(docToDelete); +} + MigrationSourceManager::MigrationSourceManager(OperationContext* opCtx, ShardsvrMoveRange&& request, WriteConcernOptions&& writeConcern, diff --git a/src/mongo/db/s/migration_source_manager.h b/src/mongo/db/s/migration_source_manager.h index a72dd1057e9..c30bb5fcd74 100644 --- a/src/mongo/db/s/migration_source_manager.h +++ b/src/mongo/db/s/migration_source_manager.h @@ -87,6 +87,15 @@ public: const CollectionShardingRuntime& csr); /** + * Returns true if the document being deleted belongs to a chunk which, while still in the + * shard, is being migrated out. (Not to be confused with "fromMigrate", which tags + * operations that are steps in performing the migration.) + */ + static bool isMigrating(OperationContext* opCtx, + NamespaceString const& nss, + BSONObj const& docToDelete); + + /** * Instantiates a new migration source manager with the specified migration parameters. Must be * called with the distributed lock acquired in advance (not asserted). * diff --git a/src/mongo/db/s/op_observer_sharding_impl.cpp b/src/mongo/db/s/op_observer_sharding_impl.cpp index 9d3057c7f13..4c72cd0e30e 100644 --- a/src/mongo/db/s/op_observer_sharding_impl.cpp +++ b/src/mongo/db/s/op_observer_sharding_impl.cpp @@ -91,20 +91,10 @@ void assertNoMovePrimaryInProgress(OperationContext* opCtx, const NamespaceStrin OpObserverShardingImpl::OpObserverShardingImpl(std::unique_ptr<OplogWriter> oplogWriter) : OpObserverImpl(std::move(oplogWriter)) {} -bool OpObserverShardingImpl::isMigrating(OperationContext* opCtx, - NamespaceString const& nss, - BSONObj const& docToDelete) { - const auto scopedCsr = - CollectionShardingRuntime::assertCollectionLockedAndAcquireShared(opCtx, nss); - auto cloner = MigrationSourceManager::getCurrentCloner(*scopedCsr); - - return cloner && cloner->isDocumentInMigratingChunk(docToDelete); -} - void OpObserverShardingImpl::shardObserveAboutToDelete(OperationContext* opCtx, NamespaceString const& nss, BSONObj const& docToDelete) { - getIsMigrating(opCtx) = isMigrating(opCtx, nss, docToDelete); + getIsMigrating(opCtx) = MigrationSourceManager::isMigrating(opCtx, nss, docToDelete); } void OpObserverShardingImpl::shardObserveInsertsOp( diff --git a/src/mongo/db/s/op_observer_sharding_impl.h b/src/mongo/db/s/op_observer_sharding_impl.h index 9f0bee0defe..9d0e1de61d3 100644 --- a/src/mongo/db/s/op_observer_sharding_impl.h +++ b/src/mongo/db/s/op_observer_sharding_impl.h @@ -37,13 +37,6 @@ class OpObserverShardingImpl : public OpObserverImpl { public: OpObserverShardingImpl(std::unique_ptr<OplogWriter> oplogWriter); - // True if the document being deleted belongs to a chunk which, while still in the shard, - // is being migrated out. (Not to be confused with "fromMigrate", which tags operations - // that are steps in performing the migration.) - static bool isMigrating(OperationContext* opCtx, - NamespaceString const& nss, - BSONObj const& docToDelete); - protected: void shardObserveAboutToDelete(OperationContext* opCtx, NamespaceString const& nss, diff --git a/src/mongo/db/s/op_observer_sharding_test.cpp b/src/mongo/db/s/op_observer_sharding_test.cpp index 644627a95b8..b3e12155c60 100644 --- a/src/mongo/db/s/op_observer_sharding_test.cpp +++ b/src/mongo/db/s/op_observer_sharding_test.cpp @@ -36,6 +36,7 @@ #include "mongo/db/op_observer/oplog_writer_impl.h" #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/database_sharding_state.h" +#include "mongo/db/s/migration_source_manager.h" #include "mongo/db/s/op_observer_sharding_impl.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/shard_server_test_fixture.h" @@ -141,7 +142,7 @@ TEST_F(DocumentKeyStateTest, MakeDocumentKeyStateUnsharded) { ASSERT_BSONOBJ_EQ(repl::getDocumentKey(operationContext(), *autoColl, doc).getShardKeyAndId(), BSON("_id" << "hello")); - ASSERT_FALSE(OpObserverShardingImpl::isMigrating(operationContext(), kTestNss, doc)); + ASSERT_FALSE(MigrationSourceManager::isMigrating(operationContext(), kTestNss, doc)); } TEST_F(DocumentKeyStateTest, MakeDocumentKeyStateShardedWithoutIdInShardKey) { @@ -170,7 +171,7 @@ TEST_F(DocumentKeyStateTest, MakeDocumentKeyStateShardedWithoutIdInShardKey) { << "abc" << "_id" << "hello")); - ASSERT_FALSE(OpObserverShardingImpl::isMigrating(operationContext(), kTestNss, doc)); + ASSERT_FALSE(MigrationSourceManager::isMigrating(operationContext(), kTestNss, doc)); } TEST_F(DocumentKeyStateTest, MakeDocumentKeyStateShardedWithIdInShardKey) { @@ -198,7 +199,7 @@ TEST_F(DocumentKeyStateTest, MakeDocumentKeyStateShardedWithIdInShardKey) { BSON("key" << 100 << "_id" << "hello" << "key2" << true)); - ASSERT_FALSE(OpObserverShardingImpl::isMigrating(operationContext(), kTestNss, doc)); + ASSERT_FALSE(MigrationSourceManager::isMigrating(operationContext(), kTestNss, doc)); } TEST_F(DocumentKeyStateTest, MakeDocumentKeyStateShardedWithIdHashInShardKey) { @@ -223,7 +224,7 @@ TEST_F(DocumentKeyStateTest, MakeDocumentKeyStateShardedWithIdHashInShardKey) { ASSERT_BSONOBJ_EQ(repl::getDocumentKey(operationContext(), *autoColl, doc).getShardKeyAndId(), BSON("_id" << "hello")); - ASSERT_FALSE(OpObserverShardingImpl::isMigrating(operationContext(), kTestNss, doc)); + ASSERT_FALSE(MigrationSourceManager::isMigrating(operationContext(), kTestNss, doc)); } TEST_F(DocumentKeyStateTest, CheckDBVersion) { |