diff options
author | Benety Goh <benety@mongodb.com> | 2019-01-08 18:54:38 -0500 |
---|---|---|
committer | Benety Goh <benety@mongodb.com> | 2019-01-08 18:54:54 -0500 |
commit | ecf269ff6494930ae4dfa98f66c4cbd6335cede2 (patch) | |
tree | f4b8d60e6a09812b06c6d65ff7645d70efded954 /src | |
parent | e2b8d928d796b4b6a6144bc4aa27db6fe95bfdd8 (diff) | |
download | mongo-ecf269ff6494930ae4dfa98f66c4cbd6335cede2.tar.gz |
SERVER-38800 OpObserver accepts numRecords for drop and rename operations
Diffstat (limited to 'src')
27 files changed, 89 insertions, 22 deletions
diff --git a/src/mongo/db/auth/auth_op_observer.cpp b/src/mongo/db/auth/auth_op_observer.cpp index 6f45185a47a..061fd1959a5 100644 --- a/src/mongo/db/auth/auth_op_observer.cpp +++ b/src/mongo/db/auth/auth_op_observer.cpp @@ -134,6 +134,7 @@ void AuthOpObserver::onDropDatabase(OperationContext* opCtx, const std::string& repl::OpTime AuthOpObserver::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { const auto cmdNss = collectionName.getCommandNS(); const auto cmdObj = BSON("drop" << collectionName.coll()); @@ -183,6 +184,7 @@ void AuthOpObserver::onRenameCollection(OperationContext* const opCtx, const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) { postRenameCollection(opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); } diff --git a/src/mongo/db/auth/auth_op_observer.h b/src/mongo/db/auth/auth_op_observer.h index b0aaa09e0cd..28646565929 100644 --- a/src/mongo/db/auth/auth_op_observer.h +++ b/src/mongo/db/auth/auth_op_observer.h @@ -96,6 +96,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) final; void onDropIndex(OperationContext* opCtx, @@ -109,6 +110,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) final; repl::OpTime preRenameCollection(OperationContext* opCtx, @@ -116,6 +118,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) final { return repl::OpTime(); } diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index c20e5bf875b..18a0506a680 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -227,6 +227,7 @@ Status createCollectionForApplyOps(OperationContext* opCtx, tmpName, futureColl->uuid(), /*dropTargetUUID*/ {}, + /*numRecords*/ 0U, stayTemp); } @@ -247,6 +248,7 @@ Status createCollectionForApplyOps(OperationContext* opCtx, newCollName, uuid, /*dropTargetUUID*/ {}, + /*numRecords*/ 0U, stayTemp); wunit.commit(); diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index 32fbd008eae..1dff3dedc2d 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -510,6 +510,8 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx, return Status::OK(); // Post condition already met. } + auto numRecords = uint64_t(0); + auto uuid = collection->uuid(); auto uuidString = uuid ? uuid.get().toString() : "no UUID"; @@ -543,7 +545,7 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx, return status; } opObserver->onDropCollection( - opCtx, fullns, uuid, OpObserver::CollectionDropType::kOnePhase); + opCtx, fullns, uuid, numRecords, OpObserver::CollectionDropType::kOnePhase); return Status::OK(); } @@ -594,7 +596,8 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx, // Log oplog entry for collection drop and proceed to complete rest of two phase drop // process. - dropOpTime = opObserver->onDropCollection(opCtx, fullns, uuid, collectionDropType); + dropOpTime = + opObserver->onDropCollection(opCtx, fullns, uuid, numRecords, collectionDropType); // The OpObserver should have written an entry to the oplog with a particular op time. // After writing the oplog entry, all errors are fatal. See getNextOpTime() comments in @@ -609,7 +612,8 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx, // in the context of applying an oplog entry on a secondary. // OpObserver::onDropCollection() should be returning a null OpTime because we should not be // writing to the oplog. - auto opTime = opObserver->onDropCollection(opCtx, fullns, uuid, collectionDropType); + auto opTime = + opObserver->onDropCollection(opCtx, fullns, uuid, numRecords, collectionDropType); if (!opTime.isNull()) { severe() << "dropCollection: " << fullns << " (" << uuidString << ") - unexpected oplog entry written to the oplog with optime " << opTime; diff --git a/src/mongo/db/catalog/drop_database_test.cpp b/src/mongo/db/catalog/drop_database_test.cpp index 61a62c098af..4fade537724 100644 --- a/src/mongo/db/catalog/drop_database_test.cpp +++ b/src/mongo/db/catalog/drop_database_test.cpp @@ -71,6 +71,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) override; std::set<std::string> droppedDatabaseNames; @@ -90,9 +91,11 @@ void OpObserverMock::onDropDatabase(OperationContext* opCtx, const std::string& repl::OpTime OpObserverMock::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { ASSERT_TRUE(opCtx->lockState()->inAWriteUnitOfWork()); - auto opTime = OpObserverNoop::onDropCollection(opCtx, collectionName, uuid, dropType); + auto opTime = + OpObserverNoop::onDropCollection(opCtx, collectionName, uuid, numRecords, dropType); invariant(opTime.isNull()); // Do not update 'droppedCollectionNames' if OpObserverNoop::onDropCollection() throws. droppedCollectionNames.insert(collectionName); diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index 61bb304bfde..bb7bb831c22 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -278,7 +278,7 @@ Status renameCollectionCommon(OperationContext* opCtx, // We have to override the provided 'dropTarget' setting for idempotency reasons to // avoid unintentionally removing a collection on a secondary with the same name as // the target. - opObserver->onRenameCollection(opCtx, source, target, sourceUUID, {}, stayTemp); + opObserver->onRenameCollection(opCtx, source, target, sourceUUID, {}, 0U, stayTemp); wunit.commit(); return Status::OK(); } @@ -331,8 +331,9 @@ Status renameCollectionCommon(OperationContext* opCtx, } } + auto numRecords = uint64_t(0); auto renameOpTime = opObserver->preRenameCollection( - opCtx, source, target, sourceUUID, dropTargetUUID, options.stayTemp); + opCtx, source, target, sourceUUID, dropTargetUUID, numRecords, options.stayTemp); if (!renameOpTimeFromApplyOps.isNull()) { // 'renameOpTime' must be null because a valid 'renameOpTimeFromApplyOps' implies diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp index 982d8d52b6a..e38f5e5ab64 100644 --- a/src/mongo/db/catalog/rename_collection_test.cpp +++ b/src/mongo/db/catalog/rename_collection_test.cpp @@ -98,6 +98,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) override; void onRenameCollection(OperationContext* opCtx, @@ -105,6 +106,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override; repl::OpTime preRenameCollection(OperationContext* opCtx, @@ -112,6 +114,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override; void postRenameCollection(OperationContext* opCtx, const NamespaceString& fromCollection, @@ -182,6 +185,7 @@ void OpObserverMock::onCreateCollection(OperationContext* opCtx, repl::OpTime OpObserverMock::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { _logOp(opCtx, collectionName, "drop"); // If the oplog is not disabled for this namespace, then we need to reserve an op time for the @@ -189,7 +193,8 @@ repl::OpTime OpObserverMock::onDropCollection(OperationContext* opCtx, if (!repl::ReplicationCoordinator::get(opCtx)->isOplogDisabledFor(opCtx, collectionName)) { OpObserver::Times::get(opCtx).reservedOpTimes.push_back(dropOpTime); } - auto noopOptime = OpObserverNoop::onDropCollection(opCtx, collectionName, uuid, dropType); + auto noopOptime = + OpObserverNoop::onDropCollection(opCtx, collectionName, uuid, numRecords, dropType); invariant(noopOptime.isNull()); return {}; } @@ -199,10 +204,12 @@ void OpObserverMock::onRenameCollection(OperationContext* opCtx, const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) { - preRenameCollection(opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); + preRenameCollection( + opCtx, fromCollection, toCollection, uuid, dropTargetUUID, numRecords, stayTemp); OpObserverNoop::onRenameCollection( - opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); + opCtx, fromCollection, toCollection, uuid, dropTargetUUID, numRecords, stayTemp); onRenameCollectionCalled = true; onRenameCollectionDropTarget = dropTargetUUID; } @@ -224,11 +231,12 @@ repl::OpTime OpObserverMock::preRenameCollection(OperationContext* opCtx, const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) { _logOp(opCtx, fromCollection, "rename"); OpObserver::Times::get(opCtx).reservedOpTimes.push_back(renameOpTime); OpObserverNoop::preRenameCollection( - opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); + opCtx, fromCollection, toCollection, uuid, dropTargetUUID, numRecords, stayTemp); return {}; } void OpObserverMock::_logOp(OperationContext* opCtx, diff --git a/src/mongo/db/catalog/uuid_catalog.cpp b/src/mongo/db/catalog/uuid_catalog.cpp index 71dff8b045a..d6b11663e32 100644 --- a/src/mongo/db/catalog/uuid_catalog.cpp +++ b/src/mongo/db/catalog/uuid_catalog.cpp @@ -77,6 +77,7 @@ void UUIDCatalogObserver::onCollMod(OperationContext* opCtx, repl::OpTime UUIDCatalogObserver::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { if (!uuid) diff --git a/src/mongo/db/catalog/uuid_catalog.h b/src/mongo/db/catalog/uuid_catalog.h index 4687cb0cf30..ec0adbdae7e 100644 --- a/src/mongo/db/catalog/uuid_catalog.h +++ b/src/mongo/db/catalog/uuid_catalog.h @@ -87,6 +87,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) override; void onDropIndex(OperationContext* opCtx, const NamespaceString& nss, @@ -99,6 +100,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override { // Do nothing: collection renames don't affect the UUID mapping. } @@ -108,6 +110,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override { // Do nothing: collection renames don't affect the UUID mapping. return {}; diff --git a/src/mongo/db/commands/mr_test.cpp b/src/mongo/db/commands/mr_test.cpp index 6ff0a8bd5a9..d2a969890c8 100644 --- a/src/mongo/db/commands/mr_test.cpp +++ b/src/mongo/db/commands/mr_test.cpp @@ -302,6 +302,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) override; // Hook for onInserts. Defaults to a no-op function but may be overridden to inject exceptions @@ -338,6 +339,7 @@ void MapReduceOpObserver::onCreateCollection(OperationContext*, repl::OpTime MapReduceOpObserver::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { // If the oplog is not disabled for this namespace, then we need to reserve an op time for the // drop. 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 467960b3c26..a7d35cca1fb 100644 --- a/src/mongo/db/free_mon/free_mon_op_observer.cpp +++ b/src/mongo/db/free_mon/free_mon_op_observer.cpp @@ -58,6 +58,7 @@ FreeMonOpObserver::~FreeMonOpObserver() = default; repl::OpTime FreeMonOpObserver::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { if (collectionName == NamespaceString::kServerConfigurationNamespace) { auto controller = FreeMonController::get(opCtx->getServiceContext()); 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 535b61cacca..be29495b4ef 100644 --- a/src/mongo/db/free_mon/free_mon_op_observer.h +++ b/src/mongo/db/free_mon/free_mon_op_observer.h @@ -97,6 +97,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) final; void onDropIndex(OperationContext* opCtx, @@ -110,6 +111,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) final {} repl::OpTime preRenameCollection(OperationContext* opCtx, @@ -117,6 +119,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) final { return repl::OpTime(); } diff --git a/src/mongo/db/op_observer.h b/src/mongo/db/op_observer.h index 52abe0618b5..91c66abb603 100644 --- a/src/mongo/db/op_observer.h +++ b/src/mongo/db/op_observer.h @@ -193,6 +193,7 @@ public: virtual repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) = 0; /** @@ -223,6 +224,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) = 0; /** * This function performs all op observer handling for a 'renameCollection' command except for @@ -246,6 +248,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) = 0; virtual void onApplyOps(OperationContext* opCtx, diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp index d9086af8939..7a4a75a1f28 100644 --- a/src/mongo/db/op_observer_impl.cpp +++ b/src/mongo/db/op_observer_impl.cpp @@ -668,6 +668,7 @@ void OpObserverImpl::onDropDatabase(OperationContext* opCtx, const std::string& repl::OpTime OpObserverImpl::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { const auto cmdNss = collectionName.getCommandNS(); const auto cmdObj = BSON("drop" << collectionName.coll()); @@ -734,6 +735,7 @@ repl::OpTime OpObserverImpl::preRenameCollection(OperationContext* const opCtx, const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) { const auto cmdNss = fromCollection.getCommandNS(); @@ -788,8 +790,10 @@ void OpObserverImpl::onRenameCollection(OperationContext* const opCtx, const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) { - preRenameCollection(opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); + preRenameCollection( + opCtx, fromCollection, toCollection, uuid, dropTargetUUID, numRecords, stayTemp); postRenameCollection(opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); } diff --git a/src/mongo/db/op_observer_impl.h b/src/mongo/db/op_observer_impl.h index 01b85ce46d0..989b7d8075e 100644 --- a/src/mongo/db/op_observer_impl.h +++ b/src/mongo/db/op_observer_impl.h @@ -83,6 +83,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) final; void onDropIndex(OperationContext* opCtx, const NamespaceString& nss, @@ -94,6 +95,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) final; void postRenameCollection(OperationContext* opCtx, const NamespaceString& fromCollection, @@ -106,6 +108,7 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) final; void onApplyOps(OperationContext* opCtx, const std::string& dbName, diff --git a/src/mongo/db/op_observer_impl_test.cpp b/src/mongo/db/op_observer_impl_test.cpp index d73610ade4b..991b452a1bc 100644 --- a/src/mongo/db/op_observer_impl_test.cpp +++ b/src/mongo/db/op_observer_impl_test.cpp @@ -217,7 +217,7 @@ TEST_F(OpObserverTest, OnDropCollectionReturnsDropOpTime) { AutoGetDb autoDb(opCtx.get(), nss.db(), MODE_X); WriteUnitOfWork wunit(opCtx.get()); opObserver.onDropCollection( - opCtx.get(), nss, uuid, OpObserver::CollectionDropType::kTwoPhase); + opCtx.get(), nss, uuid, 0U, OpObserver::CollectionDropType::kTwoPhase); dropOpTime = OpObserver::Times::get(opCtx.get()).reservedOpTimes.front(); wunit.commit(); } @@ -249,7 +249,7 @@ TEST_F(OpObserverTest, OnRenameCollectionReturnsRenameOpTime) { AutoGetDb autoDb(opCtx.get(), sourceNss.db(), MODE_X); WriteUnitOfWork wunit(opCtx.get()); opObserver.onRenameCollection( - opCtx.get(), sourceNss, targetNss, uuid, dropTargetUuid, stayTemp); + opCtx.get(), sourceNss, targetNss, uuid, dropTargetUuid, 0U, stayTemp); renameOpTime = OpObserver::Times::get(opCtx.get()).reservedOpTimes.front(); wunit.commit(); } @@ -282,7 +282,7 @@ TEST_F(OpObserverTest, OnRenameCollectionOmitsDropTargetFieldIfDropTargetUuidIsN { AutoGetDb autoDb(opCtx.get(), sourceNss.db(), MODE_X); WriteUnitOfWork wunit(opCtx.get()); - opObserver.onRenameCollection(opCtx.get(), sourceNss, targetNss, uuid, {}, stayTemp); + opObserver.onRenameCollection(opCtx.get(), sourceNss, targetNss, uuid, {}, 0U, stayTemp); wunit.commit(); } diff --git a/src/mongo/db/op_observer_noop.h b/src/mongo/db/op_observer_noop.h index 350d6df41bf..469043de57f 100644 --- a/src/mongo/db/op_observer_noop.h +++ b/src/mongo/db/op_observer_noop.h @@ -78,6 +78,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) override { return {}; } @@ -91,12 +92,14 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override {} repl::OpTime preRenameCollection(OperationContext* opCtx, const NamespaceString& fromCollection, const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override { return {}; } diff --git a/src/mongo/db/op_observer_registry.h b/src/mongo/db/op_observer_registry.h index 5c8ab409ab7..c64537f5104 100644 --- a/src/mongo/db/op_observer_registry.h +++ b/src/mongo/db/op_observer_registry.h @@ -145,10 +145,12 @@ public: repl::OpTime onDropCollection(OperationContext* const opCtx, const NamespaceString& collectionName, const OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) override { ReservedTimes times{opCtx}; for (auto& observer : this->_observers) { - auto time = observer->onDropCollection(opCtx, collectionName, uuid, dropType); + auto time = + observer->onDropCollection(opCtx, collectionName, uuid, numRecords, dropType); invariant(time.isNull()); } return _getOpTimeToReturn(times.get().reservedOpTimes); @@ -170,11 +172,12 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override { ReservedTimes times{opCtx}; for (auto& o : _observers) o->onRenameCollection( - opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); + opCtx, fromCollection, toCollection, uuid, dropTargetUUID, numRecords, stayTemp); } repl::OpTime preRenameCollection(OperationContext* const opCtx, @@ -182,11 +185,12 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override { ReservedTimes times{opCtx}; for (auto& observer : this->_observers) { const auto time = observer->preRenameCollection( - opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); + opCtx, fromCollection, toCollection, uuid, dropTargetUUID, numRecords, stayTemp); invariant(time.isNull()); } return _getOpTimeToReturn(times.get().reservedOpTimes); diff --git a/src/mongo/db/op_observer_registry_test.cpp b/src/mongo/db/op_observer_registry_test.cpp index e7281598601..118b8682ea0 100644 --- a/src/mongo/db/op_observer_registry_test.cpp +++ b/src/mongo/db/op_observer_registry_test.cpp @@ -57,6 +57,7 @@ struct TestObserver : public OpObserverNoop { repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { drops++; OpObserver::Times::get(opCtx).reservedOpTimes.push_back(opTime); @@ -67,8 +68,10 @@ struct TestObserver : public OpObserverNoop { const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) { - preRenameCollection(opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); + preRenameCollection( + opCtx, fromCollection, toCollection, uuid, dropTargetUUID, numRecords, stayTemp); postRenameCollection(opCtx, fromCollection, toCollection, uuid, dropTargetUUID, stayTemp); } repl::OpTime preRenameCollection(OperationContext* opCtx, @@ -76,6 +79,7 @@ struct TestObserver : public OpObserverNoop { const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) { OpObserver::Times::get(opCtx).reservedOpTimes.push_back(opTime); return {}; @@ -172,7 +176,7 @@ TEST_F(OpObserverRegistryTest, OnDropCollectionObserverResultReturnsRightTime) { registry.addObserver(std::make_unique<OpObserverNoop>()); auto op = [&]() -> repl::OpTime { return registry.onDropCollection( - &opCtx, testNss, {}, OpObserver::CollectionDropType::kOnePhase); + &opCtx, testNss, {}, 0U, OpObserver::CollectionDropType::kOnePhase); }; checkConsistentOpTime(op); } @@ -182,7 +186,7 @@ TEST_F(OpObserverRegistryTest, PreRenameCollectionObserverResultReturnsRightTime registry.addObserver(std::move(unique1)); registry.addObserver(std::make_unique<OpObserverNoop>()); auto op = [&]() -> repl::OpTime { - auto opTime = registry.preRenameCollection(&opCtx, testNss, testNss, {}, {}, false); + auto opTime = registry.preRenameCollection(&opCtx, testNss, testNss, {}, {}, 0U, false); registry.postRenameCollection(&opCtx, testNss, testNss, {}, {}, false); return opTime; }; @@ -195,7 +199,7 @@ DEATH_TEST_F(OpObserverRegistryTest, OnDropCollectionReturnsInconsistentTime, "i registry.addObserver(std::move(unique2)); auto op = [&]() -> repl::OpTime { return registry.onDropCollection( - &opCtx, testNss, {}, OpObserver::CollectionDropType::kOnePhase); + &opCtx, testNss, {}, 0U, OpObserver::CollectionDropType::kOnePhase); }; checkInconsistentOpTime(op); } @@ -205,7 +209,7 @@ DEATH_TEST_F(OpObserverRegistryTest, PreRenameCollectionReturnsInconsistentTime, registry.addObserver(std::move(unique1)); registry.addObserver(std::move(unique2)); auto op = [&]() -> repl::OpTime { - auto opTime = registry.preRenameCollection(&opCtx, testNss, testNss, {}, {}, false); + auto opTime = registry.preRenameCollection(&opCtx, testNss, testNss, {}, {}, 0U, false); registry.postRenameCollection(&opCtx, testNss, testNss, {}, {}, false); return opTime; }; diff --git a/src/mongo/db/repl/replication_recovery_test.cpp b/src/mongo/db/repl/replication_recovery_test.cpp index d9d2a46f494..569b76d0a17 100644 --- a/src/mongo/db/repl/replication_recovery_test.cpp +++ b/src/mongo/db/repl/replication_recovery_test.cpp @@ -116,6 +116,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) override { // If the oplog is not disabled for this namespace, then we need to reserve an op time for // the drop. diff --git a/src/mongo/db/repl/rollback_test_fixture.cpp b/src/mongo/db/repl/rollback_test_fixture.cpp index c6644d81249..95a3d1ea635 100644 --- a/src/mongo/db/repl/rollback_test_fixture.cpp +++ b/src/mongo/db/repl/rollback_test_fixture.cpp @@ -72,6 +72,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) override { // If the oplog is not disabled for this namespace, then we need to reserve an op time for // the drop. diff --git a/src/mongo/db/s/config_server_op_observer.cpp b/src/mongo/db/s/config_server_op_observer.cpp index cdf45de44f5..3706b476228 100644 --- a/src/mongo/db/s/config_server_op_observer.cpp +++ b/src/mongo/db/s/config_server_op_observer.cpp @@ -66,6 +66,7 @@ void ConfigServerOpObserver::onDelete(OperationContext* opCtx, repl::OpTime ConfigServerOpObserver::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { if (collectionName == VersionType::ConfigNS) { if (!repl::ReplicationCoordinator::get(opCtx)->getMemberState().rollback()) { diff --git a/src/mongo/db/s/config_server_op_observer.h b/src/mongo/db/s/config_server_op_observer.h index 458d9627955..3b128534f3d 100644 --- a/src/mongo/db/s/config_server_op_observer.h +++ b/src/mongo/db/s/config_server_op_observer.h @@ -97,6 +97,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) override; void onDropIndex(OperationContext* opCtx, @@ -110,12 +111,14 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override {} repl::OpTime preRenameCollection(OperationContext* opCtx, const NamespaceString& fromCollection, const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override { return repl::OpTime(); } diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index 4164864ea6c..c211377f998 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -392,6 +392,7 @@ void ShardServerOpObserver::onDelete(OperationContext* opCtx, repl::OpTime ShardServerOpObserver::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { if (collectionName == NamespaceString::kServerConfigurationNamespace) { // Dropping system collections is not allowed for end users diff --git a/src/mongo/db/s/shard_server_op_observer.h b/src/mongo/db/s/shard_server_op_observer.h index 61e0f0dfca0..5261851bbb3 100644 --- a/src/mongo/db/s/shard_server_op_observer.h +++ b/src/mongo/db/s/shard_server_op_observer.h @@ -98,6 +98,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) override; void onDropIndex(OperationContext* opCtx, @@ -111,12 +112,14 @@ public: const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override {} repl::OpTime preRenameCollection(OperationContext* opCtx, const NamespaceString& fromCollection, const NamespaceString& toCollection, OptionalCollectionUUID uuid, OptionalCollectionUUID dropTargetUUID, + std::uint64_t numRecords, bool stayTemp) override { return repl::OpTime(); } diff --git a/src/mongo/db/transaction_participant_retryable_writes_test.cpp b/src/mongo/db/transaction_participant_retryable_writes_test.cpp index 0a7f938b391..a65de737246 100644 --- a/src/mongo/db/transaction_participant_retryable_writes_test.cpp +++ b/src/mongo/db/transaction_participant_retryable_writes_test.cpp @@ -125,6 +125,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) override { // If the oplog is not disabled for this namespace, then we need to reserve an op time for // the drop. diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp index e9271227c3a..3b8e4712f20 100644 --- a/src/mongo/db/transaction_participant_test.cpp +++ b/src/mongo/db/transaction_participant_test.cpp @@ -115,6 +115,7 @@ public: repl::OpTime onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, CollectionDropType dropType) override; const repl::OpTime dropOpTime = {Timestamp(Seconds(100), 1U), 1LL}; @@ -165,6 +166,7 @@ void OpObserverMock::onTransactionAbort(OperationContext* opCtx, repl::OpTime OpObserverMock::onDropCollection(OperationContext* opCtx, const NamespaceString& collectionName, OptionalCollectionUUID uuid, + std::uint64_t numRecords, const CollectionDropType dropType) { // If the oplog is not disabled for this namespace, then we need to reserve an op time for the // drop. |