diff options
Diffstat (limited to 'src')
21 files changed, 60 insertions, 58 deletions
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp index a12247d6b69..91bf8f07154 100644 --- a/src/mongo/db/catalog/capped_utils.cpp +++ b/src/mongo/db/catalog/capped_utils.cpp @@ -74,7 +74,7 @@ Status emptyCapped(OperationContext* opCtx, const NamespaceString& collectionNam CollectionWriter collection(opCtx, collectionName); uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "emptycapped not supported on view: " << collectionName.ns(), - collection || !ViewCatalog::get(db)->lookup(opCtx, collectionName.ns())); + collection || !ViewCatalog::get(db)->lookup(opCtx, collectionName)); uassert(ErrorCodes::NamespaceNotFound, "no such collection", collection); if (collectionName.isSystem() && !collectionName.isSystemDotProfile()) { @@ -126,7 +126,7 @@ void cloneCollectionAsCapped(OperationContext* opCtx, if (!fromCollection) { uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "cloneCollectionAsCapped not supported for views: " << fromNss, - !ViewCatalog::get(db)->lookup(opCtx, fromNss.ns())); + !ViewCatalog::get(db)->lookup(opCtx, fromNss)); uasserted(ErrorCodes::NamespaceNotFound, str::stream() << "source collection " << fromNss << " does not exist"); diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp index 3f3482dc199..4089551c0e6 100644 --- a/src/mongo/db/catalog/coll_mod.cpp +++ b/src/mongo/db/catalog/coll_mod.cpp @@ -501,7 +501,7 @@ Status _collModInternal(OperationContext* opCtx, // May also modify a view instead of a collection. boost::optional<ViewDefinition> view; if (db && !coll) { - const auto sharedView = ViewCatalog::get(db)->lookup(opCtx, nss.ns()); + const auto sharedView = ViewCatalog::get(db)->lookup(opCtx, nss); if (sharedView) { // We copy the ViewDefinition as it is modified below to represent the requested state. view = {*sharedView}; diff --git a/src/mongo/db/catalog/collection_compact.cpp b/src/mongo/db/catalog/collection_compact.cpp index 6f699daf158..da74618fc1a 100644 --- a/src/mongo/db/catalog/collection_compact.cpp +++ b/src/mongo/db/catalog/collection_compact.cpp @@ -60,7 +60,7 @@ CollectionPtr getCollectionForCompact(OperationContext* opCtx, if (!collection) { std::shared_ptr<const ViewDefinition> view = - ViewCatalog::get(database)->lookup(opCtx, collectionNss.ns()); + ViewCatalog::get(database)->lookup(opCtx, collectionNss); uassert(ErrorCodes::CommandNotSupportedOnView, "can't compact a view", !view); uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist"); } diff --git a/src/mongo/db/catalog/create_collection.cpp b/src/mongo/db/catalog/create_collection.cpp index 8ebd4f8c9ee..4f7a8167d69 100644 --- a/src/mongo/db/catalog/create_collection.cpp +++ b/src/mongo/db/catalog/create_collection.cpp @@ -205,7 +205,7 @@ Status _createTimeseries(OperationContext* opCtx, } auto db = autoDb.ensureDbExists(); - if (auto view = ViewCatalog::get(db)->lookup(opCtx, ns.ns()); view) { + if (auto view = ViewCatalog::get(db)->lookup(opCtx, ns); view) { if (view->timeseries()) { return Status(ErrorCodes::NamespaceExists, str::stream() @@ -292,7 +292,7 @@ Status _createTimeseries(OperationContext* opCtx, } auto db = autoColl.ensureDbExists(); - if (auto view = ViewCatalog::get(db)->lookup(opCtx, ns.ns())) { + if (auto view = ViewCatalog::get(db)->lookup(opCtx, ns)) { if (view->timeseries()) { return {ErrorCodes::NamespaceExists, str::stream() << "A timeseries collection already exists. NS: " << ns}; @@ -384,7 +384,7 @@ Status _createCollection(OperationContext* opCtx, str::stream() << "Collection already exists. NS: " << nss); } auto db = autoDb.ensureDbExists(); - if (auto view = ViewCatalog::get(db)->lookup(opCtx, nss.ns()); view) { + if (auto view = ViewCatalog::get(db)->lookup(opCtx, nss); view) { if (view->timeseries()) { return Status(ErrorCodes::NamespaceExists, str::stream() diff --git a/src/mongo/db/catalog/drop_collection.cpp b/src/mongo/db/catalog/drop_collection.cpp index 5377d433fe2..e15204ddfca 100644 --- a/src/mongo/db/catalog/drop_collection.cpp +++ b/src/mongo/db/catalog/drop_collection.cpp @@ -77,8 +77,7 @@ Status _dropView(OperationContext* opCtx, audit::logDropView(opCtx->getClient(), collectionName, "", {}, status.code()); return status; } - auto view = - ViewCatalog::get(db)->lookupWithoutValidatingDurableViews(opCtx, collectionName.ns()); + auto view = ViewCatalog::get(db)->lookupWithoutValidatingDurableViews(opCtx, collectionName); if (!view) { Status status = Status(ErrorCodes::NamespaceNotFound, "ns not found"); audit::logDropView(opCtx->getClient(), collectionName, "", {}, status.code()); @@ -86,7 +85,7 @@ Status _dropView(OperationContext* opCtx, } // Validates the view or throws an "invalid view" error. - ViewCatalog::get(db)->lookup(opCtx, collectionName.ns()); + ViewCatalog::get(db)->lookup(opCtx, collectionName); Lock::CollectionLock collLock(opCtx, collectionName, MODE_IX); // Operations all lock system.views in the end to prevent deadlock. @@ -361,8 +360,8 @@ Status dropCollection(OperationContext* opCtx, false /* appendNs */); }; - auto view = ViewCatalog::get(db)->lookupWithoutValidatingDurableViews( - opCtx, collectionName.ns()); + auto view = + ViewCatalog::get(db)->lookupWithoutValidatingDurableViews(opCtx, collectionName); if (!view) { // Timeseries bucket collection may exist even without the view. If that is the case // delete it. diff --git a/src/mongo/db/catalog/drop_indexes.cpp b/src/mongo/db/catalog/drop_indexes.cpp index 4af7afc812e..b299eec9ec7 100644 --- a/src/mongo/db/catalog/drop_indexes.cpp +++ b/src/mongo/db/catalog/drop_indexes.cpp @@ -65,7 +65,7 @@ Status checkView(OperationContext* opCtx, Database* db, const CollectionPtr& collection) { if (!collection) { - if (db && ViewCatalog::get(db)->lookup(opCtx, nss.ns())) { + if (db && ViewCatalog::get(db)->lookup(opCtx, nss)) { return Status(ErrorCodes::CommandNotSupportedOnView, str::stream() << "Cannot drop indexes on view " << nss); } diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index 429f8100455..06f1fa8bc35 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -106,7 +106,7 @@ Status checkSourceAndTargetNamespaces(OperationContext* opCtx, auto catalog = CollectionCatalog::get(opCtx); const auto sourceColl = catalog->lookupCollectionByNamespace(opCtx, source); if (!sourceColl) { - if (ViewCatalog::get(db)->lookup(opCtx, source.ns())) + if (ViewCatalog::get(db)->lookup(opCtx, source)) return Status(ErrorCodes::CommandNotSupportedOnView, str::stream() << "cannot rename view: " << source); return Status(ErrorCodes::NamespaceNotFound, @@ -118,7 +118,7 @@ Status checkSourceAndTargetNamespaces(OperationContext* opCtx, const auto targetColl = catalog->lookupCollectionByNamespace(opCtx, target); if (!targetColl) { - if (ViewCatalog::get(db)->lookup(opCtx, target.ns())) + if (ViewCatalog::get(db)->lookup(opCtx, target)) return Status(ErrorCodes::NamespaceExists, str::stream() << "a view already exists with that name: " << target); } else { @@ -496,7 +496,7 @@ Status renameBetweenDBs(OperationContext* opCtx, auto catalog = CollectionCatalog::get(opCtx); const auto sourceColl = catalog->lookupCollectionByNamespace(opCtx, source); if (!sourceColl) { - if (sourceDB && ViewCatalog::get(sourceDB)->lookup(opCtx, source.ns())) + if (sourceDB && ViewCatalog::get(sourceDB)->lookup(opCtx, source)) return Status(ErrorCodes::CommandNotSupportedOnView, str::stream() << "cannot rename view: " << source); return Status(ErrorCodes::NamespaceNotFound, "source namespace does not exist"); @@ -525,7 +525,7 @@ Status renameBetweenDBs(OperationContext* opCtx, return Status(ErrorCodes::NamespaceExists, "target namespace exists"); } - } else if (targetDB && ViewCatalog::get(targetDB)->lookup(opCtx, target.ns())) { + } else if (targetDB && ViewCatalog::get(targetDB)->lookup(opCtx, target)) { return Status(ErrorCodes::NamespaceExists, str::stream() << "a view already exists with that name: " << target); } diff --git a/src/mongo/db/catalog/validate_state.cpp b/src/mongo/db/catalog/validate_state.cpp index 3a3a3f1b4cc..8109275ccd9 100644 --- a/src/mongo/db/catalog/validate_state.cpp +++ b/src/mongo/db/catalog/validate_state.cpp @@ -80,7 +80,7 @@ ValidateState::ValidateState(OperationContext* opCtx, _collection = CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, _nss); if (!_collection) { - if (_database && ViewCatalog::get(_database)->lookup(opCtx, _nss.ns())) { + if (_database && ViewCatalog::get(_database)->lookup(opCtx, _nss)) { uasserted(ErrorCodes::CommandNotSupportedOnView, "Cannot validate a view"); } diff --git a/src/mongo/db/catalog_raii.cpp b/src/mongo/db/catalog_raii.cpp index b7486200e80..bc21e6a5ef8 100644 --- a/src/mongo/db/catalog_raii.cpp +++ b/src/mongo/db/catalog_raii.cpp @@ -170,7 +170,7 @@ AutoGetCollection::AutoGetCollection(OperationContext* opCtx, return; } - _view = ViewCatalog::get(db)->lookup(opCtx, _resolvedNss.ns()); + _view = ViewCatalog::get(db)->lookup(opCtx, _resolvedNss); uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "Namespace " << _resolvedNss.ns() << " is a timeseries collection", !_view || viewMode == AutoGetCollectionViewMode::kViewsPermitted || @@ -282,7 +282,7 @@ AutoGetCollectionLockFree::AutoGetCollectionLockFree(OperationContext* opCtx, return; } - _view = viewCatalog->lookup(opCtx, _resolvedNss.ns()); + _view = viewCatalog->lookup(opCtx, _resolvedNss); uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "Namespace " << _resolvedNss.ns() << " is a timeseries collection", !_view || viewMode == AutoGetCollectionViewMode::kViewsPermitted || diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp index 94073a1cd38..44b909fbce9 100644 --- a/src/mongo/db/commands/create_indexes.cpp +++ b/src/mongo/db/commands/create_indexes.cpp @@ -295,7 +295,7 @@ CreateIndexesReply runCreateIndexesOnNewCollection( auto db = databaseHolder->getDb(opCtx, ns.db()); uassert(ErrorCodes::CommandNotSupportedOnView, "Cannot create indexes on a view", - !db || !ViewCatalog::get(db)->lookup(opCtx, ns.ns())); + !db || !ViewCatalog::get(db)->lookup(opCtx, ns)); if (createCollImplicitly) { // We need to create the collection. diff --git a/src/mongo/db/commands/drop_indexes.cpp b/src/mongo/db/commands/drop_indexes.cpp index c9ce56aae76..606b630fd4b 100644 --- a/src/mongo/db/commands/drop_indexes.cpp +++ b/src/mongo/db/commands/drop_indexes.cpp @@ -189,7 +189,7 @@ public: AutoGetCollection autoColl(opCtx, toReIndexNss, MODE_X); if (!autoColl) { auto db = autoColl.getDb(); - if (db && ViewCatalog::get(db)->lookup(opCtx, toReIndexNss.ns())) + if (db && ViewCatalog::get(db)->lookup(opCtx, toReIndexNss)) uasserted(ErrorCodes::CommandNotSupportedOnView, "can't re-index a view"); else uasserted(ErrorCodes::NamespaceNotFound, "collection does not exist"); diff --git a/src/mongo/db/commands/list_collections.cpp b/src/mongo/db/commands/list_collections.cpp index 326a59aebd4..60fd329951d 100644 --- a/src/mongo/db/commands/list_collections.cpp +++ b/src/mongo/db/commands/list_collections.cpp @@ -370,8 +370,8 @@ public: opCtx, collection, includePendingDrops, nameOnly); } - auto view = viewCatalog->lookupWithoutValidatingDurableViews( - opCtx, nss.ns()); + auto view = + viewCatalog->lookupWithoutValidatingDurableViews(opCtx, nss); if (view && view->timeseries()) { if (auto bucketsCollection = CollectionCatalog::get(opCtx) ->lookupCollectionByNamespace( @@ -398,7 +398,7 @@ public: if (collection && collection->getTimeseriesOptions() && !collection->ns().isDropPendingNamespace() && viewCatalog->lookupWithoutValidatingDurableViews( - opCtx, collection->ns().getTimeseriesViewNamespace().ns()) && + opCtx, collection->ns().getTimeseriesViewNamespace()) && (!authorizedCollections || as->isAuthorizedForAnyActionOnResource( ResourcePattern::forExactNamespace( diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp index a36560215ca..7626cfc06cc 100644 --- a/src/mongo/db/commands/run_aggregate.cpp +++ b/src/mongo/db/commands/run_aggregate.cpp @@ -362,7 +362,7 @@ StatusWith<StringMap<ExpressionContext::ResolvedNamespace>> resolveInvolvedNames // that the inverse scenario (mistaking a view for a collection) is not an issue // because $merge/$out cannot target a view. auto nssToCheck = NamespaceString(request.getNamespace().db(), involvedNs.coll()); - if (viewCatalog && viewCatalog->lookup(opCtx, nssToCheck.ns())) { + if (viewCatalog && viewCatalog->lookup(opCtx, nssToCheck)) { auto status = resolveViewDefinition(nssToCheck, viewCatalog); if (!status.isOK()) { return status; @@ -379,7 +379,7 @@ StatusWith<StringMap<ExpressionContext::ResolvedNamespace>> resolveInvolvedNames // pipeline because 'involvedNs' doesn't refer to a view namespace in our consistent // snapshot of the view catalog. resolvedNamespaces[involvedNs.coll()] = {involvedNs, std::vector<BSONObj>{}}; - } else if (viewCatalog->lookup(opCtx, involvedNs.ns())) { + } else if (viewCatalog->lookup(opCtx, involvedNs)) { auto status = resolveViewDefinition(involvedNs, viewCatalog); if (!status.isOK()) { return status; @@ -412,7 +412,7 @@ Status collatorCompatibleWithPipeline(OperationContext* opCtx, continue; } - auto view = viewCatalog->lookup(opCtx, potentialViewNs.ns()); + auto view = viewCatalog->lookup(opCtx, potentialViewNs); if (!view) { continue; } @@ -625,7 +625,7 @@ Status runAggregate(OperationContext* opCtx, if (!origNss.isCollectionlessAggregateNS()) { auto viewCatalog = DatabaseHolder::get(opCtx)->getViewCatalog(opCtx, origNss.db()); if (viewCatalog) { - auto view = viewCatalog->lookup(opCtx, origNss.ns()); + auto view = viewCatalog->lookup(opCtx, origNss); uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "Namespace " << origNss.ns() << " is a timeseries collection", diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index 6c0b433d8ca..c4dac17cfec 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -288,8 +288,8 @@ Message getMore(OperationContext* opCtx, Top::LockType::NotLocked, AutoStatsTracker::LogMode::kUpdateTopAndCurOp, CollectionCatalog::get(opCtx)->getDatabaseProfileLevel(nss.db())); - auto view = autoDb.getDb() ? ViewCatalog::get(autoDb.getDb())->lookup(opCtx, nss.ns()) - : nullptr; + auto view = + autoDb.getDb() ? ViewCatalog::get(autoDb.getDb())->lookup(opCtx, nss) : nullptr; uassert( ErrorCodes::CommandNotSupportedOnView, str::stream() << "Namespace " << nss.ns() diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index 2be565ae310..e9d9d988335 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -1168,7 +1168,7 @@ Status applyOperation_inlock(OperationContext* opCtx, const bool haveWrappingWriteUnitOfWork = opCtx->lockState()->inAWriteUnitOfWork(); uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "applyOps not supported on view: " << requestNss.ns(), - collection || !ViewCatalog::get(db)->lookup(opCtx, requestNss.ns())); + collection || !ViewCatalog::get(db)->lookup(opCtx, requestNss)); // Decide whether to timestamp the write with the 'ts' field found in the operation. In general, // we do this for secondary oplog application, but there are some exceptions. @@ -1730,7 +1730,7 @@ Status applyCommand_inlock(OperationContext* opCtx, auto databaseHolder = DatabaseHolder::get(opCtx); auto db = databaseHolder->getDb(opCtx, nss.ns()); if (db && !CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss) && - ViewCatalog::get(db)->lookup(opCtx, nss.ns())) { + ViewCatalog::get(db)->lookup(opCtx, nss)) { return {ErrorCodes::CommandNotSupportedOnView, str::stream() << "applyOps not supported on view:" << nss.ns()}; } diff --git a/src/mongo/db/s/rename_collection_coordinator.cpp b/src/mongo/db/s/rename_collection_coordinator.cpp index f0e35dc6afb..d5c23e1df56 100644 --- a/src/mongo/db/s/rename_collection_coordinator.cpp +++ b/src/mongo/db/s/rename_collection_coordinator.cpp @@ -186,7 +186,7 @@ ExecutorFuture<void> RenameCollectionCoordinator::_runImpl( uassert(ErrorCodes::CommandNotSupportedOnView, str::stream() << "Can't rename to target collection `" << toNss << "` because it is a view.", - !ViewCatalog::get(db)->lookup(opCtx, toNss.ns())); + !ViewCatalog::get(db)->lookup(opCtx, toNss)); } } diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp index c5b6353909e..608289cc0fe 100644 --- a/src/mongo/db/s/set_shard_version_command.cpp +++ b/src/mongo/db/s/set_shard_version_command.cpp @@ -152,7 +152,7 @@ public: if (autoDb->getDb() && !CollectionCatalog::get(opCtx)->lookupCollectionByNamespace(opCtx, nss) && ViewCatalog::get(autoDb->getDb()) - ->lookupWithoutValidatingDurableViews(opCtx, nss.ns())) { + ->lookupWithoutValidatingDurableViews(opCtx, nss)) { return true; } diff --git a/src/mongo/db/stats/storage_stats.cpp b/src/mongo/db/stats/storage_stats.cpp index 6fa79c4ed52..73ae280e1c1 100644 --- a/src/mongo/db/stats/storage_stats.cpp +++ b/src/mongo/db/stats/storage_stats.cpp @@ -55,7 +55,7 @@ Status appendCollectionStorageStats(OperationContext* opCtx, bool isTimeseries = false; if (auto viewCatalog = DatabaseHolder::get(opCtx)->getViewCatalog(opCtx, nss.db())) { - if (auto viewDef = viewCatalog->lookupWithoutValidatingDurableViews(opCtx, nss.ns())) { + if (auto viewDef = viewCatalog->lookupWithoutValidatingDurableViews(opCtx, nss)) { isTimeseries = viewDef->timeseries(); } } diff --git a/src/mongo/db/views/view_catalog.cpp b/src/mongo/db/views/view_catalog.cpp index 9d72eb06d60..e13f83d748a 100644 --- a/src/mongo/db/views/view_catalog.cpp +++ b/src/mongo/db/views/view_catalog.cpp @@ -511,7 +511,7 @@ Status ViewCatalog::_validateCollation(OperationContext* opCtx, const std::vector<NamespaceString>& refs) const { for (auto&& potentialViewNss : refs) { auto otherView = - _lookup(opCtx, potentialViewNss.ns(), ViewCatalogLookupBehavior::kValidateDurableViews); + _lookup(opCtx, potentialViewNss, ViewCatalogLookupBehavior::kValidateDurableViews); if (otherView && !CollatorInterface::collatorsMatch(view.defaultCollator(), otherView->defaultCollator())) { @@ -542,8 +542,7 @@ Status ViewCatalog::createView(OperationContext* opCtx, return Status(ErrorCodes::BadValue, "View must be created on a view or collection in the same database"); - if (catalog->_lookup( - opCtx, StringData(viewName.ns()), ViewCatalogLookupBehavior::kValidateDurableViews)) + if (catalog->_lookup(opCtx, viewName, ViewCatalogLookupBehavior::kValidateDurableViews)) return Status(ErrorCodes::NamespaceExists, "Namespace already exists"); if (!NamespaceString::validCollectionName(viewOn.coll())) @@ -585,7 +584,7 @@ Status ViewCatalog::modifyView(OperationContext* opCtx, "View must be created on a view or collection in the same database"); auto viewPtr = - catalog->_lookup(opCtx, viewName.ns(), ViewCatalogLookupBehavior::kValidateDurableViews); + catalog->_lookup(opCtx, viewName, ViewCatalogLookupBehavior::kValidateDurableViews); if (!viewPtr) return Status(ErrorCodes::NamespaceNotFound, str::stream() << "cannot modify missing view " << viewName.ns()); @@ -642,8 +641,8 @@ Status ViewCatalog::dropView(OperationContext* opCtx, catalogStorage.setIgnoreExternalChange(true); // Save a copy of the view definition in case we need to roll back. - auto viewPtr = catalog->_lookup( - opCtx, viewName.ns(), ViewCatalogLookupBehavior::kValidateDurableViews); + auto viewPtr = + catalog->_lookup(opCtx, viewName, ViewCatalogLookupBehavior::kValidateDurableViews); if (!viewPtr) { return {ErrorCodes::NamespaceNotFound, str::stream() << "cannot drop missing view: " << viewName.ns()}; @@ -679,8 +678,10 @@ Status ViewCatalog::dropView(OperationContext* opCtx, } std::shared_ptr<const ViewDefinition> ViewCatalog::_lookup( - OperationContext* opCtx, StringData ns, ViewCatalogLookupBehavior lookupBehavior) const { - ViewMap::const_iterator it = _viewMap.find(ns); + OperationContext* opCtx, + const NamespaceString& ns, + ViewCatalogLookupBehavior lookupBehavior) const { + ViewMap::const_iterator it = _viewMap.find(ns.ns()); if (it != _viewMap.end()) { return it->second; } @@ -688,17 +689,17 @@ std::shared_ptr<const ViewDefinition> ViewCatalog::_lookup( } std::shared_ptr<ViewDefinition> ViewCatalog::_lookup(OperationContext* opCtx, - StringData ns, + const NamespaceString& ns, ViewCatalogLookupBehavior lookupBehavior) { return std::const_pointer_cast<ViewDefinition>( std::as_const(*this)._lookup(opCtx, ns, lookupBehavior)); } std::shared_ptr<const ViewDefinition> ViewCatalog::lookup(OperationContext* opCtx, - StringData ns) const { + const NamespaceString& ns) const { if (!_valid && opCtx->getClient()->isFromUserConnection()) { // We want to avoid lookups on invalid collection names. - if (!NamespaceString::validCollectionName(ns)) { + if (!NamespaceString::validCollectionName(ns.ns())) { return nullptr; } @@ -712,7 +713,7 @@ std::shared_ptr<const ViewDefinition> ViewCatalog::lookup(OperationContext* opCt } std::shared_ptr<const ViewDefinition> ViewCatalog::lookupWithoutValidatingDurableViews( - OperationContext* opCtx, StringData ns) const { + OperationContext* opCtx, const NamespaceString& ns) const { return _lookup(opCtx, ns, ViewCatalogLookupBehavior::kAllowInvalidDurableViews); } @@ -742,7 +743,7 @@ StatusWith<ResolvedView> ViewCatalog::resolveView(OperationContext* opCtx, int depth = 0; for (; depth < ViewGraph::kMaxViewDepth; depth++) { auto view = - _lookup(opCtx, resolvedNss->ns(), ViewCatalogLookupBehavior::kValidateDurableViews); + _lookup(opCtx, *resolvedNss, ViewCatalogLookupBehavior::kValidateDurableViews); if (!view) { // Return error status if pipeline is too large. int pipelineSize = 0; diff --git a/src/mongo/db/views/view_catalog.h b/src/mongo/db/views/view_catalog.h index dc8a20c1baa..0903fb46cb3 100644 --- a/src/mongo/db/views/view_catalog.h +++ b/src/mongo/db/views/view_catalog.h @@ -122,14 +122,15 @@ public: * Look up the 'nss' in the view catalog, returning a shared pointer to a View definition, or * nullptr if it doesn't exist. */ - std::shared_ptr<const ViewDefinition> lookup(OperationContext* opCtx, StringData nss) const; + std::shared_ptr<const ViewDefinition> lookup(OperationContext* opCtx, + const NamespaceString& nss) const; /** * Same functionality as above, except this function skips validating durable views in the view * catalog. */ std::shared_ptr<const ViewDefinition> lookupWithoutValidatingDurableViews( - OperationContext* opCtx, StringData nss) const; + OperationContext* opCtx, const NamespaceString& nss) const; /** * Resolve the views on 'nss', transforming the pipeline appropriately. This function returns a @@ -206,10 +207,10 @@ private: const std::vector<NamespaceString>& refs) const; std::shared_ptr<const ViewDefinition> _lookup(OperationContext* opCtx, - StringData ns, + const NamespaceString& ns, ViewCatalogLookupBehavior lookupBehavior) const; std::shared_ptr<ViewDefinition> _lookup(OperationContext* opCtx, - StringData ns, + const NamespaceString& ns, ViewCatalogLookupBehavior lookupBehavior); Status _reload(OperationContext* opCtx, diff --git a/src/mongo/db/views/view_catalog_test.cpp b/src/mongo/db/views/view_catalog_test.cpp index 742d281e30c..0a611924036 100644 --- a/src/mongo/db/views/view_catalog_test.cpp +++ b/src/mongo/db/views/view_catalog_test.cpp @@ -164,7 +164,8 @@ public: return _db; } - std::shared_ptr<const ViewDefinition> lookup(OperationContext* opCtx, StringData ns) { + std::shared_ptr<const ViewDefinition> lookup(OperationContext* opCtx, + const NamespaceString& ns) { Lock::DBLock dbLock(operationContext(), NamespaceString(ns).db(), MODE_IS); return getViewCatalog()->lookup(operationContext(), ns); } @@ -495,7 +496,7 @@ TEST_F(ReplViewCatalogFixture, ModifyViewWithPipelineFailsOnIneligibleStage) { } TEST_F(ViewCatalogFixture, LookupMissingView) { - ASSERT(!lookup(operationContext(), "db.view"_sd)); + ASSERT(!lookup(operationContext(), NamespaceString("db.view"))); } TEST_F(ViewCatalogFixture, LookupExistingView) { @@ -504,7 +505,7 @@ TEST_F(ViewCatalogFixture, LookupExistingView) { ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); - ASSERT(lookup(operationContext(), "db.view"_sd)); + ASSERT(lookup(operationContext(), viewName)); } TEST_F(ViewCatalogFixture, LookupRIDExistingView) { @@ -621,13 +622,13 @@ TEST_F(ViewCatalogFixture, LookupRIDAfterModifyRollback) { } TEST_F(ViewCatalogFixture, CreateViewThenDropAndLookup) { - const NamespaceString viewName("db.view"); + NamespaceString viewName("db.view"); const NamespaceString viewOn("db.coll"); ASSERT_OK(createView(operationContext(), viewName, viewOn, emptyPipeline, emptyCollation)); ASSERT_OK(dropView(operationContext(), viewName)); - ASSERT(!lookup(operationContext(), "db.view"_sd)); + ASSERT(!lookup(operationContext(), viewName)); } TEST_F(ViewCatalogFixture, Iterate) { |