From 7626535bbcc2f90b7815cbf1a8e6d2c0bef732f1 Mon Sep 17 00:00:00 2001 From: Siyuan Zhou Date: Wed, 30 Aug 2017 23:58:30 -0400 Subject: SERVER-30591 Do changeStream lookups by UUID instead of namespace. --- src/mongo/db/db_raii.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/mongo/db/db_raii.cpp') diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp index 018a2591ed3..07e65df9aa1 100644 --- a/src/mongo/db/db_raii.cpp +++ b/src/mongo/db/db_raii.cpp @@ -33,6 +33,7 @@ #include "mongo/db/catalog/collection.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/database_holder.h" +#include "mongo/db/catalog/uuid_catalog.h" #include "mongo/db/client.h" #include "mongo/db/curop.h" #include "mongo/db/repl/replication_coordinator_global.h" @@ -133,6 +134,25 @@ AutoStatsTracker::~AutoStatsTracker() { curOp->getReadWriteType()); } +AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, + const StringData dbName, + const UUID& uuid) { + // Lock the database since a UUID will always be in the same database even though its + // collection name may change. + Lock::DBLock dbSLock(opCtx, dbName, MODE_IS); + + auto nss = UUIDCatalog::get(opCtx).lookupNSSByUUID(uuid); + + // If the UUID doesn't exist, we leave _autoColl to be boost::none. + if (!nss.isEmpty()) { + _autoColl.emplace( + opCtx, nss, MODE_IS, AutoGetCollection::ViewMode::kViewsForbidden, std::move(dbSLock)); + + // Note: this can yield. + _ensureMajorityCommittedSnapshotIsValid(nss, opCtx); + } +} + AutoGetCollectionForRead::AutoGetCollectionForRead(OperationContext* opCtx, const NamespaceString& nss, AutoGetCollection::ViewMode viewMode) { @@ -226,6 +246,23 @@ AutoGetCollectionOrViewForReadCommand::AutoGetCollectionOrViewForReadCommand( ? _autoCollForRead->getDb()->getViewCatalog()->lookup(opCtx, nss.ns()) : nullptr) {} +AutoGetCollectionForReadCommand::AutoGetCollectionForReadCommand(OperationContext* opCtx, + const StringData dbName, + const UUID& uuid) { + _autoCollForRead.emplace(opCtx, dbName, uuid); + if (_autoCollForRead->getCollection()) { + _statsTracker.emplace(opCtx, + _autoCollForRead->getCollection()->ns(), + Top::LockType::ReadLocked, + _autoCollForRead->getDb()->getProfilingLevel()); + + // We have both the DB and collection locked, which is the prerequisite to do a stable shard + // version check, but we'd like to do the check after we have a satisfactory snapshot. + auto css = CollectionShardingState::get(opCtx, _autoCollForRead->getCollection()->ns()); + css->checkShardVersionOrThrow(opCtx); + } +} + void AutoGetCollectionOrViewForReadCommand::releaseLocksForView() noexcept { invariant(_view); _view = nullptr; -- cgit v1.2.1