Skip to content

Commit c254978

Browse files
committed
SERVER-31520 metadata commands on mongos should transparently pass config server response back to client
1 parent b5cea94 commit c254978

File tree

4 files changed

+15
-38
lines changed

4 files changed

+15
-38
lines changed

src/mongo/s/commands/cluster_add_shard_cmd.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "mongo/s/grid.h"
4242
#include "mongo/s/request_types/add_shard_request_type.h"
4343
#include "mongo/util/log.h"
44+
#include "mongo/util/scopeguard.h"
4445

4546
namespace mongo {
4647

@@ -86,30 +87,22 @@ class AddShardCmd : public BasicCommand {
8687
BSONObjBuilder& result) {
8788
auto parsedRequest = uassertStatusOK(AddShardRequest::parseFromMongosCommand(cmdObj));
8889

90+
// Force a reload of this node's shard list cache at the end of this command.
91+
ON_BLOCK_EXIT([opCtx] {
92+
if (!Grid::get(opCtx)->shardRegistry()->reload(opCtx)) {
93+
Grid::get(opCtx)->shardRegistry()->reload(opCtx);
94+
}
95+
});
96+
8997
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
90-
auto cmdResponseStatus = uassertStatusOK(
98+
auto cmdResponse = uassertStatusOK(
9199
configShard->runCommandWithFixedRetryAttempts(opCtx,
92100
kPrimaryOnlyReadPreference,
93101
"admin",
94102
parsedRequest.toCommandForConfig(),
95103
Shard::RetryPolicy::kIdempotent));
96-
uassertStatusOK(cmdResponseStatus.commandStatus);
97-
98-
string shardAdded;
99-
uassertStatusOK(
100-
bsonExtractStringField(cmdResponseStatus.response, kShardAdded, &shardAdded));
101-
result << "shardAdded" << shardAdded;
102-
103-
// Ensure the added shard is visible to this process.
104-
auto shardRegistry = Grid::get(opCtx)->shardRegistry();
105-
if (!shardRegistry->getShard(opCtx, shardAdded).isOK()) {
106-
return appendCommandStatus(result,
107-
{ErrorCodes::OperationFailed,
108-
"Could not find shard metadata for shard after adding it. "
109-
"This most likely indicates that the shard was removed "
110-
"immediately after it was added."});
111-
}
112104

105+
Command::filterCommandReplyForPassthrough(cmdResponse.response, &result);
113106
return true;
114107
}
115108

src/mongo/s/commands/cluster_enable_sharding_cmd.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,14 @@ class EnableShardingCmd : public ErrmsgCommandDeprecated {
9999
ON_BLOCK_EXIT([opCtx, db] { Grid::get(opCtx)->catalogCache()->purgeDatabase(db); });
100100

101101
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
102-
auto cmdResponseStatus = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
102+
auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
103103
opCtx,
104104
ReadPreferenceSetting(ReadPreference::PrimaryOnly),
105105
"admin",
106106
Command::appendPassthroughFields(cmdObj, BSON("_configsvrEnableSharding" << db)),
107107
Shard::RetryPolicy::kIdempotent));
108-
uassertStatusOK(cmdResponseStatus.commandStatus);
109-
110-
if (!cmdResponseStatus.writeConcernStatus.isOK()) {
111-
appendWriteConcernErrorToCmdResponse(
112-
configShard->getId(), cmdResponseStatus.response["writeConcernError"], result);
113-
}
114108

109+
Command::filterCommandReplyForPassthrough(cmdResponse.response, &result);
115110
return true;
116111
}
117112

src/mongo/s/commands/cluster_move_primary_cmd.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,14 @@ class MoveDatabasePrimaryCommand : public BasicCommand {
112112

113113
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
114114

115-
auto cmdResponseStatus = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
115+
auto cmdResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
116116
opCtx,
117117
ReadPreferenceSetting(ReadPreference::PrimaryOnly),
118118
"admin",
119119
Command::appendPassthroughFields(cmdObj, configMovePrimaryRequest.toBSON()),
120120
Shard::RetryPolicy::kIdempotent));
121-
uassertStatusOK(cmdResponseStatus.commandStatus);
122-
123-
if (!cmdResponseStatus.writeConcernStatus.isOK()) {
124-
appendWriteConcernErrorToCmdResponse(
125-
configShard->getId(), cmdResponseStatus.response["writeConcernError"], result);
126-
}
127121

122+
Command::filterCommandReplyForPassthrough(cmdResponse.response, &result);
128123
return true;
129124
}
130125

src/mongo/s/commands/cluster_shard_collection_cmd.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,7 @@ class ShardCollectionCmd : public BasicCommand {
132132
Command::appendPassthroughFields(cmdObj, configShardCollRequest.toBSON()),
133133
Shard::RetryPolicy::kIdempotent));
134134

135-
uassertStatusOK(cmdResponse.commandStatus);
136-
137-
if (!cmdResponse.writeConcernStatus.isOK()) {
138-
appendWriteConcernErrorToCmdResponse(
139-
configShard->getId(), cmdResponse.response["writeConcernError"], result);
140-
}
141-
135+
Command::filterCommandReplyForPassthrough(cmdResponse.response, &result);
142136
return true;
143137
}
144138

0 commit comments

Comments
 (0)