summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-10-03 13:19:49 -0400
committerKaloian Manassiev <kaloian.manassiev@mongodb.com>2017-10-05 17:31:10 -0400
commited31e32a74d942ef337ef507ad4628d224d65953 (patch)
tree78c5ac0d195f8fe028fdc64cdb6227d784e4f01d
parentcb9f7cdcb7eb6ad9077ac8af3a4c0d7275c7e34f (diff)
downloadmongo-ed31e32a74d942ef337ef507ad4628d224d65953.tar.gz
SERVER-31352 Always skip OperationShardingState initialization if readConcern is `available`
-rw-r--r--src/mongo/db/repl/read_concern_args.cpp4
-rw-r--r--src/mongo/db/repl/read_concern_args.h5
-rw-r--r--src/mongo/db/service_entry_point_mongod.cpp67
-rw-r--r--src/mongo/s/commands/cluster_list_shards_cmd.cpp49
4 files changed, 54 insertions, 71 deletions
diff --git a/src/mongo/db/repl/read_concern_args.cpp b/src/mongo/db/repl/read_concern_args.cpp
index e1a709b3b24..0611dc05c4d 100644
--- a/src/mongo/db/repl/read_concern_args.cpp
+++ b/src/mongo/db/repl/read_concern_args.cpp
@@ -97,10 +97,6 @@ bool ReadConcernArgs::hasLevel() const {
return _level.is_initialized();
}
-bool ReadConcernArgs::isLevelAvailable() const {
- return hasLevel() && _level.get() == ReadConcernLevel::kAvailableReadConcern;
-}
-
boost::optional<OpTime> ReadConcernArgs::getArgsOpTime() const {
return _opTime;
}
diff --git a/src/mongo/db/repl/read_concern_args.h b/src/mongo/db/repl/read_concern_args.h
index 0358bf38cd1..2fab94d4f75 100644
--- a/src/mongo/db/repl/read_concern_args.h
+++ b/src/mongo/db/repl/read_concern_args.h
@@ -113,11 +113,6 @@ public:
bool hasLevel() const;
/**
- * Checks whether 'available' read concern level is set.
- */
- bool isLevelAvailable() const;
-
- /**
* Returns the opTime. Deprecated: will be replaced with getArgsClusterTime.
*/
boost::optional<OpTime> getArgsOpTime() const;
diff --git a/src/mongo/db/service_entry_point_mongod.cpp b/src/mongo/db/service_entry_point_mongod.cpp
index 8f9ea2f2a0f..d4a45dd7a80 100644
--- a/src/mongo/db/service_entry_point_mongod.cpp
+++ b/src/mongo/db/service_entry_point_mongod.cpp
@@ -230,19 +230,25 @@ void _generateErrorResponse(OperationContext* opCtx,
* elsewhere.
*/
class MaintenanceModeSetter {
+ MONGO_DISALLOW_COPYING(MaintenanceModeSetter);
+
public:
- MaintenanceModeSetter()
- : maintenanceModeSet(
- repl::getGlobalReplicationCoordinator()->setMaintenanceMode(true).isOK()) {}
+ MaintenanceModeSetter(OperationContext* opCtx)
+ : _opCtx(opCtx),
+ _maintenanceModeSet(
+ repl::ReplicationCoordinator::get(_opCtx)->setMaintenanceMode(true).isOK()) {}
+
~MaintenanceModeSetter() {
- if (maintenanceModeSet)
- repl::getGlobalReplicationCoordinator()
+ if (_maintenanceModeSet) {
+ repl::ReplicationCoordinator::get(_opCtx)
->setMaintenanceMode(false)
.transitional_ignore();
+ }
}
private:
- bool maintenanceModeSet;
+ OperationContext* const _opCtx;
+ const bool _maintenanceModeSet;
};
void appendReplyMetadata(OperationContext* opCtx,
@@ -250,7 +256,7 @@ void appendReplyMetadata(OperationContext* opCtx,
BSONObjBuilder* metadataBob) {
const bool isShardingAware = ShardingState::get(opCtx)->enabled();
const bool isConfig = serverGlobalParams.clusterRole == ClusterRole::ConfigServer;
- repl::ReplicationCoordinator* replCoord = repl::getGlobalReplicationCoordinator();
+ auto const replCoord = repl::ReplicationCoordinator::get(opCtx);
const bool isReplSet =
replCoord->getReplicationMode() == repl::ReplicationCoordinator::modeReplSet;
@@ -346,8 +352,7 @@ void _waitForWriteConcernAndAddToCommandResponse(OperationContext* opCtx,
* uninitialized cluster time.
*/
LogicalTime getClientOperationTime(OperationContext* opCtx) {
- repl::ReplicationCoordinator* replCoord =
- repl::ReplicationCoordinator::get(opCtx->getClient()->getServiceContext());
+ auto const replCoord = repl::ReplicationCoordinator::get(opCtx);
const bool isReplSet =
replCoord->getReplicationMode() == repl::ReplicationCoordinator::modeReplSet;
LogicalTime operationTime;
@@ -367,8 +372,7 @@ LogicalTime getClientOperationTime(OperationContext* opCtx) {
LogicalTime computeOperationTime(OperationContext* opCtx,
LogicalTime startOperationTime,
repl::ReadConcernLevel level) {
- repl::ReplicationCoordinator* replCoord =
- repl::ReplicationCoordinator::get(opCtx->getClient()->getServiceContext());
+ auto const replCoord = repl::ReplicationCoordinator::get(opCtx);
const bool isReplSet =
replCoord->getReplicationMode() == repl::ReplicationCoordinator::modeReplSet;
@@ -538,15 +542,14 @@ void execCommandDatabase(OperationContext* opCtx,
rpc::readRequestMetadata(opCtx, request.body);
rpc::TrackingMetadata::get(opCtx).initWithOperName(command->getName());
- repl::ReplicationCoordinator* replCoord =
- repl::ReplicationCoordinator::get(opCtx->getClient()->getServiceContext());
+ auto const replCoord = repl::ReplicationCoordinator::get(opCtx);
initializeOperationSessionInfo(opCtx,
request.body,
command->requiresAuth(),
replCoord->getReplicationMode() ==
repl::ReplicationCoordinator::modeReplSet);
- std::string dbname = request.getDatabase().toString();
+ const auto dbname = request.getDatabase().toString();
uassert(
ErrorCodes::InvalidNamespace,
str::stream() << "Invalid database name: '" << dbname << "'",
@@ -645,7 +648,7 @@ void execCommandDatabase(OperationContext* opCtx,
}
if (command->maintenanceMode()) {
- mmSetter.reset(new MaintenanceModeSetter);
+ mmSetter.reset(new MaintenanceModeSetter(opCtx));
}
if (command->shouldAffectCommandCounter()) {
@@ -667,29 +670,22 @@ void execCommandDatabase(OperationContext* opCtx,
opCtx->setDeadlineAfterNowBy(Milliseconds{maxTimeMS});
}
- repl::ReadConcernArgs::get(opCtx) = uassertStatusOK(_extractReadConcern(
- request.body,
- command->supportsNonLocalReadConcern(request.getDatabase().toString(), request.body)));
+ auto& readConcernArgs = repl::ReadConcernArgs::get(opCtx);
+ readConcernArgs = uassertStatusOK(_extractReadConcern(
+ request.body, command->supportsNonLocalReadConcern(dbname, request.body)));
auto& oss = OperationShardingState::get(opCtx);
- // Don't handle the shard version that may have been sent along with the command iff
- // fcv==3.4: This is a secondary.
- // fcv==3.6: The 'available' rc-level is specified, or this is a secondary and neither the
- // clusterTime nor rc-level was specified -- secondaries default to 'available'
- // when neither clusterTime nor rc-level is set.
- // or this command was issued via the direct client.
- if ((iAmPrimary || (serverGlobalParams.featureCompatibility.version.load() ==
- ServerGlobalParams::FeatureCompatibility::Version::k36 &&
- (repl::ReadConcernArgs::get(opCtx).hasLevel() ||
- repl::ReadConcernArgs::get(opCtx).getArgsClusterTime()))) &&
- !opCtx->getClient()->isInDirectClient() &&
- (serverGlobalParams.featureCompatibility.version.load() ==
- ServerGlobalParams::FeatureCompatibility::Version::k34 ||
- !repl::ReadConcernArgs::get(opCtx).isLevelAvailable())) {
- auto commandNS = NamespaceString(command->parseNs(dbname, request.body));
- oss.initializeShardVersion(commandNS, shardVersionFieldIdx);
- auto shardingState = ShardingState::get(opCtx);
+ if (!opCtx->getClient()->isInDirectClient() &&
+ readConcernArgs.getLevel() != repl::ReadConcernLevel::kAvailableReadConcern &&
+ (iAmPrimary ||
+ (serverGlobalParams.featureCompatibility.version.load() ==
+ ServerGlobalParams::FeatureCompatibility::Version::k36 &&
+ (readConcernArgs.hasLevel() || readConcernArgs.getArgsClusterTime())))) {
+ oss.initializeShardVersion(NamespaceString(command->parseNs(dbname, request.body)),
+ shardVersionFieldIdx);
+
+ auto const shardingState = ShardingState::get(opCtx);
if (oss.hasShardVersion()) {
uassertStatusOK(shardingState->canAcceptShardedCommands());
}
@@ -716,6 +712,7 @@ void execCommandDatabase(OperationContext* opCtx,
<< rpc::TrackingMetadata::get(opCtx).toString();
rpc::TrackingMetadata::get(opCtx).setIsLogged(true);
}
+
retval = runCommandImpl(opCtx, command, request, replyBuilder, startOperationTime);
if (!retval) {
diff --git a/src/mongo/s/commands/cluster_list_shards_cmd.cpp b/src/mongo/s/commands/cluster_list_shards_cmd.cpp
index 8527703c3b7..7a303fd3bb2 100644
--- a/src/mongo/s/commands/cluster_list_shards_cmd.cpp
+++ b/src/mongo/s/commands/cluster_list_shards_cmd.cpp
@@ -30,7 +30,6 @@
#include <vector>
-#include "mongo/client/connpool.h"
#include "mongo/db/commands.h"
#include "mongo/s/catalog/sharding_catalog_client.h"
#include "mongo/s/catalog/type_shard.h"
@@ -43,47 +42,43 @@ class ListShardsCmd : public BasicCommand {
public:
ListShardsCmd() : BasicCommand("listShards", "listshards") {}
- virtual bool slaveOk() const {
- return true;
+ void help(std::stringstream& help) const override {
+ help << "list all shards of the system";
}
- virtual bool adminOnly() const {
+ bool adminOnly() const override {
return true;
}
-
- virtual bool supportsWriteConcern(const BSONObj& cmd) const override {
- return false;
+ virtual bool slaveOk() const {
+ return true;
}
- virtual void help(std::stringstream& help) const {
- help << "list all shards of the system";
+ bool supportsWriteConcern(const BSONObj& cmd) const override {
+ return false;
}
- virtual void addRequiredPrivileges(const std::string& dbname,
- const BSONObj& cmdObj,
- std::vector<Privilege>* out) {
+ void addRequiredPrivileges(const std::string& dbname,
+ const BSONObj& cmdObj,
+ std::vector<Privilege>* out) override {
ActionSet actions;
actions.addAction(ActionType::listShards);
out->push_back(Privilege(ResourcePattern::forClusterResource(), actions));
}
- virtual bool run(OperationContext* opCtx,
- const std::string& dbname,
- const BSONObj& cmdObj,
- BSONObjBuilder& result) {
- auto shardsStatus =
- grid.catalogClient()->getAllShards(opCtx, repl::ReadConcernLevel::kMajorityReadConcern);
- if (!shardsStatus.isOK()) {
- return appendCommandStatus(result, shardsStatus.getStatus());
- }
- std::vector<ShardType> shards = std::move(shardsStatus.getValue().value);
-
- std::vector<BSONObj> shardsObj;
- for (std::vector<ShardType>::const_iterator it = shards.begin(); it != shards.end(); it++) {
- shardsObj.push_back(it->toBSON());
+ bool run(OperationContext* opCtx,
+ const std::string& dbname,
+ const BSONObj& cmdObj,
+ BSONObjBuilder& result) override {
+ const auto opTimeWithShards =
+ uassertStatusOK(Grid::get(opCtx)->catalogClient()->getAllShards(
+ opCtx, repl::ReadConcernLevel::kMajorityReadConcern));
+
+ BSONArrayBuilder shardsArr(result.subarrayStart("shards"));
+ for (const auto& shard : opTimeWithShards.value) {
+ shardsArr.append(shard.toBSON());
}
- result.append("shards", shardsObj);
+ shardsArr.doneFast();
return true;
}