diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-10-10 10:31:02 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-10-10 14:50:19 -0400 |
commit | 63222d35678ad0bc3419e6e4bdd586da5b16acce (patch) | |
tree | b0ff145cae1305ad9d22907dd59908360d19d8cc | |
parent | db00a0d9b5045f609c1dc2647ed6ebe1bd2a339f (diff) | |
download | mongo-63222d35678ad0bc3419e6e4bdd586da5b16acce.tar.gz |
SERVER-31184 Cleanup usages of global service context objects
Also cleans up some formatting, no functional changes.
-rw-r--r-- | src/mongo/db/commands/find_and_modify.cpp | 22 | ||||
-rw-r--r-- | src/mongo/db/commands/find_and_modify.idl | 52 | ||||
-rw-r--r-- | src/mongo/db/s/config/configsvr_remove_shard_command.cpp | 70 | ||||
-rw-r--r-- | src/mongo/db/write_concern.cpp | 9 | ||||
-rw-r--r-- | src/mongo/s/client/rs_local_client.cpp | 4 |
5 files changed, 72 insertions, 85 deletions
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp index 5b47b54fa95..eb7524cfe29 100644 --- a/src/mongo/db/commands/find_and_modify.cpp +++ b/src/mongo/db/commands/find_and_modify.cpp @@ -166,12 +166,11 @@ void makeDeleteRequest(const FindAndModifyRequest& args, bool explain, DeleteReq requestOut->setExplain(explain); } -void appendCommandResponse(PlanExecutor* exec, +void appendCommandResponse(const PlanExecutor* exec, bool isRemove, const boost::optional<BSONObj>& value, - BSONObjBuilder& result) { - BSONObjBuilder lastErrorObjBuilder(result.subobjStart("lastErrorObject")); - + BSONObjBuilder* result) { + BSONObjBuilder lastErrorObjBuilder(result->subobjStart("lastErrorObject")); if (isRemove) { lastErrorObjBuilder.appendNumber("n", getDeleteStats(exec)->docsDeleted); } else { @@ -184,12 +183,12 @@ void appendCommandResponse(PlanExecutor* exec, lastErrorObjBuilder.appendAs(updateStats->objInserted["_id"], kUpsertedFieldName); } } - lastErrorObjBuilder.done(); + lastErrorObjBuilder.doneFast(); if (value) { - result.append("value", *value); + result->append("value", *value); } else { - result.appendNull("value"); + result->appendNull("value"); } } @@ -459,8 +458,8 @@ public: } recordStatsForTopCommand(opCtx); - boost::optional<BSONObj> value = advanceStatus.getValue(); - appendCommandResponse(exec.get(), args.isRemove(), value, result); + appendCommandResponse( + exec.get(), args.isRemove(), advanceStatus.getValue(), &result); } else { UpdateRequest request(nsString); UpdateLifecycleImpl updateLifecycle(nsString); @@ -573,9 +572,10 @@ public: } recordStatsForTopCommand(opCtx); - boost::optional<BSONObj> value = advanceStatus.getValue(); - appendCommandResponse(exec.get(), args.isRemove(), value, result); + appendCommandResponse( + exec.get(), args.isRemove(), advanceStatus.getValue(), &result); } + return true; }); } diff --git a/src/mongo/db/commands/find_and_modify.idl b/src/mongo/db/commands/find_and_modify.idl index d353284e1f1..694134c7392 100644 --- a/src/mongo/db/commands/find_and_modify.idl +++ b/src/mongo/db/commands/find_and_modify.idl @@ -18,37 +18,33 @@ # for that class. global: - cpp_namespace: "mongo" + cpp_namespace: "mongo" imports: - - "mongo/idl/basic_types.idl" + - "mongo/idl/basic_types.idl" structs: - FindAndModifyLastError: - description: "contains some metrics for the write result." - strict: true - fields: - updatedExisting: - description: "true if the command modified an existing document." - type: bool - optional: true - # TODO: SERVER-30532 - #upserted: - # description: "the _id value of the upserted document" - # type: any_basic_type - # optional: true - n: - description: "the number of documents that were inserted/deleted/match the update predicate" - type: safeInt64 + FindAndModifyLastError: + description: "Contains execution details for the findAndModify command" + strict: true + fields: + updatedExisting: + description: "Specifies whether the command modified an existing document" + type: bool + optional: true + n: + description: "Specifies the number of documents that were inserted/deleted or + matched the update predicate" + type: safeInt64 - FindAndModifyResult: - description: "Parser for serializing result for findAndModify" - strict: false - fields: - lastErrorObject: - type: FindAndModifyLastError - value: - description: "the document before or after the write depending on the 'new' field of - the request was set to true or false." - type: object + FindAndModifyResult: + description: "Contains the result from a findAndModify command" + strict: false + fields: + lastErrorObject: + type: FindAndModifyLastError + value: + description: "Contains document before or after the write depending on the 'new' + field of the request was set to true or false" + type: object diff --git a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp index d24516b0a9c..b7c10d58540 100644 --- a/src/mongo/db/s/config/configsvr_remove_shard_command.cpp +++ b/src/mongo/db/s/config/configsvr_remove_shard_command.cpp @@ -57,21 +57,21 @@ class ConfigSvrRemoveShardCommand : public BasicCommand { public: ConfigSvrRemoveShardCommand() : BasicCommand("_configsvrRemoveShard") {} - virtual bool slaveOk() const { - return false; + void help(std::stringstream& help) const override { + help << "Internal command, which is exported by the sharding config server. Do not call " + "directly. Removes a shard from the cluster."; } - virtual bool adminOnly() const { - return true; + bool slaveOk() const override { + return false; } - virtual bool supportsWriteConcern(const BSONObj& cmd) const override { + bool adminOnly() const override { return true; } - virtual void help(std::stringstream& help) const override { - help << "Internal command, which is exported by the sharding config server. Do not call " - "directly. Removes a shard from the cluster."; + bool supportsWriteConcern(const BSONObj& cmd) const override { + return true; } Status checkAuthForCommand(Client* client, @@ -87,8 +87,7 @@ public: bool run(OperationContext* opCtx, const std::string& dbname, const BSONObj& cmdObj, - BSONObjBuilder& result) { - + BSONObjBuilder& result) override { uassert(ErrorCodes::IllegalOperation, "_configsvrRemoveShard can only be run on config servers", serverGlobalParams.clusterRole == ClusterRole::ConfigServer); @@ -99,51 +98,45 @@ public: cmdObj.firstElement().type() == BSONType::String); const std::string target = cmdObj.firstElement().str(); - const auto shardStatus = grid.shardRegistry()->getShard(opCtx, ShardId(target)); + const auto shardStatus = + Grid::get(opCtx)->shardRegistry()->getShard(opCtx, ShardId(target)); if (!shardStatus.isOK()) { std::string msg(str::stream() << "Could not drop shard '" << target << "' because it does not exist"); log() << msg; return appendCommandStatus(result, Status(ErrorCodes::ShardNotFound, msg)); } - const auto shard = shardStatus.getValue(); + const auto& shard = shardStatus.getValue(); const auto shardingCatalogManager = ShardingCatalogManager::get(opCtx); - StatusWith<ShardDrainingStatus> removeShardResult = - shardingCatalogManager->removeShard(opCtx, shard->getId()); - if (!removeShardResult.isOK()) { - return appendCommandStatus(result, removeShardResult.getStatus()); - } + const auto shardDrainingStatus = + uassertStatusOK(shardingCatalogManager->removeShard(opCtx, shard->getId())); std::vector<std::string> databases; - Status status = - shardingCatalogManager->getDatabasesForShard(opCtx, shard->getId(), &databases); - if (!status.isOK()) { - return appendCommandStatus(result, status); - } + uassertStatusOK( + shardingCatalogManager->getDatabasesForShard(opCtx, shard->getId(), &databases)); // Get BSONObj containing: // 1) note about moving or dropping databases in a shard // 2) list of databases (excluding 'local' database) that need to be moved - BSONObj dbInfo; - { + const auto dbInfo = [&] { BSONObjBuilder dbInfoBuilder; dbInfoBuilder.append("note", "you need to drop or movePrimary these databases"); + BSONArrayBuilder dbs(dbInfoBuilder.subarrayStart("dbsToMove")); - for (std::vector<std::string>::const_iterator it = databases.begin(); - it != databases.end(); - it++) { - if (*it != "local") { - dbs.append(*it); + for (const auto& db : databases) { + if (db != NamespaceString::kLocalDb) { + dbs.append(db); } } dbs.doneFast(); - dbInfo = dbInfoBuilder.obj(); - } - // TODO: Standardize/Seperate how we append to the result object - switch (removeShardResult.getValue()) { + return dbInfoBuilder.obj(); + }(); + + // TODO: Standardize/separate how we append to the result object + switch (shardDrainingStatus) { case ShardDrainingStatus::STARTED: result.append("msg", "draining started successfully"); result.append("state", "started"); @@ -166,13 +159,9 @@ public: result.append("msg", "draining ongoing"); result.append("state", "ongoing"); - { - BSONObjBuilder inner; - inner.append("chunks", static_cast<long long>(chunks.size())); - inner.append("dbs", static_cast<long long>(databases.size())); - BSONObj b = inner.obj(); - result.append("remaining", b); - } + result.append("remaining", + BSON("chunks" << static_cast<long long>(chunks.size()) << "dbs" + << static_cast<long long>(databases.size()))); result.appendElements(dbInfo); break; } @@ -180,6 +169,7 @@ public: result.append("msg", "removeshard completed successfully"); result.append("state", "completed"); result.append("shard", shard->getId().toString()); + break; } return true; diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index 234f63f54aa..c29254226e2 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -166,7 +166,8 @@ Status waitForWriteConcern(OperationContext* opCtx, WriteConcernResult* result) { LOG(2) << "Waiting for write concern. OpTime: " << replOpTime << ", write concern: " << writeConcern.toBSON(); - auto replCoord = repl::ReplicationCoordinator::get(opCtx); + + auto const replCoord = repl::ReplicationCoordinator::get(opCtx); if (!opCtx->getClient()->isInDirectClient()) { // Respecting this failpoint for internal clients prevents stepup from working properly. @@ -233,9 +234,9 @@ Status waitForWriteConcern(OperationContext* opCtx, } // Add stats - result->writtenTo = repl::getGlobalReplicationCoordinator()->getHostsWrittenTo( - replOpTime, - writeConcernWithPopulatedSyncMode.syncMode == WriteConcernOptions::SyncMode::JOURNAL); + result->writtenTo = replCoord->getHostsWrittenTo(replOpTime, + writeConcernWithPopulatedSyncMode.syncMode == + WriteConcernOptions::SyncMode::JOURNAL); gleWtimeStats.recordMillis(durationCount<Milliseconds>(replStatus.duration)); result->wTime = durationCount<Milliseconds>(replStatus.duration); diff --git a/src/mongo/s/client/rs_local_client.cpp b/src/mongo/s/client/rs_local_client.cpp index 6b297adb2f7..61ffe3e6441 100644 --- a/src/mongo/s/client/rs_local_client.cpp +++ b/src/mongo/s/client/rs_local_client.cpp @@ -48,7 +48,7 @@ namespace mongo { void RSLocalClient::_updateLastOpTimeFromClient(OperationContext* opCtx, const repl::OpTime& previousOpTimeOnClient) { - repl::OpTime lastOpTimeFromClient = + const auto lastOpTimeFromClient = repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(); if (lastOpTimeFromClient.isNull() || lastOpTimeFromClient == previousOpTimeOnClient) { @@ -72,7 +72,7 @@ repl::OpTime RSLocalClient::_getLastOpTime() { StatusWith<Shard::CommandResponse> RSLocalClient::runCommandOnce(OperationContext* opCtx, const std::string& dbName, const BSONObj& cmdObj) { - repl::OpTime currentOpTimeFromClient = + const auto currentOpTimeFromClient = repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp(); ON_BLOCK_EXIT([this, &opCtx, ¤tOpTimeFromClient] { _updateLastOpTimeFromClient(opCtx, currentOpTimeFromClient); |