diff options
Diffstat (limited to 'src/mongo/db/repl/oplog_applier_impl_test.cpp')
-rw-r--r-- | src/mongo/db/repl/oplog_applier_impl_test.cpp | 216 |
1 files changed, 0 insertions, 216 deletions
diff --git a/src/mongo/db/repl/oplog_applier_impl_test.cpp b/src/mongo/db/repl/oplog_applier_impl_test.cpp index 3ded20a0e83..07dbe78a257 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test.cpp @@ -1559,222 +1559,6 @@ TEST_F(MultiOplogEntryOplogApplierImplTest, MultiApplyTwoTransactionsOneBatch) { ASSERT_BSONOBJ_EQ(BSON("_id" << 4), *(nss1It++)); } -class MultiOplogEntryOplogApplierImplTestMultitenant : public OplogApplierImplTest { -public: - MultiOplogEntryOplogApplierImplTestMultitenant() - : _tenantId(OID::gen()), - _nss(_tenantId, "test.preptxn"), - _cmdNss(_tenantId, "admin", "$cmd"), - _txnNum(1) {} - -protected: - void setUp() override { - OplogApplierImplTest::setUp(); - - createCollectionWithUuid(_opCtx.get(), NamespaceString::kSessionTransactionsTableNamespace); - - _uuid = UUID::gen(); - _lsid = makeLogicalSessionId(_opCtx.get()); - - _opObserver->onCreateCollectionFn = [&](OperationContext* opCtx, - const CollectionPtr&, - const NamespaceString& collNss, - const CollectionOptions&, - const BSONObj&) { - stdx::lock_guard<Latch> lock(_mutex); - if (collNss.isOplog()) { - _oplogDocs.insert(_oplogDocs.end(), BSON("create" << collNss.coll())); - } else if (collNss == _nss || - collNss == NamespaceString::kSessionTransactionsTableNamespace) { - // Storing the documents in a sorted data structure to make checking for valid - // results easier. The inserts will be performed by different threads and - // there's no guarantee of the order. - (_docs[collNss]).push_back(BSON("create" << collNss.coll())); - } else - FAIL("Unexpected create") << " on " << collNss; - }; - - _opObserver->onInsertsFn = [&](OperationContext*, - const NamespaceString& nss, - const std::vector<BSONObj>& docs) { - stdx::lock_guard<Latch> lock(_mutex); - if (nss.isOplog()) { - _oplogDocs.insert(_oplogDocs.end(), docs.begin(), docs.end()); - } else if (nss == _nss || nss == NamespaceString::kSessionTransactionsTableNamespace) { - // Storing the inserted documents in a sorted data structure to make checking - // for valid results easier. The inserts will be performed by different threads - // and there's no guarantee of the order. - (_docs[nss]).insert(_docs[nss].end(), docs.begin(), docs.end()); - } else - FAIL("Unexpected insert") << " into " << nss << " first doc: " << docs.front(); - }; - - _writerPool = makeReplWriterPool(); - } - - void tearDown() override { - OplogApplierImplTest::tearDown(); - } - - std::vector<BSONObj>& oplogDocs() { - return _oplogDocs; - } - -protected: - TenantId _tenantId; - NamespaceString _nss; - NamespaceString _cmdNss; - boost::optional<UUID> _uuid; - LogicalSessionId _lsid; - TxnNumber _txnNum; - boost::optional<OplogEntry> _commitOp; - std::map<NamespaceString, std::vector<BSONObj>> _docs; - std::vector<BSONObj> _oplogDocs; - std::unique_ptr<ThreadPool> _writerPool; - -private: - Mutex _mutex = MONGO_MAKE_LATCH("MultiOplogEntryOplogApplierImplTest::_mutex"); -}; - -TEST_F(MultiOplogEntryOplogApplierImplTestMultitenant, - MultiApplyUnpreparedTransactionTwoBatchesFeatureFlagOn) { - RAIIServerParameterControllerForTest multitenanyController("multitenancySupport", true); - RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", true); - // Tests an unprepared transaction with ops both in the batch with the commit and prior - // batches. Populate transaction with 2 linked entries - a create collection and an insert. - std::vector<OplogEntry> ops; - ops.push_back(makeCommandOplogEntryWithSessionInfoAndStmtIds( - {Timestamp(Seconds(1), 1), 1LL}, - _cmdNss, - BSON("applyOps" << BSON_ARRAY(BSON("op" - << "c" - << "tid" << _tenantId << "ns" << _nss.ns() << "ui" - << *_uuid << "o" << BSON("create" << _nss.coll()))) - << "partialTxn" << true), - _lsid, - _txnNum, - {StmtId(0)}, - OpTime())); - - ops.push_back(makeCommandOplogEntryWithSessionInfoAndStmtIds( - {Timestamp(Seconds(1), 2), 1LL}, - _cmdNss, - BSON("applyOps" << BSON_ARRAY(BSON("op" - << "i" - << "tid" << _tenantId << "ns" << _nss.ns() << "ui" - << *_uuid << "o" << BSON("_id" << 1))) - << "partialTxn" << true), - _lsid, - _txnNum, - {StmtId(1)}, - ops.back().getOpTime())); - - auto commitOp = makeCommandOplogEntryWithSessionInfoAndStmtIds({Timestamp(Seconds(1), 3), 1LL}, - _cmdNss, - BSON("applyOps" << BSONArray()), - _lsid, - _txnNum, - {StmtId(2)}, - ops.back().getOpTime()); - - NoopOplogApplierObserver observer; - OplogApplierImpl oplogApplier( - nullptr, // executor - nullptr, // oplogBuffer - &observer, - ReplicationCoordinator::get(_opCtx.get()), - getConsistencyMarkers(), - getStorageInterface(), - repl::OplogApplier::Options(repl::OplogApplication::Mode::kSecondary), - _writerPool.get()); - - // Insert the first entry in its own batch. This should result in the oplog entry being written - // but the entry should not be applied as it is part of a pending transaction. - ASSERT_OK(oplogApplier.applyOplogBatch(_opCtx.get(), {ops[0]})); - ASSERT_EQ(1U, oplogDocs().size()); - ASSERT_EQ(0U, _docs[_nss].size()); - - // Insert the rest of the entries, including the commit. These entries should be added to the - // oplog, and all the entries including the first should be applied. - ASSERT_OK(oplogApplier.applyOplogBatch(_opCtx.get(), {ops[1], commitOp})); - ASSERT_EQ(3U, oplogDocs().size()); - ASSERT_EQ(2U, _docs[_nss].size()); - - // Check that we applied the expected documents - auto nssIt = _docs[_nss].begin(); - ASSERT_BSONOBJ_EQ(BSON("create" << _nss.coll()), *nssIt); - ASSERT_BSONOBJ_EQ(BSON("_id" << 1), *(++nssIt)); -} - -TEST_F(MultiOplogEntryOplogApplierImplTestMultitenant, - MultiApplyUnpreparedTransactionTwoBatchesFeatureFlagOff) { - RAIIServerParameterControllerForTest multitenanyController("multitenancySupport", true); - RAIIServerParameterControllerForTest featureFlagController("featureFlagRequireTenantID", false); - // Tests an unprepared transaction with ops both in the batch with the commit and prior - // batches. Populate transaction with 2 linked entries - a create collection and an insert. - std::vector<OplogEntry> ops; - ops.push_back(makeCommandOplogEntryWithSessionInfoAndStmtIds( - {Timestamp(Seconds(1), 1), 1LL}, - _cmdNss, - BSON("applyOps" << BSON_ARRAY(BSON("op" - << "c" - << "ns" << _nss.toStringWithTenantId() << "ui" << *_uuid - << "o" << BSON("create" << _nss.coll()))) - << "partialTxn" << true), - _lsid, - _txnNum, - {StmtId(0)}, - OpTime())); - - ops.push_back(makeCommandOplogEntryWithSessionInfoAndStmtIds( - {Timestamp(Seconds(1), 2), 1LL}, - _cmdNss, - BSON("applyOps" << BSON_ARRAY(BSON("op" - << "i" - << "ns" << _nss.toStringWithTenantId() << "ui" << *_uuid - << "o" << BSON("_id" << 1))) - << "partialTxn" << true), - _lsid, - _txnNum, - {StmtId(1)}, - ops.back().getOpTime())); - - auto commitOp = makeCommandOplogEntryWithSessionInfoAndStmtIds({Timestamp(Seconds(1), 3), 1LL}, - _cmdNss, - BSON("applyOps" << BSONArray()), - _lsid, - _txnNum, - {StmtId(2)}, - ops.back().getOpTime()); - - NoopOplogApplierObserver observer; - OplogApplierImpl oplogApplier( - nullptr, // executor - nullptr, // oplogBuffer - &observer, - ReplicationCoordinator::get(_opCtx.get()), - getConsistencyMarkers(), - getStorageInterface(), - repl::OplogApplier::Options(repl::OplogApplication::Mode::kSecondary), - _writerPool.get()); - - // Insert the first entry in its own batch. This should result in the oplog entry being written - // but the entry should not be applied as it is part of a pending transaction. - ASSERT_OK(oplogApplier.applyOplogBatch(_opCtx.get(), {ops[0]})); - ASSERT_EQ(1U, oplogDocs().size()); - ASSERT_EQ(0U, _docs[_nss].size()); - - // Insert the rest of the entries, including the commit. These entries should be added to the - // oplog, and all the entries including the first should be applied. - ASSERT_OK(oplogApplier.applyOplogBatch(_opCtx.get(), {ops[1], commitOp})); - ASSERT_EQ(3U, oplogDocs().size()); - ASSERT_EQ(2U, _docs[_nss].size()); - - // Check that we applied the expected documents - auto nssIt = _docs[_nss].begin(); - ASSERT_BSONOBJ_EQ(BSON("create" << _nss.coll()), *nssIt); - ASSERT_BSONOBJ_EQ(BSON("_id" << 1), *(++nssIt)); -} class MultiOplogEntryPreparedTransactionTest : public MultiOplogEntryOplogApplierImplTest { protected: |