summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/s/commands/cluster_add_shard_cmd.cpp27
-rw-r--r--src/mongo/s/commands/cluster_enable_sharding_cmd.cpp9
-rw-r--r--src/mongo/s/commands/cluster_move_primary_cmd.cpp9
-rw-r--r--src/mongo/s/commands/cluster_shard_collection_cmd.cpp8
4 files changed, 15 insertions, 38 deletions
diff --git a/src/mongo/s/commands/cluster_add_shard_cmd.cpp b/src/mongo/s/commands/cluster_add_shard_cmd.cpp
index 458e5a40f76..ec6cffea1e9 100644
--- a/src/mongo/s/commands/cluster_add_shard_cmd.cpp
+++ b/src/mongo/s/commands/cluster_add_shard_cmd.cpp
@@ -41,6 +41,7 @@
#include "mongo/s/grid.h"
#include "mongo/s/request_types/add_shard_request_type.h"
#include "mongo/util/log.h"
+#include "mongo/util/scopeguard.h"
namespace mongo {
@@ -86,30 +87,22 @@ public:
BSONObjBuilder& result) {
auto parsedRequest = uassertStatusOK(AddShardRequest::parseFromMongosCommand(cmdObj));
+ // Force a reload of this node's shard list cache at the end of this command.
+ ON_BLOCK_EXIT([opCtx] {
+ if (!Grid::get(opCtx)->shardRegistry()->reload(opCtx)) {
+ Grid::get(opCtx)->shardRegistry()->reload(opCtx);
+ }
+ });
+
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
- auto cmdResponseStatus = uassertStatusOK(
+ auto cmdResponse = uassertStatusOK(
configShard->runCommandWithFixedRetryAttempts(opCtx,
kPrimaryOnlyReadPreference,
"admin",
parsedRequest.toCommandForConfig(),
Shard::RetryPolicy::kIdempotent));
- uassertStatusOK(cmdResponseStatus.commandStatus);
-
- string shardAdded;
- uassertStatusOK(
- bsonExtractStringField(cmdResponseStatus.response, kShardAdded, &shardAdded));
- result << "shardAdded" << shardAdded;
-
- // Ensure the added shard is visible to this process.
- auto shardRegistry = Grid::get(opCtx)->shardRegistry();
- if (!shardRegistry->getShard(opCtx, shardAdded).isOK()) {
- return appendCommandStatus(result,
- {ErrorCodes::OperationFailed,
- "Could not find shard metadata for shard after adding it. "
- "This most likely indicates that the shard was removed "
- "immediately after it was added."});
- }
+ Command::filterCommandReplyForPassthrough(cmdResponse.response, &result);
return true;
}
diff --git a/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp b/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp
index d33823630dc..80067cbeea3 100644
--- a/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp
+++ b/src/mongo/s/commands/cluster_enable_sharding_cmd.cpp
@@ -99,19 +99,14 @@ public:
ON_BLOCK_EXIT([opCtx, db] { Grid::get(opCtx)->catalogCache()->purgeDatabase(db); });
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
- auto cmdResponseStatus = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
+ auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
opCtx,
ReadPreferenceSetting(ReadPreference::PrimaryOnly),
"admin",
Command::appendPassthroughFields(cmdObj, BSON("_configsvrEnableSharding" << db)),
Shard::RetryPolicy::kIdempotent));
- uassertStatusOK(cmdResponseStatus.commandStatus);
-
- if (!cmdResponseStatus.writeConcernStatus.isOK()) {
- appendWriteConcernErrorToCmdResponse(
- configShard->getId(), cmdResponseStatus.response["writeConcernError"], result);
- }
+ Command::filterCommandReplyForPassthrough(cmdResponse.response, &result);
return true;
}
diff --git a/src/mongo/s/commands/cluster_move_primary_cmd.cpp b/src/mongo/s/commands/cluster_move_primary_cmd.cpp
index e67afb64e04..33c99a0d77b 100644
--- a/src/mongo/s/commands/cluster_move_primary_cmd.cpp
+++ b/src/mongo/s/commands/cluster_move_primary_cmd.cpp
@@ -112,19 +112,14 @@ public:
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
- auto cmdResponseStatus = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
+ auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
opCtx,
ReadPreferenceSetting(ReadPreference::PrimaryOnly),
"admin",
Command::appendPassthroughFields(cmdObj, configMovePrimaryRequest.toBSON()),
Shard::RetryPolicy::kIdempotent));
- uassertStatusOK(cmdResponseStatus.commandStatus);
-
- if (!cmdResponseStatus.writeConcernStatus.isOK()) {
- appendWriteConcernErrorToCmdResponse(
- configShard->getId(), cmdResponseStatus.response["writeConcernError"], result);
- }
+ Command::filterCommandReplyForPassthrough(cmdResponse.response, &result);
return true;
}
diff --git a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp
index b2566ec7584..5e5de39cd05 100644
--- a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp
+++ b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp
@@ -132,13 +132,7 @@ public:
Command::appendPassthroughFields(cmdObj, configShardCollRequest.toBSON()),
Shard::RetryPolicy::kIdempotent));
- uassertStatusOK(cmdResponse.commandStatus);
-
- if (!cmdResponse.writeConcernStatus.isOK()) {
- appendWriteConcernErrorToCmdResponse(
- configShard->getId(), cmdResponse.response["writeConcernError"], result);
- }
-
+ Command::filterCommandReplyForPassthrough(cmdResponse.response, &result);
return true;
}