From ba1b7bfcc7bc133fcb3ebf6ea44c6a55edab0bea Mon Sep 17 00:00:00 2001 From: Esha Maharishi Date: Fri, 24 Jan 2020 15:56:42 +0000 Subject: SERVER-45749 Tests in range_deletion_util_test.cpp that insert into config.rangeDeletions should set the collection's filtering metadata before the insert --- src/mongo/db/s/migration_util.cpp | 4 ++-- src/mongo/db/s/range_deletion_util_test.cpp | 31 +++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/mongo/db/s/migration_util.cpp b/src/mongo/db/s/migration_util.cpp index 964addcd78f..d98acf3f32d 100644 --- a/src/mongo/db/s/migration_util.cpp +++ b/src/mongo/db/s/migration_util.cpp @@ -151,8 +151,8 @@ ExecutorFuture submitRangeDeletionTask(OperationContext* opCtx, LOG(0) << "Filtering metadata for namespace in deletion task " << deletionTask.toBSON() << (css->getCurrentMetadataIfKnown() - ? "has UUID that does not match UUID of the deletion task" - : "is not known") + ? " has UUID that does not match UUID of the deletion task" + : " is not known") << ", forcing a refresh of " << deletionTask.getNss(); // TODO (SERVER-45577): Add an asynchronous version of diff --git a/src/mongo/db/s/range_deletion_util_test.cpp b/src/mongo/db/s/range_deletion_util_test.cpp index a2d245e185c..f66d983a26e 100644 --- a/src/mongo/db/s/range_deletion_util_test.cpp +++ b/src/mongo/db/s/range_deletion_util_test.cpp @@ -31,6 +31,8 @@ #include "mongo/db/db_raii.h" #include "mongo/db/dbdirectclient.h" +#include "mongo/db/s/collection_sharding_runtime.h" +#include "mongo/db/s/metadata_manager.h" #include "mongo/db/s/persistent_task_store.h" #include "mongo/db/s/range_deletion_task_gen.h" #include "mongo/db/s/range_deletion_util.h" @@ -82,6 +84,28 @@ public: ShardServerTestFixture::tearDown(); } + void setFilteringMetadataWithUUID(const UUID& uuid) { + const OID epoch = OID::gen(); + + auto rt = RoutingTableHistory::makeNew( + kNss, + uuid, + kShardKeyPattern, + nullptr, + false, + epoch, + {ChunkType{kNss, + ChunkRange{BSON(kShardKey << MINKEY), BSON(kShardKey << MAXKEY)}, + ChunkVersion(1, 0, epoch), + ShardId("dummyShardId")}}); + + std::shared_ptr cm = std::make_shared(rt, boost::none); + + CollectionShardingRuntime::get(operationContext(), kNss) + ->setFilteringMetadata(operationContext(), + CollectionMetadata(cm, ShardId("dummyShardId"))); + } + UUID uuid() const { return _uuid; } @@ -421,9 +445,9 @@ TEST_F(RangeDeleterTest, RemoveDocumentsInRangeRetriesOnWriteConflictException) dbclient.insert(kNss.toString(), BSON(kShardKey << 5)); // Insert range deletion task for this collection and range. + setFilteringMetadataWithUUID(uuid()); PersistentTaskStore store(operationContext(), NamespaceString::kRangeDeletionNamespace); - RangeDeletionTask t( UUID::gen(), kNss, uuid(), ShardId("donor"), range, CleanWhenEnum::kDelayed); store.add(operationContext(), t); @@ -459,9 +483,9 @@ TEST_F(RangeDeleterTest, RemoveDocumentsInRangeRetriesOnUnexpectedError) { dbclient.insert(kNss.toString(), BSON(kShardKey << 5)); // Insert range deletion task for this collection and range. + setFilteringMetadataWithUUID(uuid()); PersistentTaskStore store(operationContext(), NamespaceString::kRangeDeletionNamespace); - RangeDeletionTask t( UUID::gen(), kNss, uuid(), ShardId("donor"), range, CleanWhenEnum::kDelayed); store.add(operationContext(), t); @@ -576,6 +600,7 @@ TEST_F(RangeDeleterTest, RemoveDocumentsInRangeRemovesRangeDeletionTaskOnSuccess dbclient.insert(kNss.toString(), BSON(kShardKey << 5)); // Insert range deletion task for this collection and range. + setFilteringMetadataWithUUID(uuid()); PersistentTaskStore store(operationContext(), NamespaceString::kRangeDeletionNamespace); @@ -613,6 +638,7 @@ TEST_F(RangeDeleterTest, dbclient.insert(kNss.toString(), BSON(kShardKey << 5)); // Insert range deletion task for this collection and range. + setFilteringMetadataWithUUID(fakeUuid); PersistentTaskStore store(operationContext(), NamespaceString::kRangeDeletionNamespace); @@ -650,6 +676,7 @@ TEST_F(RangeDeleterTest, dbclient.insert(kNss.toString(), BSON(kShardKey << 5)); // Insert range deletion task for this collection and range. + setFilteringMetadataWithUUID(uuid()); PersistentTaskStore store(operationContext(), NamespaceString::kRangeDeletionNamespace); -- cgit v1.2.1