diff options
author | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2019-08-06 23:00:28 -0400 |
---|---|---|
committer | A. Jesse Jiryu Davis <jesse@mongodb.com> | 2019-08-21 11:55:02 -0400 |
commit | 609e2697c2619925073d4ac0f57f33e789d05100 (patch) | |
tree | 0c94a13d998f40b9cd16f4da272e98744d6bb98b /src/mongo/db/repl/sync_tail_test.cpp | |
parent | 08f836390d61726235e583f46012f43995695c85 (diff) | |
download | mongo-609e2697c2619925073d4ac0f57f33e789d05100.tar.gz |
SERVER-42022 Remove missing-document fetcher
Diffstat (limited to 'src/mongo/db/repl/sync_tail_test.cpp')
-rw-r--r-- | src/mongo/db/repl/sync_tail_test.cpp | 89 |
1 files changed, 9 insertions, 80 deletions
diff --git a/src/mongo/db/repl/sync_tail_test.cpp b/src/mongo/db/repl/sync_tail_test.cpp index d6a194ba29d..1e544e731fb 100644 --- a/src/mongo/db/repl/sync_tail_test.cpp +++ b/src/mongo/db/repl/sync_tail_test.cpp @@ -101,51 +101,14 @@ OplogEntry makeOplogEntry(OpTypeEnum opType, NamespaceString nss, OptionalCollec } /** - * Testing-only SyncTail that returns user-provided "document" for getMissingDoc(). + * Testing-only SyncTail. */ -class SyncTailWithLocalDocumentFetcher : public SyncTail, OplogApplier::Observer { +class SyncTailForTest : public SyncTail { public: - SyncTailWithLocalDocumentFetcher(const BSONObj& document); - BSONObj getMissingDoc(OperationContext* opCtx, const OplogEntry& oplogEntry) override; - - // OplogApplier::Observer functions - void onBatchBegin(const OplogApplier::Operations&) final {} - void onBatchEnd(const StatusWith<OpTime>&, const OplogApplier::Operations&) final {} - void onMissingDocumentsFetchedAndInserted(const std::vector<FetchInfo>& docs) final { - numFetched += docs.size(); - } - - std::size_t numFetched = 0U; - -private: - BSONObj _document; -}; - -/** - * Testing-only SyncTail that checks the operation context in fetchAndInsertMissingDocument(). - */ -class SyncTailWithOperationContextChecker : public SyncTail { -public: - SyncTailWithOperationContextChecker(); - void fetchAndInsertMissingDocument(OperationContext* opCtx, - const OplogEntry& oplogEntry) override; - bool called = false; + SyncTailForTest(); }; -SyncTailWithLocalDocumentFetcher::SyncTailWithLocalDocumentFetcher(const BSONObj& document) - : SyncTail(this, // observer - nullptr, // consistency markers - nullptr, // storage interface - SyncTail::MultiSyncApplyFunc(), - nullptr, // writer pool - SyncTailTest::makeInitialSyncOptions()), - _document(document) {} - -BSONObj SyncTailWithLocalDocumentFetcher::getMissingDoc(OperationContext*, const OplogEntry&) { - return _document; -} - -SyncTailWithOperationContextChecker::SyncTailWithOperationContextChecker() +SyncTailForTest::SyncTailForTest() : SyncTail(nullptr, // observer nullptr, // consistency markers nullptr, // storage interface @@ -153,14 +116,6 @@ SyncTailWithOperationContextChecker::SyncTailWithOperationContextChecker() nullptr, // writer pool SyncTailTest::makeInitialSyncOptions()) {} -void SyncTailWithOperationContextChecker::fetchAndInsertMissingDocument(OperationContext* opCtx, - const OplogEntry&) { - ASSERT_FALSE(opCtx->writesAreReplicated()); - ASSERT_FALSE(opCtx->lockState()->shouldConflictWithSecondaryBatchApplication()); - ASSERT_TRUE(documentValidationDisabled(opCtx)); - called = true; -} - /** * Creates collection options suitable for oplog. */ @@ -1769,8 +1724,7 @@ TEST_F(SyncTailTest, MultiSyncApplyFallsBackOnApplyingInsertsIndividuallyWhenGro } TEST_F(SyncTailTest, MultiSyncApplyIgnoresUpdateOperationIfDocumentIsMissingFromSyncSource) { - BSONObj emptyDoc; - SyncTailWithLocalDocumentFetcher syncTail(emptyDoc); + SyncTailForTest syncTail; NamespaceString nss("test.t"); { Lock::GlobalWrite globalLock(_opCtx.get()); @@ -1786,17 +1740,14 @@ TEST_F(SyncTailTest, MultiSyncApplyIgnoresUpdateOperationIfDocumentIsMissingFrom WorkerMultikeyPathInfo pathInfo; ASSERT_OK(multiSyncApply(_opCtx.get(), &ops, &syncTail, &pathInfo)); - // Since the missing document is not found on the sync source, the collection referenced by - // the failed operation should not be automatically created. + // Since the document was missing when we cloned data from the sync source, the collection + // referenced by the failed operation should not be automatically created. ASSERT_FALSE(AutoGetCollectionForReadCommand(_opCtx.get(), nss).getCollection()); - - // Fetch count should remain zero if we failed to copy the missing document. - ASSERT_EQUALS(syncTail.numFetched, 0U); } TEST_F(SyncTailTest, MultiSyncApplySkipsDocumentOnNamespaceNotFoundDuringInitialSync) { BSONObj emptyDoc; - SyncTailWithLocalDocumentFetcher syncTail(emptyDoc); + SyncTailForTest syncTail; NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); NamespaceString badNss("local." + _agent.getSuiteName() + "_" + _agent.getTestName() + "bad"); auto doc1 = BSON("_id" << 1); @@ -1809,7 +1760,6 @@ TEST_F(SyncTailTest, MultiSyncApplySkipsDocumentOnNamespaceNotFoundDuringInitial MultiApplier::OperationPtrs ops = {&op0, &op1, &op2, &op3}; WorkerMultikeyPathInfo pathInfo; ASSERT_OK(multiSyncApply(_opCtx.get(), &ops, &syncTail, &pathInfo)); - ASSERT_EQUALS(syncTail.numFetched, 0U); CollectionReader collectionReader(_opCtx.get(), nss); ASSERT_BSONOBJ_EQ(doc1, unittest::assertGet(collectionReader.next())); @@ -1819,7 +1769,7 @@ TEST_F(SyncTailTest, MultiSyncApplySkipsDocumentOnNamespaceNotFoundDuringInitial TEST_F(SyncTailTest, MultiSyncApplySkipsIndexCreationOnNamespaceNotFoundDuringInitialSync) { BSONObj emptyDoc; - SyncTailWithLocalDocumentFetcher syncTail(emptyDoc); + SyncTailForTest syncTail; NamespaceString nss("local." + _agent.getSuiteName() + "_" + _agent.getTestName()); NamespaceString badNss("local." + _agent.getSuiteName() + "_" + _agent.getTestName() + "bad"); auto doc1 = BSON("_id" << 1); @@ -1834,7 +1784,6 @@ TEST_F(SyncTailTest, MultiSyncApplySkipsIndexCreationOnNamespaceNotFoundDuringIn MultiApplier::OperationPtrs ops = {&op0, &op1, &op2, &op3}; WorkerMultikeyPathInfo pathInfo; ASSERT_OK(multiSyncApply(_opCtx.get(), &ops, &syncTail, &pathInfo)); - ASSERT_EQUALS(syncTail.numFetched, 0U); CollectionReader collectionReader(_opCtx.get(), nss); ASSERT_BSONOBJ_EQ(doc1, unittest::assertGet(collectionReader.next())); @@ -1845,26 +1794,6 @@ TEST_F(SyncTailTest, MultiSyncApplySkipsIndexCreationOnNamespaceNotFoundDuringIn ASSERT_FALSE(AutoGetCollectionForReadCommand(_opCtx.get(), badNss).getCollection()); } -TEST_F(SyncTailTest, MultiSyncApplyFetchesMissingDocumentIfDocumentIsAvailableFromSyncSource) { - SyncTailWithLocalDocumentFetcher syncTail(BSON("_id" << 0 << "x" << 1)); - NamespaceString nss("test.t"); - createCollection(_opCtx.get(), nss, {}); - auto updatedDocument = BSON("_id" << 0 << "x" << 1); - auto op = makeUpdateDocumentOplogEntry( - {Timestamp(Seconds(1), 0), 1LL}, nss, BSON("_id" << 0), updatedDocument); - MultiApplier::OperationPtrs ops = {&op}; - WorkerMultikeyPathInfo pathInfo; - ASSERT_OK(multiSyncApply(_opCtx.get(), &ops, &syncTail, &pathInfo)); - ASSERT_EQUALS(syncTail.numFetched, 1U); - - // The collection referenced by "ns" in the failed operation is automatically created to hold - // the missing document fetched from the sync source. We verify the contents of the collection - // with the CollectionReader class. - CollectionReader collectionReader(_opCtx.get(), nss); - ASSERT_BSONOBJ_EQ(updatedDocument, unittest::assertGet(collectionReader.next())); - ASSERT_EQUALS(ErrorCodes::CollectionIsEmpty, collectionReader.next().getStatus()); -} - namespace { class ReplicationCoordinatorSignalDrainCompleteThrows : public ReplicationCoordinatorMock { |