summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Edin <henrik.edin@mongodb.com>2023-02-15 14:12:23 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-02-15 15:41:49 +0000
commitc3a54fa12ceb2e4e7b5fad5bd117bbab9b9c486f (patch)
tree26e1b286c300deb75b72e1747900c39347415aca /src
parent8f36c90d997708507e1d73c4200d79a92619f422 (diff)
downloadmongo-c3a54fa12ceb2e4e7b5fad5bd117bbab9b9c486f.tar.gz
SERVER-73818 Remove CollectionPtr from CollectionCatalog interface
Interfaces instead return 'const Collection*' and if a CollectionPtr is needed it must be created by the user.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/capped_utils.cpp8
-rw-r--r--src/mongo/db/catalog/catalog_control.cpp4
-rw-r--r--src/mongo/db/catalog/collection_catalog.cpp99
-rw-r--r--src/mongo/db/catalog/collection_catalog.h43
-rw-r--r--src/mongo/db/catalog/collection_catalog_helper.cpp4
-rw-r--r--src/mongo/db/catalog/collection_catalog_test.cpp128
-rw-r--r--src/mongo/db/catalog/collection_compact.cpp2
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch.cpp17
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch.h11
-rw-r--r--src/mongo/db/catalog/collection_writer_test.cpp7
-rw-r--r--src/mongo/db/catalog/create_collection.cpp3
-rw-r--r--src/mongo/db/catalog/database_impl.cpp2
-rw-r--r--src/mongo/db/catalog/drop_collection.cpp21
-rw-r--r--src/mongo/db/catalog/index_repair.cpp4
-rw-r--r--src/mongo/db/catalog/multi_index_block.cpp4
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp10
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp5
-rw-r--r--src/mongo/db/catalog/validate_state.cpp9
-rw-r--r--src/mongo/db/catalog_raii.cpp12
-rw-r--r--src/mongo/db/cloner.cpp9
-rw-r--r--src/mongo/db/commands/dbcheck.cpp2
-rw-r--r--src/mongo/db/commands/dbhash.cpp67
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp8
-rw-r--r--src/mongo/db/commands/fle2_compact_cmd.cpp6
-rw-r--r--src/mongo/db/commands/list_collections.cpp6
-rw-r--r--src/mongo/db/commands/set_feature_compatibility_version_command.cpp10
-rw-r--r--src/mongo/db/commands/test_commands.cpp4
-rw-r--r--src/mongo/db/db_raii.cpp20
-rw-r--r--src/mongo/db/dbhelpers.cpp13
-rw-r--r--src/mongo/db/exec/sbe/stages/collection_helpers.cpp4
-rw-r--r--src/mongo/db/index_builds_coordinator.cpp4
-rw-r--r--src/mongo/db/index_builds_coordinator_test.cpp2
-rw-r--r--src/mongo/db/introspect.cpp6
-rw-r--r--src/mongo/db/matcher/expression_text.cpp4
-rw-r--r--src/mongo/db/mongod_main.cpp4
-rw-r--r--src/mongo/db/op_observer/op_observer_impl.cpp3
-rw-r--r--src/mongo/db/ops/update.cpp3
-rw-r--r--src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp4
-rw-r--r--src/mongo/db/rebuild_indexes.cpp4
-rw-r--r--src/mongo/db/rebuild_indexes.h6
-rw-r--r--src/mongo/db/repl/oplog.cpp12
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp2
-rw-r--r--src/mongo/db/repl/rollback_impl.cpp2
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp6
-rw-r--r--src/mongo/db/repl/tenant_migration_util.cpp5
-rw-r--r--src/mongo/db/s/config/configsvr_run_restore_command.cpp12
-rw-r--r--src/mongo/db/s/global_index/global_index_cloning_service.cpp2
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp6
-rw-r--r--src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp2
-rw-r--r--src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp2
-rw-r--r--src/mongo/db/shard_role.cpp2
-rw-r--r--src/mongo/db/startup_recovery.cpp16
-rw-r--r--src/mongo/db/storage/kv/durable_catalog_test.cpp4
-rw-r--r--src/mongo/db/storage/storage_engine_impl.cpp2
-rw-r--r--src/mongo/db/storage/storage_engine_test_fixture.h2
-rw-r--r--src/mongo/db/timeseries/timeseries_extended_range.cpp4
-rw-r--r--src/mongo/db/timeseries/timeseries_extended_range.h2
-rw-r--r--src/mongo/db/transaction/transaction_participant_test.cpp4
-rw-r--r--src/mongo/dbtests/dbhelper_tests.cpp6
-rw-r--r--src/mongo/dbtests/dbtests.h3
-rw-r--r--src/mongo/dbtests/multikey_paths_test.cpp4
-rw-r--r--src/mongo/dbtests/pdfiletests.cpp7
-rw-r--r--src/mongo/dbtests/plan_executor_invalidation_test.cpp3
-rw-r--r--src/mongo/dbtests/query_plan_executor.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_batched_delete.cpp8
-rw-r--r--src/mongo/dbtests/query_stage_count_scan.cpp3
-rw-r--r--src/mongo/dbtests/query_stage_fetch.cpp8
-rw-r--r--src/mongo/dbtests/query_stage_sort.cpp24
-rw-r--r--src/mongo/dbtests/query_stage_update.cpp4
-rw-r--r--src/mongo/dbtests/querytests.cpp4
-rw-r--r--src/mongo/dbtests/repltests.cpp12
-rw-r--r--src/mongo/dbtests/rollbacktests.cpp2
-rw-r--r--src/mongo/dbtests/validate_tests.cpp3
73 files changed, 398 insertions, 366 deletions
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp
index 75435b458bc..213f45be4a8 100644
--- a/src/mongo/db/catalog/capped_utils.cpp
+++ b/src/mongo/db/catalog/capped_utils.cpp
@@ -122,8 +122,8 @@ void cloneCollectionAsCapped(OperationContext* opCtx,
const NamespaceString& toNss,
long long size,
bool temp) {
- CollectionPtr fromCollection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, fromNss);
+ CollectionPtr fromCollection(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, fromNss));
if (!fromCollection) {
uassert(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "cloneCollectionAsCapped not supported for views: " << fromNss,
@@ -164,8 +164,8 @@ void cloneCollectionAsCapped(OperationContext* opCtx,
uassertStatusOK(createCollection(opCtx, toNss.dbName(), cmd.done()));
}
- CollectionPtr toCollection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, toNss);
+ CollectionPtr toCollection(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, toNss));
invariant(toCollection); // we created above
// how much data to ignore because it won't fit anyway
diff --git a/src/mongo/db/catalog/catalog_control.cpp b/src/mongo/db/catalog/catalog_control.cpp
index d5b2895fb3b..4b9de30f076 100644
--- a/src/mongo/db/catalog/catalog_control.cpp
+++ b/src/mongo/db/catalog/catalog_control.cpp
@@ -123,7 +123,7 @@ void reopenAllDatabasesAndReloadCollectionCatalog(OperationContext* opCtx,
extendedRangeSetting = it->second;
} else {
extendedRangeSetting =
- timeseries::collectionMayRequireExtendedRangeSupport(opCtx, collection);
+ timeseries::collectionMayRequireExtendedRangeSupport(opCtx, *collection);
}
if (extendedRangeSetting) {
@@ -140,7 +140,7 @@ void reopenAllDatabasesAndReloadCollectionCatalog(OperationContext* opCtx,
// batched catalog write and continue on a new batch afterwards.
catalogWriter.reset();
- repl::establishOplogCollectionForLogging(opCtx, collection.get());
+ repl::establishOplogCollectionForLogging(opCtx, collection);
catalogWriter.emplace(opCtx);
}
}
diff --git a/src/mongo/db/catalog/collection_catalog.cpp b/src/mongo/db/catalog/collection_catalog.cpp
index 5f06c5b92b4..1a9dec3dccd 100644
--- a/src/mongo/db/catalog/collection_catalog.cpp
+++ b/src/mongo/db/catalog/collection_catalog.cpp
@@ -401,10 +401,10 @@ CollectionCatalog::iterator::iterator(
CollectionCatalog::iterator::value_type CollectionCatalog::iterator::operator*() {
if (_exhausted()) {
- return CollectionPtr();
+ return nullptr;
}
- return {CollectionPtr(_mapIter->second.get())};
+ return _mapIter->second.get();
}
Collection* CollectionCatalog::iterator::getWritableCollection(OperationContext* opCtx) {
@@ -660,7 +660,7 @@ Status CollectionCatalog::createView(OperationContext* opCtx,
IgnoreExternalViewChangesForDatabase ignore(opCtx, viewName.dbName());
assertViewCatalogValid(viewsForDb);
- auto systemViews = _lookupSystemViews(opCtx, viewName.dbName());
+ CollectionPtr systemViews(_lookupSystemViews(opCtx, viewName.dbName()));
ViewsForDatabase writable{viewsForDb};
auto status = writable.insert(
@@ -709,7 +709,7 @@ Status CollectionCatalog::modifyView(
ViewsForDatabase writable{viewsForDb};
auto status = writable.update(opCtx,
- systemViews,
+ CollectionPtr(systemViews),
viewName,
viewOn,
pipeline,
@@ -742,7 +742,7 @@ Status CollectionCatalog::dropView(OperationContext* opCtx, const NamespaceStrin
{
IgnoreExternalViewChangesForDatabase ignore(opCtx, viewName.dbName());
- auto systemViews = _lookupSystemViews(opCtx, viewName.dbName());
+ CollectionPtr systemViews(_lookupSystemViews(opCtx, viewName.dbName()));
ViewsForDatabase writable{viewsForDb};
writable.remove(opCtx, systemViews, viewName);
@@ -778,13 +778,13 @@ void CollectionCatalog::reloadViews(OperationContext* opCtx, const DatabaseName&
LOGV2_DEBUG(22546, 1, "Reloading view catalog for database", "db"_attr = dbName.toString());
ViewsForDatabase viewsForDb;
- viewsForDb.reload(opCtx, _lookupSystemViews(opCtx, dbName)).ignore();
+ viewsForDb.reload(opCtx, CollectionPtr(_lookupSystemViews(opCtx, dbName))).ignore();
uncommittedCatalogUpdates.replaceViewsForDatabase(dbName, std::move(viewsForDb));
PublishCatalogUpdates::ensureRegisteredWithRecoveryUnit(opCtx, uncommittedCatalogUpdates);
}
-CollectionPtr CollectionCatalog::establishConsistentCollection(
+const Collection* CollectionCatalog::establishConsistentCollection(
OperationContext* opCtx,
const NamespaceStringOrUUID& nssOrUUID,
boost::optional<Timestamp> readTimestamp) const {
@@ -814,11 +814,12 @@ bool CollectionCatalog::_needsOpenCollection(OperationContext* opCtx,
}
}
-CollectionPtr CollectionCatalog::_openCollection(OperationContext* opCtx,
- const NamespaceStringOrUUID& nssOrUUID,
- boost::optional<Timestamp> readTimestamp) const {
+const Collection* CollectionCatalog::_openCollection(
+ OperationContext* opCtx,
+ const NamespaceStringOrUUID& nssOrUUID,
+ boost::optional<Timestamp> readTimestamp) const {
if (!feature_flags::gPointInTimeCatalogLookups.isEnabledAndIgnoreFCV()) {
- return CollectionPtr();
+ return nullptr;
}
// The implementation of openCollection() is quite different at a timestamp compared to at
@@ -843,7 +844,7 @@ CollectionPtr CollectionCatalog::_openCollection(OperationContext* opCtx,
}
}
-CollectionPtr CollectionCatalog::_openCollectionAtLatestByNamespace(
+const Collection* CollectionCatalog::_openCollectionAtLatestByNamespace(
OperationContext* opCtx, const NamespaceString& nss) const {
auto& openedCollections = OpenedCollections::get(opCtx);
@@ -876,7 +877,7 @@ CollectionPtr CollectionCatalog::_openCollectionAtLatestByNamespace(
// find a collection.
if (catalogEntry.isEmpty()) {
openedCollections.store(nullptr, nss, uuid);
- return CollectionPtr();
+ return nullptr;
}
// If the catalog entry has a different namespace in our snapshot, then there is a
@@ -903,7 +904,7 @@ CollectionPtr CollectionCatalog::_openCollectionAtLatestByNamespace(
// Last, mark 'nss' as not existing
openedCollections.store(nullptr, nss, boost::none);
- return CollectionPtr();
+ return nullptr;
}
auto metadata = DurableCatalog::getMetadataFromCatalogEntry(catalogEntry);
@@ -918,16 +919,16 @@ CollectionPtr CollectionCatalog::_openCollectionAtLatestByNamespace(
invariant(pendingCollection && pendingCollection->isMetadataEqual(metadata));
// TODO(SERVER-72193): Test this code path.
openedCollections.store(pendingCollection, nss, uuid);
- return CollectionPtr(pendingCollection.get());
+ return pendingCollection.get();
}
invariant(latestCollection->isMetadataEqual(metadata));
openedCollections.store(latestCollection, nss, uuid);
- return CollectionPtr(latestCollection.get());
+ return latestCollection.get();
}
-CollectionPtr CollectionCatalog::_openCollectionAtLatestByUUID(OperationContext* opCtx,
- const UUID& uuid) const {
+const Collection* CollectionCatalog::_openCollectionAtLatestByUUID(OperationContext* opCtx,
+ const UUID& uuid) const {
auto& openedCollections = OpenedCollections::get(opCtx);
// When openCollection is called with no timestamp, the namespace must be pending commit. We
@@ -961,7 +962,7 @@ CollectionPtr CollectionCatalog::_openCollectionAtLatestByUUID(OperationContext*
if (catalogEntry.isEmpty()) {
openedCollections.store(
nullptr, latestCollection ? latestCollection->ns() : pendingCollection->ns(), uuid);
- return CollectionPtr();
+ return nullptr;
}
NamespaceString nss = DurableCatalog::getNamespaceFromCatalogEntry(catalogEntry);
@@ -974,12 +975,12 @@ CollectionPtr CollectionCatalog::_openCollectionAtLatestByUUID(OperationContext*
if (latestCollection->ns() == nss) {
openedCollections.store(nullptr, pendingCollection->ns(), boost::none);
openedCollections.store(latestCollection, nss, uuid);
- return CollectionPtr(latestCollection.get());
+ return latestCollection.get();
} else {
invariant(pendingCollection->ns() == nss);
openedCollections.store(nullptr, latestCollection->ns(), boost::none);
openedCollections.store(pendingCollection, nss, uuid);
- return CollectionPtr(pendingCollection.get());
+ return pendingCollection.get();
}
}
@@ -998,14 +999,14 @@ CollectionPtr CollectionCatalog::_openCollectionAtLatestByUUID(OperationContext*
// operating on this snapshot.
invariant(pendingCollection && pendingCollection->isMetadataEqual(metadata));
openedCollections.store(pendingCollection, nss, uuid);
- return CollectionPtr(pendingCollection.get());
+ return pendingCollection.get();
}
invariant(latestCollection->isMetadataEqual(metadata));
openedCollections.store(latestCollection, nss, uuid);
- return CollectionPtr(latestCollection.get());
+ return latestCollection.get();
}
-CollectionPtr CollectionCatalog::_openCollectionAtPointInTimeByNamespace(
+const Collection* CollectionCatalog::_openCollectionAtPointInTimeByNamespace(
OperationContext* opCtx, const NamespaceString& nss, Timestamp readTimestamp) const {
auto& openedCollections = OpenedCollections::get(opCtx);
@@ -1013,7 +1014,7 @@ CollectionPtr CollectionCatalog::_openCollectionAtPointInTimeByNamespace(
auto catalogEntry = _fetchPITCatalogEntry(opCtx, nss, readTimestamp);
if (!catalogEntry) {
openedCollections.store(nullptr, nss, boost::none);
- return CollectionPtr();
+ return nullptr;
}
auto latestCollection = _lookupCollectionByUUID(*catalogEntry->metadata->options.uuid);
@@ -1021,7 +1022,7 @@ CollectionPtr CollectionCatalog::_openCollectionAtPointInTimeByNamespace(
// Return the in-memory Collection instance if it is compatible with the read timestamp.
if (isExistingCollectionCompatible(latestCollection, readTimestamp)) {
openedCollections.store(latestCollection, nss, latestCollection->uuid());
- return CollectionPtr(latestCollection.get());
+ return latestCollection.get();
}
// Use the shared collection state from the latest Collection in the in-memory collection
@@ -1030,7 +1031,7 @@ CollectionPtr CollectionCatalog::_openCollectionAtPointInTimeByNamespace(
_createCompatibleCollection(opCtx, latestCollection, readTimestamp, catalogEntry.get());
if (compatibleCollection) {
openedCollections.store(compatibleCollection, nss, compatibleCollection->uuid());
- return CollectionPtr(compatibleCollection.get());
+ return compatibleCollection.get();
}
// There is no state in-memory that matches the catalog entry. Try to instantiate a new
@@ -1038,11 +1039,11 @@ CollectionPtr CollectionCatalog::_openCollectionAtPointInTimeByNamespace(
auto newCollection = _createNewPITCollection(opCtx, readTimestamp, catalogEntry.get());
if (newCollection) {
openedCollections.store(newCollection, nss, newCollection->uuid());
- return CollectionPtr(newCollection.get());
+ return newCollection.get();
}
openedCollections.store(nullptr, nss, boost::none);
- return CollectionPtr();
+ return nullptr;
}
boost::optional<DurableCatalogEntry> CollectionCatalog::_fetchPITCatalogEntry(
@@ -1354,26 +1355,27 @@ Collection* CollectionCatalog::lookupCollectionByUUIDForMetadataWrite(OperationC
return ptr;
}
-CollectionPtr CollectionCatalog::lookupCollectionByUUID(OperationContext* opCtx, UUID uuid) const {
+const Collection* CollectionCatalog::lookupCollectionByUUID(OperationContext* opCtx,
+ UUID uuid) const {
// If UUID is managed by UncommittedCatalogUpdates (but not newly created) return the pointer
// which will be nullptr in case of a drop.
auto [found, uncommittedPtr, newColl] =
UncommittedCatalogUpdates::lookupCollection(opCtx, uuid);
if (found) {
- return CollectionPtr(uncommittedPtr.get());
+ return uncommittedPtr.get();
}
// Return any previously instantiated collection on this namespace for this snapshot
if (auto openedColl = OpenedCollections::get(opCtx).lookupByUUID(uuid)) {
- return openedColl.value() ? CollectionPtr(openedColl->get()) : CollectionPtr();
+ return openedColl.value() ? openedColl->get() : nullptr;
}
auto coll = _lookupCollectionByUUID(uuid);
- return (coll && coll->isCommitted()) ? CollectionPtr(coll.get()) : CollectionPtr();
+ return (coll && coll->isCommitted()) ? coll.get() : nullptr;
}
-CollectionPtr CollectionCatalog::lookupCollectionByNamespaceOrUUID(
+const Collection* CollectionCatalog::lookupCollectionByNamespaceOrUUID(
OperationContext* opCtx, const NamespaceStringOrUUID& nssOrUUID) const {
if (boost::optional<UUID> uuid = nssOrUUID.uuid())
return lookupCollectionByUUID(opCtx, *uuid);
@@ -1419,7 +1421,7 @@ Collection* CollectionCatalog::lookupCollectionByNamespaceForMetadataWrite(
// Oplog is special and can only be modified in a few contexts. It is modified inplace and care
// need to be taken for concurrency.
if (nss.isOplog()) {
- return const_cast<Collection*>(lookupCollectionByNamespace(opCtx, nss).get());
+ return const_cast<Collection*>(lookupCollectionByNamespace(opCtx, nss));
}
auto& uncommittedCatalogUpdates = UncommittedCatalogUpdates::get(opCtx);
@@ -1476,28 +1478,28 @@ Collection* CollectionCatalog::lookupCollectionByNamespaceForMetadataWrite(
return ptr;
}
-CollectionPtr CollectionCatalog::lookupCollectionByNamespace(OperationContext* opCtx,
- const NamespaceString& nss) const {
+const Collection* CollectionCatalog::lookupCollectionByNamespace(OperationContext* opCtx,
+ const NamespaceString& nss) const {
// If uncommittedPtr is valid, found is always true. Return the pointer as the collection still
// exists.
auto [found, uncommittedPtr, newColl] = UncommittedCatalogUpdates::lookupCollection(opCtx, nss);
if (uncommittedPtr) {
- return CollectionPtr(uncommittedPtr.get());
+ return uncommittedPtr.get();
}
// Report the drop or rename as nothing new was created.
if (found) {
- return CollectionPtr();
+ return nullptr;
}
// Return any previously instantiated collection on this namespace for this snapshot
if (auto openedColl = OpenedCollections::get(opCtx).lookupByNamespace(nss)) {
- return CollectionPtr(openedColl->get());
+ return openedColl->get();
}
auto it = _collections.find(nss);
auto coll = (it == _collections.end() ? nullptr : it->second);
- return (coll && coll->isCommitted()) ? CollectionPtr(coll.get()) : CollectionPtr();
+ return (coll && coll->isCommitted()) ? coll.get() : nullptr;
}
boost::optional<NamespaceString> CollectionCatalog::lookupNSSByUUID(OperationContext* opCtx,
@@ -1568,7 +1570,7 @@ boost::optional<UUID> CollectionCatalog::lookupUUIDByNSS(OperationContext* opCtx
}
bool CollectionCatalog::containsCollection(OperationContext* opCtx,
- const CollectionPtr& collection) const {
+ const Collection* collection) const {
// Any writable Collection instance created under MODE_X lock is considered to belong to this
// catalog instance
auto& uncommittedCatalogUpdates = UncommittedCatalogUpdates::get(opCtx);
@@ -1576,7 +1578,7 @@ bool CollectionCatalog::containsCollection(OperationContext* opCtx,
auto entriesIt = std::find_if(entries.begin(),
entries.end(),
[&collection](const UncommittedCatalogUpdates::Entry& entry) {
- return entry.collection.get() == collection.get();
+ return entry.collection.get() == collection;
});
if (entriesIt != entries.end())
return true;
@@ -1586,7 +1588,7 @@ bool CollectionCatalog::containsCollection(OperationContext* opCtx,
if (it == _catalog.end())
return false;
- return it->second.get() == collection.get();
+ return it->second.get() == collection;
}
CollectionCatalog::CatalogIdLookup CollectionCatalog::lookupCatalogIdByNSS(
@@ -1711,7 +1713,7 @@ bool CollectionCatalog::checkIfCollectionSatisfiable(UUID uuid, CollectionInfoFn
return false;
}
- return predicate(CollectionPtr(collection.get()));
+ return predicate(collection.get());
}
std::vector<UUID> CollectionCatalog::getAllCollectionUUIDsFromDb(const DatabaseName& dbName) const {
@@ -1924,7 +1926,8 @@ void CollectionCatalog::_registerCollection(OperationContext* opCtx,
if (!storageGlobalParams.repair && coll->ns().isSystemDotViews()) {
auto [it, emplaced] = _viewsForDatabase.try_emplace(coll->ns().dbName());
- if (auto status = it->second.reload(opCtx, _lookupSystemViews(opCtx, coll->ns().dbName()));
+ if (auto status = it->second.reload(
+ opCtx, CollectionPtr(_lookupSystemViews(opCtx, coll->ns().dbName())));
!status.isOK()) {
LOGV2_WARNING_OPTIONS(20326,
{logv2::LogTag::kStartupWarnings},
@@ -2461,8 +2464,8 @@ bool CollectionCatalog::hasExclusiveAccessToCollection(OperationContext* opCtx,
opCtx->lockState()->isCollectionLockedForMode(nss, MODE_IX));
}
-CollectionPtr CollectionCatalog::_lookupSystemViews(OperationContext* opCtx,
- const DatabaseName& dbName) const {
+const Collection* CollectionCatalog::_lookupSystemViews(OperationContext* opCtx,
+ const DatabaseName& dbName) const {
return lookupCollectionByNamespace(opCtx, NamespaceString::makeSystemDotViewsNamespace(dbName));
}
diff --git a/src/mongo/db/catalog/collection_catalog.h b/src/mongo/db/catalog/collection_catalog.h
index fd8c32c2b44..f10430dbe5a 100644
--- a/src/mongo/db/catalog/collection_catalog.h
+++ b/src/mongo/db/catalog/collection_catalog.h
@@ -50,7 +50,7 @@ class CollectionCatalog {
friend class iterator;
public:
- using CollectionInfoFn = std::function<bool(const CollectionPtr& collection)>;
+ using CollectionInfoFn = std::function<bool(const Collection* collection)>;
// Number of how many Collection references for a single Collection that is stored in the
// catalog. Used to determine whether there are external references (uniquely owned). Needs to
@@ -59,7 +59,7 @@ public:
class iterator {
public:
- using value_type = CollectionPtr;
+ using value_type = const Collection*;
iterator(OperationContext* opCtx,
const DatabaseName& dbName,
@@ -242,9 +242,9 @@ public:
*
* No collection level lock is required to call this function.
*/
- CollectionPtr establishConsistentCollection(OperationContext* opCtx,
- const NamespaceStringOrUUID& nssOrUUID,
- boost::optional<Timestamp> readTimestamp) const;
+ const Collection* establishConsistentCollection(OperationContext* opCtx,
+ const NamespaceStringOrUUID& nssOrUUID,
+ boost::optional<Timestamp> readTimestamp) const;
/**
* Returns a shared_ptr to a drop pending index if it's found and not expired.
@@ -386,7 +386,7 @@ public:
*/
Collection* lookupCollectionByUUIDForMetadataWrite(OperationContext* opCtx,
const UUID& uuid) const;
- CollectionPtr lookupCollectionByUUID(OperationContext* opCtx, UUID uuid) const;
+ const Collection* lookupCollectionByUUID(OperationContext* opCtx, UUID uuid) const;
std::shared_ptr<const Collection> lookupCollectionByUUIDForRead(OperationContext* opCtx,
const UUID& uuid) const;
@@ -414,8 +414,8 @@ public:
*/
Collection* lookupCollectionByNamespaceForMetadataWrite(OperationContext* opCtx,
const NamespaceString& nss) const;
- CollectionPtr lookupCollectionByNamespace(OperationContext* opCtx,
- const NamespaceString& nss) const;
+ const Collection* lookupCollectionByNamespace(OperationContext* opCtx,
+ const NamespaceString& nss) const;
std::shared_ptr<const Collection> lookupCollectionByNamespaceForRead(
OperationContext* opCtx, const NamespaceString& nss) const;
@@ -427,8 +427,8 @@ public:
*
* Returns nullptr is the namespace or uuid is unknown.
*/
- CollectionPtr lookupCollectionByNamespaceOrUUID(OperationContext* opCtx,
- const NamespaceStringOrUUID& nssOrUUID) const;
+ const Collection* lookupCollectionByNamespaceOrUUID(
+ OperationContext* opCtx, const NamespaceStringOrUUID& nssOrUUID) const;
/**
* This function gets the NamespaceString from the collection catalog entry that
@@ -447,7 +447,7 @@ public:
/**
* Returns true if this CollectionCatalog contains the provided collection instance
*/
- bool containsCollection(OperationContext* opCtx, const CollectionPtr& collection) const;
+ bool containsCollection(OperationContext* opCtx, const Collection* collection) const;
/**
* Returns the CatalogId for a given 'nss' at timestamp 'ts'.
@@ -699,7 +699,7 @@ private:
std::shared_ptr<Collection> _lookupCollectionByUUID(UUID uuid) const;
- CollectionPtr _lookupSystemViews(OperationContext* opCtx, const DatabaseName& dbName) const;
+ const Collection* _lookupSystemViews(OperationContext* opCtx, const DatabaseName& dbName) const;
/**
* Searches for a catalog entry at a point-in-time.
@@ -834,17 +834,18 @@ private:
*
* Returns nullptr when reading from a point-in-time where the collection did not exist.
*/
- CollectionPtr _openCollection(OperationContext* opCtx,
- const NamespaceStringOrUUID& nssOrUUID,
- boost::optional<Timestamp> readTimestamp) const;
+ const Collection* _openCollection(OperationContext* opCtx,
+ const NamespaceStringOrUUID& nssOrUUID,
+ boost::optional<Timestamp> readTimestamp) const;
// Helpers to perform openCollection at latest or at point-in-time on Namespace/UUID.
- CollectionPtr _openCollectionAtLatestByNamespace(OperationContext* opCtx,
- const NamespaceString& nss) const;
- CollectionPtr _openCollectionAtLatestByUUID(OperationContext* opCtx, const UUID& uuid) const;
- CollectionPtr _openCollectionAtPointInTimeByNamespace(OperationContext* opCtx,
- const NamespaceString& nss,
- Timestamp readTimestamp) const;
+ const Collection* _openCollectionAtLatestByNamespace(OperationContext* opCtx,
+ const NamespaceString& nss) const;
+ const Collection* _openCollectionAtLatestByUUID(OperationContext* opCtx,
+ const UUID& uuid) const;
+ const Collection* _openCollectionAtPointInTimeByNamespace(OperationContext* opCtx,
+ const NamespaceString& nss,
+ Timestamp readTimestamp) const;
/**
* When present, indicates that the catalog is in closed state, and contains a map from UUID
diff --git a/src/mongo/db/catalog/collection_catalog_helper.cpp b/src/mongo/db/catalog/collection_catalog_helper.cpp
index a8382878417..4e4a526141b 100644
--- a/src/mongo/db/catalog/collection_catalog_helper.cpp
+++ b/src/mongo/db/catalog/collection_catalog_helper.cpp
@@ -86,7 +86,7 @@ void forEachCollectionFromDb(OperationContext* opCtx,
if (catalog->lookupNSSByUUID(opCtx, uuid) == nss) {
// Success: locked the namespace and the UUID still maps to it.
- collection = catalog->lookupCollectionByUUID(opCtx, uuid);
+ collection = CollectionPtr(catalog->lookupCollectionByUUID(opCtx, uuid));
invariant(collection);
break;
}
@@ -102,7 +102,7 @@ void forEachCollectionFromDb(OperationContext* opCtx,
if (!collection)
continue;
- if (!callback(collection))
+ if (!callback(collection.get()))
break;
hangBeforeGettingNextCollection.pauseWhileSet();
diff --git a/src/mongo/db/catalog/collection_catalog_test.cpp b/src/mongo/db/catalog/collection_catalog_test.cpp
index b8ecc929fca..6f7d643ffc6 100644
--- a/src/mongo/db/catalog/collection_catalog_test.cpp
+++ b/src/mongo/db/catalog/collection_catalog_test.cpp
@@ -325,7 +325,7 @@ TEST_F(CollectionCatalogIterationTest, GetUUIDWontRepositionEvenIfEntryIsDropped
}
TEST_F(CollectionCatalogTest, OnCreateCollection) {
- ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), colUUID) == col);
+ ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), colUUID) == col.get());
}
TEST_F(CollectionCatalogTest, LookupCollectionByUUID) {
@@ -333,7 +333,7 @@ TEST_F(CollectionCatalogTest, LookupCollectionByUUID) {
// nss.ns().
ASSERT_EQUALS(catalog.lookupCollectionByUUID(opCtx.get(), colUUID)->ns().ns(), nss.ns());
// Ensure lookups of unknown UUIDs result in null pointers.
- ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), UUID::gen()).get() == nullptr);
+ ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), UUID::gen()) == nullptr);
}
TEST_F(CollectionCatalogTest, LookupNSSByUUID) {
@@ -347,10 +347,10 @@ TEST_F(CollectionCatalogTest, InsertAfterLookup) {
auto newUUID = UUID::gen();
NamespaceString newNss = NamespaceString::createNamespaceString_forTest(nss.dbName(), "newcol");
std::shared_ptr<Collection> newCollShared = std::make_shared<CollectionMock>(newNss);
- auto newCol = CollectionPtr(newCollShared.get());
+ auto newCol = newCollShared.get();
// Ensure that looking up non-existing UUIDs doesn't affect later registration of those UUIDs.
- ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), newUUID).get() == nullptr);
+ ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), newUUID) == nullptr);
ASSERT_EQUALS(catalog.lookupNSSByUUID(opCtx.get(), newUUID), boost::none);
catalog.registerCollection(opCtx.get(), newUUID, std::move(newCollShared), boost::none);
ASSERT_EQUALS(catalog.lookupCollectionByUUID(opCtx.get(), newUUID), newCol);
@@ -358,7 +358,7 @@ TEST_F(CollectionCatalogTest, InsertAfterLookup) {
}
TEST_F(CollectionCatalogTest, OnDropCollection) {
- auto yieldableColl = catalog.lookupCollectionByUUID(opCtx.get(), colUUID);
+ CollectionPtr yieldableColl(catalog.lookupCollectionByUUID(opCtx.get(), colUUID));
ASSERT(yieldableColl);
ASSERT_EQUALS(yieldableColl, col);
@@ -387,7 +387,7 @@ TEST_F(CollectionCatalogTest, OnDropCollection) {
catalog.deregisterCollection(opCtx.get(), colUUID, /*isDropPending=*/false, boost::none);
// Ensure the lookup returns a null pointer upon removing the colUUID entry.
- ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), colUUID).get() == nullptr);
+ ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), colUUID) == nullptr);
// After dropping the collection, we should fail to restore the CollectionPtr.
yieldableColl.restore();
@@ -400,7 +400,7 @@ TEST_F(CollectionCatalogTest, RenameCollection) {
std::shared_ptr<Collection> collShared = std::make_shared<CollectionMock>(uuid, oldNss);
auto collection = collShared.get();
catalog.registerCollection(opCtx.get(), uuid, std::move(collShared), boost::none);
- auto yieldableColl = catalog.lookupCollectionByUUID(opCtx.get(), uuid);
+ CollectionPtr yieldableColl(catalog.lookupCollectionByUUID(opCtx.get(), uuid));
ASSERT(yieldableColl);
ASSERT_EQUALS(yieldableColl, CollectionPtr(collection));
@@ -430,7 +430,7 @@ TEST_F(CollectionCatalogTest, RenameCollection) {
NamespaceString newNss = NamespaceString::createNamespaceString_forTest(nss.dbName(), "newcol");
ASSERT_OK(collection->rename(opCtx.get(), newNss, false));
ASSERT_EQ(collection->ns(), newNss);
- ASSERT_EQUALS(catalog.lookupCollectionByUUID(opCtx.get(), uuid), CollectionPtr(collection));
+ ASSERT_EQUALS(catalog.lookupCollectionByUUID(opCtx.get(), uuid), collection);
// After renaming the collection, we should fail to restore the CollectionPtr.
yieldableColl.restore();
@@ -444,7 +444,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsOldNSSIfDrop
}
catalog.deregisterCollection(opCtx.get(), colUUID, /*isDropPending=*/false, boost::none);
- ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), colUUID).get() == nullptr);
+ ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), colUUID) == nullptr);
ASSERT_EQUALS(*catalog.lookupNSSByUUID(opCtx.get(), colUUID), nss);
{
@@ -459,7 +459,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreated
auto newUUID = UUID::gen();
NamespaceString newNss = NamespaceString::createNamespaceString_forTest(nss.dbName(), "newcol");
std::shared_ptr<Collection> newCollShared = std::make_shared<CollectionMock>(newNss);
- auto newCol = CollectionPtr(newCollShared.get());
+ auto newCol = newCollShared.get();
// Ensure that looking up non-existing UUIDs doesn't affect later registration of those UUIDs.
{
@@ -467,7 +467,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreated
catalog.onCloseCatalog();
}
- ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), newUUID).get() == nullptr);
+ ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), newUUID) == nullptr);
ASSERT_EQUALS(catalog.lookupNSSByUUID(opCtx.get(), newUUID), boost::none);
catalog.registerCollection(opCtx.get(), newUUID, std::move(newCollShared), boost::none);
ASSERT_EQUALS(catalog.lookupCollectionByUUID(opCtx.get(), newUUID), newCol);
@@ -486,7 +486,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsNewlyCreated
TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS) {
NamespaceString newNss = NamespaceString::createNamespaceString_forTest(nss.dbName(), "newcol");
std::shared_ptr<Collection> newCollShared = std::make_shared<CollectionMock>(newNss);
- auto newCol = CollectionPtr(newCollShared.get());
+ auto newCol = newCollShared.get();
{
Lock::GlobalLock globalLk(opCtx.get(), MODE_X);
@@ -494,7 +494,7 @@ TEST_F(CollectionCatalogTest, LookupNSSByUUIDForClosedCatalogReturnsFreshestNSS)
}
catalog.deregisterCollection(opCtx.get(), colUUID, /*isDropPending=*/false, boost::none);
- ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), colUUID).get() == nullptr);
+ ASSERT(catalog.lookupCollectionByUUID(opCtx.get(), colUUID) == nullptr);
ASSERT_EQUALS(*catalog.lookupNSSByUUID(opCtx.get(), colUUID), nss);
{
Lock::GlobalWrite lk(opCtx.get());
@@ -627,7 +627,7 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt
// One dbName with only an invisible collection does not appear in dbNames. Use const_cast to
// modify the collection in the catalog inplace, this bypasses copy-on-write behavior.
auto invisibleCollA =
- const_cast<Collection*>(catalog.lookupCollectionByNamespace(opCtx.get(), aColl).get());
+ const_cast<Collection*>(catalog.lookupCollectionByNamespace(opCtx.get(), aColl));
invisibleCollA->setCommitted(false);
Lock::DBLock dbLock(opCtx.get(), aColl.dbName(), MODE_S);
@@ -651,7 +651,7 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt
// Use const_cast to modify the collection in the catalog inplace, this bypasses
// copy-on-write behavior.
auto invisibleCollD =
- const_cast<Collection*>(catalog.lookupCollectionByNamespace(opCtx.get(), nss).get());
+ const_cast<Collection*>(catalog.lookupCollectionByNamespace(opCtx.get(), nss));
invisibleCollD->setCommitted(false);
Lock::DBLock dbLock(opCtx.get(), d1Coll.dbName(), MODE_S);
@@ -670,7 +670,7 @@ TEST_F(CollectionCatalogTest, GetAllCollectionNamesAndGetAllDbNamesWithUncommitt
// Use const_cast to modify the collection in the catalog inplace, this bypasses
// copy-on-write behavior.
auto invisibleColl =
- const_cast<Collection*>(catalog.lookupCollectionByNamespace(opCtx.get(), nss).get());
+ const_cast<Collection*>(catalog.lookupCollectionByNamespace(opCtx.get(), nss));
invisibleColl->setCommitted(false);
}
@@ -715,13 +715,11 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) {
const DatabaseName dbName(boost::none, "db");
auto dbLock = std::make_unique<Lock::DBLock>(opCtx, dbName, MODE_IX);
int numCollectionsTraversed = 0;
- catalog::forEachCollectionFromDb(
- opCtx, dbName, MODE_X, [&](const CollectionPtr& collection) {
- ASSERT_TRUE(
- opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_X));
- numCollectionsTraversed++;
- return true;
- });
+ catalog::forEachCollectionFromDb(opCtx, dbName, MODE_X, [&](const Collection* collection) {
+ ASSERT_TRUE(opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_X));
+ numCollectionsTraversed++;
+ return true;
+ });
ASSERT_EQUALS(numCollectionsTraversed, 3);
}
@@ -730,13 +728,11 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) {
const DatabaseName dbName(boost::none, "db2");
auto dbLock = std::make_unique<Lock::DBLock>(opCtx, dbName, MODE_IX);
int numCollectionsTraversed = 0;
- catalog::forEachCollectionFromDb(
- opCtx, dbName, MODE_IS, [&](const CollectionPtr& collection) {
- ASSERT_TRUE(
- opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_IS));
- numCollectionsTraversed++;
- return true;
- });
+ catalog::forEachCollectionFromDb(opCtx, dbName, MODE_IS, [&](const Collection* collection) {
+ ASSERT_TRUE(opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_IS));
+ numCollectionsTraversed++;
+ return true;
+ });
ASSERT_EQUALS(numCollectionsTraversed, 1);
}
@@ -745,11 +741,10 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDb) {
const DatabaseName dbName(boost::none, "db3");
auto dbLock = std::make_unique<Lock::DBLock>(opCtx, dbName, MODE_IX);
int numCollectionsTraversed = 0;
- catalog::forEachCollectionFromDb(
- opCtx, dbName, MODE_S, [&](const CollectionPtr& collection) {
- numCollectionsTraversed++;
- return true;
- });
+ catalog::forEachCollectionFromDb(opCtx, dbName, MODE_S, [&](const Collection* collection) {
+ numCollectionsTraversed++;
+ return true;
+ });
ASSERT_EQUALS(numCollectionsTraversed, 0);
}
@@ -767,13 +762,13 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDbWithPredicate) {
opCtx,
dbName,
MODE_X,
- [&](const CollectionPtr& collection) {
+ [&](const Collection* collection) {
ASSERT_TRUE(
opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_X));
numCollectionsTraversed++;
return true;
},
- [&](const CollectionPtr& collection) {
+ [&](const Collection* collection) {
ASSERT_TRUE(
opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_NONE));
return collection->getCollectionOptions().temp;
@@ -790,13 +785,13 @@ TEST_F(ForEachCollectionFromDbTest, ForEachCollectionFromDbWithPredicate) {
opCtx,
dbName,
MODE_IX,
- [&](const CollectionPtr& collection) {
+ [&](const Collection* collection) {
ASSERT_TRUE(
opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_IX));
numCollectionsTraversed++;
return true;
},
- [&](const CollectionPtr& collection) {
+ [&](const Collection* collection) {
ASSERT_TRUE(
opCtx->lockState()->isCollectionLockedForMode(collection->ns(), MODE_NONE));
return !collection->getCollectionOptions().temp;
@@ -1251,7 +1246,7 @@ private:
// Stash the catalog so we may perform multiple lookups that will be in sync with our
// snapshot
CollectionCatalog::stash(opCtx, CollectionCatalog::get(opCtx));
- CollectionPtr coll = CollectionCatalog::get(opCtx)->establishConsistentCollection(
+ const Collection* coll = CollectionCatalog::get(opCtx)->establishConsistentCollection(
opCtx, nssOrUUID, boost::none);
// Notify the thread that our openCollection lookup is done.
@@ -1271,12 +1266,10 @@ private:
ASSERT_EQ(coll->ns(), nss);
// Check that lookup returns the same instance as openCollection above
- ASSERT_EQ(
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, coll->ns()).get(),
- coll.get());
- ASSERT_EQ(
- CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, coll->uuid()).get(),
- coll.get());
+ ASSERT_EQ(CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, coll->ns()),
+ coll);
+ ASSERT_EQ(CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, coll->uuid()),
+ coll);
ASSERT_EQ(CollectionCatalog::get(opCtx)->lookupNSSByUUID(opCtx, coll->uuid()), nss);
ASSERT_EQ(coll->getIndexCatalog()->numIndexesTotal(), expectedNumIndexes);
@@ -1290,11 +1283,11 @@ private:
ASSERT_EQ(CollectionCatalog::get(opCtx)
->lookupCollectionByNamespaceForRead(opCtx, coll->ns())
.get(),
- coll.get());
+ coll);
ASSERT_EQ(CollectionCatalog::get(opCtx)
->lookupCollectionByUUIDForRead(opCtx, coll->uuid())
.get(),
- coll.get());
+ coll);
} else {
ASSERT(!coll);
if (auto nss = nssOrUUID.nss()) {
@@ -1307,7 +1300,7 @@ private:
ASSERT_EQ(CollectionCatalog::get(opCtx)
->lookupCollectionByNamespaceForRead(opCtx, *nss)
.get(),
- coll.get());
+ coll);
} else if (auto uuid = nssOrUUID.uuid()) {
// TODO SERVER-71222: Check UUID->catalogId mapping here.
@@ -1316,7 +1309,7 @@ private:
ASSERT_EQ(CollectionCatalog::get(opCtx)
->lookupCollectionByUUIDForRead(opCtx, *uuid)
.get(),
- coll.get());
+ coll);
}
}
@@ -1398,7 +1391,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenCollectionBeforeCreateTimestamp) {
ASSERT_EQ(CollectionCatalog::get(opCtx.get())
->lookupCollectionByNamespaceForRead(opCtx.get(), nss)
.get(),
- coll.get());
+ coll);
}
TEST_F(CollectionCatalogTimestampTest, OpenEarlierCollection) {
@@ -1438,7 +1431,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenEarlierCollection) {
ASSERT_EQ(1, latestColl->getIndexCatalog()->numIndexesTotal());
// Ensure the idents are shared between the collection instances.
- ASSERT_NE(coll.get(), latestColl.get());
+ ASSERT_NE(coll, latestColl.get());
ASSERT_EQ(coll->getSharedIdent(), latestColl->getSharedIdent());
}
@@ -1485,7 +1478,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenEarlierCollectionWithIndex) {
ASSERT_EQ(2, latestColl->getIndexCatalog()->numIndexesTotal());
// Ensure the idents are shared between the collection and index instances.
- ASSERT_NE(coll.get(), latestColl.get());
+ ASSERT_NE(coll, latestColl.get());
ASSERT_EQ(coll->getSharedIdent(), latestColl->getSharedIdent());
auto indexDescPast = coll->getIndexCatalog()->findIndexByName(opCtx.get(), "x_1");
@@ -1523,7 +1516,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenLatestCollectionWithIndex) {
// Verify that the CollectionCatalog returns the latest collection.
auto currentColl =
CollectionCatalog::get(opCtx.get())->lookupCollectionByNamespaceForRead(opCtx.get(), nss);
- ASSERT_EQ(coll.get(), currentColl.get());
+ ASSERT_EQ(coll, currentColl.get());
// Ensure the idents are shared between the collection and index instances.
ASSERT_EQ(coll->getSharedIdent(), currentColl->getSharedIdent());
@@ -1586,7 +1579,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenEarlierCollectionWithDropPendingIndex
auto newOpCtx = cc().makeOperationContext();
auto latestColl = CollectionCatalog::get(newOpCtx.get())
->lookupCollectionByNamespaceForRead(newOpCtx.get(), nss);
- ASSERT_NE(coll.get(), latestColl.get());
+ ASSERT_NE(coll, latestColl.get());
auto indexDescX = coll->getIndexCatalog()->findIndexByName(opCtx.get(), "x_1");
auto indexDescY = coll->getIndexCatalog()->findIndexByName(opCtx.get(), "y_1");
@@ -1683,11 +1676,11 @@ TEST_F(CollectionCatalogTimestampTest,
auto latestColl = CollectionCatalog::get(newOpCtx.get())
->lookupCollectionByNamespaceForRead(newOpCtx.get(), nss);
- ASSERT_NE(coll.get(), latestColl.get());
+ ASSERT_NE(coll, latestColl.get());
auto indexDescZ = coll->getIndexCatalog()->findIndexByName(opCtx.get(), zIndexName);
auto indexEntryZ = coll->getIndexCatalog()->getEntryShared(indexDescZ);
- auto indexEntryZIsMultikey = indexEntryZ->isMultikey(newOpCtx.get(), coll);
+ auto indexEntryZIsMultikey = indexEntryZ->isMultikey(newOpCtx.get(), CollectionPtr(coll));
ASSERT_FALSE(indexEntryZIsMultikey);
}
@@ -1796,7 +1789,7 @@ TEST_F(CollectionCatalogTimestampTest, OpenNewCollectionUsingDropPendingCollecti
auto openedColl = CollectionCatalog::get(opCtx.get())
->establishConsistentCollection(opCtx.get(), nss, readTimestamp);
ASSERT(openedColl);
- ASSERT_NE(coll.get(), openedColl.get());
+ ASSERT_NE(coll.get(), openedColl);
// Ensure the idents are shared between the opened collection and the drop pending collection.
ASSERT_EQ(coll->getSharedIdent(), openedColl->getSharedIdent());
opCtx->recoveryUnit()->abandonSnapshot();
@@ -1846,7 +1839,6 @@ TEST_F(CollectionCatalogTimestampTest, OpenExistingCollectionWithReaper) {
// The ident is now expired and should be removed the next time the ident reaper runs.
coll.reset();
- openedColl.reset();
}
{
@@ -2822,7 +2814,7 @@ TEST_F(CollectionCatalogTimestampTest, CollectionLifetimeTiedToStorageTransactio
std::shared_ptr<const Collection> fetchedColl =
OpenedCollections::get(opCtx.get()).lookupByNamespace(nss).value();
ASSERT(fetchedColl);
- ASSERT_EQ(coll.get(), fetchedColl.get());
+ ASSERT_EQ(coll, fetchedColl.get());
ASSERT_EQ(coll->getSharedIdent(), fetchedColl->getSharedIdent());
opCtx->recoveryUnit()->abandonSnapshot();
@@ -2843,7 +2835,7 @@ TEST_F(CollectionCatalogTimestampTest, CollectionLifetimeTiedToStorageTransactio
std::shared_ptr<const Collection> fetchedColl =
OpenedCollections::get(opCtx.get()).lookupByNamespace(nss).value();
ASSERT(fetchedColl);
- ASSERT_EQ(coll.get(), fetchedColl.get());
+ ASSERT_EQ(coll, fetchedColl.get());
ASSERT_EQ(coll->getSharedIdent(), fetchedColl->getSharedIdent());
wuow.commit();
@@ -2867,7 +2859,7 @@ TEST_F(CollectionCatalogTimestampTest, CollectionLifetimeTiedToStorageTransactio
std::shared_ptr<const Collection> fetchedColl =
OpenedCollections::get(opCtx.get()).lookupByNamespace(nss).value();
ASSERT(fetchedColl);
- ASSERT_EQ(coll.get(), fetchedColl.get());
+ ASSERT_EQ(coll, fetchedColl.get());
ASSERT_EQ(coll->getSharedIdent(), fetchedColl->getSharedIdent());
// The storage snapshot is aborted when the WriteUnitOfWork destructor runs.
@@ -2979,8 +2971,8 @@ DEATH_TEST_F(CollectionCatalogTimestampTest, OpenCollectionInWriteUnitOfWork, "i
WriteUnitOfWork wuow(opCtx.get());
Lock::GlobalLock globalLock(opCtx.get(), MODE_IS);
- auto coll = CollectionCatalog::get(opCtx.get())
- ->establishConsistentCollection(opCtx.get(), nss, readTimestamp);
+ CollectionCatalog::get(opCtx.get())
+ ->establishConsistentCollection(opCtx.get(), nss, readTimestamp);
}
TEST_F(CollectionCatalogTimestampTest, ConcurrentCreateCollectionAndOpenCollectionBeforeCommit) {
@@ -3558,11 +3550,11 @@ TEST_F(CollectionCatalogTimestampTest, OpenCollectionBetweenIndexBuildInProgress
ASSERT_EQ(CollectionCatalog::get(opCtx.get())
->lookupCollectionByNamespaceForRead(opCtx.get(), coll->ns())
.get(),
- coll.get());
+ coll);
ASSERT_EQ(CollectionCatalog::get(opCtx.get())
->lookupCollectionByUUIDForRead(opCtx.get(), coll->uuid())
.get(),
- coll.get());
+ coll);
}
finishIndexBuild(opCtx.get(), nss, std::move(indexBuildBlock), indexReadyTs);
@@ -3582,11 +3574,11 @@ TEST_F(CollectionCatalogTimestampTest, OpenCollectionBetweenIndexBuildInProgress
ASSERT_EQ(CollectionCatalog::get(opCtx.get())
->lookupCollectionByNamespaceForRead(opCtx.get(), coll->ns())
.get(),
- coll.get());
+ coll);
ASSERT_EQ(CollectionCatalog::get(opCtx.get())
->lookupCollectionByUUIDForRead(opCtx.get(), coll->uuid())
.get(),
- coll.get());
+ coll);
}
}
} // namespace
diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp
index dbd1bfdf886..ee9e8e8e4a5 100644
--- a/src/mongo/db/catalog/collection_compact.cpp
+++ b/src/mongo/db/catalog/collection_compact.cpp
@@ -63,7 +63,7 @@ CollectionPtr getCollectionForCompact(OperationContext* opCtx,
}
auto collectionCatalog = CollectionCatalog::get(opCtx);
- CollectionPtr collection = collectionCatalog->lookupCollectionByNamespace(opCtx, resolvedNs);
+ CollectionPtr collection(collectionCatalog->lookupCollectionByNamespace(opCtx, resolvedNs));
if (!collection) {
std::shared_ptr<const ViewDefinition> view =
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.cpp b/src/mongo/db/catalog/collection_uuid_mismatch.cpp
index 1f7dffc27d7..6c68130f701 100644
--- a/src/mongo/db/catalog/collection_uuid_mismatch.cpp
+++ b/src/mongo/db/catalog/collection_uuid_mismatch.cpp
@@ -37,16 +37,31 @@ namespace mongo {
void checkCollectionUUIDMismatch(OperationContext* opCtx,
const NamespaceString& ns,
- const CollectionPtr& coll,
+ const Collection* coll,
const boost::optional<UUID>& uuid) {
checkCollectionUUIDMismatch(opCtx, CollectionCatalog::get(opCtx), ns, coll, uuid);
}
void checkCollectionUUIDMismatch(OperationContext* opCtx,
+ const NamespaceString& ns,
+ const CollectionPtr& coll,
+ const boost::optional<UUID>& uuid) {
+ checkCollectionUUIDMismatch(opCtx, CollectionCatalog::get(opCtx), ns, coll.get(), uuid);
+}
+
+void checkCollectionUUIDMismatch(OperationContext* opCtx,
const std::shared_ptr<const CollectionCatalog>& catalog,
const NamespaceString& ns,
const CollectionPtr& coll,
const boost::optional<UUID>& uuid) {
+ checkCollectionUUIDMismatch(opCtx, catalog, ns, coll.get(), uuid);
+}
+
+void checkCollectionUUIDMismatch(OperationContext* opCtx,
+ const std::shared_ptr<const CollectionCatalog>& catalog,
+ const NamespaceString& ns,
+ const Collection* coll,
+ const boost::optional<UUID>& uuid) {
if (!uuid) {
return;
}
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.h b/src/mongo/db/catalog/collection_uuid_mismatch.h
index bc4f3d4158c..03561276e73 100644
--- a/src/mongo/db/catalog/collection_uuid_mismatch.h
+++ b/src/mongo/db/catalog/collection_uuid_mismatch.h
@@ -37,6 +37,11 @@ namespace mongo {
void checkCollectionUUIDMismatch(OperationContext* opCtx,
const NamespaceString& ns,
+ const Collection* coll,
+ const boost::optional<UUID>& uuid);
+
+void checkCollectionUUIDMismatch(OperationContext* opCtx,
+ const NamespaceString& ns,
const CollectionPtr& coll,
const boost::optional<UUID>& uuid);
@@ -46,6 +51,12 @@ void checkCollectionUUIDMismatch(OperationContext* opCtx,
void checkCollectionUUIDMismatch(OperationContext* opCtx,
const std::shared_ptr<const CollectionCatalog>& catalog,
const NamespaceString& ns,
+ const Collection* coll,
+ const boost::optional<UUID>& uuid);
+
+void checkCollectionUUIDMismatch(OperationContext* opCtx,
+ const std::shared_ptr<const CollectionCatalog>& catalog,
+ const NamespaceString& ns,
const CollectionPtr& coll,
const boost::optional<UUID>& uuid);
diff --git a/src/mongo/db/catalog/collection_writer_test.cpp b/src/mongo/db/catalog/collection_writer_test.cpp
index 64401d38a3c..979801f62fc 100644
--- a/src/mongo/db/catalog/collection_writer_test.cpp
+++ b/src/mongo/db/catalog/collection_writer_test.cpp
@@ -66,8 +66,8 @@ protected:
}
CollectionPtr lookupCollectionFromCatalog() {
- return CollectionCatalog::get(operationContext())
- ->lookupCollectionByNamespace(operationContext(), kNss);
+ return CollectionPtr(CollectionCatalog::get(operationContext())
+ ->lookupCollectionByNamespace(operationContext(), kNss));
}
const Collection* lookupCollectionFromCatalogForRead() {
@@ -82,8 +82,7 @@ protected:
auto opCtx = client->makeOperationContext();
ASSERT_EQ(expected,
CollectionCatalog::get(opCtx.get())
- ->lookupCollectionByNamespace(opCtx.get(), kNss)
- .get());
+ ->lookupCollectionByNamespace(opCtx.get(), kNss));
});
t.join();
}
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
index 082bde953e7..910dd16e1c8 100644
--- a/src/mongo/db/catalog/create_collection.cpp
+++ b/src/mongo/db/catalog/create_collection.cpp
@@ -713,8 +713,7 @@ Status createCollectionForApplyOps(OperationContext* opCtx,
// a random temporary name is correct: once all entries are replayed no temporary
// names will remain.
const bool stayTemp = true;
- auto futureColl =
- db ? catalog->lookupCollectionByNamespace(opCtx, newCollName) : CollectionPtr();
+ auto futureColl = db ? catalog->lookupCollectionByNamespace(opCtx, newCollName) : nullptr;
bool needsRenaming(futureColl);
invariant(!needsRenaming || allowRenameOutOfTheWay,
str::stream() << "Current collection name: " << currentName << ", UUID: " << uuid
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 66b681a0178..c5927c84cf8 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -279,7 +279,7 @@ void DatabaseImpl::getStats(OperationContext* opCtx,
invariant(opCtx->lockState()->isDbLockedForMode(name(), MODE_IS));
catalog::forEachCollectionFromDb(
- opCtx, name(), MODE_IS, [&](const CollectionPtr& collection) -> bool {
+ opCtx, name(), MODE_IS, [&](const Collection* collection) -> bool {
nCollections += 1;
objects += collection->numRecords(opCtx);
size += collection->dataSize(opCtx);
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp
index 408a581c04a..eeade83224a 100644
--- a/src/mongo/db/catalog/drop_collection.cpp
+++ b/src/mongo/db/catalog/drop_collection.cpp
@@ -201,8 +201,8 @@ Status _abortIndexBuildsAndDrop(OperationContext* opCtx,
// which may have changed when we released the collection lock temporarily.
opCtx->recoveryUnit()->abandonSnapshot();
- CollectionPtr coll =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, startingNss);
+ CollectionPtr coll(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, startingNss));
// Even if the collection doesn't exist, UUID mismatches must return an error.
Status status = _checkUUIDAndReplState(opCtx, coll, startingNss, expectedUUID);
@@ -261,7 +261,8 @@ Status _abortIndexBuildsAndDrop(OperationContext* opCtx,
// disk state, which may have changed when we released the collection lock temporarily.
opCtx->recoveryUnit()->abandonSnapshot();
- coll = CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, collectionUUID);
+ coll = CollectionPtr(
+ CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, collectionUUID));
// Even if the collection doesn't exist, UUID mismatches must return an error.
status = _checkUUIDAndReplState(opCtx, coll, startingNss, expectedUUID);
@@ -313,8 +314,8 @@ Status _dropCollectionForApplyOps(OperationContext* opCtx,
DropCollectionSystemCollectionMode systemCollectionMode,
DropReply* reply) {
Lock::CollectionLock collLock(opCtx, collectionName, MODE_X);
- const CollectionPtr& coll =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, collectionName);
+ CollectionPtr coll(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, collectionName));
// Even if the collection doesn't exist, UUID mismatches must return an error.
Status status = _checkUUIDAndReplState(opCtx, coll, collectionName);
@@ -580,8 +581,8 @@ Status dropCollectionForApplyOps(OperationContext* opCtx,
return Status::OK();
}
- const CollectionPtr& coll =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, collectionName);
+ CollectionPtr coll(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, collectionName));
DropReply unusedReply;
if (!coll) {
@@ -622,7 +623,7 @@ void checkForIdIndexesAndDropPendingCollections(OperationContext* opCtx,
if (nss.isSystem())
continue;
- CollectionPtr coll = catalog->lookupCollectionByNamespace(opCtx, nss);
+ CollectionPtr coll(catalog->lookupCollectionByNamespace(opCtx, nss));
if (!coll)
continue;
@@ -649,7 +650,7 @@ void clearTempCollections(OperationContext* opCtx, const DatabaseName& dbName) {
auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, dbName);
invariant(db);
- CollectionCatalog::CollectionInfoFn callback = [&](const CollectionPtr& collection) {
+ CollectionCatalog::CollectionInfoFn callback = [&](const Collection* collection) {
try {
WriteUnitOfWork wuow(opCtx);
Status status = db->dropCollection(opCtx, collection->ns());
@@ -673,7 +674,7 @@ void clearTempCollections(OperationContext* opCtx, const DatabaseName& dbName) {
};
catalog::forEachCollectionFromDb(
- opCtx, dbName, MODE_X, callback, [&](const CollectionPtr& collection) {
+ opCtx, dbName, MODE_X, callback, [&](const Collection* collection) {
return collection->getCollectionOptions().temp;
});
}
diff --git a/src/mongo/db/catalog/index_repair.cpp b/src/mongo/db/catalog/index_repair.cpp
index a291f7a7017..ce97cecde4a 100644
--- a/src/mongo/db/catalog/index_repair.cpp
+++ b/src/mongo/db/catalog/index_repair.cpp
@@ -47,7 +47,7 @@ StatusWith<int> moveRecordToLostAndFound(OperationContext* opCtx,
AutoGetCollection autoColl(opCtx, lostAndFoundNss, MODE_IX);
auto catalog = CollectionCatalog::get(opCtx);
auto originalCollection = catalog->lookupCollectionByNamespace(opCtx, nss);
- CollectionPtr localCollection = catalog->lookupCollectionByNamespace(opCtx, lostAndFoundNss);
+ CollectionPtr localCollection(catalog->lookupCollectionByNamespace(opCtx, lostAndFoundNss));
// Creates the collection if it doesn't exist.
if (!localCollection) {
@@ -103,7 +103,7 @@ StatusWith<int> moveRecordToLostAndFound(OperationContext* opCtx,
// this document matches the record id of the element it tries to unindex. This avoids
// wrongly unindexing a document with the same _id.
collection_internal::deleteDocument(opCtx,
- originalCollection,
+ CollectionPtr(originalCollection),
kUninitializedStmtId,
dupRecord,
nullptr /* opDebug */,
diff --git a/src/mongo/db/catalog/multi_index_block.cpp b/src/mongo/db/catalog/multi_index_block.cpp
index fdcc8cda182..604122a5fe0 100644
--- a/src/mongo/db/catalog/multi_index_block.cpp
+++ b/src/mongo/db/catalog/multi_index_block.cpp
@@ -838,8 +838,8 @@ Status MultiIndexBlock::drainBackgroundWrites(
ReadSourceScope readSourceScope(opCtx, readSource);
- CollectionPtr coll =
- CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, _collectionUUID.value());
+ CollectionPtr coll(
+ CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, _collectionUUID.value()));
coll.makeYieldable(opCtx, LockedCollectionYieldRestore(opCtx, coll));
// Drain side-writes table for each index. This only drains what is visible. Assuming intent
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index 3b40cd96f64..08c9d8f5f75 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -339,7 +339,7 @@ Status renameCollectionWithinDB(OperationContext* opCtx,
return renameCollectionDirectly(opCtx, db, sourceColl->uuid(), source, target, options);
} else {
return renameCollectionAndDropTarget(
- opCtx, db, sourceColl->uuid(), source, target, targetColl, options, {});
+ opCtx, db, sourceColl->uuid(), source, target, CollectionPtr(targetColl), options, {});
}
}
@@ -403,7 +403,7 @@ Status renameCollectionWithinDBForApplyOps(OperationContext* opCtx,
opCtx, source, sourceColl->uuid(), db, target, targetColl->uuid());
if (!status.isOK())
return status;
- targetColl = CollectionPtr();
+ targetColl = nullptr;
}
}
@@ -434,7 +434,7 @@ Status renameCollectionWithinDBForApplyOps(OperationContext* opCtx,
sourceColl->uuid(),
source,
target,
- targetColl,
+ CollectionPtr(targetColl),
options,
renameOpTimeFromApplyOps);
}
@@ -526,7 +526,7 @@ Status renameCollectionAcrossDatabases(OperationContext* opCtx,
// Return a non-OK status if target exists and dropTarget is not true or if the collection
// is sharded.
const auto targetColl =
- targetDB ? catalog->lookupCollectionByNamespace(opCtx, target) : CollectionPtr();
+ targetDB ? catalog->lookupCollectionByNamespace(opCtx, target) : nullptr;
if (targetColl) {
if (sourceColl->uuid() == targetColl->uuid()) {
invariant(source == target);
@@ -769,7 +769,7 @@ void doLocalRenameIfOptionsAndIndexesHaveNotChanged(OperationContext* opCtx,
AutoGetDb dbLock(opCtx, targetNs.dbName(), MODE_X);
auto collection = dbLock.getDb()
? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, targetNs)
- : CollectionPtr();
+ : nullptr;
BSONObj collectionOptions = {};
if (collection) {
// We do not include the UUID field in the options comparison. It is ok if the target
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index 2f806091548..b8dc2544588 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -441,8 +441,7 @@ UUID _getCollectionUuid(OperationContext* opCtx, const NamespaceString& nss) {
* Get collection namespace by UUID.
*/
NamespaceString _getCollectionNssFromUUID(OperationContext* opCtx, const UUID& uuid) {
- const CollectionPtr& source =
- CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, uuid);
+ const Collection* source = CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, uuid);
return source ? source->ns() : NamespaceString();
}
@@ -511,7 +510,7 @@ CollectionPtr _getCollection_inlock(OperationContext* opCtx, const NamespaceStri
if (!db) {
return CollectionPtr();
}
- return CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ return CollectionPtr(CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss));
}
TEST_F(RenameCollectionTest, RenameCollectionReturnsNamespaceNotFoundIfDatabaseDoesNotExist) {
diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp
index ba5f45a1838..886333305c5 100644
--- a/src/mongo/db/catalog/validate_state.cpp
+++ b/src/mongo/db/catalog/validate_state.cpp
@@ -80,7 +80,8 @@ ValidateState::ValidateState(OperationContext* opCtx,
_database = _databaseLock->getDb() ? _databaseLock->getDb() : nullptr;
if (_database)
- _collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, _nss);
+ _collection =
+ CollectionPtr(CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, _nss));
if (!_collection) {
auto view = CollectionCatalog::get(opCtx)->lookupView(opCtx, _nss);
@@ -100,7 +101,8 @@ ValidateState::ValidateState(OperationContext* opCtx,
} else {
_collectionLock.emplace(opCtx, _nss, MODE_X);
}
- _collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, _nss);
+ _collection = CollectionPtr(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, _nss));
uassert(
ErrorCodes::NamespaceNotFound,
fmt::format(
@@ -409,7 +411,8 @@ void ValidateState::_relockDatabaseAndCollection(OperationContext* opCtx) {
uasserted(ErrorCodes::Interrupted, collErrMsg);
}
- _collection = CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, *_uuid);
+ _collection =
+ CollectionPtr(CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, *_uuid));
uassert(ErrorCodes::Interrupted, collErrMsg, _collection);
// The namespace of the collection can be changed during a same database collection rename.
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp
index 816c1e1100d..4533ec2a7d7 100644
--- a/src/mongo/db/catalog_raii.cpp
+++ b/src/mongo/db/catalog_raii.cpp
@@ -58,7 +58,7 @@ void verifyDbAndCollection(OperationContext* opCtx,
LockMode modeColl,
const NamespaceStringOrUUID& nsOrUUID,
const NamespaceString& resolvedNss,
- CollectionPtr& coll,
+ const Collection* coll,
Database* db,
bool verifyWriteEligible) {
invariant(!nsOrUUID.uuid() || coll,
@@ -303,7 +303,7 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
// Check that the collections are all safe to use.
_resolvedNss = catalog->resolveNamespaceStringOrUUID(opCtx, nsOrUUID);
- _coll = catalog->lookupCollectionByNamespace(opCtx, _resolvedNss);
+ _coll = CollectionPtr(catalog->lookupCollectionByNamespace(opCtx, _resolvedNss));
_coll.makeYieldable(opCtx, LockedCollectionYieldRestore{opCtx, _coll});
if (_coll) {
@@ -317,7 +317,7 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
checkCollectionUUIDMismatch(opCtx, _resolvedNss, _coll, options._expectedUUID);
verifyDbAndCollection(
- opCtx, modeColl, nsOrUUID, _resolvedNss, _coll, _autoDb.getDb(), verifyWriteEligible);
+ opCtx, modeColl, nsOrUUID, _resolvedNss, _coll.get(), _autoDb.getDb(), verifyWriteEligible);
for (auto& secondaryNssOrUUID : secondaryNssOrUUIDs) {
auto secondaryResolvedNss =
catalog->resolveNamespaceStringOrUUID(opCtx, secondaryNssOrUUID);
@@ -546,7 +546,8 @@ CollectionWriter::CollectionWriter(OperationContext* opCtx, const UUID& uuid)
_managed(true),
_sharedImpl(std::make_shared<SharedImpl>(this)) {
- _storedCollection = CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, uuid);
+ _storedCollection =
+ CollectionPtr(CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, uuid));
_storedCollection.makeYieldable(opCtx, LockedCollectionYieldRestore(opCtx, _storedCollection));
_sharedImpl->_writableCollectionInitializer = [opCtx, uuid]() {
return CollectionCatalog::get(opCtx)->lookupCollectionByUUIDForMetadataWrite(opCtx, uuid);
@@ -557,7 +558,8 @@ CollectionWriter::CollectionWriter(OperationContext* opCtx, const NamespaceStrin
: _collection(&_storedCollection),
_managed(true),
_sharedImpl(std::make_shared<SharedImpl>(this)) {
- _storedCollection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ _storedCollection =
+ CollectionPtr(CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss));
_storedCollection.makeYieldable(opCtx, LockedCollectionYieldRestore(opCtx, _storedCollection));
_sharedImpl->_writableCollectionInitializer = [opCtx, nss]() {
return CollectionCatalog::get(opCtx)->lookupCollectionByNamespaceForMetadataWrite(opCtx,
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 6450593641e..0d463359385 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -193,8 +193,11 @@ struct Cloner::BatchHandler {
WriteUnitOfWork wunit(opCtx);
BSONObj doc = tmp;
- Status status = collection_internal::insertDocument(
- opCtx, collection, InsertStatement(doc), nullptr /* OpDebug */, true);
+ Status status = collection_internal::insertDocument(opCtx,
+ CollectionPtr(collection),
+ InsertStatement(doc),
+ nullptr /* OpDebug */,
+ true);
if (!status.isOK() && status.code() != ErrorCodes::DuplicateKey) {
LOGV2_ERROR(20424,
"error: exception cloning object",
@@ -365,7 +368,7 @@ Status Cloner::_createCollectionsForDb(
opCtx->checkForInterrupt();
WriteUnitOfWork wunit(opCtx);
- CollectionPtr collection = catalog->lookupCollectionByNamespace(opCtx, nss);
+ const Collection* collection = catalog->lookupCollectionByNamespace(opCtx, nss);
if (collection) {
if (!params.shardedColl) {
// If the collection is unsharded then we want to fail when a collection
diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp
index 9a61fcf3c51..7289a410125 100644
--- a/src/mongo/db/commands/dbcheck.cpp
+++ b/src/mongo/db/commands/dbcheck.cpp
@@ -208,7 +208,7 @@ std::unique_ptr<DbCheckRun> fullDatabaseRun(OperationContext* opCtx,
const auto maxBytesPerBatch = invocation.getMaxBytesPerBatch();
const auto maxBatchTimeMillis = invocation.getMaxBatchTimeMillis();
auto result = std::make_unique<DbCheckRun>();
- auto perCollectionWork = [&](const CollectionPtr& coll) {
+ auto perCollectionWork = [&](const Collection* coll) {
if (!coll->ns().isReplicated()) {
return true;
}
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 2eaadf286d2..895c225ac1c 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -246,49 +246,48 @@ public:
std::map<std::string, UUID> collectionToUUIDMap;
std::set<std::string> cappedCollectionSet;
- catalog::forEachCollectionFromDb(
- opCtx, dbName, MODE_IS, [&](const CollectionPtr& collection) {
- auto collNss = collection->ns();
+ catalog::forEachCollectionFromDb(opCtx, dbName, MODE_IS, [&](const Collection* collection) {
+ auto collNss = collection->ns();
- uassert(ErrorCodes::BadValue,
- str::stream() << "weird fullCollectionName [" << collNss.toString() << "]",
- collNss.size() - 1 > dbName.db().size());
+ uassert(ErrorCodes::BadValue,
+ str::stream() << "weird fullCollectionName [" << collNss.toString() << "]",
+ collNss.size() - 1 > dbName.db().size());
- if (repl::ReplicationCoordinator::isOplogDisabledForNS(collNss)) {
- return true;
- }
+ if (repl::ReplicationCoordinator::isOplogDisabledForNS(collNss)) {
+ return true;
+ }
- if (collNss.coll().startsWith("tmp.mr.")) {
- // We skip any incremental map reduce collections as they also aren't
- // replicated.
- return true;
- }
+ if (collNss.coll().startsWith("tmp.mr.")) {
+ // We skip any incremental map reduce collections as they also aren't
+ // replicated.
+ return true;
+ }
- if (skipTempCollections && collection->isTemporary()) {
- return true;
- }
+ if (skipTempCollections && collection->isTemporary()) {
+ return true;
+ }
- if (desiredCollections.size() > 0 &&
- desiredCollections.count(collNss.coll().toString()) == 0)
- return true;
+ if (desiredCollections.size() > 0 &&
+ desiredCollections.count(collNss.coll().toString()) == 0)
+ return true;
- // Don't include 'drop pending' collections.
- if (collNss.isDropPendingNamespace())
- return true;
+ // Don't include 'drop pending' collections.
+ if (collNss.isDropPendingNamespace())
+ return true;
- if (collection->isCapped()) {
- cappedCollectionSet.insert(collNss.coll().toString());
- }
+ if (collection->isCapped()) {
+ cappedCollectionSet.insert(collNss.coll().toString());
+ }
- collectionToUUIDMap.emplace(collNss.coll().toString(), collection->uuid());
+ collectionToUUIDMap.emplace(collNss.coll().toString(), collection->uuid());
- // Compute the hash for this collection.
- std::string hash = _hashCollection(opCtx, db, collNss);
+ // Compute the hash for this collection.
+ std::string hash = _hashCollection(opCtx, db, collNss);
- collectionToHashMap[collNss.coll().toString()] = hash;
+ collectionToHashMap[collNss.coll().toString()] = hash;
- return true;
- });
+ return true;
+ });
BSONObjBuilder bb(result.subobjStart("collections"));
BSONArrayBuilder cappedCollections;
@@ -329,8 +328,8 @@ public:
private:
std::string _hashCollection(OperationContext* opCtx, Database* db, const NamespaceString& nss) {
- CollectionPtr collection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ CollectionPtr collection(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss));
invariant(collection);
boost::optional<Lock::CollectionLock> collLock;
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index 4e9c4a6f3c7..d6b5384aaf0 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -451,8 +451,8 @@ write_ops::FindAndModifyCommandReply CmdFindAndModify::Invocation::writeConflict
if (!*collectionPtr && request.getUpsert() && *request.getUpsert()) {
assertCanWrite_inlock(opCtx, nsString);
- createdCollection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nsString);
+ createdCollection = CollectionPtr(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nsString));
// If someone else beat us to creating the collection, do nothing
if (!createdCollection) {
@@ -464,8 +464,8 @@ write_ops::FindAndModifyCommandReply CmdFindAndModify::Invocation::writeConflict
uassertStatusOK(db->userCreateNS(opCtx, nsString, defaultCollectionOptions));
wuow.commit();
- createdCollection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nsString);
+ createdCollection = CollectionPtr(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nsString));
}
invariant(createdCollection);
diff --git a/src/mongo/db/commands/fle2_compact_cmd.cpp b/src/mongo/db/commands/fle2_compact_cmd.cpp
index 403f8928e16..0fcc330e2c9 100644
--- a/src/mongo/db/commands/fle2_compact_cmd.cpp
+++ b/src/mongo/db/commands/fle2_compact_cmd.cpp
@@ -89,10 +89,10 @@ CompactStats compactEncryptedCompactionCollection(OperationContext* opCtx,
str::stream() << "Collection '" << edcNss << "' does not exist");
}
- validateCompactRequest(request, *edc.get());
+ validateCompactRequest(request, *edc);
auto namespaces =
- uassertStatusOK(EncryptedStateCollectionsNamespaces::createFromDataCollection(*edc.get()));
+ uassertStatusOK(EncryptedStateCollectionsNamespaces::createFromDataCollection(*edc));
// Step 1: rename the ECOC collection if it exists
auto ecoc = catalog->lookupCollectionByNamespace(opCtx, namespaces.ecocNss);
@@ -110,7 +110,7 @@ CompactStats compactEncryptedCompactionCollection(OperationContext* opCtx,
RenameCollectionOptions renameOpts;
validateAndRunRenameCollection(
opCtx, namespaces.ecocNss, namespaces.ecocRenameNss, renameOpts);
- ecoc.reset();
+ ecoc = nullptr;
}
if (!ecoc) {
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index 6505eab5411..5cc543c334f 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -169,7 +169,7 @@ BSONObj buildViewBson(const ViewDefinition& view, bool nameOnly) {
return b.obj();
}
-BSONObj buildTimeseriesBson(const CollectionPtr& collection, bool nameOnly) {
+BSONObj buildTimeseriesBson(const Collection* collection, bool nameOnly) {
invariant(collection);
BSONObjBuilder builder;
@@ -207,7 +207,7 @@ BSONObj buildTimeseriesBson(StringData collName, bool nameOnly) {
* Return an object describing the collection. Takes a collection lock if nameOnly is false.
*/
BSONObj buildCollectionBson(OperationContext* opCtx,
- const CollectionPtr& collection,
+ const Collection* collection,
bool includePendingDrops,
bool nameOnly) {
if (!collection) {
@@ -398,7 +398,7 @@ public:
}
}
} else {
- auto perCollectionWork = [&](const CollectionPtr& collection) {
+ auto perCollectionWork = [&](const Collection* collection) {
if (collection && collection->getTimeseriesOptions() &&
!collection->ns().isDropPendingNamespace()) {
auto viewNss = collection->ns().getTimeseriesViewNamespace();
diff --git a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
index fed4f6db247..d87195afb92 100644
--- a/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
+++ b/src/mongo/db/commands/set_feature_compatibility_version_command.cpp
@@ -812,7 +812,7 @@ private:
opCtx,
dbName,
MODE_S,
- [&](const CollectionPtr& collection) {
+ [&](const Collection* collection) {
auto tsOptions = collection->getTimeseriesOptions();
invariant(tsOptions);
@@ -861,7 +861,7 @@ private:
return true;
},
- [&](const CollectionPtr& collection) {
+ [&](const Collection* collection) {
return collection->getTimeseriesOptions() != boost::none;
});
}
@@ -872,7 +872,7 @@ private:
for (const auto& dbName : DatabaseHolder::get(opCtx)->getNames()) {
Lock::DBLock dbLock(opCtx, dbName, MODE_IX);
catalog::forEachCollectionFromDb(
- opCtx, dbName, MODE_X, [&](const CollectionPtr& collection) {
+ opCtx, dbName, MODE_X, [&](const Collection* collection) {
auto& efc = collection->getCollectionOptions().encryptedFieldConfig;
uassert(ErrorCodes::CannotDowngrade,
@@ -893,7 +893,7 @@ private:
opCtx,
dbName,
MODE_S,
- [&](const CollectionPtr& collection) {
+ [&](const Collection* collection) {
uasserted(
ErrorCodes::CannotDowngrade,
str::stream()
@@ -903,7 +903,7 @@ private:
<< collection->ns() << "'");
return true;
},
- [&](const CollectionPtr& collection) {
+ [&](const Collection* collection) {
return collection->isCapped() &&
collection->getCappedMaxSize() % 256 != 0;
});
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index a11d35b4cbd..b28dae581e0 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -104,8 +104,8 @@ public:
WriteUnitOfWork wunit(opCtx);
UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx);
- CollectionPtr collection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ CollectionPtr collection(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss));
if (!collection) {
collection = CollectionPtr(db->createCollection(opCtx, nss));
uassert(ErrorCodes::CannotCreateCollection, "could not create collection", collection);
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index e4259bb33a3..83caea3e7ff 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -103,7 +103,7 @@ private:
* compatible with 'readTimestamp'. Throws a SnapshotUnavailable error if the assertion fails.
*/
void assertCollectionChangesCompatibleWithReadTimestamp(OperationContext* opCtx,
- const CollectionPtr& collection,
+ const Collection* collection,
boost::optional<Timestamp> readTimestamp) {
// Check that the collection exists.
if (!collection) {
@@ -745,7 +745,7 @@ AutoGetCollectionForReadPITCatalog::AutoGetCollectionForReadPITCatalog(
// Check that the collections are all safe to use. First acquire collection from our catalog
// compatible with the specified 'readTimestamp'. Creates and places a compatible PIT collection
// reference in the 'catalog' if needed and the collection exists at that PIT.
- _coll = catalog->establishConsistentCollection(opCtx, nsOrUUID, readTimestamp);
+ _coll = CollectionPtr(catalog->establishConsistentCollection(opCtx, nsOrUUID, readTimestamp));
_coll.makeYieldable(opCtx, LockedCollectionYieldRestore{opCtx, _coll});
// Validate primary collection.
@@ -1155,7 +1155,7 @@ std::shared_ptr<const ViewDefinition> lookupView(
return view;
}
-std::tuple<NamespaceString, CollectionPtr, std::shared_ptr<const ViewDefinition>>
+std::tuple<NamespaceString, const Collection*, std::shared_ptr<const ViewDefinition>>
getCollectionForLockFreeRead(OperationContext* opCtx,
const std::shared_ptr<const CollectionCatalog>& catalog,
boost::optional<Timestamp> readTimestamp,
@@ -1177,7 +1177,7 @@ getCollectionForLockFreeRead(OperationContext* opCtx,
// Returns a collection reference compatible with the specified 'readTimestamp'. Creates and
// places a compatible PIT collection reference in the 'catalog' if needed and the collection
// exists at that PIT.
- CollectionPtr coll = catalog->establishConsistentCollection(opCtx, nsOrUUID, readTimestamp);
+ const Collection* coll = catalog->establishConsistentCollection(opCtx, nsOrUUID, readTimestamp);
// TODO (SERVER-71222): This is broken if the UUID doesn't exist in the latest catalog.
//
// Note: This call to resolveNamespaceStringOrUUID must happen after getCollectionFromCatalog
@@ -1188,7 +1188,7 @@ getCollectionForLockFreeRead(OperationContext* opCtx,
std::shared_ptr<const ViewDefinition> viewDefinition =
coll ? nullptr : lookupView(opCtx, catalog, nss, options._viewMode);
- return {nss, std::move(coll), std::move(viewDefinition)};
+ return {nss, coll, std::move(viewDefinition)};
}
static const Lock::GlobalLockSkipOptions kLockFreeReadsGlobalLockOptions{[] {
@@ -1201,7 +1201,7 @@ struct CatalogStateForNamespace {
std::shared_ptr<const CollectionCatalog> catalog;
bool isAnySecondaryNssShardedOrAView;
NamespaceString resolvedNss;
- CollectionPtr collection;
+ const Collection* collection;
std::shared_ptr<const ViewDefinition> view;
};
@@ -1223,7 +1223,7 @@ CatalogStateForNamespace acquireCatalogStateForNamespace(
getCollectionForLockFreeRead(opCtx, catalog, readTimestamp, nsOrUUID, options);
return CatalogStateForNamespace{
- catalog, isAnySecondaryNssShardedOrAView, resolvedNss, std::move(collection), view};
+ catalog, isAnySecondaryNssShardedOrAView, resolvedNss, collection, view};
}
boost::optional<ShouldNotConflictWithSecondaryBatchApplicationBlock>
@@ -1262,7 +1262,7 @@ CollectionPtr::RestoreFn AutoGetCollectionForReadLockFreePITCatalog::_makeRestor
_view = catalogStateForNamespace.view;
_catalogStasher.stash(std::move(catalogStateForNamespace.catalog));
- return catalogStateForNamespace.collection.get();
+ return catalogStateForNamespace.collection;
} catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
// Calls to CollectionCatalog::resolveNamespaceStringOrUUID (called from
// acquireCatalogStateForNamespace) will result in a NamespaceNotFound error if the
@@ -1320,7 +1320,7 @@ AutoGetCollectionForReadLockFreePITCatalog::AutoGetCollectionForReadLockFreePITC
if (_view) {
_lockFreeReadsBlock.reset();
}
- _collectionPtr = std::move(collection);
+ _collectionPtr = CollectionPtr(collection);
// Nested operations should never yield as we don't yield when the global lock is held
// recursively. But this is not known when we create the Query plan for this sub operation.
// Pretend that we are yieldable but don't allow yield to actually be called.
@@ -1345,7 +1345,7 @@ AutoGetCollectionForReadLockFreePITCatalog::AutoGetCollectionForReadLockFreePITC
_catalogStasher.stash(std::move(catalogStateForNamespace.catalog));
_secondaryNssIsAViewOrSharded = catalogStateForNamespace.isAnySecondaryNssShardedOrAView;
- _collectionPtr = std::move(catalogStateForNamespace.collection);
+ _collectionPtr = CollectionPtr(catalogStateForNamespace.collection);
_collectionPtr.makeYieldable(
opCtx,
_makeRestoreFromYieldFn(options,
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index d2d7137cd8c..67c6a3a1e91 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -143,9 +143,8 @@ bool Helpers::findById(OperationContext* opCtx,
BSONObj& result,
bool* nsFound,
bool* indexFound) {
- // TODO ForRead?
- CollectionPtr collection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ auto collCatalog = CollectionCatalog::get(opCtx);
+ const Collection* collection = collCatalog->lookupCollectionByNamespace(opCtx, nss);
if (!collection) {
return false;
}
@@ -181,7 +180,7 @@ bool Helpers::findById(OperationContext* opCtx,
*indexFound = 1;
auto recordId = catalog->getEntry(desc)->accessMethod()->asSortedData()->findSingle(
- opCtx, collection, query["_id"].wrap());
+ opCtx, CollectionPtr(collection), query["_id"].wrap());
if (recordId.isNull())
return false;
result = collection->docFor(opCtx, recordId).value();
@@ -355,9 +354,9 @@ BSONObj Helpers::inferKeyPattern(const BSONObj& o) {
void Helpers::emptyCollection(OperationContext* opCtx, const NamespaceString& nss) {
OldClientContext context(opCtx, nss);
repl::UnreplicatedWritesBlock uwb(opCtx);
- CollectionPtr collection = context.db()
- ? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss)
- : CollectionPtr();
+ CollectionPtr collection = CollectionPtr(
+ context.db() ? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss)
+ : nullptr);
deleteObjects(opCtx, collection, nss, BSONObj(), false);
}
diff --git a/src/mongo/db/exec/sbe/stages/collection_helpers.cpp b/src/mongo/db/exec/sbe/stages/collection_helpers.cpp
index 66ddb039f64..4853846a0ae 100644
--- a/src/mongo/db/exec/sbe/stages/collection_helpers.cpp
+++ b/src/mongo/db/exec/sbe/stages/collection_helpers.cpp
@@ -41,7 +41,7 @@ std::tuple<CollectionPtr, NamespaceString, uint64_t> acquireCollection(Operation
// with the storage engine snapshot from which we are reading) has been stashed on the
// 'OperationContext'. Either way, this means that the UUID must still exist in our view of the
// collection catalog.
- CollectionPtr collPtr = CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, collUuid);
+ CollectionPtr collPtr(CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, collUuid));
tassert(5071000, str::stream() << "Collection uuid " << collUuid << " does not exist", collPtr);
auto nss = collPtr->ns();
@@ -57,7 +57,7 @@ CollectionPtr restoreCollection(OperationContext* opCtx,
// lookup will result in a null pointer. If the collection has been renamed, then the resulting
// collection object should have a different name from the original 'collName'. In either
// scenario, we throw a 'QueryPlanKilled' error and terminate the query.
- CollectionPtr collPtr = CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, collUuid);
+ CollectionPtr collPtr(CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, collUuid));
if (!collPtr) {
PlanYieldPolicy::throwCollectionDroppedError(collUuid);
}
diff --git a/src/mongo/db/index_builds_coordinator.cpp b/src/mongo/db/index_builds_coordinator.cpp
index b145d63b15f..0ba202869ed 100644
--- a/src/mongo/db/index_builds_coordinator.cpp
+++ b/src/mongo/db/index_builds_coordinator.cpp
@@ -2747,8 +2747,8 @@ CollectionPtr IndexBuildsCoordinator::_setUpForScanCollectionAndInsertSortedKeys
// storage engines if they're missing.
invariant(_indexBuildsManager.isBackgroundBuilding(replState->buildUUID));
- auto collection =
- CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, replState->collectionUUID);
+ CollectionPtr collection(
+ CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, replState->collectionUUID));
invariant(collection);
collection.makeYieldable(opCtx, LockedCollectionYieldRestore(opCtx, collection));
diff --git a/src/mongo/db/index_builds_coordinator_test.cpp b/src/mongo/db/index_builds_coordinator_test.cpp
index d2298a70077..d97002eb602 100644
--- a/src/mongo/db/index_builds_coordinator_test.cpp
+++ b/src/mongo/db/index_builds_coordinator_test.cpp
@@ -66,7 +66,7 @@ void IndexBuildsCoordinatorTest::createCollectionWithDuplicateDocs(OperationCont
// Helper to refetch the Collection from the catalog in order to see any changes made to it
CollectionPtr coll(OperationContext* opCtx, const NamespaceString& nss) {
- return CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ return CollectionPtr(CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss));
}
TEST_F(IndexBuildsCoordinatorTest, ForegroundUniqueEnforce) {
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index 7973c81b227..fed02af17e5 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -119,8 +119,8 @@ void profile(OperationContext* opCtx, NetworkOp op) {
}
uassertStatusOK(createProfileCollection(newCtx.get(), db));
- auto coll = CollectionCatalog::get(newCtx.get())
- ->lookupCollectionByNamespace(newCtx.get(), dbProfilingNS);
+ CollectionPtr coll(CollectionCatalog::get(newCtx.get())
+ ->lookupCollectionByNamespace(newCtx.get(), dbProfilingNS));
WriteUnitOfWork wuow(newCtx.get());
OpDebug* const nullOpDebug = nullptr;
@@ -149,7 +149,7 @@ Status createProfileCollection(OperationContext* opCtx, Database* db) {
// collection creation would endlessly throw errors because the collection exists: must check
// and see the collection exists in order to break free.
return writeConflictRetry(opCtx, "createProfileCollection", dbProfilingNS.ns(), [&] {
- const CollectionPtr collection =
+ const Collection* collection =
CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, dbProfilingNS);
if (collection) {
if (!collection->isCapped()) {
diff --git a/src/mongo/db/matcher/expression_text.cpp b/src/mongo/db/matcher/expression_text.cpp
index 98937e42b95..a4168808c31 100644
--- a/src/mongo/db/matcher/expression_text.cpp
+++ b/src/mongo/db/matcher/expression_text.cpp
@@ -66,8 +66,8 @@ TextMatchExpression::TextMatchExpression(OperationContext* opCtx,
<< nss.ns() << "')",
db);
- CollectionPtr collection =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ CollectionPtr collection(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss));
uassert(ErrorCodes::IndexNotFound,
str::stream() << "text index required for $text query (no such collection '"
diff --git a/src/mongo/db/mongod_main.cpp b/src/mongo/db/mongod_main.cpp
index 31aa1d7079b..c2060a15738 100644
--- a/src/mongo/db/mongod_main.cpp
+++ b/src/mongo/db/mongod_main.cpp
@@ -288,7 +288,7 @@ void logStartup(OperationContext* opCtx) {
Lock::GlobalWrite lk(opCtx);
AutoGetDb autoDb(opCtx, startupLogCollectionName.dbName(), mongo::MODE_X);
auto db = autoDb.ensureDbExists(opCtx);
- CollectionPtr collection =
+ auto collection =
CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, startupLogCollectionName);
WriteUnitOfWork wunit(opCtx);
if (!collection) {
@@ -303,7 +303,7 @@ void logStartup(OperationContext* opCtx) {
invariant(collection);
uassertStatusOK(collection_internal::insertDocument(
- opCtx, collection, InsertStatement(o), nullptr /* OpDebug */, false));
+ opCtx, CollectionPtr(collection), InsertStatement(o), nullptr /* OpDebug */, false));
wunit.commit();
}
diff --git a/src/mongo/db/op_observer/op_observer_impl.cpp b/src/mongo/db/op_observer/op_observer_impl.cpp
index 3ebf7ea6c2b..eaeae400f49 100644
--- a/src/mongo/db/op_observer/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer/op_observer_impl.cpp
@@ -1230,8 +1230,7 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx,
if (!db) {
return;
}
- const CollectionPtr& coll =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ const Collection* coll = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
invariant(coll->uuid() == uuid);
}
diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp
index 65807d64022..c1e95dd993a 100644
--- a/src/mongo/db/ops/update.cpp
+++ b/src/mongo/db/ops/update.cpp
@@ -70,7 +70,8 @@ UpdateResult update(OperationContext* opCtx, Database* db, const UpdateRequest&
// The update stage does not create its own collection. As such, if the update is
// an upsert, create the collection that the update stage inserts into beforehand.
writeConflictRetry(opCtx, "createCollection", nsString.ns(), [&] {
- collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nsString);
+ collection = CollectionPtr(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nsString));
if (collection || !request.isUpsert()) {
return;
}
diff --git a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
index ec6faecc0df..471727946c4 100644
--- a/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
+++ b/src/mongo/db/pipeline/process_interface/common_mongod_process_interface.cpp
@@ -601,8 +601,8 @@ bool CommonMongodProcessInterface::fieldsHaveSupportingUniqueIndex(
Lock::CollectionLock collLock(opCtx, nss, MODE_IS);
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, nss.dbName());
- auto collection = db ? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss)
- : CollectionPtr();
+ auto collection =
+ db ? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss) : nullptr;
if (!collection) {
return fieldPaths == std::set<FieldPath>{"_id"};
}
diff --git a/src/mongo/db/rebuild_indexes.cpp b/src/mongo/db/rebuild_indexes.cpp
index a872170de77..d605b2a7867 100644
--- a/src/mongo/db/rebuild_indexes.cpp
+++ b/src/mongo/db/rebuild_indexes.cpp
@@ -45,7 +45,7 @@
namespace mongo {
-StatusWith<IndexNameObjs> getIndexNameObjs(const CollectionPtr& collection,
+StatusWith<IndexNameObjs> getIndexNameObjs(const Collection* collection,
std::function<bool(const std::string&)> filter) {
IndexNameObjs ret;
std::vector<std::string>& indexNames = ret.first;
@@ -91,7 +91,7 @@ StatusWith<IndexNameObjs> getIndexNameObjs(const CollectionPtr& collection,
}
Status rebuildIndexesOnCollection(OperationContext* opCtx,
- const CollectionPtr& collection,
+ const Collection* collection,
const std::vector<BSONObj>& indexSpecs,
RepairData repair) {
// Skip the rest if there are no indexes to rebuild.
diff --git a/src/mongo/db/rebuild_indexes.h b/src/mongo/db/rebuild_indexes.h
index 595b38a0cdc..27189980cdb 100644
--- a/src/mongo/db/rebuild_indexes.h
+++ b/src/mongo/db/rebuild_indexes.h
@@ -50,7 +50,7 @@ typedef std::pair<std::vector<std::string>, std::vector<BSONObj>> IndexNameObjs;
* should be included in the result.
*/
StatusWith<IndexNameObjs> getIndexNameObjs(
- const CollectionPtr& collection,
+ const Collection* collection,
std::function<bool(const std::string&)> filter = [](const std::string& indexName) {
return true;
});
@@ -63,7 +63,7 @@ StatusWith<IndexNameObjs> getIndexNameObjs(
*/
enum class RepairData { kYes, kNo };
Status rebuildIndexesOnCollection(OperationContext* opCtx,
- const CollectionPtr& collection,
+ const Collection* collection,
const std::vector<BSONObj>& indexSpecs,
RepairData repair);
@@ -72,7 +72,7 @@ Status rebuildIndexesOnCollection(OperationContext* opCtx,
* One example usage is when a 'dropIndex' command is rolled back. The dropped index must be remade.
*/
Status rebuildIndexesOnCollection(OperationContext* opCtx,
- const CollectionPtr& collection,
+ const Collection* collection,
const std::vector<BSONObj>& indexSpecs);
} // namespace mongo
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index f3620ad9ac0..e7e1aa3e79f 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -222,9 +222,8 @@ void createIndexForApplyOps(OperationContext* opCtx,
// Check if collection exists.
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, indexNss.dbName());
- auto indexCollection = db
- ? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, indexNss)
- : CollectionPtr();
+ auto indexCollection = CollectionPtr(
+ db ? CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, indexNss) : nullptr);
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "Failed to create index due to missing collection: " << indexNss.ns(),
indexCollection);
@@ -763,7 +762,7 @@ void createOplog(OperationContext* opCtx,
const ReplSettings& replSettings = ReplicationCoordinator::get(opCtx)->getSettings();
OldClientContext ctx(opCtx, oplogCollectionName);
- CollectionPtr collection =
+ const Collection* collection =
CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, oplogCollectionName);
if (collection) {
@@ -1360,7 +1359,7 @@ Status applyOperation_inlock(OperationContext* opCtx,
CollectionPtr collection;
if (auto uuid = op.getUuid()) {
auto catalog = CollectionCatalog::get(opCtx);
- collection = catalog->lookupCollectionByUUID(opCtx, uuid.value());
+ collection = CollectionPtr(catalog->lookupCollectionByUUID(opCtx, uuid.value()));
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "Failed to apply operation due to missing collection ("
<< uuid.value() << "): " << redact(opOrGroupedInserts.toBSON()),
@@ -1372,7 +1371,8 @@ Status applyOperation_inlock(OperationContext* opCtx,
invariant(requestNss.coll().size());
dassert(opCtx->lockState()->isCollectionLockedForMode(requestNss, MODE_IX),
requestNss.ns());
- collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, requestNss);
+ collection = CollectionPtr(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, requestNss));
}
BSONObj o = op.getObject();
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index 3ac6b996133..89173f118a7 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -820,7 +820,7 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx,
// Find an oplog entry <= truncateAfterTimestamp.
boost::optional<BSONObj> truncateAfterOplogEntryBSON =
_storageInterface->findOplogEntryLessThanOrEqualToTimestamp(
- opCtx, oplogCollection, truncateAfterTimestamp);
+ opCtx, CollectionPtr(oplogCollection), truncateAfterTimestamp);
if (!truncateAfterOplogEntryBSON) {
LOGV2_FATAL_NOTRACE(40296,
"Reached end of oplog looking for an oplog entry lte to "
diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp
index ff4e13416a9..0968e7f464a 100644
--- a/src/mongo/db/repl/rollback_impl.cpp
+++ b/src/mongo/db/repl/rollback_impl.cpp
@@ -715,7 +715,7 @@ void RollbackImpl::_correctRecordStoreCounts(OperationContext* opCtx) {
"namespace"_attr = nss.ns(),
"uuid"_attr = uuid.toString());
AutoGetCollectionForRead collToScan(opCtx, nss);
- invariant(coll == collToScan.getCollection(),
+ invariant(coll == collToScan.getCollection().get(),
str::stream() << "Catalog returned invalid collection: " << nss.ns() << " ("
<< uuid.toString() << ")");
auto exec = getCollectionScanExecutor(opCtx,
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index b22c0905fc6..f8998c1c32a 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -975,7 +975,7 @@ void rollbackDropIndexes(OperationContext* opCtx,
invariant(nss);
Lock::DBLock dbLock(opCtx, nss->dbName(), MODE_IX);
Lock::CollectionLock collLock(opCtx, *nss, MODE_X);
- CollectionPtr collection = catalog->lookupCollectionByNamespace(opCtx, *nss);
+ const Collection* collection = catalog->lookupCollectionByNamespace(opCtx, *nss);
// If we cannot find the collection, we skip over dropping the index.
if (!collection) {
@@ -1395,8 +1395,8 @@ void syncFixUp(OperationContext* opCtx,
Database* db = dbLock.getDb();
if (db) {
- CollectionPtr collection =
- CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, uuid);
+ CollectionPtr collection(
+ CollectionCatalog::get(opCtx)->lookupCollectionByUUID(opCtx, uuid));
dropCollection(opCtx, *nss, collection, db);
LOGV2_DEBUG(21698,
1,
diff --git a/src/mongo/db/repl/tenant_migration_util.cpp b/src/mongo/db/repl/tenant_migration_util.cpp
index 7a573c325cf..824ad84a039 100644
--- a/src/mongo/db/repl/tenant_migration_util.cpp
+++ b/src/mongo/db/repl/tenant_migration_util.cpp
@@ -112,11 +112,10 @@ void createOplogViewForTenantMigrations(OperationContext* opCtx, Database* db) {
{
// Create 'system.views' in a separate WUOW if it does not exist.
WriteUnitOfWork wuow(opCtx);
- CollectionPtr coll = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(
+ const Collection* coll = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(
opCtx, NamespaceString(db->getSystemViewsName()));
if (!coll) {
- coll = CollectionPtr(
- db->createCollection(opCtx, NamespaceString(db->getSystemViewsName())));
+ coll = db->createCollection(opCtx, NamespaceString(db->getSystemViewsName()));
}
invariant(coll);
wuow.commit();
diff --git a/src/mongo/db/s/config/configsvr_run_restore_command.cpp b/src/mongo/db/s/config/configsvr_run_restore_command.cpp
index f5cbddd0dfc..38d2a47aebc 100644
--- a/src/mongo/db/s/config/configsvr_run_restore_command.cpp
+++ b/src/mongo/db/s/config/configsvr_run_restore_command.cpp
@@ -178,8 +178,8 @@ public:
{
// The "local.system.collections_to_restore" collection needs to exist prior to running
// this command.
- CollectionPtr restoreColl = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(
- opCtx, NamespaceString::kConfigsvrRestoreNamespace);
+ CollectionPtr restoreColl(CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(
+ opCtx, NamespaceString::kConfigsvrRestoreNamespace));
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "Collection " << NamespaceString::kConfigsvrRestoreNamespace
<< " is missing",
@@ -193,8 +193,8 @@ public:
LOGV2(6261300, "1st Phase - Restoring collection entries", logAttrs(nss));
- CollectionPtr coll =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ CollectionPtr coll(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss));
if (!coll) {
LOGV2(6261301, "Collection not found, skipping", logAttrs(nss));
continue;
@@ -275,8 +275,8 @@ public:
// database was restored.
for (const NamespaceString& nss : databasesEntries) {
LOGV2(6261303, "2nd Phase - Restoring database entries", logAttrs(nss));
- CollectionPtr coll =
- CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
+ CollectionPtr coll(
+ CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss));
if (!coll) {
LOGV2(6261304, "Collection not found, skipping", logAttrs(nss));
return true;
diff --git a/src/mongo/db/s/global_index/global_index_cloning_service.cpp b/src/mongo/db/s/global_index/global_index_cloning_service.cpp
index 2cbd8e5b91b..7592a417013 100644
--- a/src/mongo/db/s/global_index/global_index_cloning_service.cpp
+++ b/src/mongo/db/s/global_index/global_index_cloning_service.cpp
@@ -471,7 +471,7 @@ void GlobalIndexCloningService::CloningStateMachine::_ensureCollection(Operation
// Create the destination collection if necessary.
writeConflictRetry(opCtx, "CloningStateMachine::_ensureCollection", nss.toString(), [&] {
- const CollectionPtr coll =
+ const Collection* coll =
CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
if (coll) {
return;
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 4c384e7b2a4..9462ad00760 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -990,7 +990,7 @@ void MigrationDestinationManager::cloneCollectionIndexesAndOptions(
// missing (auto-heal indexes).
// Checks that the collection's UUID matches the donor's.
- auto checkUUIDsMatch = [&](const CollectionPtr& collection) {
+ auto checkUUIDsMatch = [&](const Collection* collection) {
uassert(ErrorCodes::NotWritablePrimary,
str::stream() << "Unable to create collection " << nss.ns()
<< " because the node is not primary",
@@ -1030,7 +1030,7 @@ void MigrationDestinationManager::cloneCollectionIndexesAndOptions(
AutoGetCollection collection(opCtx, nss, MODE_IS);
if (collection) {
- checkUUIDsMatch(collection.getCollection());
+ checkUUIDsMatch(collection.getCollection().get());
auto indexSpecs =
checkEmptyOrGetMissingIndexesFromDonor(collection.getCollection());
if (indexSpecs.empty()) {
@@ -1078,7 +1078,7 @@ void MigrationDestinationManager::cloneCollectionIndexesAndOptions(
collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
}
- auto indexSpecs = checkEmptyOrGetMissingIndexesFromDonor(collection);
+ auto indexSpecs = checkEmptyOrGetMissingIndexesFromDonor(CollectionPtr(collection));
if (!indexSpecs.empty()) {
WriteUnitOfWork wunit(opCtx);
CollectionWriter collWriter(opCtx, collection->uuid());
diff --git a/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp b/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
index a2cf65fadc4..8b3621a409f 100644
--- a/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
+++ b/src/mongo/db/s/resharding/resharding_oplog_fetcher.cpp
@@ -236,7 +236,7 @@ void ReshardingOplogFetcher::_ensureCollection(Client* client,
// Create the destination collection if necessary.
writeConflictRetry(opCtx, "createReshardingLocalOplogBuffer", nss.toString(), [&] {
- const CollectionPtr coll =
+ const Collection* coll =
CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
if (coll) {
return;
diff --git a/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp b/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp
index 5682f0c650f..bdbc0d804f6 100644
--- a/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp
+++ b/src/mongo/db/s/shardsvr_check_metadata_consistency_participant_command.cpp
@@ -92,7 +92,7 @@ public:
std::vector<CollectionPtr> localCollection;
for (const auto& localNss : localNssCollections) {
localCollection.push_back(
- collectionCatalog->lookupCollectionByNamespace(opCtx, localNss));
+ CollectionPtr(collectionCatalog->lookupCollectionByNamespace(opCtx, localNss)));
}
// Check consistency between local metadata and configsvr metadata
diff --git a/src/mongo/db/shard_role.cpp b/src/mongo/db/shard_role.cpp
index 8618b69bd44..b4d093fa97a 100644
--- a/src/mongo/db/shard_role.cpp
+++ b/src/mongo/db/shard_role.cpp
@@ -193,7 +193,7 @@ CollectionPtr acquireCollectionPtr(OperationContext* opCtx,
const auto& nss = prerequisites.nss;
const auto catalog = CollectionCatalog::get(opCtx);
- auto coll = catalog->lookupCollectionByNamespace(opCtx, nss);
+ CollectionPtr coll(catalog->lookupCollectionByNamespace(opCtx, nss));
if (coll) {
verifyDbAndCollection(opCtx, nss, coll);
diff --git a/src/mongo/db/startup_recovery.cpp b/src/mongo/db/startup_recovery.cpp
index 49207205bfe..f678a5723f8 100644
--- a/src/mongo/db/startup_recovery.cpp
+++ b/src/mongo/db/startup_recovery.cpp
@@ -101,8 +101,8 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx
uassertStatusOK(createCollection(opCtx, fcvNss.dbName(), BSON("create" << fcvNss.coll())));
}
- const CollectionPtr& fcvColl =
- catalog->lookupCollectionByNamespace(opCtx, NamespaceString::kServerConfigurationNamespace);
+ const CollectionPtr fcvColl(catalog->lookupCollectionByNamespace(
+ opCtx, NamespaceString::kServerConfigurationNamespace));
invariant(fcvColl);
// Restore the featureCompatibilityVersion document if it is missing.
@@ -139,7 +139,7 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx
* Returns true if the collection associated with the given CollectionCatalogEntry has an index on
* the _id field
*/
-bool checkIdIndexExists(OperationContext* opCtx, const CollectionPtr& coll) {
+bool checkIdIndexExists(OperationContext* opCtx, const Collection* coll) {
auto indexCount = coll->getTotalIndexCount();
auto indexNames = std::vector<std::string>(indexCount);
coll->getAllIndexes(&indexNames);
@@ -230,14 +230,14 @@ Status ensureCollectionProperties(OperationContext* opCtx,
LOGV2(21001,
"collection {coll_ns} is missing an _id index",
"Collection is missing an _id index",
- logAttrs(*coll.get()));
+ logAttrs(*coll));
if (EnsureIndexPolicy::kBuildMissing == ensureIndexPolicy) {
auto status = buildMissingIdIndex(opCtx, collIt.getWritableCollection(opCtx));
if (!status.isOK()) {
LOGV2_ERROR(21021,
"could not build an _id index on collection {coll_ns}: {error}",
"Could not build an _id index on collection",
- logAttrs(*coll.get()),
+ logAttrs(*coll),
"error"_attr = status);
return downgradeError;
}
@@ -247,7 +247,7 @@ Status ensureCollectionProperties(OperationContext* opCtx,
}
if (coll->getTimeseriesOptions() &&
- timeseries::collectionMayRequireExtendedRangeSupport(opCtx, coll)) {
+ timeseries::collectionMayRequireExtendedRangeSupport(opCtx, *coll)) {
coll->setRequiresTimeseriesExtendedRangeSupport(opCtx);
}
}
@@ -294,7 +294,7 @@ bool hasReplSetConfigDoc(OperationContext* opCtx) {
void assertCappedOplog(OperationContext* opCtx) {
const NamespaceString oplogNss(NamespaceString::kRsOplogNamespace);
invariant(opCtx->lockState()->isDbLockedForMode(oplogNss.dbName(), MODE_IS));
- const CollectionPtr& oplogCollection =
+ const Collection* oplogCollection =
CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, oplogNss);
if (oplogCollection && !oplogCollection->isCapped()) {
LOGV2_FATAL_NOTRACE(
@@ -446,7 +446,7 @@ void setReplSetMemberInStandaloneMode(OperationContext* opCtx, StartupRecoveryMo
}
invariant(opCtx->lockState()->isW());
- CollectionPtr collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(
+ const Collection* collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(
opCtx, NamespaceString::kSystemReplSetNamespace);
if (collection && !collection->isEmpty(opCtx)) {
setReplSetMemberInStandaloneMode(opCtx->getServiceContext(), true);
diff --git a/src/mongo/db/storage/kv/durable_catalog_test.cpp b/src/mongo/db/storage/kv/durable_catalog_test.cpp
index b079b4b965c..8ac439bbe9e 100644
--- a/src/mongo/db/storage/kv/durable_catalog_test.cpp
+++ b/src/mongo/db/storage/kv/durable_catalog_test.cpp
@@ -79,8 +79,8 @@ public:
}
CollectionPtr getCollection() {
- return CollectionCatalog::get(operationContext())
- ->lookupCollectionByUUID(operationContext(), *_collectionUUID);
+ return CollectionPtr(CollectionCatalog::get(operationContext())
+ ->lookupCollectionByUUID(operationContext(), *_collectionUUID));
}
CollectionWriter getCollectionWriter() {
diff --git a/src/mongo/db/storage/storage_engine_impl.cpp b/src/mongo/db/storage/storage_engine_impl.cpp
index 6b96b63526b..82122a9e1f7 100644
--- a/src/mongo/db/storage/storage_engine_impl.cpp
+++ b/src/mongo/db/storage/storage_engine_impl.cpp
@@ -1411,7 +1411,7 @@ void StorageEngineImpl::TimestampMonitor::clearListeners() {
int64_t StorageEngineImpl::sizeOnDiskForDb(OperationContext* opCtx, const DatabaseName& dbName) {
int64_t size = 0;
- auto perCollectionWork = [&](const CollectionPtr& collection) {
+ auto perCollectionWork = [&](const Collection* collection) {
size += collection->getRecordStore()->storageSize(opCtx);
auto it = collection->getIndexCatalog()->getIndexIterator(
diff --git a/src/mongo/db/storage/storage_engine_test_fixture.h b/src/mongo/db/storage/storage_engine_test_fixture.h
index 89d8425fb3f..ba81dc4613e 100644
--- a/src/mongo/db/storage/storage_engine_test_fixture.h
+++ b/src/mongo/db/storage/storage_engine_test_fixture.h
@@ -196,7 +196,7 @@ public:
}
Status removeEntry(OperationContext* opCtx, StringData collNs, DurableCatalog* catalog) {
- CollectionPtr collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(
+ const Collection* collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(
opCtx, NamespaceString::createNamespaceString_forTest(collNs));
return dynamic_cast<DurableCatalogImpl*>(catalog)->_removeEntry(opCtx,
collection->getCatalogId());
diff --git a/src/mongo/db/timeseries/timeseries_extended_range.cpp b/src/mongo/db/timeseries/timeseries_extended_range.cpp
index 44a7ff060d9..16121dc8f8b 100644
--- a/src/mongo/db/timeseries/timeseries_extended_range.cpp
+++ b/src/mongo/db/timeseries/timeseries_extended_range.cpp
@@ -62,7 +62,7 @@ bool bucketsHaveDateOutsideStandardRange(const TimeseriesOptions& options,
}
bool collectionMayRequireExtendedRangeSupport(OperationContext* opCtx,
- const CollectionPtr& collection) {
+ const Collection& collection) {
bool requiresExtendedRangeSupport = false;
// We use a heuristic here to perform a check as quickly as possible and get the correct answer
@@ -73,7 +73,7 @@ bool collectionMayRequireExtendedRangeSupport(OperationContext* opCtx,
// document exists, then the maximum OID will have this bit set. So we can just check the last
// document in the record store and test this high bit of it's _id.
- auto* rs = collection->getRecordStore();
+ auto* rs = collection.getRecordStore();
auto cursor = rs->getCursor(opCtx, /* forward */ false);
if (auto record = cursor->next()) {
const auto& obj = record->data.toBson();
diff --git a/src/mongo/db/timeseries/timeseries_extended_range.h b/src/mongo/db/timeseries/timeseries_extended_range.h
index f37ac278c26..a1c14f341d8 100644
--- a/src/mongo/db/timeseries/timeseries_extended_range.h
+++ b/src/mongo/db/timeseries/timeseries_extended_range.h
@@ -55,7 +55,7 @@ bool bucketsHaveDateOutsideStandardRange(const TimeseriesOptions& options,
* with dates that fall outside the standard range.
*/
bool collectionMayRequireExtendedRangeSupport(OperationContext* opCtx,
- const CollectionPtr& collection);
+ const Collection& collection);
/**
* Determines whether a time-series collection has an index primarily ordered by a time field. This
diff --git a/src/mongo/db/transaction/transaction_participant_test.cpp b/src/mongo/db/transaction/transaction_participant_test.cpp
index bc93cdf8f0e..47df19d4326 100644
--- a/src/mongo/db/transaction/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction/transaction_participant_test.cpp
@@ -430,7 +430,7 @@ void insertTxnRecord(OperationContext* opCtx, unsigned i, DurableTxnStateEnum st
ASSERT(coll);
OpDebug* const nullOpDebug = nullptr;
ASSERT_OK(collection_internal::insertDocument(
- opCtx, coll, InsertStatement(record.toBSON()), nullOpDebug, false));
+ opCtx, CollectionPtr(coll), InsertStatement(record.toBSON()), nullOpDebug, false));
wuow.commit();
}
} // namespace
@@ -4547,7 +4547,7 @@ TEST_F(TxnParticipantTest, OldestActiveTransactionTimestamp) {
if (bson["startOpTime"]["ts"].timestamp() == ts) {
collection_internal::deleteDocument(
- opCtx(), coll, kUninitializedStmtId, record->id, nullptr);
+ opCtx(), CollectionPtr(coll), kUninitializedStmtId, record->id, nullptr);
wuow.commit();
return;
}
diff --git a/src/mongo/dbtests/dbhelper_tests.cpp b/src/mongo/dbtests/dbhelper_tests.cpp
index 27f2c5af53d..6db45c25324 100644
--- a/src/mongo/dbtests/dbhelper_tests.cpp
+++ b/src/mongo/dbtests/dbhelper_tests.cpp
@@ -201,7 +201,8 @@ private:
.getTimestamp();
ASSERT_OK(opCtx2->recoveryUnit()->setTimestamp(lastApplied + 1));
BSONObj res;
- ASSERT_TRUE(Helpers::findByIdAndNoopUpdate(opCtx2, collection2, idQuery, res));
+ ASSERT_TRUE(
+ Helpers::findByIdAndNoopUpdate(opCtx2, CollectionPtr(collection2), idQuery, res));
ASSERT_THROWS(Helpers::emptyCollection(opCtx1, nss), WriteConflictException);
@@ -245,7 +246,8 @@ private:
ASSERT(collection2);
BSONObj res;
- ASSERT_THROWS(Helpers::findByIdAndNoopUpdate(opCtx2, collection2, idQuery, res),
+ ASSERT_THROWS(Helpers::findByIdAndNoopUpdate(
+ opCtx2, CollectionPtr(collection2), idQuery, res),
WriteConflictException);
}
diff --git a/src/mongo/dbtests/dbtests.h b/src/mongo/dbtests/dbtests.h
index 4701c48b38a..54c9fa33d58 100644
--- a/src/mongo/dbtests/dbtests.h
+++ b/src/mongo/dbtests/dbtests.h
@@ -75,7 +75,8 @@ public:
}
CollectionPtr getCollection() const {
- return CollectionCatalog::get(_opCtx)->lookupCollectionByNamespace(_opCtx, _nss);
+ return CollectionPtr(
+ CollectionCatalog::get(_opCtx)->lookupCollectionByNamespace(_opCtx, _nss));
}
private:
diff --git a/src/mongo/dbtests/multikey_paths_test.cpp b/src/mongo/dbtests/multikey_paths_test.cpp
index 6498311e026..5aac5e9d656 100644
--- a/src/mongo/dbtests/multikey_paths_test.cpp
+++ b/src/mongo/dbtests/multikey_paths_test.cpp
@@ -79,8 +79,8 @@ public:
// Helper to refetch the Collection from the catalog in order to see any changes made to it
CollectionPtr collection() const {
- return CollectionCatalog::get(_opCtx.get())
- ->lookupCollectionByNamespace(_opCtx.get(), _nss);
+ return CollectionPtr(
+ CollectionCatalog::get(_opCtx.get())->lookupCollectionByNamespace(_opCtx.get(), _nss));
}
diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp
index 9780e7a80a8..89f71a624f9 100644
--- a/src/mongo/dbtests/pdfiletests.cpp
+++ b/src/mongo/dbtests/pdfiletests.cpp
@@ -55,7 +55,8 @@ protected:
return NamespaceString("unittests.pdfiletests.Insert");
}
CollectionPtr collection() {
- return CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ return CollectionPtr(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
}
const ServiceContext::UniqueOperationContext _opCtxPtr = cc().makeOperationContext();
@@ -70,8 +71,8 @@ public:
WriteUnitOfWork wunit(&_opCtx);
BSONObj x = BSON("x" << 1);
ASSERT(x["_id"].type() == 0);
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
coll = CollectionPtr(_context.db()->createCollection(&_opCtx, nss()));
}
diff --git a/src/mongo/dbtests/plan_executor_invalidation_test.cpp b/src/mongo/dbtests/plan_executor_invalidation_test.cpp
index 28b2a72e944..50b8a790f92 100644
--- a/src/mongo/dbtests/plan_executor_invalidation_test.cpp
+++ b/src/mongo/dbtests/plan_executor_invalidation_test.cpp
@@ -191,7 +191,8 @@ public:
private:
void _refreshCollection() {
- _coll = CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss);
+ _coll = CollectionPtr(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss));
}
BSONObj _makeMinimalIndexSpec(BSONObj keyPattern) {
diff --git a/src/mongo/dbtests/query_plan_executor.cpp b/src/mongo/dbtests/query_plan_executor.cpp
index 33aebde3cc6..0c61db68b79 100644
--- a/src/mongo/dbtests/query_plan_executor.cpp
+++ b/src/mongo/dbtests/query_plan_executor.cpp
@@ -185,8 +185,8 @@ protected:
private:
const IndexDescriptor* getIndex(Database* db, const BSONObj& obj) {
- CollectionPtr collection =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss);
+ CollectionPtr collection(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss));
std::vector<const IndexDescriptor*> indexes;
collection->getIndexCatalog()->findIndexesByKeyPattern(
&_opCtx, obj, IndexCatalog::InclusionPolicy::kReady, &indexes);
diff --git a/src/mongo/dbtests/query_stage_batched_delete.cpp b/src/mongo/dbtests/query_stage_batched_delete.cpp
index 588a07055f2..2decfc270cc 100644
--- a/src/mongo/dbtests/query_stage_batched_delete.cpp
+++ b/src/mongo/dbtests/query_stage_batched_delete.cpp
@@ -355,8 +355,8 @@ TEST_F(QueryStageBatchedDeleteTest, BatchedDeleteStagedDocIsDeletedWriteConflict
auto nDocs = 11;
prePopulateCollection(nDocs);
- const CollectionPtr& coll = CollectionCatalog::get(batchedDeleteOpCtx.get())
- ->lookupCollectionByNamespace(batchedDeleteOpCtx.get(), nss);
+ CollectionPtr coll(CollectionCatalog::get(batchedDeleteOpCtx.get())
+ ->lookupCollectionByNamespace(batchedDeleteOpCtx.get(), nss));
ASSERT(coll);
@@ -484,8 +484,8 @@ TEST_F(QueryStageBatchedDeleteTest, BatchedDeleteStagedDocIsUpdatedToNotMatchCli
auto nDocs = 11;
prePopulateCollection(nDocs);
- const CollectionPtr& coll = CollectionCatalog::get(batchedDeleteOpCtx.get())
- ->lookupCollectionByNamespace(batchedDeleteOpCtx.get(), nss);
+ CollectionPtr coll(CollectionCatalog::get(batchedDeleteOpCtx.get())
+ ->lookupCollectionByNamespace(batchedDeleteOpCtx.get(), nss));
ASSERT(coll);
diff --git a/src/mongo/dbtests/query_stage_count_scan.cpp b/src/mongo/dbtests/query_stage_count_scan.cpp
index c4f785607fe..510c0070aee 100644
--- a/src/mongo/dbtests/query_stage_count_scan.cpp
+++ b/src/mongo/dbtests/query_stage_count_scan.cpp
@@ -90,7 +90,8 @@ public:
}
CollectionPtr getCollection() {
- return CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, ns());
+ return CollectionPtr(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, ns()));
}
const IndexDescriptor* getIndex(Database* db, const BSONObj& obj) {
diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp
index 4075fa65a8b..d6e91c25ad7 100644
--- a/src/mongo/dbtests/query_stage_fetch.cpp
+++ b/src/mongo/dbtests/query_stage_fetch.cpp
@@ -102,8 +102,8 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
@@ -169,8 +169,8 @@ public:
Lock::DBLock lk(&_opCtx, nss().dbName(), MODE_X);
OldClientContext ctx(&_opCtx, nss());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp
index eb17f6b951c..b20c6c2c7e6 100644
--- a/src/mongo/dbtests/query_stage_sort.cpp
+++ b/src/mongo/dbtests/query_stage_sort.cpp
@@ -268,8 +268,8 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
@@ -291,8 +291,8 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
@@ -323,8 +323,8 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
@@ -349,8 +349,8 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
@@ -479,8 +479,8 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
@@ -586,8 +586,8 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp
index 0b9ebdc21b5..375beb289f1 100644
--- a/src/mongo/dbtests/query_stage_update.cpp
+++ b/src/mongo/dbtests/query_stage_update.cpp
@@ -265,8 +265,8 @@ public:
CurOp& curOp = *CurOp::get(_opCtx);
OpDebug* opDebug = &curOp.debug();
UpdateDriver driver(_expCtx);
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss);
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss));
ASSERT(coll);
// Get the RecordIds that would be returned by an in-order scan.
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 51dac9cd2f6..17611e685fd 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -78,8 +78,8 @@ public:
{
WriteUnitOfWork wunit(&_opCtx);
_database = _context.db();
- auto collection =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr collection(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (collection) {
_database->dropCollection(&_opCtx, nss()).transitional_ignore();
}
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index 9bf826dfba1..eff6a2b80b5 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -127,8 +127,8 @@ public:
dbtests::WriteContextForTests ctx(&_opCtx, ns());
WriteUnitOfWork wuow(&_opCtx);
- CollectionPtr c =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr c(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!c) {
c = CollectionPtr(ctx.db()->createCollection(&_opCtx, nss()));
}
@@ -193,8 +193,8 @@ protected:
Lock::GlobalWrite lk(&_opCtx);
OldClientContext ctx(&_opCtx, nss());
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
WriteUnitOfWork wunit(&_opCtx);
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
@@ -290,8 +290,8 @@ protected:
OldClientContext ctx(&_opCtx, nss());
WriteUnitOfWork wunit(&_opCtx);
Database* db = ctx.db();
- CollectionPtr coll =
- CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss());
+ CollectionPtr coll(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, nss()));
if (!coll) {
coll = CollectionPtr(db->createCollection(&_opCtx, nss()));
}
diff --git a/src/mongo/dbtests/rollbacktests.cpp b/src/mongo/dbtests/rollbacktests.cpp
index 5058eb3f8c7..ec40f2fa28e 100644
--- a/src/mongo/dbtests/rollbacktests.cpp
+++ b/src/mongo/dbtests/rollbacktests.cpp
@@ -89,7 +89,7 @@ void insertRecord(OperationContext* opCtx, const NamespaceString& nss, const BSO
auto coll = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss);
OpDebug* const nullOpDebug = nullptr;
ASSERT_OK(collection_internal::insertDocument(
- opCtx, coll, InsertStatement(data), nullOpDebug, false));
+ opCtx, CollectionPtr(coll), InsertStatement(data), nullOpDebug, false));
}
void assertOnlyRecord(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& data) {
diff --git a/src/mongo/dbtests/validate_tests.cpp b/src/mongo/dbtests/validate_tests.cpp
index 59daa44ea2a..9caad7073b5 100644
--- a/src/mongo/dbtests/validate_tests.cpp
+++ b/src/mongo/dbtests/validate_tests.cpp
@@ -118,7 +118,8 @@ public:
// Helper to refetch the Collection from the catalog in order to see any changes made to it
CollectionPtr coll() const {
- return CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, _nss);
+ return CollectionPtr(
+ CollectionCatalog::get(&_opCtx)->lookupCollectionByNamespace(&_opCtx, _nss));
}
protected: