diff options
author | Benety Goh <benety@mongodb.com> | 2021-11-19 06:25:11 -0500 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-19 11:54:03 +0000 |
commit | 3327daa086ffb61a14827f7989603aced74ab906 (patch) | |
tree | 3d8d58ea37286828fd153d46640cb59b89c0d547 /src/mongo | |
parent | 60280010d13224a26aa3445944065975cc0b81a7 (diff) | |
download | mongo-3327daa086ffb61a14827f7989603aced74ab906.tar.gz |
SERVER-61611 OpObserver::aboutToDelete() accepts UUID
Diffstat (limited to 'src/mongo')
23 files changed, 42 insertions, 14 deletions
diff --git a/src/mongo/db/auth/auth_op_observer.cpp b/src/mongo/db/auth/auth_op_observer.cpp index 25e7effc9fe..729493ed970 100644 --- a/src/mongo/db/auth/auth_op_observer.cpp +++ b/src/mongo/db/auth/auth_op_observer.cpp @@ -76,6 +76,7 @@ void AuthOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateEntryArg void AuthOpObserver::aboutToDelete(OperationContext* opCtx, NamespaceString const& nss, + const UUID& uuid, BSONObj const& doc) { audit::logRemoveOperation(opCtx->getClient(), nss, doc); diff --git a/src/mongo/db/auth/auth_op_observer.h b/src/mongo/db/auth/auth_op_observer.h index 6d9c6ef354e..a4503e96c20 100644 --- a/src/mongo/db/auth/auth_op_observer.h +++ b/src/mongo/db/auth/auth_op_observer.h @@ -88,6 +88,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) final; void onDelete(OperationContext* opCtx, diff --git a/src/mongo/db/auth/auth_op_observer_test.cpp b/src/mongo/db/auth/auth_op_observer_test.cpp index be5c426aafe..72f1230af43 100644 --- a/src/mongo/db/auth/auth_op_observer_test.cpp +++ b/src/mongo/db/auth/auth_op_observer_test.cpp @@ -133,9 +133,9 @@ TEST_F(AuthOpObserverTest, MultipleAboutToDeleteAndOnDelete) { NamespaceString nss = {"test", "coll"}; AutoGetDb autoDb(opCtx.get(), nss.db(), MODE_X); WriteUnitOfWork wunit(opCtx.get()); - opObserver.aboutToDelete(opCtx.get(), nss, BSON("_id" << 1)); + opObserver.aboutToDelete(opCtx.get(), nss, uuid, BSON("_id" << 1)); opObserver.onDelete(opCtx.get(), nss, uuid, {}, {}); - opObserver.aboutToDelete(opCtx.get(), nss, BSON("_id" << 1)); + opObserver.aboutToDelete(opCtx.get(), nss, uuid, BSON("_id" << 1)); opObserver.onDelete(opCtx.get(), nss, uuid, {}, {}); } @@ -148,13 +148,14 @@ DEATH_TEST_F(AuthOpObserverTest, AboutToDeleteMustPreceedOnDelete, "invariant") } DEATH_TEST_F(AuthOpObserverTest, EachOnDeleteRequiresAboutToDelete, "invariant") { + auto uuid = UUID::gen(); AuthOpObserver opObserver; auto opCtx = cc().makeOperationContext(); cc().swapLockState(std::make_unique<LockerNoop>()); NamespaceString nss = {"test", "coll"}; - opObserver.aboutToDelete(opCtx.get(), nss, {}); - opObserver.onDelete(opCtx.get(), nss, UUID::gen(), {}, {}); - opObserver.onDelete(opCtx.get(), nss, UUID::gen(), {}, {}); + opObserver.aboutToDelete(opCtx.get(), nss, uuid, {}); + opObserver.onDelete(opCtx.get(), nss, uuid, {}, {}); + opObserver.onDelete(opCtx.get(), nss, uuid, {}, {}); } } // namespace diff --git a/src/mongo/db/catalog/collection_impl.cpp b/src/mongo/db/catalog/collection_impl.cpp index 4bcc1657708..7ba1084c750 100644 --- a/src/mongo/db/catalog/collection_impl.cpp +++ b/src/mongo/db/catalog/collection_impl.cpp @@ -1053,7 +1053,7 @@ void CollectionImpl::_cappedDeleteAsNeeded(OperationContext* opCtx, BSONObj doc = record->data.toBson(); if (ns().isReplicated()) { OpObserver* opObserver = opCtx->getServiceContext()->getOpObserver(); - opObserver->aboutToDelete(opCtx, ns(), doc); + opObserver->aboutToDelete(opCtx, ns(), uuid(), doc); OplogDeleteEntryArgs args; // Explicitly setting values despite them being the defaults. @@ -1184,7 +1184,7 @@ void CollectionImpl::deleteDocument(OperationContext* opCtx, retryableFindAndModifyLocation, oplogSlots}; - getGlobalServiceContext()->getOpObserver()->aboutToDelete(opCtx, ns(), doc.value()); + getGlobalServiceContext()->getOpObserver()->aboutToDelete(opCtx, ns(), uuid(), doc.value()); boost::optional<BSONObj> deletedDoc; const bool isRecordingPreImageForRetryableWrite = diff --git a/src/mongo/db/fcv_op_observer.h b/src/mongo/db/fcv_op_observer.h index 7a9e021ce81..60cce448d8d 100644 --- a/src/mongo/db/fcv_op_observer.h +++ b/src/mongo/db/fcv_op_observer.h @@ -101,6 +101,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) final {} void onInternalOpMessage(OperationContext* opCtx, const NamespaceString& nss, diff --git a/src/mongo/db/free_mon/free_mon_op_observer.cpp b/src/mongo/db/free_mon/free_mon_op_observer.cpp index 7e22ab872a8..1a0785c1df8 100644 --- a/src/mongo/db/free_mon/free_mon_op_observer.cpp +++ b/src/mongo/db/free_mon/free_mon_op_observer.cpp @@ -120,6 +120,7 @@ void FreeMonOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateEntry void FreeMonOpObserver::aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) { bool isFreeMonDoc = (nss == NamespaceString::kServerConfigurationNamespace) && diff --git a/src/mongo/db/free_mon/free_mon_op_observer.h b/src/mongo/db/free_mon/free_mon_op_observer.h index 9e291f2afdd..8a8a6adc74f 100644 --- a/src/mongo/db/free_mon/free_mon_op_observer.h +++ b/src/mongo/db/free_mon/free_mon_op_observer.h @@ -88,6 +88,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) final; void onDelete(OperationContext* opCtx, diff --git a/src/mongo/db/op_observer.h b/src/mongo/db/op_observer.h index 4b243896f82..a50920cf2e4 100644 --- a/src/mongo/db/op_observer.h +++ b/src/mongo/db/op_observer.h @@ -171,6 +171,7 @@ public: virtual void onUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs& args) = 0; virtual void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) = 0; /** diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp index ab5cd06a0f2..0c3702ea8b7 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -785,6 +785,7 @@ void OpObserverImpl::onUpdate(OperationContext* opCtx, const OplogUpdateEntryArg void OpObserverImpl::aboutToDelete(OperationContext* opCtx, NamespaceString const& nss, + const UUID& uuid, BSONObj const& doc) { documentKeyDecoration(opCtx).emplace(getDocumentKey(opCtx, nss, doc)); diff --git a/src/mongo/db/op_observer_impl.h b/src/mongo/db/op_observer_impl.h index 57b7c591c83..a8980be67a4 100644 --- a/src/mongo/db/op_observer_impl.h +++ b/src/mongo/db/op_observer_impl.h @@ -104,6 +104,7 @@ public: void onUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs& args) final; void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) final; void onDelete(OperationContext* opCtx, const NamespaceString& nss, diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp index 47228adbacd..1b03b11ade3 100644 --- a/src/mongo/db/op_observer_impl_test.cpp +++ b/src/mongo/db/op_observer_impl_test.cpp @@ -698,9 +698,9 @@ TEST_F(OpObserverTest, MultipleAboutToDeleteAndOnDelete) { NamespaceString nss = {"test", "coll"}; AutoGetDb autoDb(opCtx.get(), nss.db(), MODE_X); WriteUnitOfWork wunit(opCtx.get()); - opObserver.aboutToDelete(opCtx.get(), nss, BSON("_id" << 1)); + opObserver.aboutToDelete(opCtx.get(), nss, uuid, BSON("_id" << 1)); opObserver.onDelete(opCtx.get(), nss, uuid, kUninitializedStmtId, {}); - opObserver.aboutToDelete(opCtx.get(), nss, BSON("_id" << 1)); + opObserver.aboutToDelete(opCtx.get(), nss, uuid, BSON("_id" << 1)); opObserver.onDelete(opCtx.get(), nss, uuid, kUninitializedStmtId, {}); } @@ -718,7 +718,7 @@ DEATH_TEST_F(OpObserverTest, EachOnDeleteRequiresAboutToDelete, "invariant") { cc().swapLockState(std::make_unique<LockerNoop>()); NamespaceString nss = {"test", "coll"}; UUID uuid = UUID::gen(); - opObserver.aboutToDelete(opCtx.get(), nss, {}); + opObserver.aboutToDelete(opCtx.get(), nss, uuid, {}); opObserver.onDelete(opCtx.get(), nss, uuid, kUninitializedStmtId, {}); opObserver.onDelete(opCtx.get(), nss, uuid, kUninitializedStmtId, {}); } @@ -913,6 +913,7 @@ TEST_F(OpObserverTransactionTest, TransactionalPrepareTest) { opObserver().aboutToDelete(opCtx(), nss1, + uuid1, BSON("_id" << 0 << "data" << "x")); opObserver().onDelete(opCtx(), nss1, uuid1, 0, {}); @@ -1420,11 +1421,13 @@ TEST_F(OpObserverTransactionTest, TransactionalDeleteTest) { AutoGetCollection autoColl2(opCtx(), nss2, MODE_IX); opObserver().aboutToDelete(opCtx(), nss1, + uuid1, BSON("_id" << 0 << "data" << "x")); opObserver().onDelete(opCtx(), nss1, uuid1, 0, {}); opObserver().aboutToDelete(opCtx(), nss2, + uuid2, BSON("_id" << 1 << "data" << "y")); opObserver().onDelete(opCtx(), nss2, uuid2, 0, {}); @@ -1572,7 +1575,7 @@ TEST_F(OpObserverRetryableFindAndModifyTest, RetryableFindAndModifyDeleteHasNeed AutoGetDb autoDb(opCtx(), nss.db(), MODE_X); const auto deletedDoc = BSON("_id" << 0 << "data" << "x"); - opObserver().aboutToDelete(opCtx(), nss, deletedDoc); + opObserver().aboutToDelete(opCtx(), nss, uuid, deletedDoc); OplogDeleteEntryArgs args; args.retryableFindAndModifyLocation = RetryableFindAndModifyLocation::kSideCollection; args.deletedDoc = &deletedDoc; @@ -2272,7 +2275,7 @@ TEST_F(OpObserverMultiEntryTransactionTest, TransactionPreImageTest) { OplogDeleteEntryArgs args; args.deletedDoc = &deletedDoc; args.preImageRecordingEnabledForCollection = true; - opObserver().aboutToDelete(opCtx(), nss1, deletedDoc); + opObserver().aboutToDelete(opCtx(), nss1, uuid1, deletedDoc); opObserver().onDelete(opCtx(), nss1, uuid1, 0, args); auto txnOps = txnParticipant.retrieveCompletedTransactionOperations(opCtx()); @@ -2349,7 +2352,7 @@ TEST_F(OpObserverMultiEntryTransactionTest, PreparedTransactionPreImageTest) { OplogDeleteEntryArgs args; args.deletedDoc = &deletedDoc; args.preImageRecordingEnabledForCollection = true; - opObserver().aboutToDelete(opCtx(), nss1, deletedDoc); + opObserver().aboutToDelete(opCtx(), nss1, uuid1, deletedDoc); opObserver().onDelete(opCtx(), nss1, uuid1, 0, args); repl::OpTime prepareOpTime; @@ -2415,11 +2418,13 @@ TEST_F(OpObserverMultiEntryTransactionTest, TransactionalDeleteTest) { AutoGetCollection autoColl2(opCtx(), nss2, MODE_IX); opObserver().aboutToDelete(opCtx(), nss1, + uuid1, BSON("_id" << 0 << "data" << "x")); opObserver().onDelete(opCtx(), nss1, uuid1, 0, {}); opObserver().aboutToDelete(opCtx(), nss2, + uuid2, BSON("_id" << 1 << "data" << "y")); opObserver().onDelete(opCtx(), nss2, uuid2, 0, {}); @@ -2629,11 +2634,13 @@ TEST_F(OpObserverMultiEntryTransactionTest, TransactionalDeletePrepareTest) { AutoGetCollection autoColl2(opCtx(), nss2, MODE_IX); opObserver().aboutToDelete(opCtx(), nss1, + uuid1, BSON("_id" << 0 << "data" << "x")); opObserver().onDelete(opCtx(), nss1, uuid1, 0, {}); opObserver().aboutToDelete(opCtx(), nss2, + uuid2, BSON("_id" << 1 << "data" << "y")); opObserver().onDelete(opCtx(), nss2, uuid2, 0, {}); diff --git a/src/mongo/db/op_observer_noop.h b/src/mongo/db/op_observer_noop.h index b7a39363d7e..e43b1ed9fa0 100644 --- a/src/mongo/db/op_observer_noop.h +++ b/src/mongo/db/op_observer_noop.h @@ -78,6 +78,7 @@ public: void onUpdate(OperationContext* opCtx, const OplogUpdateEntryArgs& args) override{}; void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) override {} void onDelete(OperationContext* opCtx, const NamespaceString& nss, diff --git a/src/mongo/db/op_observer_registry.h b/src/mongo/db/op_observer_registry.h index c14123c3e5f..ca593c0f9aa 100644 --- a/src/mongo/db/op_observer_registry.h +++ b/src/mongo/db/op_observer_registry.h @@ -140,10 +140,11 @@ public: void aboutToDelete(OperationContext* const opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) override { ReservedTimes times{opCtx}; for (auto& o : _observers) - o->aboutToDelete(opCtx, nss, doc); + o->aboutToDelete(opCtx, nss, uuid, doc); } void onDelete(OperationContext* const opCtx, 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 2d048454a20..3ed52e7ec6b 100644 --- a/src/mongo/db/repl/primary_only_service_op_observer.cpp +++ b/src/mongo/db/repl/primary_only_service_op_observer.cpp @@ -51,6 +51,7 @@ PrimaryOnlyServiceOpObserver::~PrimaryOnlyServiceOpObserver() = default; void PrimaryOnlyServiceOpObserver::aboutToDelete(OperationContext* opCtx, NamespaceString const& nss, + const UUID& uuid, BSONObj const& doc) { // Extract the _id field from the document. If it does not have an _id, use the // document itself as the _id. 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 9e9d1bd69d6..8a94f2347e1 100644 --- a/src/mongo/db/repl/primary_only_service_op_observer.h +++ b/src/mongo/db/repl/primary_only_service_op_observer.h @@ -90,6 +90,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) final; void onDelete(OperationContext* opCtx, 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 9295ed1f325..8b3945f398b 100644 --- a/src/mongo/db/repl/tenant_migration_donor_op_observer.cpp +++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.cpp @@ -258,6 +258,7 @@ void TenantMigrationDonorOpObserver::onUpdate(OperationContext* opCtx, void TenantMigrationDonorOpObserver::aboutToDelete(OperationContext* opCtx, NamespaceString const& nss, + const UUID& uuid, BSONObj const& doc) { if (nss == NamespaceString::kTenantMigrationDonorsNamespace && !tenant_migration_access_blocker::inRecoveryMode(opCtx)) { 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 fe240e8f503..3f59fb7a35c 100644 --- a/src/mongo/db/repl/tenant_migration_donor_op_observer.h +++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.h @@ -88,6 +88,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) final; void onDelete(OperationContext* opCtx, 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 2fc7c45d3be..47919008aab 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp +++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp @@ -129,6 +129,7 @@ void TenantMigrationRecipientOpObserver::onUpdate(OperationContext* opCtx, void TenantMigrationRecipientOpObserver::aboutToDelete(OperationContext* opCtx, NamespaceString const& nss, + const UUID& uuid, BSONObj const& doc) { if (nss == NamespaceString::kTenantMigrationRecipientsNamespace && !tenant_migration_access_blocker::inRecoveryMode(opCtx)) { 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 791fd7eeccd..a94b4723fa0 100644 --- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h +++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h @@ -89,6 +89,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) final; void onDelete(OperationContext* opCtx, diff --git a/src/mongo/db/s/config_server_op_observer.h b/src/mongo/db/s/config_server_op_observer.h index 53e54132952..1e1f91c78ce 100644 --- a/src/mongo/db/s/config_server_op_observer.h +++ b/src/mongo/db/s/config_server_op_observer.h @@ -91,6 +91,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) override {} void onDelete(OperationContext* opCtx, diff --git a/src/mongo/db/s/resharding/resharding_op_observer.h b/src/mongo/db/s/resharding/resharding_op_observer.h index 4b786ee2796..4477c9f0d00 100644 --- a/src/mongo/db/s/resharding/resharding_op_observer.h +++ b/src/mongo/db/s/resharding/resharding_op_observer.h @@ -106,6 +106,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) override {} void onDelete(OperationContext* opCtx, diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index a3b7a6eaf18..67df49364dc 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -449,6 +449,7 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE void ShardServerOpObserver::aboutToDelete(OperationContext* opCtx, NamespaceString const& nss, + const UUID& uuid, BSONObj const& doc) { if (nss == NamespaceString::kCollectionCriticalSectionsNamespace) { diff --git a/src/mongo/db/s/shard_server_op_observer.h b/src/mongo/db/s/shard_server_op_observer.h index 34fbb1a6ebf..0c145aeb596 100644 --- a/src/mongo/db/s/shard_server_op_observer.h +++ b/src/mongo/db/s/shard_server_op_observer.h @@ -88,6 +88,7 @@ public: void aboutToDelete(OperationContext* opCtx, const NamespaceString& nss, + const UUID& uuid, const BSONObj& doc) override; void onDelete(OperationContext* opCtx, |