diff options
author | Alex Taskov <alex.taskov@mongodb.com> | 2020-10-12 10:21:24 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-10-12 15:35:53 +0000 |
commit | ea5c903938ad3f54bd1364644e5a93ee94e7404b (patch) | |
tree | 55fe8e7d09611c84329ae1db7b74a3510e539bd7 /src/mongo/db/s/resharding_destined_recipient_test.cpp | |
parent | ffcd2895d7c0a810c4705b41305d185ea8cfd7c9 (diff) | |
download | mongo-ea5c903938ad3f54bd1364644e5a93ee94e7404b.tar.gz |
SERVER-49824 Add destined recipient to oplog entries from deletes
Diffstat (limited to 'src/mongo/db/s/resharding_destined_recipient_test.cpp')
-rw-r--r-- | src/mongo/db/s/resharding_destined_recipient_test.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/mongo/db/s/resharding_destined_recipient_test.cpp b/src/mongo/db/s/resharding_destined_recipient_test.cpp index fae78ff6949..596beeaf471 100644 --- a/src/mongo/db/s/resharding_destined_recipient_test.cpp +++ b/src/mongo/db/s/resharding_destined_recipient_test.cpp @@ -268,6 +268,28 @@ protected: Helpers::update(opCtx, nss.toString(), filter, update); } + void deleteDoc(OperationContext* opCtx, + const NamespaceString& nss, + const BSONObj& query, + const ReshardingEnv& env) { + AutoGetCollection coll(opCtx, nss, MODE_IX); + + // TODO(SERVER-50027): This is to temporarily make this test pass until getOwnershipFilter + // has been updated to detect frozen migrations. + if (!OperationShardingState::isOperationVersioned(opCtx)) { + OperationShardingState::get(opCtx).initializeClientRoutingVersions( + kNss, env.version, env.dbVersion); + } + + RecordId rid = Helpers::findOne(opCtx, coll.getCollection(), query, false); + ASSERT(!rid.isNull()); + + WriteUnitOfWork wuow(opCtx); + OpDebug opDebug; + coll->deleteDocument(opCtx, kUninitializedStmtId, rid, &opDebug); + wuow.commit(); + } + repl::OplogEntry getLastOplogEntry(OperationContext* opCtx) { repl::OplogInterfaceLocal oplogInterface(opCtx); auto oplogIter = oplogInterface.makeIterator(); @@ -415,5 +437,47 @@ TEST_F(DestinedRecipientTest, TestOpObserverSetsDestinedRecipientOnUpdatesInTran ASSERT_EQ(*recipShard, env.destShard); } +TEST_F(DestinedRecipientTest, TestOpObserverSetsDestinedRecipientOnDeletes) { + auto opCtx = operationContext(); + + DBDirectClient client(opCtx); + client.insert(kNss.toString(), BSON("_id" << 0 << "x" << 2 << "y" << 10 << "z" << 4)); + + auto env = setupReshardingEnv(opCtx, true); + + deleteDoc(opCtx, kNss, BSON("_id" << 0), env); + + auto entry = getLastOplogEntry(opCtx); + auto recipShard = entry.getDestinedRecipient(); + + ASSERT(recipShard); + ASSERT_EQ(*recipShard, env.destShard); +} + +TEST_F(DestinedRecipientTest, TestOpObserverSetsDestinedRecipientOnDeletesInTransaction) { + auto opCtx = operationContext(); + + DBDirectClient client(opCtx); + client.insert(kNss.toString(), BSON("_id" << 0 << "x" << 2 << "y" << 10)); + + auto env = setupReshardingEnv(opCtx, true); + + runInTransaction(opCtx, [&]() { deleteDoc(opCtx, kNss, BSON("_id" << 0), env); }); + + // Look for destined recipient in latest oplog entry. Since this write was done in a + // transaction, the write operation will be embedded in an applyOps entry and needs to be + // extracted. + auto entry = getLastOplogEntry(opCtx); + auto info = repl::ApplyOpsCommandInfo::parse(entry.getOperationToApply()); + + auto ops = info.getOperations(); + auto replOp = repl::ReplOperation::parse(IDLParserErrorContext("deleteOp"), ops[0]); + ASSERT_EQ(replOp.getNss(), kNss); + + auto recipShard = replOp.getDestinedRecipient(); + ASSERT(recipShard); + ASSERT_EQ(*recipShard, env.destShard); +} + } // namespace } // namespace mongo |