diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-08-11 16:43:18 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-08-14 15:29:38 -0400 |
commit | 58b36b8bbc6ca7159e100ada6dc15852af0a8661 (patch) | |
tree | 16934881e75c10af862aa3f5f7d280c21928246b /src/mongo/db/s | |
parent | 2176ab64295b23e8c67f7799d1310791f14db147 (diff) | |
download | mongo-58b36b8bbc6ca7159e100ada6dc15852af0a8661.tar.gz |
SERVER-30424 Remove opCtx/serviceContext null checks from db.cpp since ServiceContext must always exist
Diffstat (limited to 'src/mongo/db/s')
-rw-r--r-- | src/mongo/db/s/migration_source_manager.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/s/operation_sharding_state.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/s/operation_sharding_state.h | 25 | ||||
-rw-r--r-- | src/mongo/db/s/set_shard_version_command.cpp | 101 | ||||
-rw-r--r-- | src/mongo/db/s/sharding_state.cpp | 11 |
5 files changed, 50 insertions, 109 deletions
diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index 95616ee7a18..0e8b9d8355d 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -39,7 +39,6 @@ #include "mongo/db/s/collection_sharding_state.h" #include "mongo/db/s/migration_chunk_cloner_source_legacy.h" #include "mongo/db/s/migration_util.h" -#include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/sharding_state_recovery.h" #include "mongo/s/catalog/sharding_catalog_client.h" diff --git a/src/mongo/db/s/operation_sharding_state.cpp b/src/mongo/db/s/operation_sharding_state.cpp index 4b8e6304111..f465cc22a24 100644 --- a/src/mongo/db/s/operation_sharding_state.cpp +++ b/src/mongo/db/s/operation_sharding_state.cpp @@ -130,25 +130,4 @@ void OperationShardingState::_clear() { _ns = NamespaceString(); } -OperationShardingState::IgnoreVersioningBlock::IgnoreVersioningBlock(OperationContext* opCtx, - const NamespaceString& ns) - : _opCtx(opCtx), _ns(ns) { - auto& oss = OperationShardingState::get(opCtx); - _hadOriginalVersion = oss._hasVersion; - if (_hadOriginalVersion) { - _originalVersion = oss.getShardVersion(ns); - } - oss.setShardVersion(ns, ChunkVersion::IGNORED()); -} - -OperationShardingState::IgnoreVersioningBlock::~IgnoreVersioningBlock() { - auto& oss = OperationShardingState::get(_opCtx); - invariant(ChunkVersion::isIgnoredVersion(oss.getShardVersion(_ns))); - if (_hadOriginalVersion) { - oss.setShardVersion(_ns, _originalVersion); - } else { - oss._clear(); - } -} - } // namespace mongo diff --git a/src/mongo/db/s/operation_sharding_state.h b/src/mongo/db/s/operation_sharding_state.h index d4a0e778af1..53ed73f89af 100644 --- a/src/mongo/db/s/operation_sharding_state.h +++ b/src/mongo/db/s/operation_sharding_state.h @@ -32,8 +32,8 @@ #include "mongo/base/disallow_copying.h" #include "mongo/db/namespace_string.h" -#include "mongo/db/s/migration_source_manager.h" #include "mongo/s/chunk_version.h" +#include "mongo/util/concurrency/notification.h" namespace mongo { @@ -51,8 +51,6 @@ class OperationShardingState { MONGO_DISALLOW_COPYING(OperationShardingState); public: - class IgnoreVersioningBlock; - OperationShardingState(); /** @@ -129,25 +127,4 @@ private: std::shared_ptr<Notification<void>> _migrationCriticalSectionSignal; }; -/** - * RAII type that sets the shard version for the current operation to IGNORED in its constructor, - * then restores the original version in its destructor. Used for temporarily disabling shard - * version checking for certain operations, such as multi-updates, that need to be unversioned - * but may be part of a larger group of operations with a single OperationContext where the other - * sub-operations might still require versioning. - */ -class OperationShardingState::IgnoreVersioningBlock { - MONGO_DISALLOW_COPYING(IgnoreVersioningBlock); - -public: - IgnoreVersioningBlock(OperationContext* opCtx, const NamespaceString& ns); - ~IgnoreVersioningBlock(); - -private: - OperationContext* _opCtx; - NamespaceString _ns; - ChunkVersion _originalVersion; - bool _hadOriginalVersion; -}; - } // namespace mongo diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp index 929332c29d9..561b13b335d 100644 --- a/src/mongo/db/s/set_shard_version_command.cpp +++ b/src/mongo/db/s/set_shard_version_command.cpp @@ -97,7 +97,7 @@ public: "can't issue setShardVersion from 'eval'", !opCtx->getClient()->isInDirectClient()); - auto shardingState = ShardingState::get(opCtx); + auto const shardingState = ShardingState::get(opCtx); uassertStatusOK(shardingState->canAcceptShardedCommands()); // Steps @@ -158,8 +158,8 @@ public: // Step 3 // Validate shardName parameter. - string shardName = cmdObj["shard"].str(); - auto storedShardName = ShardingState::get(opCtx)->getShardName(); + const auto shardName = cmdObj["shard"].str(); + const auto storedShardName = ShardingState::get(opCtx)->getShardName(); uassert(ErrorCodes::BadValue, str::stream() << "received shardName " << shardName << " which differs from stored shardName " @@ -167,45 +167,29 @@ public: storedShardName == shardName); // Validate config connection string parameter. + const auto configdb = cmdObj["configdb"].String(); + uassert(ErrorCodes::BadValue, + "Config server connection string cannot be empty", + !configdb.empty()); - const auto configdb = cmdObj["configdb"].str(); - if (configdb.size() == 0) { - errmsg = "no configdb"; - return false; - } - - auto givenConnStrStatus = ConnectionString::parse(configdb); - uassertStatusOK(givenConnStrStatus); - - const auto& givenConnStr = givenConnStrStatus.getValue(); - if (givenConnStr.type() != ConnectionString::SET) { - errmsg = str::stream() << "given config server string is not of type SET"; - return false; - } - - ConnectionString storedConnStr = ShardingState::get(opCtx)->getConfigServer(opCtx); - if (givenConnStr.getSetName() != storedConnStr.getSetName()) { - errmsg = str::stream() - << "given config server set name: " << givenConnStr.getSetName() - << " differs from known set name: " << storedConnStr.getSetName(); + const auto givenConnStr = uassertStatusOK(ConnectionString::parse(configdb)); + uassert(ErrorCodes::InvalidOptions, + str::stream() << "Given config server string " << givenConnStr.toString() + << " is not of type SET", + givenConnStr.type() == ConnectionString::SET); - return false; - } + const auto storedConnStr = ShardingState::get(opCtx)->getConfigServer(opCtx); + uassert(ErrorCodes::IllegalOperation, + str::stream() << "Given config server set name: " << givenConnStr.getSetName() + << " differs from known set name: " + << storedConnStr.getSetName(), + givenConnStr.getSetName() == storedConnStr.getSetName()); // Validate namespace parameter. - - const string ns = cmdObj["setShardVersion"].valuestrsafe(); - if (ns.size() == 0) { - errmsg = "need to specify namespace"; - return false; - } - - // Backwards compatibility for SERVER-23119 - const NamespaceString nss(ns); - if (!nss.isValid()) { - warning() << "Invalid namespace used for setShardVersion: " << ns; - return true; - } + const NamespaceString nss(cmdObj["setShardVersion"].String()); + uassert(ErrorCodes::InvalidNamespace, + str::stream() << "Invalid namespace " << nss.ns(), + nss.isValid()); // Validate chunk version parameter. const ChunkVersion requestedVersion = @@ -213,7 +197,7 @@ public: // Step 4 - const ChunkVersion connectionVersion = info->getVersion(ns); + const ChunkVersion connectionVersion = info->getVersion(nss.ns()); connectionVersion.addToBSON(result, "oldVersion"); { @@ -252,15 +236,15 @@ public: // A migration occurred. if (connectionVersion < collectionShardVersion && connectionVersion.epoch() == collectionShardVersion.epoch()) { - info->setVersion(ns, requestedVersion); + info->setVersion(nss.ns(), requestedVersion); } // The collection was dropped and recreated. else if (authoritative) { - info->setVersion(ns, requestedVersion); + info->setVersion(nss.ns(), requestedVersion); } else { - result.append("ns", ns); + result.append("ns", nss.ns()); result.appendBool("need_authoritative", true); - errmsg = "verifying drop on '" + ns + "'"; + errmsg = str::stream() << "verifying drop on '" << nss.ns() << "'"; return false; } } @@ -276,7 +260,7 @@ public: if (isDropRequested) { if (!authoritative) { result.appendBool("need_authoritative", true); - result.append("ns", ns); + result.append("ns", nss.ns()); collectionShardVersion.addToBSON(result, "globalVersion"); errmsg = "dropping needs to be authoritative"; return false; @@ -292,8 +276,8 @@ public: if (requestedVersion < connectionVersion && requestedVersion.epoch() == connectionVersion.epoch()) { errmsg = str::stream() << "this connection already had a newer version " - << "of collection '" << ns << "'"; - result.append("ns", ns); + << "of collection '" << nss.ns() << "'"; + result.append("ns", nss.ns()); requestedVersion.addToBSON(result, "newVersion"); collectionShardVersion.addToBSON(result, "globalVersion"); return false; @@ -315,8 +299,8 @@ public: } errmsg = str::stream() << "shard global version for collection is higher " - << "than trying to set to '" << ns << "'"; - result.append("ns", ns); + << "than trying to set to '" << nss.ns() << "'"; + result.append("ns", nss.ns()); requestedVersion.addToBSON(result, "version"); collectionShardVersion.addToBSON(result, "globalVersion"); result.appendBool("reloadConfig", true); @@ -339,9 +323,9 @@ public: } // need authoritative for first look - result.append("ns", ns); + result.append("ns", nss.ns()); result.appendBool("need_authoritative", true); - errmsg = "first time for collection '" + ns + "'"; + errmsg = str::stream() << "first time for collection '" << nss.ns() << "'"; return false; } @@ -365,14 +349,15 @@ public: if (!status.isOK()) { // The reload itself was interrupted or confused here - errmsg = str::stream() - << "could not refresh metadata for " << ns << " with requested shard version " - << requestedVersion.toString() << ", stored shard version is " - << currVersion.toString() << causedBy(redact(status)); + errmsg = str::stream() << "could not refresh metadata for " << nss.ns() + << " with requested shard version " + << requestedVersion.toString() + << ", stored shard version is " << currVersion.toString() + << causedBy(redact(status)); warning() << errmsg; - result.append("ns", ns); + result.append("ns", nss.ns()); requestedVersion.addToBSON(result, "version"); currVersion.addToBSON(result, "globalVersion"); result.appendBool("reloadConfig", true); @@ -382,7 +367,7 @@ public: // We reloaded a version that doesn't match the version mongos was trying to // set. errmsg = str::stream() << "requested shard version differs from" - << " config shard version for " << ns + << " config shard version for " << nss.ns() << ", requested version is " << requestedVersion.toString() << " but found version " << currVersion.toString(); @@ -391,7 +376,7 @@ public: // WARNING: the exact fields below are important for compatibility with mongos // version reload. - result.append("ns", ns); + result.append("ns", nss.ns()); currVersion.addToBSON(result, "globalVersion"); // If this was a reset of a collection or the last chunk moved out, inform mongos to @@ -411,7 +396,7 @@ public: } } - info->setVersion(ns, requestedVersion); + info->setVersion(nss.ns(), requestedVersion); return true; } diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp index b775ca6ae0b..f091aec2d48 100644 --- a/src/mongo/db/s/sharding_state.cpp +++ b/src/mongo/db/s/sharding_state.cpp @@ -165,8 +165,8 @@ string ShardingState::getShardName() { void ShardingState::shutDown(OperationContext* opCtx) { stdx::unique_lock<stdx::mutex> lk(_mutex); if (enabled()) { - grid.getExecutorPool()->shutdownAndJoin(); - grid.catalogClient()->shutDown(opCtx); + Grid::get(opCtx)->getExecutorPool()->shutdownAndJoin(); + Grid::get(opCtx)->catalogClient()->shutDown(opCtx); } } @@ -184,7 +184,7 @@ Status ShardingState::updateConfigServerOpTimeFromMetadata(OperationContext* opC return Status(ErrorCodes::Unauthorized, "Unauthorized to update config opTime"); } - grid.advanceConfigOpTime(*opTime); + Grid::get(opCtx)->advanceConfigOpTime(*opTime); } return Status::OK(); @@ -307,7 +307,8 @@ Status ShardingState::initializeFromShardIdentity(OperationContext* opCtx, invariant(!_shardName.empty()); fassert(40372, _shardName == shardIdentity.getShardName()); - auto prevConfigsvrConnStr = grid.shardRegistry()->getConfigServerConnectionString(); + auto prevConfigsvrConnStr = + Grid::get(opCtx)->shardRegistry()->getConfigServerConnectionString(); invariant(prevConfigsvrConnStr.type() == ConnectionString::SET); fassert(40373, prevConfigsvrConnStr.getSetName() == configSvrConnStr.getSetName()); @@ -549,7 +550,7 @@ void ShardingState::appendInfo(OperationContext* opCtx, BSONObjBuilder& builder) stdx::lock_guard<stdx::mutex> lk(_mutex); builder.append("configServer", - grid.shardRegistry()->getConfigServerConnectionString().toString()); + Grid::get(opCtx)->shardRegistry()->getConfigServerConnectionString().toString()); builder.append("shardName", _shardName); builder.append("clusterId", _clusterId); |