diff options
author | Esha Maharishi <esha.maharishi@mongodb.com> | 2018-02-05 22:24:37 -0500 |
---|---|---|
committer | Esha Maharishi <esha.maharishi@mongodb.com> | 2018-02-05 22:27:04 -0500 |
commit | 05c8669da01904fabd28c2fd7b3f7e2d3949fea6 (patch) | |
tree | 58343f01027267576bbc600d4f877a34f0d20afd /src/mongo/s | |
parent | 65ffca94ad05cb4310a293316c3228e04ed1899b (diff) | |
download | mongo-05c8669da01904fabd28c2fd7b3f7e2d3949fea6.tar.gz |
Revert "SERVER-33022 make the CatalogCache cache the databaseVersion in the DatabaseInfoEntry"
This reverts commit 481e017d1d4fbe3468292c952ee0ba4ce31a92e9.
Diffstat (limited to 'src/mongo/s')
-rw-r--r-- | src/mongo/s/catalog_cache.cpp | 10 | ||||
-rw-r--r-- | src/mongo/s/catalog_cache.h | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_commands_helpers.cpp | 11 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_commands_helpers.h | 7 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_get_shard_version_cmd.cpp | 39 |
5 files changed, 28 insertions, 45 deletions
diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp index c89cc38b0fc..a1f44b678f2 100644 --- a/src/mongo/s/catalog_cache.cpp +++ b/src/mongo/s/catalog_cache.cpp @@ -337,10 +337,8 @@ std::shared_ptr<CatalogCache::DatabaseInfoEntry> CatalogCache::_getDatabase(Oper collectionEntries[coll.getNs().ns()].needsRefresh = true; } - return std::make_shared<DatabaseInfoEntry>(DatabaseInfoEntry{dbDesc.getPrimary(), - dbDesc.getSharded(), - std::move(collectionEntries), - dbDesc.getVersion()}); + return _databases[dbName] = std::shared_ptr<DatabaseInfoEntry>(new DatabaseInfoEntry{ + dbDesc.getPrimary(), dbDesc.getSharded(), std::move(collectionEntries)}); } void CatalogCache::_scheduleCollectionRefresh(WithLock lk, @@ -486,10 +484,6 @@ bool CachedDatabaseInfo::shardingEnabled() const { return _db->shardingEnabled; } -boost::optional<DatabaseVersion> CachedDatabaseInfo::databaseVersion() const { - return _db->databaseVersion; -} - CachedCollectionRoutingInfo::CachedCollectionRoutingInfo(ShardId primaryId, std::shared_ptr<ChunkManager> cm) : _primaryId(std::move(primaryId)), _cm(std::move(cm)) {} diff --git a/src/mongo/s/catalog_cache.h b/src/mongo/s/catalog_cache.h index b4b93eced47..aeeae8cb25e 100644 --- a/src/mongo/s/catalog_cache.h +++ b/src/mongo/s/catalog_cache.h @@ -34,7 +34,6 @@ #include "mongo/s/catalog_cache_loader.h" #include "mongo/s/chunk_manager.h" #include "mongo/s/client/shard.h" -#include "mongo/s/database_version_gen.h" #include "mongo/stdx/memory.h" #include "mongo/stdx/mutex.h" #include "mongo/util/concurrency/notification.h" @@ -172,9 +171,6 @@ private: bool shardingEnabled; StringMap<CollectionRoutingInfoEntry> collections; - - // Optional while featureCompatibilityVersion 3.6 is supported. - boost::optional<DatabaseVersion> databaseVersion; }; using DatabaseInfoMap = StringMap<std::shared_ptr<DatabaseInfoEntry>>; @@ -249,8 +245,6 @@ public: bool shardingEnabled() const; - boost::optional<DatabaseVersion> databaseVersion() const; - private: friend class CatalogCache; diff --git a/src/mongo/s/commands/cluster_commands_helpers.cpp b/src/mongo/s/commands/cluster_commands_helpers.cpp index 2f985d2aee6..7d4312ecd53 100644 --- a/src/mongo/s/commands/cluster_commands_helpers.cpp +++ b/src/mongo/s/commands/cluster_commands_helpers.cpp @@ -393,6 +393,17 @@ bool appendEmptyResultSet(BSONObjBuilder& result, Status status, const std::stri return CommandHelpers::appendCommandStatus(result, status); } +CachedCollectionRoutingInfo getShardedCollection(OperationContext* opCtx, + const NamespaceString& nss) { + auto routingInfo = + uassertStatusOK(Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfo(opCtx, nss)); + uassert(ErrorCodes::NamespaceNotSharded, + str::stream() << "Collection " << nss.ns() << " is not sharded.", + routingInfo.cm()); + + return routingInfo; +} + StatusWith<CachedDatabaseInfo> createShardDatabase(OperationContext* opCtx, StringData dbName) { auto dbStatus = Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, dbName); if (dbStatus == ErrorCodes::NamespaceNotFound) { diff --git a/src/mongo/s/commands/cluster_commands_helpers.h b/src/mongo/s/commands/cluster_commands_helpers.h index da6ad16c513..60e153fde20 100644 --- a/src/mongo/s/commands/cluster_commands_helpers.h +++ b/src/mongo/s/commands/cluster_commands_helpers.h @@ -146,6 +146,13 @@ int getUniqueCodeFromCommandResults(const std::vector<Strategy::CommandResult>& bool appendEmptyResultSet(BSONObjBuilder& result, Status status, const std::string& ns); /** + * Abstracts the common pattern of refreshing a collection and checking if it is sharded used across + * multiple commands. + */ +CachedCollectionRoutingInfo getShardedCollection(OperationContext* opCtx, + const NamespaceString& nss); + +/** * If the specified database exists already, loads it in the cache (if not already there) and * returns it. Otherwise, if it does not exist, this call will implicitly create it as non-sharded. */ diff --git a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp index 1cc01d0a00c..05f04d9249a 100644 --- a/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp +++ b/src/mongo/s/commands/cluster_get_shard_version_cmd.cpp @@ -37,7 +37,6 @@ #include "mongo/db/commands.h" #include "mongo/s/catalog_cache.h" #include "mongo/s/commands/cluster_commands_helpers.h" -#include "mongo/s/database_version_gen.h" #include "mongo/s/grid.h" #include "mongo/util/log.h" @@ -77,12 +76,7 @@ public: } std::string parseNs(const std::string& dbname, const BSONObj& cmdObj) const override { - BSONElement first = cmdObj.firstElement(); - uassert(ErrorCodes::BadValue, - str::stream() << "namespace has invalid type " << typeName(first.type()), - first.canonicalType() == canonicalizeBSONType(mongo::String)); - const NamespaceString nss(first.valueStringData()); - return nss.ns(); + return CommandHelpers::parseNsFullyQualified(dbname, cmdObj); } bool run(OperationContext* opCtx, @@ -91,32 +85,15 @@ public: BSONObjBuilder& result) override { const NamespaceString nss(parseNs(dbname, cmdObj)); - const auto catalogCache = Grid::get(opCtx)->catalogCache(); - - if (nss.coll().empty()) { - // Return the database's information. - auto cachedDbInfo = uassertStatusOK(catalogCache->getDatabase(opCtx, nss.ns())); - result.append("primaryShard", cachedDbInfo.primaryId().toString()); - result.append("shardingEnabled", cachedDbInfo.shardingEnabled()); - if (cachedDbInfo.databaseVersion()) { - result.append("version", cachedDbInfo.databaseVersion()->toBSON()); - } - } else { - // Return the collection's information. - auto cachedCollInfo = - uassertStatusOK(catalogCache->getCollectionRoutingInfo(opCtx, nss)); - uassert(ErrorCodes::NamespaceNotSharded, - str::stream() << "Collection " << nss.ns() << " is not sharded.", - cachedCollInfo.cm()); - const auto cm = cachedCollInfo.cm(); - - for (const auto& chunk : cm->chunks()) { - log() << redact(chunk->toString()); - } - - cm->getVersion().addToBSON(result, "version"); + auto routingInfo = getShardedCollection(opCtx, nss); + const auto cm = routingInfo.cm(); + + for (const auto& chunk : cm->chunks()) { + log() << redact(chunk->toString()); } + cm->getVersion().addToBSON(result, "version"); + return true; } |