diff options
-rw-r--r-- | src/mongo/db/catalog/database_impl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.cpp | 22 | ||||
-rw-r--r-- | src/mongo/db/namespace_string.h | 23 | ||||
-rw-r--r-- | src/mongo/db/s/collection_sharding_state.cpp | 23 | ||||
-rw-r--r-- | src/mongo/db/s/shard_metadata_util.cpp | 18 | ||||
-rw-r--r-- | src/mongo/db/s/shard_metadata_util_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/s/shard_server_op_observer.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/s/split_chunk_command.cpp | 13 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_shard_collection.cpp | 3 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_shard_collection.h | 3 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_shard_database.cpp | 5 | ||||
-rw-r--r-- | src/mongo/s/catalog/type_shard_database.h | 3 | ||||
-rw-r--r-- | src/mongo/s/catalog_cache.cpp | 2 |
13 files changed, 50 insertions, 77 deletions
diff --git a/src/mongo/db/catalog/database_impl.cpp b/src/mongo/db/catalog/database_impl.cpp index a3727707381..038061c36b8 100644 --- a/src/mongo/db/catalog/database_impl.cpp +++ b/src/mongo/db/catalog/database_impl.cpp @@ -454,7 +454,7 @@ Status DatabaseImpl::dropCollection(OperationContext* opCtx, "turn off profiling before dropping system.profile collection"); } else if (!(nss.isSystemDotViews() || nss.isHealthlog() || nss == SessionsCollection::kSessionsNamespaceString || - nss.ns() == NamespaceString::kSystemKeysCollectionName)) { + nss == NamespaceString::kSystemKeysNamespace)) { return Status(ErrorCodes::IllegalOperation, str::stream() << "can't drop system collection " << fullns); } diff --git a/src/mongo/db/namespace_string.cpp b/src/mongo/db/namespace_string.cpp index 2e59ef396bf..5f82119ea17 100644 --- a/src/mongo/db/namespace_string.cpp +++ b/src/mongo/db/namespace_string.cpp @@ -36,13 +36,8 @@ #include "mongo/util/mongoutils/str.h" namespace mongo { - -using std::string; - namespace { -const char kServerConfiguration[] = "admin.system.version"; - constexpr auto listCollectionsCursorCol = "$cmd.listCollections"_sd; constexpr auto listIndexesCursorNSPrefix = "$cmd.listIndexes."_sd; constexpr auto collectionlessAggregateCursorCol = "$cmd.aggregate"_sd; @@ -54,13 +49,17 @@ constexpr StringData NamespaceString::kAdminDb; constexpr StringData NamespaceString::kLocalDb; constexpr StringData NamespaceString::kConfigDb; constexpr StringData NamespaceString::kSystemDotViewsCollectionName; -constexpr StringData NamespaceString::kShardConfigCollectionsCollectionName; -constexpr StringData NamespaceString::kShardConfigDatabasesCollectionName; -constexpr StringData NamespaceString::kSystemKeysCollectionName; -const NamespaceString NamespaceString::kServerConfigurationNamespace(kServerConfiguration); +const NamespaceString NamespaceString::kServerConfigurationNamespace(NamespaceString::kAdminDb, + "system.version"); const NamespaceString NamespaceString::kSessionTransactionsTableNamespace( NamespaceString::kConfigDb, "transactions"); +const NamespaceString NamespaceString::kShardConfigCollectionsNamespace(NamespaceString::kConfigDb, + "cache.collections"); +const NamespaceString NamespaceString::kShardConfigDatabasesNamespace(NamespaceString::kConfigDb, + "cache.databases"); +const NamespaceString NamespaceString::kSystemKeysNamespace(NamespaceString::kAdminDb, + "system.keys"); const NamespaceString NamespaceString::kRsOplogNamespace(NamespaceString::kLocalDb, "oplog.rs"); bool NamespaceString::isListCollectionsCursorNS() const { @@ -80,9 +79,9 @@ bool NamespaceString::isLegalClientSystemNS() const { if (db() == "admin") { if (ns() == "admin.system.roles") return true; - if (ns() == kServerConfiguration) + if (ns() == kServerConfigurationNamespace.ns()) return true; - if (ns() == kSystemKeysCollectionName) + if (ns() == kSystemKeysNamespace.ns()) return true; if (ns() == "admin.system.new_users") return true; @@ -92,6 +91,7 @@ bool NamespaceString::isLegalClientSystemNS() const { if (ns() == "config.system.sessions") return true; } + if (ns() == "local.system.replset") return true; diff --git a/src/mongo/db/namespace_string.h b/src/mongo/db/namespace_string.h index a5e9f15bd39..8e5eaa5e460 100644 --- a/src/mongo/db/namespace_string.h +++ b/src/mongo/db/namespace_string.h @@ -60,18 +60,6 @@ public: // Name for the system views collection static constexpr StringData kSystemDotViewsCollectionName = "system.views"_sd; - // Name for a shard's collections metadata collection, each document of which indicates the - // state of a specific collection. - static constexpr StringData kShardConfigCollectionsCollectionName = - "config.cache.collections"_sd; - - // Name for a shard's databases metadata collection, each document of which indicates the - // state of a specific database. - static constexpr StringData kShardConfigDatabasesCollectionName = "config.cache.databases"_sd; - - // Name for causal consistency's key collection. - static constexpr StringData kSystemKeysCollectionName = "admin.system.keys"_sd; - // Namespace for storing configuration data, which needs to be replicated if the server is // running as a replica set. Documents in this collection should represent some configuration // state of the server, which needs to be recovered/consulted at startup. Each document in this @@ -82,6 +70,17 @@ public: // Namespace for storing the transaction information for each session static const NamespaceString kSessionTransactionsTableNamespace; + // Name for a shard's collections metadata collection, each document of which indicates the + // state of a specific collection + static const NamespaceString kShardConfigCollectionsNamespace; + + // Name for a shard's databases metadata collection, each document of which indicates the state + // of a specific database + static const NamespaceString kShardConfigDatabasesNamespace; + + // Name for causal consistency's key collection. + static const NamespaceString kSystemKeysNamespace; + // Namespace of the the oplog collection. static const NamespaceString kRsOplogNamespace; diff --git a/src/mongo/db/s/collection_sharding_state.cpp b/src/mongo/db/s/collection_sharding_state.cpp index a19c93d0e64..fdbedadbe51 100644 --- a/src/mongo/db/s/collection_sharding_state.cpp +++ b/src/mongo/db/s/collection_sharding_state.cpp @@ -39,7 +39,6 @@ #include "mongo/db/operation_context.h" #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/sharded_connection_info.h" -#include "mongo/db/s/sharding_state.h" #include "mongo/db/server_parameters.h" #include "mongo/db/service_context.h" #include "mongo/executor/network_interface_factory.h" @@ -108,15 +107,16 @@ class CollectionShardingStateMap { public: CollectionShardingStateMap() = default; - CollectionShardingState& getOrCreate(OperationContext* opCtx, const std::string& ns) { + static const ServiceContext::Decoration<CollectionShardingStateMap> get; + + CollectionShardingState& getOrCreate(const std::string& ns) { stdx::lock_guard<stdx::mutex> lg(_mutex); auto it = _collections.find(ns); if (it == _collections.end()) { - auto inserted = - _collections.emplace(ns, - std::make_unique<CollectionShardingState>( - opCtx->getServiceContext(), NamespaceString(ns))); + auto inserted = _collections.emplace( + ns, + std::make_unique<CollectionShardingState>(get.owner(this), NamespaceString(ns))); invariant(inserted.second); it = std::move(inserted.first); } @@ -151,7 +151,7 @@ private: CollectionsMap _collections; }; -const auto getCollectionShardingStateMap = +const ServiceContext::Decoration<CollectionShardingStateMap> CollectionShardingStateMap::get = ServiceContext::declareDecoration<CollectionShardingStateMap>(); } // namespace @@ -171,12 +171,12 @@ CollectionShardingState* CollectionShardingState::get(OperationContext* opCtx, // Collection lock must be held to have a reference to the collection's sharding state dassert(opCtx->lockState()->isCollectionLockedForMode(ns, MODE_IS)); - auto& collectionsMap = getCollectionShardingStateMap(opCtx->getServiceContext()); - return &collectionsMap.getOrCreate(opCtx, ns); + auto& collectionsMap = CollectionShardingStateMap::get(opCtx->getServiceContext()); + return &collectionsMap.getOrCreate(ns); } void CollectionShardingState::report(OperationContext* opCtx, BSONObjBuilder* builder) { - auto& collectionsMap = getCollectionShardingStateMap(opCtx->getServiceContext()); + auto& collectionsMap = CollectionShardingStateMap::get(opCtx->getServiceContext()); collectionsMap.report(opCtx, builder); } @@ -313,7 +313,6 @@ bool CollectionShardingState::_checkShardVersionOk(OperationContext* opCtx, std::string* errmsg, ChunkVersion* expectedShardVersion, ChunkVersion* actualShardVersion) { - auto* const client = opCtx->getClient(); auto& oss = OperationShardingState::get(opCtx); // If there is a version attached to the OperationContext, use it as the received version. @@ -321,7 +320,7 @@ bool CollectionShardingState::_checkShardVersionOk(OperationContext* opCtx, if (oss.hasShardVersion()) { *expectedShardVersion = oss.getShardVersion(_nss); } else { - ShardedConnectionInfo* info = ShardedConnectionInfo::get(client, false); + auto const info = ShardedConnectionInfo::get(opCtx->getClient(), false); if (!info) { // There is no shard version information on either 'opCtx' or 'client'. This means that // the operation represented by 'opCtx' is unversioned, and the shard version is always diff --git a/src/mongo/db/s/shard_metadata_util.cpp b/src/mongo/db/s/shard_metadata_util.cpp index 8f4e3dcf3c1..b5669bdc004 100644 --- a/src/mongo/db/s/shard_metadata_util.cpp +++ b/src/mongo/db/s/shard_metadata_util.cpp @@ -142,11 +142,11 @@ StatusWith<ShardCollectionType> readShardCollectionsEntry(OperationContext* opCt try { DBDirectClient client(opCtx); std::unique_ptr<DBClientCursor> cursor = - client.query(ShardCollectionType::ConfigNS.ns(), fullQuery, 1); + client.query(NamespaceString::kShardConfigCollectionsNamespace.ns(), fullQuery, 1); if (!cursor) { return Status(ErrorCodes::OperationFailed, str::stream() << "Failed to establish a cursor for reading " - << ShardCollectionType::ConfigNS.ns() + << NamespaceString::kShardConfigCollectionsNamespace.ns() << " from local storage"); } @@ -175,11 +175,11 @@ StatusWith<ShardDatabaseType> readShardDatabasesEntry(OperationContext* opCtx, S try { DBDirectClient client(opCtx); std::unique_ptr<DBClientCursor> cursor = - client.query(ShardDatabaseType::ConfigNS.ns(), fullQuery, 1); + client.query(NamespaceString::kShardConfigDatabasesNamespace.ns(), fullQuery, 1); if (!cursor) { return Status(ErrorCodes::OperationFailed, str::stream() << "Failed to establish a cursor for reading " - << ShardDatabaseType::ConfigNS.ns() + << NamespaceString::kShardConfigDatabasesNamespace.ns() << " from local storage"); } @@ -228,7 +228,7 @@ Status updateShardCollectionsEntry(OperationContext* opCtx, } auto commandResponse = client.runCommand([&] { - write_ops::Update updateOp(NamespaceString{ShardCollectionType::ConfigNS}); + write_ops::Update updateOp(NamespaceString::kShardConfigCollectionsNamespace); updateOp.setUpdates({[&] { write_ops::UpdateOpEntry entry; entry.setQ(query); @@ -271,7 +271,7 @@ Status updateShardDatabasesEntry(OperationContext* opCtx, } auto commandResponse = client.runCommand([&] { - write_ops::Update updateOp(NamespaceString{ShardDatabaseType::ConfigNS}); + write_ops::Update updateOp(NamespaceString::kShardConfigDatabasesNamespace); updateOp.setUpdates({[&] { write_ops::UpdateOpEntry entry; entry.setQ(query); @@ -407,8 +407,7 @@ Status dropChunksAndDeleteCollectionsEntry(OperationContext* opCtx, const Namesp DBDirectClient client(opCtx); auto deleteCommandResponse = client.runCommand([&] { - write_ops::Delete deleteOp( - NamespaceString{NamespaceString::kShardConfigCollectionsCollectionName}); + write_ops::Delete deleteOp(NamespaceString::kShardConfigCollectionsNamespace); deleteOp.setDeletes({[&] { write_ops::DeleteOpEntry entry; entry.setQ(BSON(ShardCollectionType::ns << nss.ns())); @@ -442,8 +441,7 @@ Status deleteDatabasesEntry(OperationContext* opCtx, StringData dbName) { DBDirectClient client(opCtx); auto deleteCommandResponse = client.runCommand([&] { - write_ops::Delete deleteOp( - NamespaceString{NamespaceString::kShardConfigDatabasesCollectionName}); + write_ops::Delete deleteOp(NamespaceString::kShardConfigDatabasesNamespace); deleteOp.setDeletes({[&] { write_ops::DeleteOpEntry entry; entry.setQ(BSON(ShardDatabaseType::name << dbName.toString())); diff --git a/src/mongo/db/s/shard_metadata_util_test.cpp b/src/mongo/db/s/shard_metadata_util_test.cpp index f6596c1230a..8c650e17531 100644 --- a/src/mongo/db/s/shard_metadata_util_test.cpp +++ b/src/mongo/db/s/shard_metadata_util_test.cpp @@ -325,7 +325,7 @@ TEST_F(ShardMetadataUtilTest, DropChunksAndDeleteCollectionsEntry) { ASSERT_OK(dropChunksAndDeleteCollectionsEntry(operationContext(), kNss)); checkCollectionIsEmpty(kChunkMetadataNss); // Collections collection should be empty because it only had one entry. - checkCollectionIsEmpty(ShardCollectionType::ConfigNS); + checkCollectionIsEmpty(NamespaceString::kShardConfigCollectionsNamespace); } } // namespace diff --git a/src/mongo/db/s/shard_server_op_observer.cpp b/src/mongo/db/s/shard_server_op_observer.cpp index 37691cab462..a7bc335294d 100644 --- a/src/mongo/db/s/shard_server_op_observer.cpp +++ b/src/mongo/db/s/shard_server_op_observer.cpp @@ -230,7 +230,7 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE auto const css = CollectionShardingState::get(opCtx, args.nss); const auto metadata = css->getMetadata(opCtx); - if (args.nss.ns() == NamespaceString::kShardConfigCollectionsCollectionName) { + if (args.nss == NamespaceString::kShardConfigCollectionsNamespace) { // Notification of routing table changes are only needed on secondaries if (isStandaloneOrPrimary(opCtx)) { return; @@ -283,7 +283,7 @@ void ShardServerOpObserver::onUpdate(OperationContext* opCtx, const OplogUpdateE } } - if (args.nss.ns() == NamespaceString::kShardConfigDatabasesCollectionName) { + if (args.nss == NamespaceString::kShardConfigDatabasesNamespace) { // Notification of routing table changes are only needed on secondaries if (isStandaloneOrPrimary(opCtx)) { return; @@ -337,10 +337,10 @@ void ShardServerOpObserver::onDelete(OperationContext* opCtx, const boost::optional<BSONObj>& deletedDoc) { auto& deleteState = getDeleteState(opCtx); - if (nss.ns() == NamespaceString::kShardConfigCollectionsCollectionName) { + if (nss == NamespaceString::kShardConfigCollectionsNamespace) { onConfigDeleteInvalidateCachedCollectionMetadataAndNotify(opCtx, deleteState.documentKey); } - if (nss.ns() == NamespaceString::kShardConfigDatabasesCollectionName) { + if (nss == NamespaceString::kShardConfigDatabasesNamespace) { if (isStandaloneOrPrimary(opCtx)) { return; } diff --git a/src/mongo/db/s/split_chunk_command.cpp b/src/mongo/db/s/split_chunk_command.cpp index f9084e4cfd7..b69b33173e0 100644 --- a/src/mongo/db/s/split_chunk_command.cpp +++ b/src/mongo/db/s/split_chunk_command.cpp @@ -41,6 +41,7 @@ #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/split_chunk.h" +#include "mongo/s/catalog/type_chunk.h" #include "mongo/s/stale_exception.h" #include "mongo/util/log.h" #include "mongo/util/mongoutils/str.h" @@ -64,7 +65,7 @@ public: "splitKeys : [ {a:150} , ... ]}"; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { + bool supportsWriteConcern(const BSONObj& cmd) const override { return false; } @@ -95,19 +96,11 @@ public: const BSONObj& cmdObj, std::string& errmsg, BSONObjBuilder& result) override { - uassertStatusOK(ShardingState::get(opCtx)->canAcceptShardedCommands()); - // - // Check whether parameters passed to splitChunk are sound - // const NamespaceString nss = NamespaceString(parseNs(dbname, cmdObj)); - if (!nss.isValid()) { - errmsg = str::stream() << "invalid namespace '" << nss.toString() - << "' specified for command"; - return false; - } + // Check whether parameters passed to splitChunk are sound BSONObj keyPatternObj; { BSONElement keyPatternElem; diff --git a/src/mongo/s/catalog/type_shard_collection.cpp b/src/mongo/s/catalog/type_shard_collection.cpp index 7343238a1b1..41c9090e570 100644 --- a/src/mongo/s/catalog/type_shard_collection.cpp +++ b/src/mongo/s/catalog/type_shard_collection.cpp @@ -39,9 +39,6 @@ namespace mongo { -const NamespaceString ShardCollectionType::ConfigNS( - NamespaceString::kShardConfigCollectionsCollectionName); - const BSONField<std::string> ShardCollectionType::ns("_id"); const BSONField<UUID> ShardCollectionType::uuid("uuid"); const BSONField<OID> ShardCollectionType::epoch("epoch"); diff --git a/src/mongo/s/catalog/type_shard_collection.h b/src/mongo/s/catalog/type_shard_collection.h index 0df48ffe59b..ce5910787d5 100644 --- a/src/mongo/s/catalog/type_shard_collection.h +++ b/src/mongo/s/catalog/type_shard_collection.h @@ -70,9 +70,6 @@ class StatusWith; */ class ShardCollectionType { public: - // Name of the collections collection on the shard server. - static const NamespaceString ConfigNS; - static const BSONField<std::string> ns; // "_id" static const BSONField<UUID> uuid; static const BSONField<OID> epoch; diff --git a/src/mongo/s/catalog/type_shard_database.cpp b/src/mongo/s/catalog/type_shard_database.cpp index 5be668cceae..78a26a02f27 100644 --- a/src/mongo/s/catalog/type_shard_database.cpp +++ b/src/mongo/s/catalog/type_shard_database.cpp @@ -39,11 +39,6 @@ namespace mongo { -using std::string; - -const NamespaceString ShardDatabaseType::ConfigNS( - NamespaceString::kShardConfigDatabasesCollectionName); - const BSONField<std::string> ShardDatabaseType::name("_id"); const BSONField<DatabaseVersion> ShardDatabaseType::version("version"); const BSONField<std::string> ShardDatabaseType::primary("primary"); diff --git a/src/mongo/s/catalog/type_shard_database.h b/src/mongo/s/catalog/type_shard_database.h index f8b0209636d..2acaa912218 100644 --- a/src/mongo/s/catalog/type_shard_database.h +++ b/src/mongo/s/catalog/type_shard_database.h @@ -62,9 +62,6 @@ class StatusWith; */ class ShardDatabaseType { public: - // Name of the database collection on the shard server. - static const NamespaceString ConfigNS; - static const BSONField<std::string> name; // "_id" static const BSONField<DatabaseVersion> version; static const BSONField<std::string> primary; diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp index 434f3848e1b..254bd358cd0 100644 --- a/src/mongo/s/catalog_cache.cpp +++ b/src/mongo/s/catalog_cache.cpp @@ -32,8 +32,6 @@ #include "mongo/s/catalog_cache.h" -#include "mongo/base/status.h" -#include "mongo/base/status_with.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/db/logical_clock.h" #include "mongo/db/query/collation/collator_factory_interface.h" |