summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/catalog/capped_utils.cpp9
-rw-r--r--src/mongo/db/catalog/catalog_control.cpp2
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp3
-rw-r--r--src/mongo/db/catalog/create_collection.cpp11
-rw-r--r--src/mongo/db/catalog/database.h6
-rw-r--r--src/mongo/db/catalog/database_impl.cpp32
-rw-r--r--src/mongo/db/catalog/database_impl.h5
-rw-r--r--src/mongo/db/catalog/database_test.cpp8
-rw-r--r--src/mongo/db/catalog/drop_collection.cpp5
-rw-r--r--src/mongo/db/catalog/drop_database.cpp2
-rw-r--r--src/mongo/db/catalog/rename_collection.cpp25
-rw-r--r--src/mongo/db/catalog/rename_collection_test.cpp2
-rw-r--r--src/mongo/db/catalog/validate_state.cpp4
-rw-r--r--src/mongo/db/catalog_raii.cpp2
-rw-r--r--src/mongo/db/cloner.cpp15
-rw-r--r--src/mongo/db/commands/create_indexes.cpp4
-rw-r--r--src/mongo/db/commands/dbcheck.cpp2
-rw-r--r--src/mongo/db/commands/dbhash.cpp2
-rw-r--r--src/mongo/db/commands/drop_indexes.cpp3
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp11
-rw-r--r--src/mongo/db/commands/list_collections.cpp3
-rw-r--r--src/mongo/db/commands/mr.cpp13
-rw-r--r--src/mongo/db/commands/resize_oplog.cpp2
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp4
-rw-r--r--src/mongo/db/commands/test_commands.cpp2
-rw-r--r--src/mongo/db/db.cpp6
-rw-r--r--src/mongo/db/db_raii.cpp6
-rw-r--r--src/mongo/db/dbhelpers.cpp6
-rw-r--r--src/mongo/db/index_build_entry_helpers.cpp50
-rw-r--r--src/mongo/db/introspect.cpp7
-rw-r--r--src/mongo/db/matcher/expression_text.cpp2
-rw-r--r--src/mongo/db/op_observer_impl.cpp2
-rw-r--r--src/mongo/db/ops/update.cpp2
-rw-r--r--src/mongo/db/ops/write_ops_exec.cpp6
-rw-r--r--src/mongo/db/pipeline/document_source_cursor.cpp5
-rw-r--r--src/mongo/db/pipeline/process_interface_standalone.cpp2
-rw-r--r--src/mongo/db/query/plan_executor_impl.cpp2
-rw-r--r--src/mongo/db/repair_database_and_check_version.cpp16
-rw-r--r--src/mongo/db/repl/apply_ops.cpp4
-rw-r--r--src/mongo/db/repl/dbcheck.cpp3
-rw-r--r--src/mongo/db/repl/oplog.cpp11
-rw-r--r--src/mongo/db/repl/oplog_interface_local.cpp13
-rw-r--r--src/mongo/db/repl/replication_recovery.cpp3
-rw-r--r--src/mongo/db/repl/rs_rollback.cpp5
-rw-r--r--src/mongo/db/repl/rs_rollback_test.cpp9
-rw-r--r--src/mongo/db/repl/storage_interface_impl.cpp9
-rw-r--r--src/mongo/db/repl/sync_tail.cpp2
-rw-r--r--src/mongo/db/s/implicit_create_collection.cpp2
-rw-r--r--src/mongo/db/s/migration_destination_manager.cpp4
-rw-r--r--src/mongo/db/s/set_shard_version_command.cpp3
-rw-r--r--src/mongo/db/storage/SConscript1
-rw-r--r--src/mongo/db/storage/oplog_cap_maintainer_thread.cpp4
-rw-r--r--src/mongo/db/system_index.cpp5
-rw-r--r--src/mongo/db/transaction_participant.cpp2
-rw-r--r--src/mongo/db/transaction_participant_test.cpp4
-rw-r--r--src/mongo/db/views/durable_view_catalog.cpp9
-rw-r--r--src/mongo/dbtests/counttests.cpp2
-rw-r--r--src/mongo/dbtests/dbtests.cpp5
-rw-r--r--src/mongo/dbtests/dbtests.h2
-rw-r--r--src/mongo/dbtests/pdfiletests.cpp12
-rw-r--r--src/mongo/dbtests/plan_executor_invalidation_test.cpp14
-rw-r--r--src/mongo/dbtests/query_plan_executor.cpp5
-rw-r--r--src/mongo/dbtests/query_stage_count_scan.cpp3
-rw-r--r--src/mongo/dbtests/query_stage_fetch.cpp4
-rw-r--r--src/mongo/dbtests/query_stage_merge_sort.cpp20
-rw-r--r--src/mongo/dbtests/query_stage_sort.cpp12
-rw-r--r--src/mongo/dbtests/query_stage_update.cpp3
-rw-r--r--src/mongo/dbtests/querytests.cpp4
-rw-r--r--src/mongo/dbtests/repltests.cpp10
-rw-r--r--src/mongo/dbtests/rollbacktests.cpp32
70 files changed, 278 insertions, 232 deletions
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp
index 89d3719d095..74bed97f6d5 100644
--- a/src/mongo/db/catalog/capped_utils.cpp
+++ b/src/mongo/db/catalog/capped_utils.cpp
@@ -71,7 +71,8 @@ Status emptyCapped(OperationContext* opCtx, const NamespaceString& collectionNam
Database* db = autoDb.getDb();
uassert(ErrorCodes::NamespaceNotFound, "no such database", db);
- Collection* collection = db->getCollection(opCtx, collectionName);
+ Collection* collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(collectionName);
uassert(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "emptycapped not supported on view: " << collectionName.ns(),
collection || !ViewCatalog::get(db)->lookup(opCtx, collectionName.ns()));
@@ -117,7 +118,7 @@ void cloneCollectionAsCapped(OperationContext* opCtx,
NamespaceString fromNss(db->name(), shortFrom);
NamespaceString toNss(db->name(), shortTo);
- Collection* fromCollection = db->getCollection(opCtx, fromNss);
+ Collection* fromCollection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(fromNss);
if (!fromCollection) {
uassert(ErrorCodes::CommandNotSupportedOnView,
str::stream() << "cloneCollectionAsCapped not supported for views: " << fromNss,
@@ -135,7 +136,7 @@ void cloneCollectionAsCapped(OperationContext* opCtx,
uassert(ErrorCodes::NamespaceExists,
str::stream() << "cloneCollectionAsCapped failed - destination collection " << toNss
<< " already exists. source collection: " << fromNss,
- !db->getCollection(opCtx, toNss));
+ !CollectionCatalog::get(opCtx).lookupCollectionByNamespace(toNss));
// create new collection
{
@@ -154,7 +155,7 @@ void cloneCollectionAsCapped(OperationContext* opCtx,
uassertStatusOK(createCollection(opCtx, toNss.db().toString(), cmd.done()));
}
- Collection* toCollection = db->getCollection(opCtx, toNss);
+ Collection* toCollection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(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 4bc4dde890d..0bbdf6b81a0 100644
--- a/src/mongo/db/catalog/catalog_control.cpp
+++ b/src/mongo/db/catalog/catalog_control.cpp
@@ -168,7 +168,7 @@ void openCatalog(OperationContext* opCtx, const MinVisibleTimestampMap& minVisib
for (auto&& collNss :
CollectionCatalog::get(opCtx).getAllCollectionNamesFromDb(opCtx, dbName)) {
// Note that the collection name already includes the database component.
- auto collection = db->getCollection(opCtx, collNss);
+ auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(collNss);
invariant(collection,
str::stream()
<< "failed to get valid collection pointer for namespace " << collNss);
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index 699acb8d407..26eb6766f09 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -265,7 +265,8 @@ Status _collModInternal(OperationContext* opCtx,
StringData dbName = nss.db();
AutoGetDb autoDb(opCtx, dbName, MODE_X);
Database* const db = autoDb.getDb();
- Collection* coll = db ? db->getCollection(opCtx, nss) : nullptr;
+ Collection* coll =
+ db ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss) : nullptr;
hangAfterDatabaseLock.pauseWhileSet();
diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp
index 9f37185a551..2bddb98ee6e 100644
--- a/src/mongo/db/catalog/create_collection.cpp
+++ b/src/mongo/db/catalog/create_collection.cpp
@@ -81,7 +81,12 @@ Status _createView(OperationContext* opCtx,
// Create 'system.views' in a separate WUOW if it does not exist.
WriteUnitOfWork wuow(opCtx);
- db->getOrCreateCollection(opCtx, NamespaceString(db->getSystemViewsName()));
+ Collection* coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ NamespaceString(db->getSystemViewsName()));
+ if (!coll) {
+ coll = db->createCollection(opCtx, NamespaceString(db->getSystemViewsName()));
+ }
+ invariant(coll);
wuow.commit();
WriteUnitOfWork wunit(opCtx);
@@ -250,7 +255,9 @@ Status createCollectionForApplyOps(OperationContext* opCtx,
// of the initial sync or result in rollback to fassert, requiring a resync of that
// node.
const bool stayTemp = true;
- auto futureColl = db ? db->getCollection(opCtx, newCollName) : nullptr;
+ auto futureColl = db
+ ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(newCollName)
+ : nullptr;
bool needsRenaming = static_cast<bool>(futureColl);
for (int tries = 0; needsRenaming && tries < 10; ++tries) {
auto tmpNameResult =
diff --git a/src/mongo/db/catalog/database.h b/src/mongo/db/catalog/database.h
index 2b84a1fc06c..2b2edbac1dd 100644
--- a/src/mongo/db/catalog/database.h
+++ b/src/mongo/db/catalog/database.h
@@ -145,12 +145,6 @@ public:
const NamespaceString& viewName,
const CollectionOptions& options) const = 0;
- virtual Collection* getCollection(OperationContext* opCtx,
- const NamespaceString& nss) const = 0;
-
- virtual Collection* getOrCreateCollection(OperationContext* const opCtx,
- const NamespaceString& nss) const = 0;
-
/**
* Arguments are passed by value as they otherwise would be changing as result of renaming.
*/
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp
index 0a6e862e4ad..a072112e7ca 100644
--- a/src/mongo/db/catalog/database_impl.cpp
+++ b/src/mongo/db/catalog/database_impl.cpp
@@ -304,7 +304,7 @@ Status DatabaseImpl::dropView(OperationContext* opCtx, NamespaceString viewName)
Status DatabaseImpl::dropCollection(OperationContext* opCtx,
NamespaceString nss,
repl::OpTime dropOpTime) const {
- if (!getCollection(opCtx, nss)) {
+ if (!CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss)) {
// Collection doesn't exist so don't bother validating if it can be dropped.
return Status::OK();
}
@@ -341,7 +341,7 @@ Status DatabaseImpl::dropCollectionEvenIfSystem(OperationContext* opCtx,
"dropCollection() cannot accept a valid drop optime when writes are replicated.");
}
- Collection* collection = getCollection(opCtx, nss);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (!collection) {
return Status::OK(); // Post condition already met.
@@ -469,10 +469,6 @@ Status DatabaseImpl::_finishDropCollection(OperationContext* opCtx,
return Status::OK();
}
-Collection* DatabaseImpl::getCollection(OperationContext* opCtx, const NamespaceString& nss) const {
- return CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
-}
-
Status DatabaseImpl::renameCollection(OperationContext* opCtx,
NamespaceString fromNss,
NamespaceString toNss,
@@ -484,13 +480,13 @@ Status DatabaseImpl::renameCollection(OperationContext* opCtx,
invariant(fromNss.db() == _name);
invariant(toNss.db() == _name);
- if (getCollection(opCtx, toNss)) {
+ if (CollectionCatalog::get(opCtx).lookupCollectionByNamespace(toNss)) {
return Status(ErrorCodes::NamespaceExists,
str::stream() << "Cannot rename '" << fromNss << "' to '" << toNss
<< "' because the destination namespace already exists");
}
- Collection* collToRename = getCollection(opCtx, fromNss);
+ Collection* collToRename = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(fromNss);
if (!collToRename) {
return Status(ErrorCodes::NamespaceNotFound, "collection not found to rename");
}
@@ -499,7 +495,7 @@ Status DatabaseImpl::renameCollection(OperationContext* opCtx,
"collection "
<< fromNss);
- Collection* toColl = getCollection(opCtx, toNss);
+ Collection* toColl = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(toNss);
if (toColl) {
invariant(
!toColl->getIndexCatalog()->haveAnyIndexesInProgress(),
@@ -531,22 +527,12 @@ Status DatabaseImpl::renameCollection(OperationContext* opCtx,
return status;
}
-Collection* DatabaseImpl::getOrCreateCollection(OperationContext* opCtx,
- const NamespaceString& nss) const {
- Collection* c = getCollection(opCtx, nss);
-
- if (!c) {
- c = createCollection(opCtx, nss);
- }
- return c;
-}
-
void DatabaseImpl::_checkCanCreateCollection(OperationContext* opCtx,
const NamespaceString& nss,
const CollectionOptions& options) const {
massert(17399,
str::stream() << "Cannot create collection " << nss << " - collection already exists.",
- getCollection(opCtx, nss) == nullptr);
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss) == nullptr);
uassert(14037,
"can't create user databases on a --configsvr instance",
@@ -740,7 +726,7 @@ StatusWith<NamespaceString> DatabaseImpl::makeUniqueCollectionNamespace(
replacePercentSign);
NamespaceString nss(_name, collectionName);
- if (!getCollection(opCtx, nss)) {
+ if (!CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss)) {
return nss;
}
}
@@ -772,7 +758,7 @@ void DatabaseImpl::checkForIdIndexesAndDropPendingCollections(OperationContext*
if (nss.isSystem())
continue;
- Collection* coll = getCollection(opCtx, nss);
+ Collection* coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (!coll)
continue;
@@ -797,7 +783,7 @@ Status DatabaseImpl::userCreateNS(OperationContext* opCtx,
if (!NamespaceString::validCollectionComponent(nss.ns()))
return Status(ErrorCodes::InvalidNamespace, str::stream() << "invalid ns: " << nss);
- Collection* collection = getCollection(opCtx, nss);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (collection)
return Status(ErrorCodes::NamespaceExists,
diff --git a/src/mongo/db/catalog/database_impl.h b/src/mongo/db/catalog/database_impl.h
index fc34e401fd6..0b5e55d151e 100644
--- a/src/mongo/db/catalog/database_impl.h
+++ b/src/mongo/db/catalog/database_impl.h
@@ -103,11 +103,6 @@ public:
const NamespaceString& viewName,
const CollectionOptions& options) const final;
- Collection* getCollection(OperationContext* opCtx, const NamespaceString& nss) const;
-
- Collection* getOrCreateCollection(OperationContext* opCtx,
- const NamespaceString& nss) const final;
-
Status renameCollection(OperationContext* opCtx,
NamespaceString fromNss,
NamespaceString toNss,
diff --git a/src/mongo/db/catalog/database_test.cpp b/src/mongo/db/catalog/database_test.cpp
index 173e797851d..cab7b6380ba 100644
--- a/src/mongo/db/catalog/database_test.cpp
+++ b/src/mongo/db/catalog/database_test.cpp
@@ -184,12 +184,12 @@ void _testDropCollection(OperationContext* opCtx,
if (createCollectionBeforeDrop) {
ASSERT_TRUE(db->createCollection(opCtx, nss, collOpts));
} else {
- ASSERT_FALSE(db->getCollection(opCtx, nss));
+ ASSERT_FALSE(CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss));
}
ASSERT_OK(db->dropCollection(opCtx, nss, dropOpTime));
- ASSERT_FALSE(db->getCollection(opCtx, nss));
+ ASSERT_FALSE(CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss));
wuow.commit();
});
}
@@ -364,8 +364,8 @@ TEST_F(DatabaseTest, RenameCollectionPreservesUuidOfSourceCollectionAndUpdatesUu
auto stayTemp = false;
ASSERT_OK(db->renameCollection(opCtx, fromNss, toNss, stayTemp));
- ASSERT_FALSE(db->getCollection(opCtx, fromNss));
- auto toCollection = db->getCollection(opCtx, toNss);
+ ASSERT_FALSE(CollectionCatalog::get(opCtx).lookupCollectionByNamespace(fromNss));
+ auto toCollection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(toNss);
ASSERT_TRUE(toCollection);
auto toCollectionOptions =
diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp
index 107e9b7ddad..5167f4f8383 100644
--- a/src/mongo/db/catalog/drop_collection.cpp
+++ b/src/mongo/db/catalog/drop_collection.cpp
@@ -108,7 +108,7 @@ Status _dropCollection(OperationContext* opCtx,
DropCollectionSystemCollectionMode systemCollectionMode,
BSONObjBuilder& result) {
Lock::CollectionLock collLock(opCtx, collectionName, MODE_X);
- Collection* coll = db->getCollection(opCtx, collectionName);
+ Collection* coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(collectionName);
if (!coll) {
return Status(ErrorCodes::NamespaceNotFound, "ns not found");
}
@@ -172,7 +172,8 @@ Status dropCollection(OperationContext* opCtx,
return Status(ErrorCodes::NamespaceNotFound, "ns not found");
}
- Collection* coll = db->getCollection(opCtx, collectionName);
+ Collection* coll =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(collectionName);
if (!coll) {
return _dropView(opCtx, db, collectionName, result);
} else {
diff --git a/src/mongo/db/catalog/drop_database.cpp b/src/mongo/db/catalog/drop_database.cpp
index d81908b9d48..793d9a9f779 100644
--- a/src/mongo/db/catalog/drop_database.cpp
+++ b/src/mongo/db/catalog/drop_database.cpp
@@ -194,7 +194,7 @@ Status dropDatabase(OperationContext* opCtx, const std::string& dbName) {
BackgroundOperation::assertNoBgOpInProgForNs(nss.ns());
IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(
- db->getCollection(opCtx, nss)->uuid());
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss)->uuid());
writeConflictRetry(opCtx, "dropDatabase_collection", nss.ns(), [&] {
WriteUnitOfWork wunit(opCtx);
diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp
index c452c867bb2..f79632c3c75 100644
--- a/src/mongo/db/catalog/rename_collection.cpp
+++ b/src/mongo/db/catalog/rename_collection.cpp
@@ -115,7 +115,8 @@ Status checkSourceAndTargetNamespaces(OperationContext* opCtx,
if (!db)
return Status(ErrorCodes::NamespaceNotFound, "source namespace does not exist");
- Collection* const sourceColl = db->getCollection(opCtx, source);
+ Collection* const sourceColl =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(source);
if (!sourceColl) {
if (ViewCatalog::get(db)->lookup(opCtx, source.ns()))
return Status(ErrorCodes::CommandNotSupportedOnView,
@@ -126,7 +127,7 @@ Status checkSourceAndTargetNamespaces(OperationContext* opCtx,
BackgroundOperation::assertNoBgOpInProgForNs(source.ns());
IndexBuildsCoordinator::get(opCtx)->assertNoIndexBuildInProgForCollection(sourceColl->uuid());
- Collection* targetColl = db->getCollection(opCtx, target);
+ Collection* targetColl = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(target);
if (!targetColl) {
if (ViewCatalog::get(db)->lookup(opCtx, target.ns()))
@@ -311,8 +312,10 @@ Status renameCollectionWithinDB(OperationContext* opCtx,
return status;
auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, source.db());
- Collection* const sourceColl = db->getCollection(opCtx, source);
- Collection* const targetColl = db->getCollection(opCtx, target);
+ Collection* const sourceColl =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(source);
+ Collection* const targetColl =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(target);
AutoStatsTracker statsTracker(opCtx,
source,
@@ -351,7 +354,8 @@ Status renameCollectionWithinDBForApplyOps(OperationContext* opCtx,
return status;
auto db = DatabaseHolder::get(opCtx)->getDb(opCtx, source.db());
- Collection* const sourceColl = db->getCollection(opCtx, source);
+ Collection* const sourceColl =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(source);
AutoStatsTracker statsTracker(opCtx,
source,
@@ -360,7 +364,7 @@ Status renameCollectionWithinDBForApplyOps(OperationContext* opCtx,
db->getProfilingLevel());
return writeConflictRetry(opCtx, "renameCollection", target.ns(), [&] {
- Collection* targetColl = db->getCollection(opCtx, target);
+ Collection* targetColl = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(target);
WriteUnitOfWork wuow(opCtx);
if (targetColl) {
if (sourceColl->uuid() == targetColl->uuid()) {
@@ -404,7 +408,8 @@ Status renameCollectionWithinDBForApplyOps(OperationContext* opCtx,
auto collToDropBasedOnUUID = getNamespaceFromUUID(opCtx, uuidToDrop.get());
if (collToDropBasedOnUUID && !collToDropBasedOnUUID->isDropPendingNamespace()) {
invariant(collToDropBasedOnUUID->db() == target.db());
- targetColl = db->getCollection(opCtx, *collToDropBasedOnUUID);
+ targetColl = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ *collToDropBasedOnUUID);
}
}
@@ -464,7 +469,8 @@ Status renameBetweenDBs(OperationContext* opCtx,
AutoStatsTracker::LogMode::kUpdateTopAndCurop,
sourceDB->getProfilingLevel());
- Collection* const sourceColl = sourceDB->getCollection(opCtx, source);
+ Collection* const sourceColl =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(source);
if (!sourceColl) {
if (sourceDB && ViewCatalog::get(sourceDB)->lookup(opCtx, source.ns()))
return Status(ErrorCodes::CommandNotSupportedOnView,
@@ -490,7 +496,8 @@ Status renameBetweenDBs(OperationContext* opCtx,
// Check if the target namespace exists and if dropTarget is true.
// Return a non-OK status if target exists and dropTarget is not true or if the collection
// is sharded.
- Collection* targetColl = targetDB ? targetDB->getCollection(opCtx, target) : nullptr;
+ Collection* targetColl =
+ targetDB ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(target) : nullptr;
if (targetColl) {
if (sourceColl->uuid() == targetColl->uuid()) {
invariant(source == target);
diff --git a/src/mongo/db/catalog/rename_collection_test.cpp b/src/mongo/db/catalog/rename_collection_test.cpp
index a8bdc936670..9458d8566ba 100644
--- a/src/mongo/db/catalog/rename_collection_test.cpp
+++ b/src/mongo/db/catalog/rename_collection_test.cpp
@@ -454,7 +454,7 @@ Collection* _getCollection_inlock(OperationContext* opCtx, const NamespaceString
if (!db) {
return nullptr;
}
- return db->getCollection(opCtx, nss);
+ return CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
}
TEST_F(RenameCollectionTest, RenameCollectionReturnsNamespaceNotFoundIfDatabaseDoesNotExist) {
diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp
index 4374203db8d..b12503d48cc 100644
--- a/src/mongo/db/catalog/validate_state.cpp
+++ b/src/mongo/db/catalog/validate_state.cpp
@@ -67,7 +67,9 @@ ValidateState::ValidateState(OperationContext* opCtx,
}
_database = _databaseLock->getDb() ? _databaseLock->getDb() : nullptr;
- _collection = _database ? _database->getCollection(opCtx, _nss) : nullptr;
+ _collection =
+ _database ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(_nss) : nullptr;
+
if (!_collection) {
if (_database && ViewCatalog::get(_database)->lookup(opCtx, _nss.ns())) {
diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp
index ce29a2c495b..254694ec1cc 100644
--- a/src/mongo/db/catalog_raii.cpp
+++ b/src/mongo/db/catalog_raii.cpp
@@ -95,7 +95,7 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx,
if (!db)
return;
- _coll = db->getCollection(opCtx, _resolvedNss);
+ _coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(_resolvedNss);
invariant(!nsOrUUID.uuid() || _coll,
str::stream() << "Collection for " << _resolvedNss.ns()
<< " disappeared after successufully resolving "
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 30402ec2552..06d594d1afd 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -116,7 +116,7 @@ struct Cloner::Fun {
bool createdCollection = false;
Collection* collection = nullptr;
- collection = db->getCollection(opCtx, to_collection);
+ collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(to_collection);
if (!collection) {
massert(17321,
str::stream() << "collection dropped during clone [" << to_collection.ns()
@@ -137,7 +137,8 @@ struct Cloner::Fun {
str::stream() << "collection creation failed during clone ["
<< to_collection.ns() << "]");
wunit.commit();
- collection = db->getCollection(opCtx, to_collection);
+ collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(to_collection);
invariant(collection,
str::stream()
<< "Missing collection during clone [" << to_collection.ns() << "]");
@@ -178,7 +179,8 @@ struct Cloner::Fun {
str::stream() << "Database " << _dbName << " dropped while cloning",
db != nullptr);
- collection = db->getCollection(opCtx, to_collection);
+ collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(to_collection);
uassert(28594,
str::stream()
<< "Collection " << to_collection.ns() << " dropped while cloning",
@@ -325,7 +327,8 @@ void Cloner::copyIndexes(OperationContext* opCtx,
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->openDb(opCtx, toDBName);
- Collection* collection = db->getCollection(opCtx, to_collection);
+ Collection* collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(to_collection);
if (!collection) {
writeConflictRetry(opCtx, "createCollection", to_collection.ns(), [&] {
opCtx->checkForInterrupt();
@@ -343,7 +346,7 @@ void Cloner::copyIndexes(OperationContext* opCtx,
<< "Collection creation failed while copying indexes from "
<< from_collection.ns() << " to " << to_collection.ns() << " (Cloner)");
wunit.commit();
- collection = db->getCollection(opCtx, to_collection);
+ collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(to_collection);
invariant(collection,
str::stream() << "Missing collection " << to_collection.ns() << " (Cloner)");
});
@@ -548,7 +551,7 @@ Status Cloner::createCollectionsForDb(
opCtx->checkForInterrupt();
WriteUnitOfWork wunit(opCtx);
- Collection* collection = db->getCollection(opCtx, nss);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(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/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index eac64ba54ed..36ea0e91579 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -370,7 +370,7 @@ Collection* getOrCreateCollection(OperationContext* opCtx,
const BSONObj& cmdObj,
std::string* errmsg,
BSONObjBuilder* result) {
- if (auto collection = db->getCollection(opCtx, ns)) {
+ if (auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(ns)) {
result->appendBool(kCreateCollectionAutomaticallyFieldName, false);
return collection;
}
@@ -600,7 +600,7 @@ bool runCreateIndexesForMobile(OperationContext* opCtx,
auto databaseHolder = DatabaseHolder::get(opCtx);
db = databaseHolder->getDb(opCtx, ns.db());
- invariant(db->getCollection(opCtx, ns));
+ invariant(CollectionCatalog::get(opCtx).lookupCollectionByNamespace(ns));
// Perform the third and final drain while holding the exclusive collection lock.
uassertStatusOK(indexer.drainBackgroundWrites(opCtx));
diff --git a/src/mongo/db/commands/dbcheck.cpp b/src/mongo/db/commands/dbcheck.cpp
index 7a3a5728bf7..8e87e6b6463 100644
--- a/src/mongo/db/commands/dbcheck.cpp
+++ b/src/mongo/db/commands/dbcheck.cpp
@@ -334,7 +334,7 @@ private:
return false;
}
- auto collection = db->getCollection(opCtx, info.nss);
+ auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(info.nss);
if (!collection) {
return false;
}
diff --git a/src/mongo/db/commands/dbhash.cpp b/src/mongo/db/commands/dbhash.cpp
index 751ac181371..2e65ced1211 100644
--- a/src/mongo/db/commands/dbhash.cpp
+++ b/src/mongo/db/commands/dbhash.cpp
@@ -325,7 +325,7 @@ public:
private:
std::string _hashCollection(OperationContext* opCtx, Database* db, const NamespaceString& nss) {
- Collection* collection = db->getCollection(opCtx, nss);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
invariant(collection);
boost::optional<Lock::CollectionLock> collLock;
diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp
index 963a7aa7f83..8fbaabb68f7 100644
--- a/src/mongo/db/commands/drop_indexes.cpp
+++ b/src/mongo/db/commands/drop_indexes.cpp
@@ -136,7 +136,8 @@ public:
Lock::GlobalWrite lk(opCtx);
AutoGetOrCreateDb autoDb(opCtx, dbname, MODE_X);
- Collection* collection = autoDb.getDb()->getCollection(opCtx, toReIndexNss);
+ Collection* collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(toReIndexNss);
if (!collection) {
if (ViewCatalog::get(autoDb.getDb())->lookup(opCtx, toReIndexNss.ns()))
uasserted(ErrorCodes::CommandNotSupportedOnView, "can't re-index a view");
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index b1b169988da..f2bfd28f287 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -459,9 +459,13 @@ public:
autoDb.emplace(opCtx, dbName, MODE_X);
assertCanWrite(
- opCtx, nsString, autoDb->getDb()->getCollection(opCtx, nsString));
+ opCtx,
+ nsString,
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nsString));
- collection = autoDb->getDb()->getCollection(opCtx, nsString);
+ collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nsString);
+ ;
// If someone else beat us to creating the collection, do nothing
if (!collection) {
@@ -473,7 +477,8 @@ public:
db->userCreateNS(opCtx, nsString, defaultCollectionOptions));
wuow.commit();
- collection = autoDb->getDb()->getCollection(opCtx, nsString);
+ collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nsString);
}
invariant(collection);
diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp
index 7dc58def146..dd89bf02821 100644
--- a/src/mongo/db/commands/list_collections.cpp
+++ b/src/mongo/db/commands/list_collections.cpp
@@ -310,7 +310,8 @@ public:
}
Lock::CollectionLock clk(opCtx, nss, MODE_IS);
- Collection* collection = db->getCollection(opCtx, nss);
+ Collection* collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
BSONObj collBson =
buildCollectionBson(opCtx, collection, includePendingDrops, nameOnly);
if (!collBson.isEmpty()) {
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 80045f62d90..4a9c6adb937 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -113,7 +113,7 @@ unsigned long long collectionCount(OperationContext* opCtx,
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, nss.ns());
if (db) {
- coll = db->getCollection(opCtx, nss);
+ coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
}
} else {
ctx.emplace(opCtx, nss);
@@ -182,7 +182,8 @@ void dropTempCollections(OperationContext* cleanupOpCtx,
[cleanupOpCtx, &tempNamespace] {
AutoGetDb autoDb(cleanupOpCtx, tempNamespace.db(), MODE_X);
if (auto db = autoDb.getDb()) {
- if (auto collection = db->getCollection(cleanupOpCtx, tempNamespace)) {
+ if (auto collection = CollectionCatalog::get(cleanupOpCtx)
+ .lookupCollectionByNamespace(tempNamespace)) {
uassert(ErrorCodes::PrimarySteppedDown,
str::stream() << "no longer primary while dropping temporary "
"collection for mapReduce: "
@@ -207,7 +208,8 @@ void dropTempCollections(OperationContext* cleanupOpCtx,
Lock::DBLock lk(cleanupOpCtx, incLong.db(), MODE_X);
auto databaseHolder = DatabaseHolder::get(cleanupOpCtx);
if (auto db = databaseHolder->getDb(cleanupOpCtx, incLong.ns())) {
- if (auto collection = db->getCollection(cleanupOpCtx, incLong)) {
+ if (auto collection = CollectionCatalog::get(cleanupOpCtx)
+ .lookupCollectionByNamespace(incLong)) {
BackgroundOperation::assertNoBgOpInProgForNs(incLong.ns());
IndexBuildsCoordinator::get(cleanupOpCtx)
->assertNoIndexBuildInProgForCollection(collection->uuid());
@@ -522,7 +524,7 @@ void State::prepTempCollection() {
writeConflictRetry(_opCtx, "M/R prepTempCollection", _config.incLong.ns(), [this] {
AutoGetOrCreateDb autoGetIncCollDb(_opCtx, _config.incLong.db(), MODE_X);
auto const db = autoGetIncCollDb.getDb();
- invariant(!db->getCollection(_opCtx, _config.incLong));
+ invariant(!CollectionCatalog::get(_opCtx).lookupCollectionByNamespace(_config.incLong));
CollectionOptions options;
options.setNoIdIndex();
@@ -584,7 +586,8 @@ void State::prepTempCollection() {
// Create temp collection and insert the indexes from temporary storage
AutoGetOrCreateDb autoGetFinalDb(_opCtx, _config.tempNamespace.db(), MODE_X);
auto const db = autoGetFinalDb.getDb();
- invariant(!db->getCollection(_opCtx, _config.tempNamespace));
+ invariant(
+ !CollectionCatalog::get(_opCtx).lookupCollectionByNamespace(_config.tempNamespace));
uassert(
ErrorCodes::PrimarySteppedDown,
diff --git a/src/mongo/db/commands/resize_oplog.cpp b/src/mongo/db/commands/resize_oplog.cpp
index 7c2a954d1af..11a58e6d4be 100644
--- a/src/mongo/db/commands/resize_oplog.cpp
+++ b/src/mongo/db/commands/resize_oplog.cpp
@@ -89,7 +89,7 @@ public:
if (!database) {
uasserted(ErrorCodes::NamespaceNotFound, "database local does not exist");
}
- Collection* coll = database->getCollection(opCtx, nss);
+ Collection* coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (!coll) {
uasserted(ErrorCodes::NamespaceNotFound, "oplog does not exist");
}
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index 98a332ff145..3ecab3a4b47 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -287,7 +287,7 @@ StatusWith<StringMap<ExpressionContext::ResolvedNamespace>> resolveInvolvedNames
// from a $merge to a collection in a different database. Since we cannot write to
// views, simply assume that the namespace is a collection.
resolvedNamespaces[involvedNs.coll()] = {involvedNs, std::vector<BSONObj>{}};
- } else if (!db || db->getCollection(opCtx, involvedNs)) {
+ } else if (!db || CollectionCatalog::get(opCtx).lookupCollectionByNamespace(involvedNs)) {
// If the aggregation database exists and 'involvedNs' refers to a collection namespace,
// then we resolve it as an empty pipeline in order to read directly from the underlying
// collection. If the database doesn't exist, then we still resolve it as an empty
@@ -338,7 +338,7 @@ Status collatorCompatibleWithPipeline(OperationContext* opCtx,
return Status::OK();
}
for (auto&& potentialViewNs : liteParsedPipeline.getInvolvedNamespaces()) {
- if (db->getCollection(opCtx, potentialViewNs)) {
+ if (CollectionCatalog::get(opCtx).lookupCollectionByNamespace(potentialViewNs)) {
continue;
}
diff --git a/src/mongo/db/commands/test_commands.cpp b/src/mongo/db/commands/test_commands.cpp
index b4ca089ae3b..183d4cf4095 100644
--- a/src/mongo/db/commands/test_commands.cpp
+++ b/src/mongo/db/commands/test_commands.cpp
@@ -89,7 +89,7 @@ public:
WriteUnitOfWork wunit(opCtx);
UnreplicatedWritesBlock unreplicatedWritesBlock(opCtx);
- Collection* collection = db->getCollection(opCtx, nss);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (!collection) {
collection = db->createCollection(opCtx, nss);
if (!collection) {
diff --git a/src/mongo/db/db.cpp b/src/mongo/db/db.cpp
index f0778289bd8..2b84068ac50 100644
--- a/src/mongo/db/db.cpp
+++ b/src/mongo/db/db.cpp
@@ -230,7 +230,8 @@ void logStartup(OperationContext* opCtx) {
Lock::GlobalWrite lk(opCtx);
AutoGetOrCreateDb autoDb(opCtx, startupLogCollectionName.db(), mongo::MODE_X);
Database* db = autoDb.getDb();
- Collection* collection = db->getCollection(opCtx, startupLogCollectionName);
+ Collection* collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(startupLogCollectionName);
WriteUnitOfWork wunit(opCtx);
if (!collection) {
BSONObj options = BSON("capped" << true << "size" << 10 * 1024 * 1024);
@@ -238,7 +239,8 @@ void logStartup(OperationContext* opCtx) {
CollectionOptions collectionOptions = uassertStatusOK(
CollectionOptions::parse(options, CollectionOptions::ParseKind::parseForCommand));
uassertStatusOK(db->userCreateNS(opCtx, startupLogCollectionName, collectionOptions));
- collection = db->getCollection(opCtx, startupLogCollectionName);
+ collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(startupLogCollectionName);
}
invariant(collection);
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index 350a32c3dd6..cdb3813f985 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -344,8 +344,10 @@ OldClientContext::OldClientContext(OperationContext* opCtx, const std::string& n
break;
default:
CollectionShardingState::get(_opCtx, NamespaceString(ns))
- ->checkShardVersionOrThrow(_opCtx,
- _db->getCollection(opCtx, NamespaceString(ns)));
+ ->checkShardVersionOrThrow(
+ _opCtx,
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ NamespaceString(ns)));
break;
}
}
diff --git a/src/mongo/db/dbhelpers.cpp b/src/mongo/db/dbhelpers.cpp
index 630c0093a91..7c1e045f497 100644
--- a/src/mongo/db/dbhelpers.cpp
+++ b/src/mongo/db/dbhelpers.cpp
@@ -138,7 +138,8 @@ bool Helpers::findById(OperationContext* opCtx,
bool* indexFound) {
invariant(database);
- Collection* collection = database->getCollection(opCtx, NamespaceString(ns));
+ Collection* collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(NamespaceString(ns));
if (!collection) {
return false;
}
@@ -262,7 +263,8 @@ BSONObj Helpers::inferKeyPattern(const BSONObj& o) {
void Helpers::emptyCollection(OperationContext* opCtx, const NamespaceString& nss) {
OldClientContext context(opCtx, nss.ns());
repl::UnreplicatedWritesBlock uwb(opCtx);
- Collection* collection = context.db() ? context.db()->getCollection(opCtx, nss) : nullptr;
+ Collection* collection =
+ context.db() ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss) : nullptr;
deleteObjects(opCtx, collection, nss, BSONObj(), false);
}
diff --git a/src/mongo/db/index_build_entry_helpers.cpp b/src/mongo/db/index_build_entry_helpers.cpp
index 8ecbc4544c5..dd918677412 100644
--- a/src/mongo/db/index_build_entry_helpers.cpp
+++ b/src/mongo/db/index_build_entry_helpers.cpp
@@ -91,30 +91,32 @@ Status upsert(OperationContext* opCtx, IndexBuildEntry indexBuildEntry) {
namespace indexbuildentryhelpers {
void ensureIndexBuildEntriesNamespaceExists(OperationContext* opCtx) {
- writeConflictRetry(
- opCtx,
- "createIndexBuildCollection",
- NamespaceString::kIndexBuildEntryNamespace.ns(),
- [&]() -> void {
- AutoGetOrCreateDb autoDb(
- opCtx, NamespaceString::kIndexBuildEntryNamespace.db(), MODE_X);
- Database* db = autoDb.getDb();
-
- // Ensure the database exists.
- invariant(db);
-
- // Create the collection if it doesn't exist.
- if (!db->getCollection(opCtx, NamespaceString::kIndexBuildEntryNamespace)) {
- WriteUnitOfWork wuow(opCtx);
- CollectionOptions defaultCollectionOptions;
- Collection* collection = db->createCollection(
- opCtx, NamespaceString::kIndexBuildEntryNamespace, defaultCollectionOptions);
-
- // Ensure the collection exists.
- invariant(collection);
- wuow.commit();
- }
- });
+ writeConflictRetry(opCtx,
+ "createIndexBuildCollection",
+ NamespaceString::kIndexBuildEntryNamespace.ns(),
+ [&]() -> void {
+ AutoGetOrCreateDb autoDb(
+ opCtx, NamespaceString::kIndexBuildEntryNamespace.db(), MODE_X);
+ Database* db = autoDb.getDb();
+
+ // Ensure the database exists.
+ invariant(db);
+
+ // Create the collection if it doesn't exist.
+ if (!CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ NamespaceString::kIndexBuildEntryNamespace)) {
+ WriteUnitOfWork wuow(opCtx);
+ CollectionOptions defaultCollectionOptions;
+ Collection* collection =
+ db->createCollection(opCtx,
+ NamespaceString::kIndexBuildEntryNamespace,
+ defaultCollectionOptions);
+
+ // Ensure the collection exists.
+ invariant(collection);
+ wuow.commit();
+ }
+ });
}
Status addIndexBuildEntry(OperationContext* opCtx, IndexBuildEntry indexBuildEntry) {
diff --git a/src/mongo/db/introspect.cpp b/src/mongo/db/introspect.cpp
index 114a39305d5..c88e9ac3d6b 100644
--- a/src/mongo/db/introspect.cpp
+++ b/src/mongo/db/introspect.cpp
@@ -176,7 +176,9 @@ void profile(OperationContext* opCtx, NetworkOp op) {
// not allowed while performing writes, so temporarily enforce prepare conflicts.
EnforcePrepareConflictsBlock enforcePrepare(opCtx);
- Collection* const coll = db->getCollection(opCtx, db->getProfilingNS());
+ Collection* const coll =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(db->getProfilingNS());
+
if (coll) {
invariant(!opCtx->shouldParticipateInFlowControl());
WriteUnitOfWork wuow(opCtx);
@@ -217,7 +219,8 @@ Status createProfileCollection(OperationContext* opCtx, Database* db) {
invariant(!opCtx->shouldParticipateInFlowControl());
auto& dbProfilingNS = db->getProfilingNS();
- Collection* const collection = db->getCollection(opCtx, dbProfilingNS);
+ Collection* const collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(dbProfilingNS);
if (collection) {
if (!collection->isCapped()) {
return Status(ErrorCodes::NamespaceExists,
diff --git a/src/mongo/db/matcher/expression_text.cpp b/src/mongo/db/matcher/expression_text.cpp
index fdf4e664595..eb650fabbb9 100644
--- a/src/mongo/db/matcher/expression_text.cpp
+++ b/src/mongo/db/matcher/expression_text.cpp
@@ -66,7 +66,7 @@ TextMatchExpression::TextMatchExpression(OperationContext* opCtx,
<< nss.ns() << "')",
db);
- Collection* collection = db->getCollection(opCtx, nss);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
uassert(ErrorCodes::IndexNotFound,
str::stream() << "text index required for $text query (no such collection '"
diff --git a/src/mongo/db/op_observer_impl.cpp b/src/mongo/db/op_observer_impl.cpp
index 4ce9543740c..0c789bb301c 100644
--- a/src/mongo/db/op_observer_impl.cpp
+++ b/src/mongo/db/op_observer_impl.cpp
@@ -611,7 +611,7 @@ void OpObserverImpl::onCollMod(OperationContext* opCtx,
if (!db) {
return;
}
- Collection* coll = db->getCollection(opCtx, nss);
+ Collection* coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
invariant(coll->uuid() == uuid);
invariant(DurableCatalog::get(opCtx)->isEqualToMetadataUUID(opCtx, nss, uuid));
diff --git a/src/mongo/db/ops/update.cpp b/src/mongo/db/ops/update.cpp
index a600f37a543..f6e0fcd3eaa 100644
--- a/src/mongo/db/ops/update.cpp
+++ b/src/mongo/db/ops/update.cpp
@@ -62,7 +62,7 @@ UpdateResult update(OperationContext* opCtx, Database* db, const UpdateRequest&
invariant(!request.isExplain());
const NamespaceString& nsString = request.getNamespaceString();
- Collection* collection = db->getCollection(opCtx, nsString);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nsString);
// 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.
diff --git a/src/mongo/db/ops/write_ops_exec.cpp b/src/mongo/db/ops/write_ops_exec.cpp
index 8e46b008110..a495ab7a429 100644
--- a/src/mongo/db/ops/write_ops_exec.cpp
+++ b/src/mongo/db/ops/write_ops_exec.cpp
@@ -212,8 +212,10 @@ void makeCollection(OperationContext* opCtx, const NamespaceString& ns) {
AutoGetOrCreateDb db(opCtx, ns.db(), MODE_IX);
Lock::CollectionLock collLock(opCtx, ns, MODE_X);
- assertCanWrite_inlock(opCtx, ns, db.getDb()->getCollection(opCtx, ns));
- if (!db.getDb()->getCollection(opCtx, ns)) { // someone else may have beat us to it.
+ assertCanWrite_inlock(
+ opCtx, ns, CollectionCatalog::get(opCtx).lookupCollectionByNamespace(ns));
+ if (!CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ ns)) { // someone else may have beat us to it.
uassertStatusOK(userAllowedCreateNS(ns.db(), ns.coll()));
WriteUnitOfWork wuow(opCtx);
CollectionOptions defaultCollectionOptions;
diff --git a/src/mongo/db/pipeline/document_source_cursor.cpp b/src/mongo/db/pipeline/document_source_cursor.cpp
index 669cf02f670..368b75613ec 100644
--- a/src/mongo/db/pipeline/document_source_cursor.cpp
+++ b/src/mongo/db/pipeline/document_source_cursor.cpp
@@ -238,8 +238,9 @@ Value DocumentSourceCursor::serialize(boost::optional<ExplainOptions::Verbosity>
auto lockMode = getLockModeForQuery(opCtx, _exec->nss());
AutoGetDb dbLock(opCtx, _exec->nss().db(), lockMode);
Lock::CollectionLock collLock(opCtx, _exec->nss(), lockMode);
- auto collection =
- dbLock.getDb() ? dbLock.getDb()->getCollection(opCtx, _exec->nss()) : nullptr;
+ auto collection = dbLock.getDb()
+ ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(_exec->nss())
+ : nullptr;
Explain::explainStages(_exec.get(),
collection,
diff --git a/src/mongo/db/pipeline/process_interface_standalone.cpp b/src/mongo/db/pipeline/process_interface_standalone.cpp
index 63ecf0efced..d7e653e2ad2 100644
--- a/src/mongo/db/pipeline/process_interface_standalone.cpp
+++ b/src/mongo/db/pipeline/process_interface_standalone.cpp
@@ -565,7 +565,7 @@ bool MongoInterfaceStandalone::fieldsHaveSupportingUniqueIndex(
Lock::CollectionLock collLock(opCtx, nss, MODE_IS);
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, nss.db());
- auto collection = db ? db->getCollection(opCtx, nss) : nullptr;
+ auto collection = db ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss) : nullptr;
if (!collection) {
return fieldPaths == std::set<FieldPath>{"_id"};
}
diff --git a/src/mongo/db/query/plan_executor_impl.cpp b/src/mongo/db/query/plan_executor_impl.cpp
index 6281a2d9899..d8c964f842d 100644
--- a/src/mongo/db/query/plan_executor_impl.cpp
+++ b/src/mongo/db/query/plan_executor_impl.cpp
@@ -431,7 +431,7 @@ std::shared_ptr<CappedInsertNotifier> PlanExecutorImpl::_getCappedInsertNotifier
auto databaseHolder = DatabaseHolder::get(_opCtx);
auto db = databaseHolder->getDb(_opCtx, _nss.db());
invariant(db);
- auto collection = db->getCollection(_opCtx, _nss);
+ auto collection = CollectionCatalog::get(_opCtx).lookupCollectionByNamespace(_nss);
invariant(collection);
return collection->getCappedInsertNotifier();
diff --git a/src/mongo/db/repair_database_and_check_version.cpp b/src/mongo/db/repair_database_and_check_version.cpp
index b08d67696c0..4b9868f6037 100644
--- a/src/mongo/db/repair_database_and_check_version.cpp
+++ b/src/mongo/db/repair_database_and_check_version.cpp
@@ -94,14 +94,16 @@ Status restoreMissingFeatureCompatibilityVersionDocument(OperationContext* opCtx
// If the server configuration collection, which contains the FCV document, does not exist, then
// create it.
- if (!db->getCollection(opCtx, NamespaceString::kServerConfigurationNamespace)) {
+ if (!CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ NamespaceString::kServerConfigurationNamespace)) {
log() << "Re-creating the server configuration collection (admin.system.version) that was "
"dropped.";
uassertStatusOK(
createCollection(opCtx, fcvNss.db().toString(), BSON("create" << fcvNss.coll())));
}
- Collection* fcvColl = db->getCollection(opCtx, NamespaceString::kServerConfigurationNamespace);
+ Collection* fcvColl = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ NamespaceString::kServerConfigurationNamespace);
invariant(fcvColl);
// Restore the featureCompatibilityVersion document if it is missing.
@@ -249,7 +251,8 @@ bool hasReplSetConfigDoc(OperationContext* opCtx) {
void checkForCappedOplog(OperationContext* opCtx, Database* db) {
const NamespaceString oplogNss(NamespaceString::kRsOplogNamespace);
invariant(opCtx->lockState()->isDbLockedForMode(oplogNss.db(), MODE_IS));
- Collection* oplogCollection = db->getCollection(opCtx, oplogNss);
+ Collection* oplogCollection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(oplogNss);
if (oplogCollection && !oplogCollection->isCapped()) {
severe() << "The oplog collection " << oplogNss
<< " is not capped; a capped oplog is a requirement for replication to function.";
@@ -395,7 +398,8 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
auto db = databaseHolder->getDb(opCtx, fcvNSS.db());
Collection* versionColl;
BSONObj featureCompatibilityVersion;
- if (!db || !(versionColl = db->getCollection(opCtx, fcvNSS)) ||
+ if (!db ||
+ !(versionColl = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(fcvNSS)) ||
!Helpers::findOne(opCtx,
versionColl,
BSON("_id" << FeatureCompatibilityVersionParser::kParameterName),
@@ -501,8 +505,8 @@ bool repairDatabasesAndCheckVersion(OperationContext* opCtx) {
// If the server configuration collection already contains a valid
// featureCompatibilityVersion document, cache it in-memory as a server parameter.
if (dbName == "admin") {
- if (Collection* versionColl =
- db->getCollection(opCtx, NamespaceString::kServerConfigurationNamespace)) {
+ if (Collection* versionColl = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ NamespaceString::kServerConfigurationNamespace)) {
BSONObj featureCompatibilityVersion;
if (Helpers::findOne(
opCtx,
diff --git a/src/mongo/db/repl/apply_ops.cpp b/src/mongo/db/repl/apply_ops.cpp
index 180ea8b9306..34f241999b0 100644
--- a/src/mongo/db/repl/apply_ops.cpp
+++ b/src/mongo/db/repl/apply_ops.cpp
@@ -151,7 +151,7 @@ Status _applyOps(OperationContext* opCtx,
// NamespaceNotFound.
// Additionally for inserts, we fail early on non-existent collections.
Lock::CollectionLock collectionLock(opCtx, nss, MODE_IX);
- auto collection = db->getCollection(opCtx, nss);
+ auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (!collection && (*opType == 'i' || *opType == 'u')) {
uasserted(
ErrorCodes::AtomicityFailure,
@@ -311,7 +311,7 @@ Status _checkPrecondition(OperationContext* opCtx,
if (!database) {
return {ErrorCodes::NamespaceNotFound, "database in ns does not exist: " + nss.ns()};
}
- Collection* collection = database->getCollection(opCtx, nss);
+ Collection* collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (!collection) {
return {ErrorCodes::NamespaceNotFound, "collection in ns does not exist: " + nss.ns()};
}
diff --git a/src/mongo/db/repl/dbcheck.cpp b/src/mongo/db/repl/dbcheck.cpp
index 90f5391f161..16011047f43 100644
--- a/src/mongo/db/repl/dbcheck.cpp
+++ b/src/mongo/db/repl/dbcheck.cpp
@@ -386,7 +386,8 @@ AutoGetCollectionForDbCheck::AutoGetCollectionForDbCheck(OperationContext* opCtx
: _agd(opCtx, nss), _collLock(opCtx, nss, MODE_S) {
std::string msg;
- _collection = _agd.getDb() ? _agd.getDb()->getCollection(opCtx, nss) : nullptr;
+ _collection =
+ _agd.getDb() ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss) : nullptr;
// If the collection gets deleted after the check is launched, record that in the health log.
if (!_collection) {
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index bdae969393b..edacd2c9940 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -237,7 +237,8 @@ void createIndexForApplyOps(OperationContext* opCtx,
// Check if collection exists.
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, indexNss.ns());
- auto indexCollection = db ? db->getCollection(opCtx, indexNss) : nullptr;
+ auto indexCollection =
+ db ? CollectionCatalog::get(opCtx).lookupCollectionByNamespace(indexNss) : nullptr;
uassert(ErrorCodes::NamespaceNotFound,
str::stream() << "Failed to create index due to missing collection: " << indexNss.ns(),
indexCollection);
@@ -578,7 +579,8 @@ void createOplog(OperationContext* opCtx,
const ReplSettings& replSettings = ReplicationCoordinator::get(opCtx)->getSettings();
OldClientContext ctx(opCtx, oplogCollectionName.ns());
- Collection* collection = ctx.db()->getCollection(opCtx, oplogCollectionName);
+ Collection* collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(oplogCollectionName);
if (collection) {
if (replSettings.getOplogSizeBytes() != 0) {
@@ -1141,7 +1143,7 @@ Status applyOperation_inlock(OperationContext* opCtx,
dassert(opCtx->lockState()->isCollectionLockedForMode(
requestNss, supportsDocLocking() ? MODE_IX : MODE_X),
requestNss.ns());
- collection = db->getCollection(opCtx, requestNss);
+ collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(requestNss);
}
BSONObj o = op.getObject();
@@ -1553,7 +1555,8 @@ Status applyCommand_inlock(OperationContext* opCtx,
Lock::DBLock lock(opCtx, nss.db(), MODE_IS);
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, nss.ns());
- if (db && !db->getCollection(opCtx, nss) && ViewCatalog::get(db)->lookup(opCtx, nss.ns())) {
+ if (db && !CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss) &&
+ ViewCatalog::get(db)->lookup(opCtx, nss.ns())) {
return {ErrorCodes::CommandNotSupportedOnView,
str::stream() << "applyOps not supported on view:" << nss.ns()};
}
diff --git a/src/mongo/db/repl/oplog_interface_local.cpp b/src/mongo/db/repl/oplog_interface_local.cpp
index 9c27ed62149..fe6d6b6742d 100644
--- a/src/mongo/db/repl/oplog_interface_local.cpp
+++ b/src/mongo/db/repl/oplog_interface_local.cpp
@@ -60,12 +60,13 @@ OplogIteratorLocal::OplogIteratorLocal(OperationContext* opCtx)
: _dbLock(opCtx, NamespaceString::kRsOplogNamespace.db(), MODE_IS),
_collectionLock(opCtx, NamespaceString::kRsOplogNamespace, MODE_S),
_ctx(opCtx, NamespaceString::kRsOplogNamespace.ns()),
- _exec(InternalPlanner::collectionScan(
- opCtx,
- NamespaceString::kRsOplogNamespace.ns(),
- _ctx.db()->getCollection(opCtx, NamespaceString::kRsOplogNamespace),
- PlanExecutor::NO_YIELD,
- InternalPlanner::BACKWARD)) {}
+ _exec(
+ InternalPlanner::collectionScan(opCtx,
+ NamespaceString::kRsOplogNamespace.ns(),
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ NamespaceString::kRsOplogNamespace),
+ PlanExecutor::NO_YIELD,
+ InternalPlanner::BACKWARD)) {}
StatusWith<OplogInterface::Iterator::Value> OplogIteratorLocal::next() {
BSONObj obj;
diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp
index 4ef5b7bcc75..a6f58f7b5a9 100644
--- a/src/mongo/db/repl/replication_recovery.cpp
+++ b/src/mongo/db/repl/replication_recovery.cpp
@@ -424,7 +424,8 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx,
const NamespaceString oplogNss(NamespaceString::kRsOplogNamespace);
AutoGetDb autoDb(opCtx, oplogNss.db(), MODE_IX);
Lock::CollectionLock oplogCollectionLoc(opCtx, oplogNss, MODE_X);
- Collection* oplogCollection = autoDb.getDb()->getCollection(opCtx, oplogNss);
+ Collection* oplogCollection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(oplogNss);
if (!oplogCollection) {
fassertFailedWithStatusNoTrace(
34418,
diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp
index cfde823f12e..47209703d97 100644
--- a/src/mongo/db/repl/rs_rollback.cpp
+++ b/src/mongo/db/repl/rs_rollback.cpp
@@ -850,7 +850,7 @@ void dropCollection(OperationContext* opCtx,
void renameOutOfTheWay(OperationContext* opCtx, RenameCollectionInfo info, Database* db) {
// Finds the UUID of the collection that we are renaming out of the way.
- auto collection = db->getCollection(opCtx, info.renameTo);
+ auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(info.renameTo);
invariant(collection);
// The generated unique collection name is only guaranteed to exist if the database is
@@ -1528,7 +1528,8 @@ void rollback_internal::syncFixUp(OperationContext* opCtx,
Lock::DBLock oplogDbLock(opCtx, oplogNss.db(), MODE_IX);
Lock::CollectionLock oplogCollectionLoc(opCtx, oplogNss, MODE_X);
OldClientContext ctx(opCtx, oplogNss.ns());
- Collection* oplogCollection = ctx.db()->getCollection(opCtx, oplogNss);
+ Collection* oplogCollection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(oplogNss);
if (!oplogCollection) {
fassertFailedWithStatusNoTrace(
40495,
diff --git a/src/mongo/db/repl/rs_rollback_test.cpp b/src/mongo/db/repl/rs_rollback_test.cpp
index 85d13299072..337144013b0 100644
--- a/src/mongo/db/repl/rs_rollback_test.cpp
+++ b/src/mongo/db/repl/rs_rollback_test.cpp
@@ -325,7 +325,8 @@ int _testRollbackDelete(OperationContext* opCtx,
auto databaseHolder = DatabaseHolder::get(opCtx);
auto db = databaseHolder->getDb(opCtx, "test");
ASSERT_TRUE(db);
- auto collection = db->getCollection(opCtx, NamespaceString("test.t"));
+ auto collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(NamespaceString("test.t"));
if (!collection) {
return -1;
}
@@ -1511,7 +1512,8 @@ TEST_F(RSRollbackTest, RollbackApplyOpsCommand) {
{
AutoGetOrCreateDb autoDb(_opCtx.get(), "test", MODE_X);
mongo::WriteUnitOfWork wuow(_opCtx.get());
- coll = autoDb.getDb()->getCollection(_opCtx.get(), NamespaceString("test.t"));
+ coll = CollectionCatalog::get(_opCtx.get())
+ .lookupCollectionByNamespace(NamespaceString("test.t"));
if (!coll) {
coll =
autoDb.getDb()->createCollection(_opCtx.get(), NamespaceString("test.t"), options);
@@ -1656,7 +1658,8 @@ TEST_F(RSRollbackTest, RollbackCreateCollectionCommand) {
auto databaseHolder = DatabaseHolder::get(_opCtx.get());
auto db = databaseHolder->getDb(_opCtx.get(), "test");
ASSERT_TRUE(db);
- ASSERT_FALSE(db->getCollection(_opCtx.get(), NamespaceString("test.t")));
+ ASSERT_FALSE(CollectionCatalog::get(_opCtx.get())
+ .lookupCollectionByNamespace(NamespaceString("test.t")));
}
}
diff --git a/src/mongo/db/repl/storage_interface_impl.cpp b/src/mongo/db/repl/storage_interface_impl.cpp
index dde8249541d..79a05656b9d 100644
--- a/src/mongo/db/repl/storage_interface_impl.cpp
+++ b/src/mongo/db/repl/storage_interface_impl.cpp
@@ -440,7 +440,7 @@ Status StorageInterfaceImpl::createCollection(OperationContext* opCtx,
AutoGetOrCreateDb databaseWriteGuard(opCtx, nss.db(), MODE_X);
auto db = databaseWriteGuard.getDb();
invariant(db);
- if (db->getCollection(opCtx, nss)) {
+ if (CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss)) {
return Status(ErrorCodes::NamespaceExists,
str::stream() << "Collection " << nss.ns() << " already exists.");
}
@@ -1109,12 +1109,13 @@ Status StorageInterfaceImpl::isAdminDbValid(OperationContext* opCtx) {
return Status::OK();
}
- Collection* const usersCollection =
- adminDb->getCollection(opCtx, AuthorizationManager::usersCollectionNamespace);
+ Collection* const usersCollection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ AuthorizationManager::usersCollectionNamespace);
const bool hasUsers =
usersCollection && !Helpers::findOne(opCtx, usersCollection, BSONObj(), false).isNull();
Collection* const adminVersionCollection =
- adminDb->getCollection(opCtx, AuthorizationManager::versionCollectionNamespace);
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(
+ AuthorizationManager::versionCollectionNamespace);
BSONObj authSchemaVersionDocument;
if (!adminVersionCollection ||
!Helpers::findOne(opCtx,
diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp
index a5402fadfa7..79bf0c3c345 100644
--- a/src/mongo/db/repl/sync_tail.cpp
+++ b/src/mongo/db/repl/sync_tail.cpp
@@ -201,7 +201,7 @@ private:
return collProperties;
}
- auto collection = db->getCollection(opCtx, nss);
+ auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (!collection) {
return collProperties;
}
diff --git a/src/mongo/db/s/implicit_create_collection.cpp b/src/mongo/db/s/implicit_create_collection.cpp
index b0ccfc17e37..0154d3cff40 100644
--- a/src/mongo/db/s/implicit_create_collection.cpp
+++ b/src/mongo/db/s/implicit_create_collection.cpp
@@ -98,7 +98,7 @@ public:
auto db = databaseHolder->getDb(opCtx, _ns.db());
if (db) {
Lock::CollectionLock collLock(opCtx, _ns, MODE_IS);
- if (db->getCollection(opCtx, _ns)) {
+ if (CollectionCatalog::get(opCtx).lookupCollectionByNamespace(_ns)) {
// Collection already created, no more work needs to be done.
return Status::OK();
}
diff --git a/src/mongo/db/s/migration_destination_manager.cpp b/src/mongo/db/s/migration_destination_manager.cpp
index 307512ae2d8..c8817889615 100644
--- a/src/mongo/db/s/migration_destination_manager.cpp
+++ b/src/mongo/db/s/migration_destination_manager.cpp
@@ -651,7 +651,7 @@ void MigrationDestinationManager::cloneCollectionIndexesAndOptions(OperationCont
AutoGetOrCreateDb autoCreateDb(opCtx, nss.db(), MODE_X);
auto db = autoCreateDb.getDb();
- auto collection = db->getCollection(opCtx, nss);
+ auto collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
if (collection) {
checkUUIDsMatch(collection);
} else {
@@ -664,7 +664,7 @@ void MigrationDestinationManager::cloneCollectionIndexesAndOptions(OperationCont
uassertStatusOK(db->userCreateNS(
opCtx, nss, collectionOptions, createDefaultIndexes, donorIdIndexSpec));
wuow.commit();
- collection = db->getCollection(opCtx, nss);
+ collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
}
auto indexSpecs = checkEmptyOrGetMissingIndexesFromDonor(collection);
diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp
index 33c17c478d2..43fa7f3d12e 100644
--- a/src/mongo/db/s/set_shard_version_command.cpp
+++ b/src/mongo/db/s/set_shard_version_command.cpp
@@ -225,7 +225,8 @@ public:
// Views do not require a shard version check. We do not care about invalid system views
// for this check, only to validate if a view already exists for this namespace.
- if (autoDb->getDb() && !autoDb->getDb()->getCollection(opCtx, nss) &&
+ if (autoDb->getDb() &&
+ !CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss) &&
ViewCatalog::get(autoDb->getDb())
->lookupWithoutValidatingDurableViews(opCtx, nss.ns())) {
return true;
diff --git a/src/mongo/db/storage/SConscript b/src/mongo/db/storage/SConscript
index 44e3e5abb99..9d7a10e54b0 100644
--- a/src/mongo/db/storage/SConscript
+++ b/src/mongo/db/storage/SConscript
@@ -103,6 +103,7 @@ env.Library(
LIBDEPS_PRIVATE=[
'$BUILD_DIR/mongo/base',
'$BUILD_DIR/mongo/db/catalog/collection',
+ '$BUILD_DIR/mongo/db/catalog/collection_catalog',
'$BUILD_DIR/mongo/db/catalog/database_holder',
'$BUILD_DIR/mongo/db/concurrency/lock_manager',
'$BUILD_DIR/mongo/db/namespace_string',
diff --git a/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp b/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp
index aa6b997f75f..6c5cfec31e6 100644
--- a/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp
+++ b/src/mongo/db/storage/oplog_cap_maintainer_thread.cpp
@@ -36,6 +36,7 @@
#include "mongo/base/error_codes.h"
#include "mongo/base/string_data.h"
#include "mongo/db/catalog/collection.h"
+#include "mongo/db/catalog/collection_catalog.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/client.h"
#include "mongo/db/concurrency/d_concurrency.h"
@@ -86,7 +87,8 @@ bool OplogCapMaintainerThread::_deleteExcessDocuments() {
// We need to hold the database lock while getting the collection. Otherwise a
// concurrent collection creation would write to the map in the Database object
// while we concurrently read the map.
- Collection* collection = db->getCollection(opCtx.get(), oplogNss);
+ Collection* collection =
+ CollectionCatalog::get(opCtx.get()).lookupCollectionByNamespace(oplogNss);
if (!collection) {
LOG(2) << "no collection " << oplogNss;
return false;
diff --git a/src/mongo/db/system_index.cpp b/src/mongo/db/system_index.cpp
index b3b8ed740a6..3cde99b3a97 100644
--- a/src/mongo/db/system_index.cpp
+++ b/src/mongo/db/system_index.cpp
@@ -157,7 +157,8 @@ Status verifySystemIndexes(OperationContext* opCtx) {
return Status::OK();
}
- Collection* collection = autoDb.getDb()->getCollection(opCtx, systemUsers);
+ Collection* collection =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(systemUsers);
if (collection) {
IndexCatalog* indexCatalog = collection->getIndexCatalog();
invariant(indexCatalog);
@@ -187,7 +188,7 @@ Status verifySystemIndexes(OperationContext* opCtx) {
}
// Ensure that system indexes exist for the roles collection, if it exists.
- collection = autoDb.getDb()->getCollection(opCtx, systemRoles);
+ collection = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(systemRoles);
if (collection) {
IndexCatalog* indexCatalog = collection->getIndexCatalog();
invariant(indexCatalog);
diff --git a/src/mongo/db/transaction_participant.cpp b/src/mongo/db/transaction_participant.cpp
index ee73c565bbb..8ff2c3211c8 100644
--- a/src/mongo/db/transaction_participant.cpp
+++ b/src/mongo/db/transaction_participant.cpp
@@ -347,7 +347,7 @@ TransactionParticipant::getOldestActiveTimestamp(Timestamp stableTimestamp) {
return boost::none;
}
- auto collection = db->getCollection(opCtx.get(), nss);
+ auto collection = CollectionCatalog::get(opCtx.get()).lookupCollectionByNamespace(nss);
if (!collection) {
return boost::none;
}
diff --git a/src/mongo/db/transaction_participant_test.cpp b/src/mongo/db/transaction_participant_test.cpp
index 3c100de4122..65e94f4355b 100644
--- a/src/mongo/db/transaction_participant_test.cpp
+++ b/src/mongo/db/transaction_participant_test.cpp
@@ -3788,7 +3788,7 @@ TEST_F(TxnParticipantTest, OldestActiveTransactionTimestamp) {
AutoGetOrCreateDb autoDb(opCtx(), nss.db(), MODE_X);
WriteUnitOfWork wuow(opCtx());
- auto coll = autoDb.getDb()->getCollection(opCtx(), nss);
+ auto coll = CollectionCatalog::get(opCtx()).lookupCollectionByNamespace(nss);
ASSERT(coll);
OpDebug* const nullOpDebug = nullptr;
ASSERT_OK(
@@ -3800,7 +3800,7 @@ TEST_F(TxnParticipantTest, OldestActiveTransactionTimestamp) {
Timestamp ts(1, i);
AutoGetOrCreateDb autoDb(opCtx(), nss.db(), MODE_X);
WriteUnitOfWork wuow(opCtx());
- auto coll = autoDb.getDb()->getCollection(opCtx(), nss);
+ auto coll = CollectionCatalog::get(opCtx()).lookupCollectionByNamespace(nss);
ASSERT(coll);
auto cursor = coll->getCursor(opCtx());
while (auto record = cursor->next()) {
diff --git a/src/mongo/db/views/durable_view_catalog.cpp b/src/mongo/db/views/durable_view_catalog.cpp
index 3d969308c9a..86afedc12a7 100644
--- a/src/mongo/db/views/durable_view_catalog.cpp
+++ b/src/mongo/db/views/durable_view_catalog.cpp
@@ -111,7 +111,8 @@ void DurableViewCatalogImpl::_iterate(OperationContext* opCtx,
ViewCatalogLookupBehavior lookupBehavior) {
invariant(opCtx->lockState()->isCollectionLockedForMode(_db->getSystemViewsName(), MODE_IS));
- Collection* systemViews = _db->getCollection(opCtx, _db->getSystemViewsName());
+ Collection* systemViews =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(_db->getSystemViewsName());
if (!systemViews) {
return;
}
@@ -185,7 +186,8 @@ void DurableViewCatalogImpl::upsert(OperationContext* opCtx,
NamespaceString systemViewsNs(_db->getSystemViewsName());
dassert(opCtx->lockState()->isCollectionLockedForMode(systemViewsNs, MODE_X));
- Collection* systemViews = _db->getCollection(opCtx, systemViewsNs);
+ Collection* systemViews =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(systemViewsNs);
invariant(systemViews);
const bool requireIndex = false;
@@ -212,7 +214,8 @@ void DurableViewCatalogImpl::remove(OperationContext* opCtx, const NamespaceStri
dassert(opCtx->lockState()->isDbLockedForMode(_db->name(), MODE_IX));
dassert(opCtx->lockState()->isCollectionLockedForMode(name, MODE_IX));
- Collection* systemViews = _db->getCollection(opCtx, _db->getSystemViewsName());
+ Collection* systemViews =
+ CollectionCatalog::get(opCtx).lookupCollectionByNamespace(_db->getSystemViewsName());
dassert(opCtx->lockState()->isCollectionLockedForMode(systemViews->ns(), MODE_X));
if (!systemViews)
diff --git a/src/mongo/dbtests/counttests.cpp b/src/mongo/dbtests/counttests.cpp
index 41ad97c5203..a5a614016da 100644
--- a/src/mongo/dbtests/counttests.cpp
+++ b/src/mongo/dbtests/counttests.cpp
@@ -51,7 +51,7 @@ public:
{
WriteUnitOfWork wunit(&_opCtx);
- _collection = _database->getCollection(&_opCtx, nss());
+ _collection = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (_collection) {
_database->dropCollection(&_opCtx, nss()).transitional_ignore();
}
diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp
index 62238c52cf7..bba6a636a30 100644
--- a/src/mongo/dbtests/dbtests.cpp
+++ b/src/mongo/dbtests/dbtests.cpp
@@ -99,7 +99,10 @@ Status createIndexFromSpec(OperationContext* opCtx, StringData ns, const BSONObj
Collection* coll;
{
WriteUnitOfWork wunit(opCtx);
- coll = autoDb.getDb()->getOrCreateCollection(opCtx, NamespaceString(ns));
+ coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(NamespaceString(ns));
+ if (!coll) {
+ coll = autoDb.getDb()->createCollection(opCtx, NamespaceString(ns));
+ }
invariant(coll);
wunit.commit();
}
diff --git a/src/mongo/dbtests/dbtests.h b/src/mongo/dbtests/dbtests.h
index e64772a11b7..f0b0166aecb 100644
--- a/src/mongo/dbtests/dbtests.h
+++ b/src/mongo/dbtests/dbtests.h
@@ -80,7 +80,7 @@ public:
}
Collection* getCollection() const {
- return db()->getCollection(_opCtx, _nss);
+ return CollectionCatalog::get(_opCtx).lookupCollectionByNamespace(_nss);
}
private:
diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp
index b4f09c83c52..a57a3fb0619 100644
--- a/src/mongo/dbtests/pdfiletests.cpp
+++ b/src/mongo/dbtests/pdfiletests.cpp
@@ -60,7 +60,7 @@ protected:
return NamespaceString("unittests.pdfiletests.Insert");
}
Collection* collection() {
- return _context.db()->getCollection(&_opCtx, nss());
+ return CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
}
const ServiceContext::UniqueOperationContext _opCtxPtr = cc().makeOperationContext();
@@ -75,15 +75,19 @@ public:
WriteUnitOfWork wunit(&_opCtx);
BSONObj x = BSON("x" << 1);
ASSERT(x["_id"].type() == 0);
- Collection* collection = _context.db()->getOrCreateCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
+ if (!coll) {
+ coll = _context.db()->createCollection(&_opCtx, nss());
+ }
+ ASSERT(coll);
OpDebug* const nullOpDebug = nullptr;
- ASSERT(!collection->insertDocument(&_opCtx, InsertStatement(x), nullOpDebug, true).isOK());
+ ASSERT(!coll->insertDocument(&_opCtx, InsertStatement(x), nullOpDebug, true).isOK());
StatusWith<BSONObj> fixed = fixDocumentForInsert(_opCtx.getServiceContext(), x);
ASSERT(fixed.isOK());
x = fixed.getValue();
ASSERT(x["_id"].type() == jstOID);
- ASSERT(collection->insertDocument(&_opCtx, InsertStatement(x), nullOpDebug, true).isOK());
+ ASSERT(coll->insertDocument(&_opCtx, InsertStatement(x), nullOpDebug, true).isOK());
wunit.commit();
}
};
diff --git a/src/mongo/dbtests/plan_executor_invalidation_test.cpp b/src/mongo/dbtests/plan_executor_invalidation_test.cpp
index 590d518feae..8cb1e1401d9 100644
--- a/src/mongo/dbtests/plan_executor_invalidation_test.cpp
+++ b/src/mongo/dbtests/plan_executor_invalidation_test.cpp
@@ -85,11 +85,13 @@ public:
std::unique_ptr<CanonicalQuery> cq = std::move(statusWithCQ.getValue());
// Takes ownership of 'ws', 'scan', and 'cq'.
- auto statusWithPlanExecutor = PlanExecutor::make(std::move(cq),
- std::move(ws),
- std::move(scan),
- _ctx->db()->getCollection(&_opCtx, nss),
- PlanExecutor::YIELD_MANUAL);
+ auto statusWithPlanExecutor =
+ PlanExecutor::make(std::move(cq),
+ std::move(ws),
+ std::move(scan),
+ CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss),
+ PlanExecutor::YIELD_MANUAL);
+
ASSERT_OK(statusWithPlanExecutor.getStatus());
return std::move(statusWithPlanExecutor.getValue());
}
@@ -115,7 +117,7 @@ public:
}
Collection* collection() {
- return _ctx->db()->getCollection(&_opCtx, nss);
+ return CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss);
}
void truncateCollection(Collection* collection) const {
diff --git a/src/mongo/dbtests/query_plan_executor.cpp b/src/mongo/dbtests/query_plan_executor.cpp
index be1b3448555..1726b5c994f 100644
--- a/src/mongo/dbtests/query_plan_executor.cpp
+++ b/src/mongo/dbtests/query_plan_executor.cpp
@@ -148,7 +148,8 @@ public:
ixparams.bounds.endKey = BSON("" << end);
ixparams.bounds.boundInclusion = BoundInclusion::kIncludeBothStartAndEndKeys;
- const Collection* coll = db->getCollection(&_opCtx, nss);
+ const Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss);
+
unique_ptr<WorkingSet> ws(new WorkingSet());
auto ixscan = std::make_unique<IndexScan>(&_opCtx, ixparams, ws.get(), nullptr);
@@ -174,7 +175,7 @@ protected:
private:
const IndexDescriptor* getIndex(Database* db, const BSONObj& obj) {
- Collection* collection = db->getCollection(&_opCtx, nss);
+ Collection* collection = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss);
std::vector<const IndexDescriptor*> indexes;
collection->getIndexCatalog()->findIndexesByKeyPattern(&_opCtx, obj, false, &indexes);
ASSERT_LTE(indexes.size(), 1U);
diff --git a/src/mongo/dbtests/query_stage_count_scan.cpp b/src/mongo/dbtests/query_stage_count_scan.cpp
index 9b6a4f94383..0b3e05c5cba 100644
--- a/src/mongo/dbtests/query_stage_count_scan.cpp
+++ b/src/mongo/dbtests/query_stage_count_scan.cpp
@@ -92,7 +92,8 @@ public:
}
const IndexDescriptor* getIndex(Database* db, const BSONObj& obj) {
- Collection* collection = db->getCollection(&_opCtx, NamespaceString(ns()));
+ Collection* collection =
+ CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(NamespaceString(ns()));
std::vector<const IndexDescriptor*> indexes;
collection->getIndexCatalog()->findIndexesByKeyPattern(&_opCtx, obj, false, &indexes);
return indexes.empty() ? nullptr : indexes[0];
diff --git a/src/mongo/dbtests/query_stage_fetch.cpp b/src/mongo/dbtests/query_stage_fetch.cpp
index 8e6b0930e90..61a472f82e2 100644
--- a/src/mongo/dbtests/query_stage_fetch.cpp
+++ b/src/mongo/dbtests/query_stage_fetch.cpp
@@ -99,7 +99,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -165,7 +165,7 @@ public:
Lock::DBLock lk(&_opCtx, nss().db(), MODE_X);
OldClientContext ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
diff --git a/src/mongo/dbtests/query_stage_merge_sort.cpp b/src/mongo/dbtests/query_stage_merge_sort.cpp
index 14a0d2019d8..75795c5978e 100644
--- a/src/mongo/dbtests/query_stage_merge_sort.cpp
+++ b/src/mongo/dbtests/query_stage_merge_sort.cpp
@@ -145,7 +145,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -210,7 +210,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -274,7 +274,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -339,7 +339,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -408,7 +408,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -471,7 +471,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -523,7 +523,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -640,7 +640,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -742,7 +742,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -808,7 +808,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
diff --git a/src/mongo/dbtests/query_stage_sort.cpp b/src/mongo/dbtests/query_stage_sort.cpp
index 1bb68145894..db699ced854 100644
--- a/src/mongo/dbtests/query_stage_sort.cpp
+++ b/src/mongo/dbtests/query_stage_sort.cpp
@@ -241,7 +241,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -263,7 +263,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -294,7 +294,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -319,7 +319,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -428,7 +428,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -526,7 +526,7 @@ public:
void run() {
dbtests::WriteContextForTests ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wuow(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
diff --git a/src/mongo/dbtests/query_stage_update.cpp b/src/mongo/dbtests/query_stage_update.cpp
index 0ce3c6cbe37..665ae70f031 100644
--- a/src/mongo/dbtests/query_stage_update.cpp
+++ b/src/mongo/dbtests/query_stage_update.cpp
@@ -272,8 +272,7 @@ public:
OpDebug* opDebug = &curOp.debug();
const CollatorInterface* collator = nullptr;
UpdateDriver driver(new ExpressionContext(&_opCtx, collator));
- Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss);
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(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 9792bfcb7b4..47cb3f55f4d 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -68,7 +68,7 @@ public:
{
WriteUnitOfWork wunit(&_opCtx);
_database = _context.db();
- _collection = _database->getCollection(&_opCtx, nss());
+ _collection = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (_collection) {
_database->dropCollection(&_opCtx, nss()).transitional_ignore();
}
@@ -219,7 +219,7 @@ public:
{
WriteUnitOfWork wunit(&_opCtx);
Database* db = ctx.db();
- if (db->getCollection(&_opCtx, nss())) {
+ if (CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss())) {
_collection = nullptr;
db->dropCollection(&_opCtx, nss()).transitional_ignore();
}
diff --git a/src/mongo/dbtests/repltests.cpp b/src/mongo/dbtests/repltests.cpp
index 7ca7eb19d80..638e339766a 100644
--- a/src/mongo/dbtests/repltests.cpp
+++ b/src/mongo/dbtests/repltests.cpp
@@ -138,7 +138,7 @@ public:
dbtests::WriteContextForTests ctx(&_opCtx, ns());
WriteUnitOfWork wuow(&_opCtx);
- Collection* c = ctx.db()->getCollection(&_opCtx, nss());
+ Collection* c = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!c) {
c = ctx.db()->createCollection(&_opCtx, nss());
}
@@ -208,7 +208,7 @@ protected:
Lock::GlobalWrite lk(&_opCtx);
OldClientContext ctx(&_opCtx, ns());
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
WriteUnitOfWork wunit(&_opCtx);
coll = db->createCollection(&_opCtx, nss());
@@ -265,7 +265,7 @@ protected:
NamespaceString nss(ns);
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss);
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss);
if (!coll) {
WriteUnitOfWork wunit(&_opCtx);
coll = db->createCollection(&_opCtx, nss);
@@ -286,7 +286,7 @@ protected:
OldClientContext ctx(&_opCtx, ns);
WriteUnitOfWork wunit(&_opCtx);
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss);
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss);
if (!coll) {
coll = db->createCollection(&_opCtx, nss);
}
@@ -300,7 +300,7 @@ protected:
OldClientContext ctx(&_opCtx, ns());
WriteUnitOfWork wunit(&_opCtx);
Database* db = ctx.db();
- Collection* coll = db->getCollection(&_opCtx, nss());
+ Collection* coll = CollectionCatalog::get(&_opCtx).lookupCollectionByNamespace(nss());
if (!coll) {
coll = db->createCollection(&_opCtx, nss());
}
diff --git a/src/mongo/dbtests/rollbacktests.cpp b/src/mongo/dbtests/rollbacktests.cpp
index cd8f785d99b..d9417770b49 100644
--- a/src/mongo/dbtests/rollbacktests.cpp
+++ b/src/mongo/dbtests/rollbacktests.cpp
@@ -87,20 +87,17 @@ Status renameCollection(OperationContext* opCtx,
return renameCollection(opCtx, source, target, {});
}
Status truncateCollection(OperationContext* opCtx, const NamespaceString& nss) {
- auto databaseHolder = DatabaseHolder::get(opCtx);
- auto coll = databaseHolder->getDb(opCtx, nss.db())->getCollection(opCtx, nss);
+ auto coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
return coll->truncate(opCtx);
}
void insertRecord(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& data) {
- auto databaseHolder = DatabaseHolder::get(opCtx);
- auto coll = databaseHolder->getDb(opCtx, nss.db())->getCollection(opCtx, nss);
+ auto coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
OpDebug* const nullOpDebug = nullptr;
ASSERT_OK(coll->insertDocument(opCtx, InsertStatement(data), nullOpDebug, false));
}
void assertOnlyRecord(OperationContext* opCtx, const NamespaceString& nss, const BSONObj& data) {
- auto databaseHolder = DatabaseHolder::get(opCtx);
- auto coll = databaseHolder->getDb(opCtx, nss.db())->getCollection(opCtx, nss);
+ auto coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
auto cursor = coll->getCursor(opCtx);
auto record = cursor->next();
@@ -110,18 +107,15 @@ void assertOnlyRecord(OperationContext* opCtx, const NamespaceString& nss, const
ASSERT(!cursor->next());
}
void assertEmpty(OperationContext* opCtx, const NamespaceString& nss) {
- auto databaseHolder = DatabaseHolder::get(opCtx);
- auto coll = databaseHolder->getDb(opCtx, nss.db())->getCollection(opCtx, nss);
+ auto coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
ASSERT(!coll->getCursor(opCtx)->next());
}
bool indexExists(OperationContext* opCtx, const NamespaceString& nss, const string& idxName) {
- auto databaseHolder = DatabaseHolder::get(opCtx);
- auto coll = databaseHolder->getDb(opCtx, nss.db())->getCollection(opCtx, nss);
+ auto coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
return coll->getIndexCatalog()->findIndexByName(opCtx, idxName, true) != nullptr;
}
bool indexReady(OperationContext* opCtx, const NamespaceString& nss, const string& idxName) {
- auto databaseHolder = DatabaseHolder::get(opCtx);
- auto coll = databaseHolder->getDb(opCtx, nss.db())->getCollection(opCtx, nss);
+ auto coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
return coll->getIndexCatalog()->findIndexByName(opCtx, idxName, false) != nullptr;
}
size_t getNumIndexEntries(OperationContext* opCtx,
@@ -129,8 +123,7 @@ size_t getNumIndexEntries(OperationContext* opCtx,
const string& idxName) {
size_t numEntries = 0;
- auto databaseHolder = DatabaseHolder::get(opCtx);
- auto coll = databaseHolder->getDb(opCtx, nss.db())->getCollection(opCtx, nss);
+ auto coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
IndexCatalog* catalog = coll->getIndexCatalog();
auto desc = catalog->findIndexByName(opCtx, idxName, false);
@@ -152,8 +145,7 @@ size_t getNumIndexEntries(OperationContext* opCtx,
}
void dropIndex(OperationContext* opCtx, const NamespaceString& nss, const string& idxName) {
- auto databaseHolder = DatabaseHolder::get(opCtx);
- auto coll = databaseHolder->getDb(opCtx, nss.db())->getCollection(opCtx, nss);
+ auto coll = CollectionCatalog::get(opCtx).lookupCollectionByNamespace(nss);
auto desc = coll->getIndexCatalog()->findIndexByName(opCtx, idxName);
ASSERT(desc);
ASSERT_OK(coll->getIndexCatalog()->dropIndex(opCtx, desc));
@@ -543,7 +535,7 @@ public:
AutoGetDb autoDb(&opCtx, nss.db(), MODE_X);
- Collection* coll = autoDb.getDb()->getCollection(&opCtx, nss);
+ Collection* coll = CollectionCatalog::get(&opCtx).lookupCollectionByNamespace(nss);
IndexCatalog* catalog = coll->getIndexCatalog();
string idxName = "a";
@@ -584,7 +576,7 @@ public:
AutoGetDb autoDb(&opCtx, nss.db(), MODE_X);
- Collection* coll = autoDb.getDb()->getCollection(&opCtx, nss);
+ Collection* coll = CollectionCatalog::get(&opCtx).lookupCollectionByNamespace(nss);
IndexCatalog* catalog = coll->getIndexCatalog();
string idxName = "a";
@@ -637,7 +629,7 @@ public:
AutoGetDb autoDb(&opCtx, nss.db(), MODE_X);
- Collection* coll = autoDb.getDb()->getCollection(&opCtx, nss);
+ Collection* coll = CollectionCatalog::get(&opCtx).lookupCollectionByNamespace(nss);
IndexCatalog* catalog = coll->getIndexCatalog();
string idxName = "a";
@@ -700,7 +692,7 @@ public:
assertGet(CollectionOptions::parse(BSONObj(), CollectionOptions::parseForCommand));
ASSERT_OK(ctx.db()->userCreateNS(&opCtx, nss, collectionOptions, false));
ASSERT(collectionExists(&opCtx, &ctx, nss.ns()));
- Collection* coll = ctx.db()->getCollection(&opCtx, nss);
+ Collection* coll = CollectionCatalog::get(&opCtx).lookupCollectionByNamespace(nss);
IndexCatalog* catalog = coll->getIndexCatalog();
ASSERT_OK(catalog->createIndexOnEmptyCollection(&opCtx, specA));