summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2022-08-23 14:21:49 +0200
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-08-23 13:03:38 +0000
commita5c99e5fd1efbfcb203ba2ab2d7c422d5fa1434a (patch)
tree4a3e1dbb10dc67dd42236bf24df68a53a7a8fbfd /src
parent4ed275ae52bba8f4fdfbe025f42a52b46d3a218d (diff)
downloadmongo-a5c99e5fd1efbfcb203ba2ab2d7c422d5fa1434a.tar.gz
SERVER-67900 Thread CollectionPtr into the onInsert OpObserver
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/auth/auth_op_observer.cpp7
-rw-r--r--src/mongo/db/auth/auth_op_observer.h3
-rw-r--r--src/mongo/db/catalog/collection_write_path.cpp6
-rw-r--r--src/mongo/db/catalog/create_collection.h7
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp12
-rw-r--r--src/mongo/db/commands/mr_test.cpp8
-rw-r--r--src/mongo/db/free_mon/free_mon_op_observer.cpp5
-rw-r--r--src/mongo/db/free_mon/free_mon_op_observer.h3
-rw-r--r--src/mongo/db/op_observer/fcv_op_observer.cpp5
-rw-r--r--src/mongo/db/op_observer/fcv_op_observer.h3
-rw-r--r--src/mongo/db/op_observer/op_observer.cpp8
-rw-r--r--src/mongo/db/op_observer/op_observer.h11
-rw-r--r--src/mongo/db/op_observer/op_observer_impl.cpp8
-rw-r--r--src/mongo/db/op_observer/op_observer_impl.h6
-rw-r--r--src/mongo/db/op_observer/op_observer_noop.h3
-rw-r--r--src/mongo/db/op_observer/op_observer_registry.h8
-rw-r--r--src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp7
-rw-r--r--src/mongo/db/op_observer/user_write_block_mode_op_observer.h4
-rw-r--r--src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp19
-rw-r--r--src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp7
-rw-r--r--src/mongo/db/repl/oplog_applier_impl_test_fixture.h3
-rw-r--r--src/mongo/db/repl/primary_only_service_op_observer.h3
-rw-r--r--src/mongo/db/repl/tenant_collection_cloner_test.cpp7
-rw-r--r--src/mongo/db/repl/tenant_migration_donor_op_observer.cpp5
-rw-r--r--src/mongo/db/repl/tenant_migration_donor_op_observer.h3
-rw-r--r--src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp5
-rw-r--r--src/mongo/db/repl/tenant_migration_recipient_op_observer.h3
-rw-r--r--src/mongo/db/s/config_server_op_observer.cpp5
-rw-r--r--src/mongo/db/s/config_server_op_observer.h3
-rw-r--r--src/mongo/db/s/range_deleter_service.cpp4
-rw-r--r--src/mongo/db/s/range_deleter_service_op_observer.cpp9
-rw-r--r--src/mongo/db/s/range_deleter_service_op_observer.h4
-rw-r--r--src/mongo/db/s/resharding/resharding_op_observer.cpp5
-rw-r--r--src/mongo/db/s/resharding/resharding_op_observer.h3
-rw-r--r--src/mongo/db/s/shard_server_op_observer.cpp4
-rw-r--r--src/mongo/db/s/shard_server_op_observer.h3
-rw-r--r--src/mongo/db/serverless/SConscript2
-rw-r--r--src/mongo/db/serverless/shard_split_donor_op_observer.cpp5
-rw-r--r--src/mongo/db/serverless/shard_split_donor_op_observer.h3
-rw-r--r--src/mongo/db/serverless/shard_split_donor_op_observer_test.cpp26
-rw-r--r--src/mongo/idl/SConscript3
-rw-r--r--src/mongo/idl/cluster_server_parameter_op_observer.cpp9
-rw-r--r--src/mongo/idl/cluster_server_parameter_op_observer.h5
-rw-r--r--src/mongo/idl/cluster_server_parameter_op_observer_test.cpp18
45 files changed, 134 insertions, 147 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index f88ea43bac2..f677e021b30 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -2540,6 +2540,7 @@ if wiredtiger:
'$BUILD_DIR/mongo/db/change_collection_expired_change_remover',
'$BUILD_DIR/mongo/db/change_stream_change_collection_manager',
'$BUILD_DIR/mongo/db/change_streams_cluster_parameter',
+ '$BUILD_DIR/mongo/db/commands/create_command',
'$BUILD_DIR/mongo/db/mongohasher',
'$BUILD_DIR/mongo/db/op_observer/fcv_op_observer',
'$BUILD_DIR/mongo/db/op_observer/op_observer',
diff --git a/src/mongo/db/auth/auth_op_observer.cpp b/src/mongo/db/auth/auth_op_observer.cpp
index 922069978e7..b974eda9973 100644
--- a/src/mongo/db/auth/auth_op_observer.cpp
+++ b/src/mongo/db/auth/auth_op_observer.cpp
@@ -51,15 +51,14 @@ AuthOpObserver::AuthOpObserver() = default;
AuthOpObserver::~AuthOpObserver() = default;
void AuthOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
for (auto it = first; it != last; it++) {
- audit::logInsertOperation(opCtx->getClient(), nss, it->doc);
+ audit::logInsertOperation(opCtx->getClient(), coll->ns(), it->doc);
AuthorizationManager::get(opCtx->getServiceContext())
- ->logOp(opCtx, "i", nss, it->doc, nullptr);
+ ->logOp(opCtx, "i", coll->ns(), it->doc, nullptr);
}
}
diff --git a/src/mongo/db/auth/auth_op_observer.h b/src/mongo/db/auth/auth_op_observer.h
index 480ee25ec79..1d92efbd197 100644
--- a/src/mongo/db/auth/auth_op_observer.h
+++ b/src/mongo/db/auth/auth_op_observer.h
@@ -78,8 +78,7 @@ public:
bool fromMigrate) final {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) final;
diff --git a/src/mongo/db/catalog/collection_write_path.cpp b/src/mongo/db/catalog/collection_write_path.cpp
index 200b2b31d71..bcbe13ea7d5 100644
--- a/src/mongo/db/catalog/collection_write_path.cpp
+++ b/src/mongo/db/catalog/collection_write_path.cpp
@@ -75,7 +75,6 @@ Status insertDocumentsImpl(OperationContext* opCtx,
OpDebug* opDebug,
bool fromMigrate) {
const auto& nss = collection->ns();
- const auto& uuid = collection->uuid();
dassert(opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IX));
@@ -170,7 +169,7 @@ Status insertDocumentsImpl(OperationContext* opCtx,
if (!nss.isImplicitlyReplicated()) {
opCtx->getServiceContext()->getOpObserver()->onInserts(
- opCtx, nss, uuid, begin, end, fromMigrate);
+ opCtx, collection, begin, end, fromMigrate);
}
cappedDeleteUntilBelowConfiguredMaximum(opCtx, collection, records.begin()->id);
@@ -185,7 +184,6 @@ Status insertDocumentForBulkLoader(OperationContext* opCtx,
const BSONObj& doc,
const OnRecordInsertedFn& onRecordInserted) {
const auto& nss = collection->ns();
- const auto& uuid = collection->uuid();
auto status = checkFailCollectionInsertsFailPoint(nss, doc);
if (!status.isOK()) {
@@ -236,7 +234,7 @@ Status insertDocumentForBulkLoader(OperationContext* opCtx,
inserts.emplace_back(kUninitializedStmtId, doc, slot);
opCtx->getServiceContext()->getOpObserver()->onInserts(
- opCtx, nss, uuid, inserts.begin(), inserts.end(), false);
+ opCtx, collection, inserts.begin(), inserts.end(), false);
cappedDeleteUntilBelowConfiguredMaximum(opCtx, collection, loc.getValue());
diff --git a/src/mongo/db/catalog/create_collection.h b/src/mongo/db/catalog/create_collection.h
index 25fb295b55a..7812510484b 100644
--- a/src/mongo/db/catalog/create_collection.h
+++ b/src/mongo/db/catalog/create_collection.h
@@ -27,16 +27,17 @@
* it in the license file.
*/
+#include <boost/optional.hpp>
#include <string>
#include "mongo/base/status.h"
#include "mongo/bson/bsonobj.h"
-#include "mongo/db/catalog/collection_catalog.h"
+#include "mongo/db/catalog/collection_options.h"
+#include "mongo/db/commands/create_gen.h"
namespace mongo {
-class BSONObj;
+
class OperationContext;
-class BSONElement;
/**
* Creates a collection as described in "cmdObj" on the database "dbName". Creates the collection's
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index 7c95e382c85..dfd7d690968 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -100,8 +100,7 @@ public:
bool fromMigrate) override;
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override;
@@ -208,8 +207,7 @@ void OpObserverMock::onAbortIndexBuild(OperationContext* opCtx,
}
void OpObserverMock::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) {
@@ -218,10 +216,10 @@ void OpObserverMock::onInserts(OperationContext* opCtx,
}
onInsertsIsTargetDatabaseExclusivelyLocked =
- opCtx->lockState()->isDbLockedForMode(nss.dbName(), MODE_X);
+ opCtx->lockState()->isDbLockedForMode(coll->ns().dbName(), MODE_X);
- _logOp(opCtx, nss, "inserts");
- OpObserverNoop::onInserts(opCtx, nss, uuid, begin, end, fromMigrate);
+ _logOp(opCtx, coll->ns(), "inserts");
+ OpObserverNoop::onInserts(opCtx, coll, begin, end, fromMigrate);
}
void OpObserverMock::onCreateCollection(OperationContext* opCtx,
diff --git a/src/mongo/db/commands/mr_test.cpp b/src/mongo/db/commands/mr_test.cpp
index ef1ad304d87..ed3bbd03458 100644
--- a/src/mongo/db/commands/mr_test.cpp
+++ b/src/mongo/db/commands/mr_test.cpp
@@ -27,7 +27,6 @@
* it in the license file.
*/
-
#include <functional>
#include <memory>
#include <string>
@@ -59,7 +58,6 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kStorage
-
namespace mongo {
namespace {
@@ -263,8 +261,7 @@ public:
* collection.
*/
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override;
@@ -320,8 +317,7 @@ void MapReduceOpObserver::onStartIndexBuild(OperationContext* opCtx,
}
void MapReduceOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) {
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 1a0785c1df8..75db3aeb817 100644
--- a/src/mongo/db/free_mon/free_mon_op_observer.cpp
+++ b/src/mongo/db/free_mon/free_mon_op_observer.cpp
@@ -72,12 +72,11 @@ repl::OpTime FreeMonOpObserver::onDropCollection(OperationContext* opCtx,
}
void FreeMonOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) {
- if (nss != NamespaceString::kServerConfigurationNamespace) {
+ if (coll->ns() != NamespaceString::kServerConfigurationNamespace) {
return;
}
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 34a3312016a..2b34f06783c 100644
--- a/src/mongo/db/free_mon/free_mon_op_observer.h
+++ b/src/mongo/db/free_mon/free_mon_op_observer.h
@@ -78,8 +78,7 @@ public:
bool fromMigrate) final {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) final;
diff --git a/src/mongo/db/op_observer/fcv_op_observer.cpp b/src/mongo/db/op_observer/fcv_op_observer.cpp
index 6ea3fd00ab8..069c1c0e2af 100644
--- a/src/mongo/db/op_observer/fcv_op_observer.cpp
+++ b/src/mongo/db/op_observer/fcv_op_observer.cpp
@@ -148,12 +148,11 @@ void FcvOpObserver::_onInsertOrUpdate(OperationContext* opCtx, const BSONObj& do
}
void FcvOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
- if (nss.isServerConfigurationCollection()) {
+ if (coll->ns().isServerConfigurationCollection()) {
for (auto it = first; it != last; it++) {
_onInsertOrUpdate(opCtx, it->doc);
}
diff --git a/src/mongo/db/op_observer/fcv_op_observer.h b/src/mongo/db/op_observer/fcv_op_observer.h
index 97f78535e8b..22b2b429b52 100644
--- a/src/mongo/db/op_observer/fcv_op_observer.h
+++ b/src/mongo/db/op_observer/fcv_op_observer.h
@@ -50,8 +50,7 @@ public:
// FcvOpObserver overrides.
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) final;
diff --git a/src/mongo/db/op_observer/op_observer.cpp b/src/mongo/db/op_observer/op_observer.cpp
index 84aa40f6718..eb9b8dce995 100644
--- a/src/mongo/db/op_observer/op_observer.cpp
+++ b/src/mongo/db/op_observer/op_observer.cpp
@@ -36,14 +36,6 @@ namespace {
const auto getOpObserverTimes = OperationContext::declareDecoration<OpObserver::Times>();
} // namespace
-void OpObserver::onInserts(OperationContext* opCtx,
- const CollectionPtr& coll,
- std::vector<InsertStatement>::const_iterator begin,
- std::vector<InsertStatement>::const_iterator end,
- bool fromMigrate) {
- onInserts(opCtx, coll->ns(), coll->uuid(), begin, end, fromMigrate);
-}
-
auto OpObserver::Times::get(OperationContext* const opCtx) -> Times& {
return getOpObserverTimes(opCtx);
}
diff --git a/src/mongo/db/op_observer/op_observer.h b/src/mongo/db/op_observer/op_observer.h
index 0ac788e5e2f..79d8a00e335 100644
--- a/src/mongo/db/op_observer/op_observer.h
+++ b/src/mongo/db/op_observer/op_observer.h
@@ -161,17 +161,8 @@ public:
const Status& cause,
bool fromMigrate) = 0;
- // TODO (SERVER-67900): Make this variant of onInserts part of the interface and remove the one
- // below
- void onInserts(OperationContext* opCtx,
- const CollectionPtr& coll,
- std::vector<InsertStatement>::const_iterator begin,
- std::vector<InsertStatement>::const_iterator end,
- bool fromMigrate);
-
virtual void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) = 0;
diff --git a/src/mongo/db/op_observer/op_observer_impl.cpp b/src/mongo/db/op_observer/op_observer_impl.cpp
index 8c498e58d69..625f732bc53 100644
--- a/src/mongo/db/op_observer/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer/op_observer_impl.cpp
@@ -528,8 +528,7 @@ void OpObserverImpl::onAbortIndexBuild(OperationContext* opCtx,
}
void OpObserverImpl::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
@@ -537,7 +536,8 @@ void OpObserverImpl::onInserts(OperationContext* opCtx,
const bool inMultiDocumentTransaction =
txnParticipant && opCtx->writesAreReplicated() && txnParticipant.transactionIsOpen();
- Date_t lastWriteDate;
+ const auto& nss = coll->ns();
+ const auto& uuid = coll->uuid();
std::vector<repl::OpTime> opTimeList;
repl::OpTime lastOpTime;
@@ -623,7 +623,7 @@ void OpObserverImpl::onInserts(OperationContext* opCtx,
oplogEntryTemplate.setNss(nss);
oplogEntryTemplate.setUuid(uuid);
oplogEntryTemplate.setFromMigrateIfTrue(fromMigrate);
- lastWriteDate = getWallClockTimeForOpLog(opCtx);
+ Date_t lastWriteDate = getWallClockTimeForOpLog(opCtx);
oplogEntryTemplate.setWallClockTime(lastWriteDate);
opTimeList = _oplogWriter->logInsertOps(
diff --git a/src/mongo/db/op_observer/op_observer_impl.h b/src/mongo/db/op_observer/op_observer_impl.h
index 08631d696a9..c0346e63ccc 100644
--- a/src/mongo/db/op_observer/op_observer_impl.h
+++ b/src/mongo/db/op_observer/op_observer_impl.h
@@ -83,12 +83,8 @@ public:
const Status& cause,
bool fromMigrate) final;
- // TODO (SERVER-67900): Remove once the CollectionPtr variant of OpObserver::onInserts becomes
- // part of the interface
- using OpObserver::onInserts;
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) final;
diff --git a/src/mongo/db/op_observer/op_observer_noop.h b/src/mongo/db/op_observer/op_observer_noop.h
index 0833dae5c83..320a7180bd4 100644
--- a/src/mongo/db/op_observer/op_observer_noop.h
+++ b/src/mongo/db/op_observer/op_observer_noop.h
@@ -70,8 +70,7 @@ public:
bool fromMigrate) override {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override {}
diff --git a/src/mongo/db/op_observer/op_observer_registry.h b/src/mongo/db/op_observer/op_observer_registry.h
index 359ecdd82dd..3e387e2ea29 100644
--- a/src/mongo/db/op_observer/op_observer_registry.h
+++ b/src/mongo/db/op_observer/op_observer_registry.h
@@ -121,18 +121,14 @@ public:
}
}
- // TODO (SERVER-67900): Remove once the CollectionPtr variant of OpObserver::onInserts becomes
- // part of the interface
- using OpObserver::onInserts;
void onInserts(OperationContext* const opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override {
ReservedTimes times{opCtx};
for (auto& o : _observers)
- o->onInserts(opCtx, nss, uuid, begin, end, fromMigrate);
+ o->onInserts(opCtx, coll, begin, end, fromMigrate);
}
void onUpdate(OperationContext* const opCtx, const OplogUpdateEntryArgs& args) override {
diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp b/src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp
index 941072f2230..93fa938f2be 100644
--- a/src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp
+++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer.cpp
@@ -48,16 +48,15 @@ bool isStandaloneOrPrimary(OperationContext* opCtx) {
} // namespace
void UserWriteBlockModeOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
if (!fromMigrate) {
- _checkWriteAllowed(opCtx, nss);
+ _checkWriteAllowed(opCtx, coll->ns());
}
- if (nss == NamespaceString::kUserWritesCriticalSectionsNamespace &&
+ if (coll->ns() == NamespaceString::kUserWritesCriticalSectionsNamespace &&
!user_writes_recoverable_critical_section_util::inRecoveryMode(opCtx)) {
for (auto it = first; it != last; ++it) {
const auto& insertedDoc = it->doc;
diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer.h b/src/mongo/db/op_observer/user_write_block_mode_op_observer.h
index d6adc1f79ee..7f6b929b688 100644
--- a/src/mongo/db/op_observer/user_write_block_mode_op_observer.h
+++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer.h
@@ -48,9 +48,9 @@ public:
// Operations to check for allowed writes.
// CUD operations
+
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) final;
diff --git a/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp b/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp
index fcc62b5c39b..fff61baf687 100644
--- a/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp
+++ b/src/mongo/db/op_observer/user_write_block_mode_op_observer_test.cpp
@@ -28,6 +28,8 @@
*/
#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/catalog/create_collection.h"
+#include "mongo/db/catalog_raii.h"
#include "mongo/db/op_observer/user_write_block_mode_op_observer.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
#include "mongo/db/repl/storage_interface_mock.h"
@@ -57,6 +59,15 @@ public:
// Ensure that we are primary.
auto replCoord = repl::ReplicationCoordinator::get(opCtx.get());
ASSERT_OK(replCoord->setFollowerMode(repl::MemberState::RS_PRIMARY));
+
+ ASSERT_OK(createCollection(opCtx.get(), CreateCommand(NamespaceString("userDB.coll"))));
+ ASSERT_OK(
+ createCollection(opCtx.get(), CreateCommand(NamespaceString("userDB.system.profile"))));
+ ASSERT_OK(createCollection(opCtx.get(), CreateCommand(NamespaceString("admin.coll"))));
+ ASSERT_OK(
+ createCollection(opCtx.get(), CreateCommand(NamespaceString("admin.collForRename"))));
+ ASSERT_OK(createCollection(opCtx.get(), CreateCommand(NamespaceString("local.coll"))));
+ ASSERT_OK(createCollection(opCtx.get(), CreateCommand(NamespaceString("config.coll"))));
}
protected:
@@ -68,6 +79,10 @@ protected:
bool fromMigrate) {
ASSERT(nss.isValid());
+ AutoGetCollection autoColl(opCtx, nss, MODE_IX);
+ if (!autoColl)
+ FAIL(str::stream() << "Collection " << nss << " doesn't exist");
+
UserWriteBlockModeOpObserver opObserver;
std::vector<InsertStatement> inserts;
CollectionUpdateArgs collectionUpdateArgs;
@@ -80,7 +95,7 @@ protected:
deleteArgs.fromMigrate = fromMigrate;
if (shouldSucceed) {
try {
- opObserver.onInserts(opCtx, nss, uuid, inserts.begin(), inserts.end(), fromMigrate);
+ opObserver.onInserts(opCtx, *autoColl, inserts.begin(), inserts.end(), fromMigrate);
opObserver.onUpdate(opCtx, updateArgs);
opObserver.onDelete(opCtx, nss, uuid, StmtId(), deleteArgs);
} catch (...) {
@@ -89,7 +104,7 @@ protected:
}
} else {
ASSERT_THROWS(
- opObserver.onInserts(opCtx, nss, uuid, inserts.begin(), inserts.end(), fromMigrate),
+ opObserver.onInserts(opCtx, *autoColl, inserts.begin(), inserts.end(), fromMigrate),
AssertionException);
ASSERT_THROWS(opObserver.onUpdate(opCtx, updateArgs), AssertionException);
ASSERT_THROWS(opObserver.onDelete(opCtx, nss, uuid, StmtId(), deleteArgs),
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 0ab46880ba7..cd7599013eb 100644
--- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
+++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.cpp
@@ -27,8 +27,6 @@
* it in the license file.
*/
-#include "mongo/platform/basic.h"
-
#include "mongo/db/repl/oplog_applier_impl_test_fixture.h"
#include "mongo/db/catalog/database_holder.h"
@@ -54,8 +52,7 @@ namespace mongo {
namespace repl {
void OplogApplierImplOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) {
@@ -67,7 +64,7 @@ void OplogApplierImplOpObserver::onInserts(OperationContext* opCtx,
const InsertStatement& insertStatement = *it;
docs.push_back(insertStatement.doc.getOwned());
}
- onInsertsFn(opCtx, nss, docs);
+ onInsertsFn(opCtx, coll->ns(), docs);
}
void OplogApplierImplOpObserver::onDelete(OperationContext* opCtx,
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 1b5449fa739..7b800e5127a 100644
--- a/src/mongo/db/repl/oplog_applier_impl_test_fixture.h
+++ b/src/mongo/db/repl/oplog_applier_impl_test_fixture.h
@@ -74,8 +74,7 @@ public:
* This function is called whenever OplogApplierImpl inserts documents into a collection.
*/
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override;
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 5031b1f8e28..40307a88b0b 100644
--- a/src/mongo/db/repl/primary_only_service_op_observer.h
+++ b/src/mongo/db/repl/primary_only_service_op_observer.h
@@ -80,8 +80,7 @@ public:
bool fromMigrate) final {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) final {}
diff --git a/src/mongo/db/repl/tenant_collection_cloner_test.cpp b/src/mongo/db/repl/tenant_collection_cloner_test.cpp
index 08c7f6b0299..b98c6f129e6 100644
--- a/src/mongo/db/repl/tenant_collection_cloner_test.cpp
+++ b/src/mongo/db/repl/tenant_collection_cloner_test.cpp
@@ -27,8 +27,6 @@
* it in the license file.
*/
-#include "mongo/platform/basic.h"
-
#include <vector>
#include "mongo/bson/bsonmisc.h"
@@ -91,12 +89,11 @@ public:
}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) final {
- if (nss == nssToCapture) {
+ if (coll->ns() == nssToCapture) {
numDocsInserted += std::distance(begin, end);
}
}
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 bc3b45c0b13..264099e24cf 100644
--- a/src/mongo/db/repl/tenant_migration_donor_op_observer.cpp
+++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.cpp
@@ -224,12 +224,11 @@ private:
} // namespace
void TenantMigrationDonorOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
- if (nss == NamespaceString::kTenantMigrationDonorsNamespace &&
+ if (coll->ns() == NamespaceString::kTenantMigrationDonorsNamespace &&
!tenant_migration_access_blocker::inRecoveryMode(opCtx)) {
for (auto it = first; it != last; it++) {
auto donorStateDoc = tenant_migration_access_blocker::parseDonorStateDocument(it->doc);
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 f019e2eb2df..38f20c88966 100644
--- a/src/mongo/db/repl/tenant_migration_donor_op_observer.h
+++ b/src/mongo/db/repl/tenant_migration_donor_op_observer.h
@@ -78,8 +78,7 @@ public:
bool fromMigrate) final {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) 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 cc1dab4f37a..6aee09a4052 100644
--- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp
+++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.cpp
@@ -176,13 +176,12 @@ void TenantMigrationRecipientOpObserver::onCreateCollection(OperationContext* op
void TenantMigrationRecipientOpObserver::onInserts(
OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
- if (!shard_merge_utils::isDonatedFilesCollection(nss)) {
+ if (!shard_merge_utils::isDonatedFilesCollection(coll->ns())) {
return;
}
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 2f068be8cfd..8c62da9a371 100644
--- a/src/mongo/db/repl/tenant_migration_recipient_op_observer.h
+++ b/src/mongo/db/repl/tenant_migration_recipient_op_observer.h
@@ -79,8 +79,7 @@ public:
bool fromMigrate) final {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) final;
diff --git a/src/mongo/db/s/config_server_op_observer.cpp b/src/mongo/db/s/config_server_op_observer.cpp
index c0081d68a41..983251d7d09 100644
--- a/src/mongo/db/s/config_server_op_observer.cpp
+++ b/src/mongo/db/s/config_server_op_observer.cpp
@@ -106,12 +106,11 @@ void ConfigServerOpObserver::_onReplicationRollback(OperationContext* opCtx,
}
void ConfigServerOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) {
- if (nss != NamespaceString::kConfigsvrShardsNamespace) {
+ if (coll->ns() != NamespaceString::kConfigsvrShardsNamespace) {
return;
}
diff --git a/src/mongo/db/s/config_server_op_observer.h b/src/mongo/db/s/config_server_op_observer.h
index dc6a1a8429f..464f704dcee 100644
--- a/src/mongo/db/s/config_server_op_observer.h
+++ b/src/mongo/db/s/config_server_op_observer.h
@@ -81,8 +81,7 @@ public:
bool fromMigrate) override {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override;
diff --git a/src/mongo/db/s/range_deleter_service.cpp b/src/mongo/db/s/range_deleter_service.cpp
index 41c2b2f27c2..27844708bba 100644
--- a/src/mongo/db/s/range_deleter_service.cpp
+++ b/src/mongo/db/s/range_deleter_service.cpp
@@ -36,8 +36,9 @@
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kShardingRangeDeleter
namespace mongo {
-
+namespace {
const auto rangeDeleterServiceDecorator = ServiceContext::declareDecoration<RangeDeleterService>();
+}
RangeDeleterService* RangeDeleterService::get(ServiceContext* serviceContext) {
return &rangeDeleterServiceDecorator(serviceContext);
@@ -256,4 +257,5 @@ SharedSemiFuture<void> RangeDeleterService::getOverlappingRangeDeletionsFuture(
}
return whenAllSucceed(std::move(overlappingRangeDeletionsFutures)).share();
}
+
} // namespace mongo
diff --git a/src/mongo/db/s/range_deleter_service_op_observer.cpp b/src/mongo/db/s/range_deleter_service_op_observer.cpp
index cde58fe5d24..3326d6c4b89 100644
--- a/src/mongo/db/s/range_deleter_service_op_observer.cpp
+++ b/src/mongo/db/s/range_deleter_service_op_observer.cpp
@@ -28,26 +28,27 @@
*/
#include "mongo/db/s/range_deleter_service_op_observer.h"
+
#include "mongo/db/persistent_task_store.h"
#include "mongo/db/s/range_deleter_service.h"
#include "mongo/db/s/range_deletion_task_gen.h"
#include "mongo/db/update/update_oplog_entry_serialization.h"
namespace mongo {
-
+namespace {
// Small hack used to be able to retrieve the full removed document in the `onDelete` method
const auto deletedDocumentDecoration = OperationContext::declareDecoration<BSONObj>();
+} // namespace
RangeDeleterServiceOpObserver::RangeDeleterServiceOpObserver() = default;
RangeDeleterServiceOpObserver::~RangeDeleterServiceOpObserver() = default;
void RangeDeleterServiceOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) {
- if (nss == NamespaceString::kRangeDeletionNamespace) {
+ if (coll->ns() == NamespaceString::kRangeDeletionNamespace) {
for (auto it = begin; it != end; ++it) {
auto deletionTask = RangeDeletionTask::parse(
IDLParserContext("RangeDeleterServiceOpObserver"), it->doc);
diff --git a/src/mongo/db/s/range_deleter_service_op_observer.h b/src/mongo/db/s/range_deleter_service_op_observer.h
index 24d955ced01..299fda66880 100644
--- a/src/mongo/db/s/range_deleter_service_op_observer.h
+++ b/src/mongo/db/s/range_deleter_service_op_observer.h
@@ -46,8 +46,7 @@ public:
~RangeDeleterServiceOpObserver();
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override;
@@ -227,4 +226,5 @@ private:
void _onReplicationRollback(OperationContext* opCtx,
const RollbackObserverInfo& rbInfo) override{};
};
+
} // namespace mongo
diff --git a/src/mongo/db/s/resharding/resharding_op_observer.cpp b/src/mongo/db/s/resharding/resharding_op_observer.cpp
index d6321abb360..675cbf9206c 100644
--- a/src/mongo/db/s/resharding/resharding_op_observer.cpp
+++ b/src/mongo/db/s/resharding/resharding_op_observer.cpp
@@ -179,11 +179,12 @@ ReshardingOpObserver::ReshardingOpObserver() = default;
ReshardingOpObserver::~ReshardingOpObserver() = default;
void ReshardingOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) {
+ const auto& nss = coll->ns();
+
if (nss == NamespaceString::kDonorReshardingOperationsNamespace) {
// If a document is inserted into the resharding donor collection with a
// `minFetchTimestamp`, we assume the document was inserted as part of initial sync and do
diff --git a/src/mongo/db/s/resharding/resharding_op_observer.h b/src/mongo/db/s/resharding/resharding_op_observer.h
index 7efbbdb1f91..4b7e8131c36 100644
--- a/src/mongo/db/s/resharding/resharding_op_observer.h
+++ b/src/mongo/db/s/resharding/resharding_op_observer.h
@@ -96,8 +96,7 @@ public:
bool fromMigrate) override {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override;
diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp
index d1a29b1f722..727b9fb01d3 100644
--- a/src/mongo/db/s/shard_server_op_observer.cpp
+++ b/src/mongo/db/s/shard_server_op_observer.cpp
@@ -231,11 +231,11 @@ ShardServerOpObserver::ShardServerOpObserver() = default;
ShardServerOpObserver::~ShardServerOpObserver() = default;
void ShardServerOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) {
+ const auto& nss = coll->ns();
const auto metadata = CollectionShardingRuntime::get(opCtx, nss)->getCurrentMetadataIfKnown();
for (auto it = begin; it != end; ++it) {
diff --git a/src/mongo/db/s/shard_server_op_observer.h b/src/mongo/db/s/shard_server_op_observer.h
index 75457cce95c..1e4733832f4 100644
--- a/src/mongo/db/s/shard_server_op_observer.h
+++ b/src/mongo/db/s/shard_server_op_observer.h
@@ -78,8 +78,7 @@ public:
bool fromMigrate) override {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator begin,
std::vector<InsertStatement>::const_iterator end,
bool fromMigrate) override;
diff --git a/src/mongo/db/serverless/SConscript b/src/mongo/db/serverless/SConscript
index c58adf801ac..1111a1e912b 100644
--- a/src/mongo/db/serverless/SConscript
+++ b/src/mongo/db/serverless/SConscript
@@ -95,6 +95,8 @@ env.CppUnitTest(
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/auth/authmocks',
+ '$BUILD_DIR/mongo/db/catalog/catalog_helpers',
+ '$BUILD_DIR/mongo/db/commands/create_command',
'$BUILD_DIR/mongo/db/repl/primary_only_service',
'$BUILD_DIR/mongo/db/repl/primary_only_service_test_fixture',
'$BUILD_DIR/mongo/db/repl/replmocks',
diff --git a/src/mongo/db/serverless/shard_split_donor_op_observer.cpp b/src/mongo/db/serverless/shard_split_donor_op_observer.cpp
index 5ab9d764388..8aaedfb6fa2 100644
--- a/src/mongo/db/serverless/shard_split_donor_op_observer.cpp
+++ b/src/mongo/db/serverless/shard_split_donor_op_observer.cpp
@@ -319,12 +319,11 @@ private:
} // namespace
void ShardSplitDonorOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
- if (nss != NamespaceString::kShardSplitDonorsNamespace ||
+ if (coll->ns() != NamespaceString::kShardSplitDonorsNamespace ||
tenant_migration_access_blocker::inRecoveryMode(opCtx)) {
return;
}
diff --git a/src/mongo/db/serverless/shard_split_donor_op_observer.h b/src/mongo/db/serverless/shard_split_donor_op_observer.h
index 1cf7c338cc0..b2bcd54da7f 100644
--- a/src/mongo/db/serverless/shard_split_donor_op_observer.h
+++ b/src/mongo/db/serverless/shard_split_donor_op_observer.h
@@ -77,8 +77,7 @@ public:
bool fromMigrate) final {}
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) final;
diff --git a/src/mongo/db/serverless/shard_split_donor_op_observer_test.cpp b/src/mongo/db/serverless/shard_split_donor_op_observer_test.cpp
index 0c1a97ad495..93f7f3df93a 100644
--- a/src/mongo/db/serverless/shard_split_donor_op_observer_test.cpp
+++ b/src/mongo/db/serverless/shard_split_donor_op_observer_test.cpp
@@ -29,6 +29,8 @@
#include <utility>
+#include "mongo/db/catalog/create_collection.h"
+#include "mongo/db/catalog_raii.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/repl/tenant_migration_access_blocker_util.h"
@@ -76,6 +78,8 @@ public:
_observer = std::make_unique<ShardSplitDonorOpObserver>();
_opCtx = makeOperationContext();
_oplogSlot = 0;
+
+ ASSERT_OK(createCollection(_opCtx.get(), CreateCommand(_nss)));
}
void tearDown() override {
@@ -94,9 +98,12 @@ protected:
std::vector<InsertStatement> inserts;
inserts.emplace_back(_oplogSlot++, stateDocument.toBSON());
- WriteUnitOfWork wow(_opCtx.get());
- _observer->onInserts(_opCtx.get(), _nss, _uuid, inserts.begin(), inserts.end(), false);
- wow.commit();
+ {
+ AutoGetCollection autoColl(_opCtx.get(), _nss, MODE_IX);
+ WriteUnitOfWork wow(_opCtx.get());
+ _observer->onInserts(_opCtx.get(), *autoColl, inserts.begin(), inserts.end(), false);
+ wow.commit();
+ }
verifyAndRemoveMtab(tenants, mtabVerifier);
}
@@ -205,8 +212,10 @@ TEST_F(ShardSplitDonorOpObserverTest, InsertWrongType) {
inserts1.emplace_back(1,
BSON("_id" << 1 << "data"
<< "y"));
+
+ AutoGetCollection autoColl(_opCtx.get(), _nss, MODE_IX);
ASSERT_THROWS_CODE(
- _observer->onInserts(_opCtx.get(), _nss, _uuid, inserts1.begin(), inserts1.end(), false),
+ _observer->onInserts(_opCtx.get(), *autoColl, inserts1.begin(), inserts1.end(), false),
DBException,
ErrorCodes::TypeMismatch);
}
@@ -241,9 +250,12 @@ TEST_F(ShardSplitDonorOpObserverTest, InsertValidAbortedDocument) {
std::vector<InsertStatement> inserts;
inserts.emplace_back(_oplogSlot++, stateDocument.toBSON());
- WriteUnitOfWork wow(_opCtx.get());
- _observer->onInserts(_opCtx.get(), _nss, _uuid, inserts.begin(), inserts.end(), false);
- wow.commit();
+ {
+ AutoGetCollection autoColl(_opCtx.get(), _nss, MODE_IX);
+ WriteUnitOfWork wow(_opCtx.get());
+ _observer->onInserts(_opCtx.get(), *autoColl, inserts.begin(), inserts.end(), false);
+ wow.commit();
+ }
for (const auto& tenant : _tenantIds) {
ASSERT_FALSE(TenantMigrationAccessBlockerRegistry::get(_opCtx->getServiceContext())
diff --git a/src/mongo/idl/SConscript b/src/mongo/idl/SConscript
index 29758ea9aef..6ecab766123 100644
--- a/src/mongo/idl/SConscript
+++ b/src/mongo/idl/SConscript
@@ -110,7 +110,10 @@ env.CppUnitTest(
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/auth/authmocks',
+ '$BUILD_DIR/mongo/db/catalog/catalog_helpers',
'$BUILD_DIR/mongo/db/change_stream_options_manager',
+ '$BUILD_DIR/mongo/db/commands/create_command',
+ '$BUILD_DIR/mongo/db/op_observer/op_observer',
'$BUILD_DIR/mongo/db/repl/oplog',
'$BUILD_DIR/mongo/db/repl/oplog_interface_local',
'$BUILD_DIR/mongo/db/repl/replmocks',
diff --git a/src/mongo/idl/cluster_server_parameter_op_observer.cpp b/src/mongo/idl/cluster_server_parameter_op_observer.cpp
index 5fd94031c29..ee2e1582796 100644
--- a/src/mongo/idl/cluster_server_parameter_op_observer.cpp
+++ b/src/mongo/idl/cluster_server_parameter_op_observer.cpp
@@ -27,18 +27,14 @@
* it in the license file.
*/
-
#include "mongo/idl/cluster_server_parameter_op_observer.h"
-#include <memory>
-
#include "mongo/db/dbdirectclient.h"
#include "mongo/idl/cluster_server_parameter_initializer.h"
#include "mongo/logv2/log.h"
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kControl
-
namespace mongo {
namespace {
@@ -59,12 +55,11 @@ bool isConfigNamespace(const NamespaceString& nss) {
} // namespace
void ClusterServerParameterOpObserver::onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) {
- if (!isConfigNamespace(nss)) {
+ if (!isConfigNamespace(coll->ns())) {
return;
}
diff --git a/src/mongo/idl/cluster_server_parameter_op_observer.h b/src/mongo/idl/cluster_server_parameter_op_observer.h
index fef725041bb..62928b52d53 100644
--- a/src/mongo/idl/cluster_server_parameter_op_observer.h
+++ b/src/mongo/idl/cluster_server_parameter_op_observer.h
@@ -27,8 +27,6 @@
* it in the license file.
*/
-#include "mongo/platform/basic.h"
-
#include <boost/optional.hpp>
#include <vector>
@@ -50,8 +48,7 @@ public:
// Interface methods.
void onInserts(OperationContext* opCtx,
- const NamespaceString& nss,
- const UUID& uuid,
+ const CollectionPtr& coll,
std::vector<InsertStatement>::const_iterator first,
std::vector<InsertStatement>::const_iterator last,
bool fromMigrate) final;
diff --git a/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp b/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp
index 817ea0033f4..a4cbb48d151 100644
--- a/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp
+++ b/src/mongo/idl/cluster_server_parameter_op_observer_test.cpp
@@ -27,6 +27,8 @@
* it in the license file.
*/
+#include "mongo/db/catalog/create_collection.h"
+#include "mongo/db/catalog_raii.h"
#include "mongo/idl/cluster_server_parameter_op_observer.h"
#include "mongo/idl/cluster_server_parameter_test_util.h"
#include "mongo/logv2/log.h"
@@ -35,6 +37,7 @@
namespace mongo {
namespace {
+
using namespace cluster_server_parameter_test_util;
const std::vector<NamespaceString> kIgnoredNamespaces = {
@@ -44,14 +47,27 @@ const std::vector<NamespaceString> kIgnoredNamespaces = {
class ClusterServerParameterOpObserverTest : public ClusterServerParameterTestBase {
public:
+ void setUp() override {
+ ClusterServerParameterTestBase::setUp();
+
+ auto opCtx = makeOperationContext();
+ ASSERT_OK(createCollection(opCtx.get(),
+ CreateCommand(NamespaceString::kClusterParametersNamespace)));
+ for (auto&& nss : kIgnoredNamespaces) {
+ ASSERT_OK(createCollection(opCtx.get(), CreateCommand(nss)));
+ }
+ }
+
void doInserts(const NamespaceString& nss, std::initializer_list<BSONObj> docs) {
std::vector<InsertStatement> stmts;
std::transform(docs.begin(), docs.end(), std::back_inserter(stmts), [](auto doc) {
return InsertStatement(doc);
});
auto opCtx = cc().makeOperationContext();
+
+ AutoGetCollection autoColl(opCtx.get(), nss, MODE_IX);
observer.onInserts(
- opCtx.get(), nss, UUID::gen(), stmts.cbegin(), stmts.cend(), false /* fromMigrate */);
+ opCtx.get(), *autoColl, stmts.cbegin(), stmts.cend(), false /* fromMigrate */);
}
void doUpdate(const NamespaceString& nss, BSONObj updatedDoc) {