summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
authorJordi Serra Torrens <jordi.serra-torrens@mongodb.com>2022-09-28 10:11:50 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-11-04 18:50:12 +0000
commit53973727e253d8b797bc0b2a734326d4e3fdad6d (patch)
treed4cf0a1effcc98ab265b44317194658c975775b7 /src/mongo/db/repl
parent05cf56be4fdfa33c88d47dfb48f95a60c9cc7e09 (diff)
downloadmongo-53973727e253d8b797bc0b2a734326d4e3fdad6d.tar.gz
SERVER-70043 Thread-through CollectionPtr into the onDelete OpObserver
Co-authored-by: Daniel Gómez Ferro <daniel.gomezferro@mongodb.com>
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp10
-rw-r--r--src/mongo/db/repl/oplog_applier_impl_test_fixture.h10
-rw-r--r--src/mongo/db/repl/primary_only_service_op_observer.cpp7
-rw-r--r--src/mongo/db/repl/primary_only_service_op_observer.h6
-rw-r--r--src/mongo/db/repl/storage_timestamp_test.cpp22
-rw-r--r--src/mongo/db/repl/tenant_migration_donor_op_observer.cpp10
-rw-r--r--src/mongo/db/repl/tenant_migration_donor_op_observer.h6
-rw-r--r--src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp10
-rw-r--r--src/mongo/db/repl/tenant_migration_recipient_op_observer.h6
-rw-r--r--src/mongo/db/repl/tenant_oplog_applier_test.cpp32
10 files changed, 51 insertions, 68 deletions
diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
index 7c4a904b1a5..8d94ecb55c3 100644
--- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
+++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
@@ -70,14 +70,13 @@ void OplogApplierImplOpObserver::onInserts(OperationContext* opCtx,
}
void OplogApplierImplOpObserver::onDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) {
if (!onDeleteFn) {
return;
}
- onDeleteFn(opCtx, nss, uuid, stmtId, args);
+ onDeleteFn(opCtx, coll, stmtId, args);
}
void OplogApplierImplOpObserver::onUpdate(OperationContext* opCtx,
@@ -247,13 +246,12 @@ void OplogApplierImplTest::_testApplyOplogEntryOrGroupedInsertsCrudOperation(
};
_opObserver->onDeleteFn = [&](OperationContext* opCtx,
- const NamespaceString& nss,
- const boost::optional<UUID>& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) {
applyOpCalled = true;
checkOpCtx(opCtx);
- ASSERT_EQUALS(targetNss, nss);
+ ASSERT_EQUALS(targetNss, coll->ns());
ASSERT(args.deletedDoc);
ASSERT_BSONOBJ_EQ(op.getObject(), *(args.deletedDoc));
return Status::OK();
diff --git a/src/mongo/db/repl/oplog_applier_impl_test_fixture.h b/src/mongo/db/repl/oplog_applier_impl_test_fixture.h
index c96ca3a881a..bce8a24e9ef 100644
--- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.h
+++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.h
@@ -83,8 +83,7 @@ public:
* This function is called whenever OplogApplierImpl deletes a document from a collection.
*/
void onDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) override;
@@ -149,11 +148,8 @@ public:
std::function<void(OperationContext*, const NamespaceString&, const std::vector<BSONObj>&)>
onInsertsFn;
- std::function<void(OperationContext*,
- const NamespaceString&,
- boost::optional<UUID>,
- StmtId,
- const OplogDeleteEntryArgs&)>
+ std::function<void(
+ OperationContext*, const CollectionPtr&, StmtId, const OplogDeleteEntryArgs&)>
onDeleteFn;
std::function<void(OperationContext*, const OplogUpdateEntryArgs&)> onUpdateFn;
diff --git a/src/mongo/db/repl/primary_only_service_op_observer.cpp b/src/mongo/db/repl/primary_only_service_op_observer.cpp
index 3ed52e7ec6b..4116af9d28d 100644
--- a/src/mongo/db/repl/primary_only_service_op_observer.cpp
+++ b/src/mongo/db/repl/primary_only_service_op_observer.cpp
@@ -50,8 +50,7 @@ PrimaryOnlyServiceOpObserver::~PrimaryOnlyServiceOpObserver() = default;
void PrimaryOnlyServiceOpObserver::aboutToDelete(OperationContext* opCtx,
- NamespaceString const& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
BSONObj const& doc) {
// Extract the _id field from the document. If it does not have an _id, use the
// document itself as the _id.
@@ -59,10 +58,10 @@ void PrimaryOnlyServiceOpObserver::aboutToDelete(OperationContext* opCtx,
}
void PrimaryOnlyServiceOpObserver::onDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) {
+ const auto& nss = coll->ns();
auto& documentId = documentIdDecoration(opCtx);
invariant(!documentId.isEmpty());
diff --git a/src/mongo/db/repl/primary_only_service_op_observer.h b/src/mongo/db/repl/primary_only_service_op_observer.h
index 9c56950c19f..33874d2fab1 100644
--- a/src/mongo/db/repl/primary_only_service_op_observer.h
+++ b/src/mongo/db/repl/primary_only_service_op_observer.h
@@ -114,13 +114,11 @@ public:
void onUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs& args) final {}
void aboutToDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
const BSONObj& doc) final;
void onDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) final;
diff --git a/src/mongo/db/repl/storage_timestamp_test.cpp b/src/mongo/db/repl/storage_timestamp_test.cpp
index 28c7b520aba..3d487c0ca64 100644
--- a/src/mongo/db/repl/storage_timestamp_test.cpp
+++ b/src/mongo/db/repl/storage_timestamp_test.cpp
@@ -2796,7 +2796,8 @@ TEST_F(StorageTimestampTest, IndexBuildsResolveErrorsDuringStateChangeToPrimary)
{
RecordId badRecord = Helpers::findOne(_opCtx, collection.get(), BSON("_id" << 1));
WriteUnitOfWork wuow(_opCtx);
- collection->deleteDocument(_opCtx, kUninitializedStmtId, badRecord, nullptr);
+ collection_internal::deleteDocument(
+ _opCtx, *autoColl, kUninitializedStmtId, badRecord, nullptr);
wuow.commit();
}
@@ -3402,14 +3403,17 @@ TEST_F(RetryableFindAndModifyTest, RetryableFindAndModifyDelete) {
auto record = cursor->next();
invariant(record);
WriteUnitOfWork wuow(_opCtx);
- collection->deleteDocument(_opCtx,
- objSnapshot,
- 1,
- record->id,
- nullptr,
- false,
- false,
- Collection::StoreDeletedDoc::On);
+ collection_internal::deleteDocument(_opCtx,
+ *autoColl,
+ objSnapshot,
+ 1,
+ record->id,
+ nullptr,
+ false,
+ false,
+ collection_internal::StoreDeletedDoc::On,
+ CheckRecordId::Off,
+ collection_internal::RetryableWrite::kYes);
wuow.commit();
}
diff --git a/src/mongo/db/repl/tenant_migration_donor_op_observer.cpp b/src/mongo/db/repl/tenant_migration_donor_op_observer.cpp
index 7fb4bf05a29..cdf47a03434 100644
--- a/src/mongo/db/repl/tenant_migration_donor_op_observer.cpp
+++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.cpp
@@ -298,10 +298,9 @@ void TenantMigrationDonorOpObserver::onUpdate(OperationContext* opCtx,
}
void TenantMigrationDonorOpObserver::aboutToDelete(OperationContext* opCtx,
- NamespaceString const& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
BSONObj const& doc) {
- if (nss == NamespaceString::kTenantMigrationDonorsNamespace &&
+ if (coll->ns() == NamespaceString::kTenantMigrationDonorsNamespace &&
!tenant_migration_access_blocker::inRecoveryMode(opCtx)) {
auto donorStateDoc = tenant_migration_access_blocker::parseDonorStateDocument(doc);
uassert(ErrorCodes::IllegalOperation,
@@ -321,11 +320,10 @@ void TenantMigrationDonorOpObserver::aboutToDelete(OperationContext* opCtx,
}
void TenantMigrationDonorOpObserver::onDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) {
- if (nss == NamespaceString::kTenantMigrationDonorsNamespace &&
+ if (coll->ns() == NamespaceString::kTenantMigrationDonorsNamespace &&
!tenant_migration_access_blocker::inRecoveryMode(opCtx)) {
auto tmi = tenantMigrationInfo(opCtx);
if (!tmi) {
diff --git a/src/mongo/db/repl/tenant_migration_donor_op_observer.h b/src/mongo/db/repl/tenant_migration_donor_op_observer.h
index 510ec3c56a1..6a50e2fba8d 100644
--- a/src/mongo/db/repl/tenant_migration_donor_op_observer.h
+++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.h
@@ -112,13 +112,11 @@ public:
void onUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs& args) final;
void aboutToDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
const BSONObj& doc) final;
void onDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) final;
diff --git a/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp b/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp
index b955988ab2d..1ec471f259f 100644
--- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp
+++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp
@@ -269,10 +269,9 @@ void TenantMigrationRecipientOpObserver::onUpdate(OperationContext* opCtx,
}
void TenantMigrationRecipientOpObserver::aboutToDelete(OperationContext* opCtx,
- NamespaceString const& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
BSONObj const& doc) {
- if (nss == NamespaceString::kTenantMigrationRecipientsNamespace &&
+ if (coll->ns() == NamespaceString::kTenantMigrationRecipientsNamespace &&
!tenant_migration_access_blocker::inRecoveryMode(opCtx)) {
auto recipientStateDoc =
TenantMigrationRecipientDocument::parse(IDLParserContext("recipientStateDoc"), doc);
@@ -293,11 +292,10 @@ void TenantMigrationRecipientOpObserver::aboutToDelete(OperationContext* opCtx,
}
void TenantMigrationRecipientOpObserver::onDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) {
- if (nss == NamespaceString::kTenantMigrationRecipientsNamespace &&
+ if (coll->ns() == NamespaceString::kTenantMigrationRecipientsNamespace &&
!tenant_migration_access_blocker::inRecoveryMode(opCtx)) {
auto tmi = tenantMigrationInfo(opCtx);
if (!tmi) {
diff --git a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h
index 7b1d51fe334..7309c9d6297 100644
--- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h
+++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h
@@ -113,13 +113,11 @@ public:
void onUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs& args) final;
void aboutToDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
const BSONObj& doc) final;
void onDelete(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
StmtId stmtId,
const OplogDeleteEntryArgs& args) final;
diff --git a/src/mongo/db/repl/tenant_oplog_applier_test.cpp b/src/mongo/db/repl/tenant_oplog_applier_test.cpp
index 319ef74c58f..bd668250a4f 100644
--- a/src/mongo/db/repl/tenant_oplog_applier_test.cpp
+++ b/src/mongo/db/repl/tenant_oplog_applier_test.cpp
@@ -742,11 +742,10 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_DatabaseMissing) {
auto entry = makeOplogEntry(
OpTypeEnum::kDelete, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen());
bool onDeleteCalled = false;
- _opObserver->onDeleteFn = [&](OperationContext* opCtx,
- const NamespaceString&,
- boost::optional<UUID>,
- StmtId,
- const OplogDeleteEntryArgs&) { onDeleteCalled = true; };
+ _opObserver->onDeleteFn =
+ [&](OperationContext* opCtx, const CollectionPtr&, StmtId, const OplogDeleteEntryArgs&) {
+ onDeleteCalled = true;
+ };
pushOps({entry});
auto writerPool = makeTenantMigrationWriterPool();
@@ -773,11 +772,10 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_CollectionMissing) {
auto entry = makeOplogEntry(
OpTypeEnum::kDelete, NamespaceString(_dbName.toStringWithTenantId(), "bar"), UUID::gen());
bool onDeleteCalled = false;
- _opObserver->onDeleteFn = [&](OperationContext* opCtx,
- const NamespaceString&,
- boost::optional<UUID>,
- StmtId,
- const OplogDeleteEntryArgs&) { onDeleteCalled = true; };
+ _opObserver->onDeleteFn =
+ [&](OperationContext* opCtx, const CollectionPtr&, StmtId, const OplogDeleteEntryArgs&) {
+ onDeleteCalled = true;
+ };
pushOps({entry});
auto writerPool = makeTenantMigrationWriterPool();
@@ -804,11 +802,10 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_DocumentMissing) {
auto uuid = createCollectionWithUuid(_opCtx.get(), nss);
auto entry = makeOplogEntry(OpTypeEnum::kDelete, nss, uuid, BSON("_id" << 0));
bool onDeleteCalled = false;
- _opObserver->onDeleteFn = [&](OperationContext* opCtx,
- const NamespaceString&,
- boost::optional<UUID>,
- StmtId,
- const OplogDeleteEntryArgs&) { onDeleteCalled = true; };
+ _opObserver->onDeleteFn =
+ [&](OperationContext* opCtx, const CollectionPtr&, StmtId, const OplogDeleteEntryArgs&) {
+ onDeleteCalled = true;
+ };
pushOps({entry});
auto writerPool = makeTenantMigrationWriterPool();
@@ -837,8 +834,7 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_Success) {
auto entry = makeOplogEntry(OpTypeEnum::kDelete, nss, uuid, BSON("_id" << 0));
bool onDeleteCalled = false;
_opObserver->onDeleteFn = [&](OperationContext* opCtx,
- const NamespaceString& nss,
- const boost::optional<UUID>& observer_uuid,
+ const CollectionPtr& coll,
StmtId,
const OplogDeleteEntryArgs& args) {
onDeleteCalled = true;
@@ -851,7 +847,7 @@ TEST_F(TenantOplogApplierTest, ApplyDelete_Success) {
// passes "tid" to the NamespaceString constructor
ASSERT_EQUALS(nss.dbName().db(), _dbName.toStringWithTenantId());
ASSERT_EQUALS(nss.coll(), "bar");
- ASSERT_EQUALS(uuid, observer_uuid);
+ ASSERT_EQUALS(uuid, coll->uuid());
};
pushOps({entry});
auto writerPool = makeTenantMigrationWriterPool();