From 6508f5d6ad5d514f433b660f0da7f513625973be Mon Sep 17 00:00:00 2001 From: Alex Taskov Date: Fri, 6 Nov 2020 10:41:04 -0500 Subject: SERVER-49825 Replicate updates changing value under new shard key pattern as delete + insert in a transaction --- .../db/s/resharding_destined_recipient_test.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'src/mongo/db/s/resharding_destined_recipient_test.cpp') diff --git a/src/mongo/db/s/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding_destined_recipient_test.cpp index ba3579501de..7e3a1c9f3bc 100644 --- a/src/mongo/db/s/resharding_destined_recipient_test.cpp +++ b/src/mongo/db/s/resharding_destined_recipient_test.cpp @@ -216,6 +216,7 @@ protected: _mockCatalogCacheLoader->setCollectionRefreshValues( env.tempNss, collType, createChunks(env.version.epoch(), "y"), boost::none); + forceDatabaseRefresh(opCtx, kNss.db()); forceShardFilteringMetadataRefresh(opCtx, kNss); if (refreshTempNss) @@ -474,5 +475,35 @@ TEST_F(DestinedRecipientTest, TestOpObserverSetsDestinedRecipientOnDeletesInTran ASSERT_EQ(*recipShard, env.destShard); } +TEST_F(DestinedRecipientTest, TestUpdateChangesOwningShardThrows) { + auto opCtx = operationContext(); + + DBDirectClient client(opCtx); + client.insert(kNss.toString(), BSON("_id" << 0 << "x" << 2 << "y" << 2 << "z" << 4)); + + auto env = setupReshardingEnv(opCtx, true); + + ASSERT_THROWS(runInTransaction( + opCtx, + [&]() { + updateDoc( + opCtx, kNss, BSON("_id" << 0), BSON("$set" << BSON("y" << 50)), env); + }), + ExceptionFor); +} + +TEST_F(DestinedRecipientTest, TestUpdateSameOwningShard) { + auto opCtx = operationContext(); + + DBDirectClient client(opCtx); + client.insert(kNss.toString(), BSON("_id" << 0 << "x" << 2 << "y" << 2 << "z" << 4)); + + auto env = setupReshardingEnv(opCtx, true); + + runInTransaction(opCtx, [&]() { + updateDoc(opCtx, kNss, BSON("_id" << 0), BSON("$set" << BSON("y" << 3)), env); + }); +} + } // namespace } // namespace mongo -- cgit v1.2.1