summaryrefslogtreecommitdiff
path: root/src/mongo/s/cluster_commands_helpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/cluster_commands_helpers.cpp')
-rw-r--r--src/mongo/s/cluster_commands_helpers.cpp36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp
index 3d6cf6ed18b..d411f79f991 100644
--- a/src/mongo/s/cluster_commands_helpers.cpp
+++ b/src/mongo/s/cluster_commands_helpers.cpp
@@ -507,36 +507,34 @@ bool appendEmptyResultSet(OperationContext* opCtx,
return true;
}
-StatusWith<CachedDatabaseInfo> createShardDatabase(OperationContext* opCtx, StringData dbName) {
+void createShardDatabase(OperationContext* opCtx, StringData dbName) {
auto dbStatus = Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, dbName);
+
if (dbStatus == ErrorCodes::NamespaceNotFound) {
ConfigsvrCreateDatabase configCreateDatabaseRequest(dbName.toString());
configCreateDatabaseRequest.setDbName(NamespaceString::kAdminDb);
auto configShard = Grid::get(opCtx)->shardRegistry()->getConfigShard();
- auto createDbStatus =
- uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
- opCtx,
- ReadPreferenceSetting(ReadPreference::PrimaryOnly),
- "admin",
- CommandHelpers::appendMajorityWriteConcern(
- configCreateDatabaseRequest.toBSON({})),
- Shard::RetryPolicy::kIdempotent))
- .commandStatus;
-
- if (createDbStatus.isOK() || createDbStatus == ErrorCodes::NamespaceExists) {
- dbStatus = Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, dbName);
- } else {
- dbStatus = createDbStatus;
+ auto createDbResponse = uassertStatusOK(configShard->runCommandWithFixedRetryAttempts(
+ opCtx,
+ ReadPreferenceSetting(ReadPreference::PrimaryOnly),
+ "admin",
+ CommandHelpers::appendMajorityWriteConcern(configCreateDatabaseRequest.toBSON({})),
+ Shard::RetryPolicy::kIdempotent));
+
+ uassertStatusOK(createDbResponse.writeConcernStatus);
+
+ if (createDbResponse.commandStatus != ErrorCodes::NamespaceExists) {
+ uassertStatusOKWithContext(createDbResponse.commandStatus,
+ str::stream() << "Database " << dbName
+ << " could not be created");
}
- }
- if (dbStatus.isOK()) {
- return dbStatus;
+ dbStatus = Grid::get(opCtx)->catalogCache()->getDatabase(opCtx, dbName);
}
- return dbStatus.getStatus().withContext(str::stream() << "Database " << dbName << " not found");
+ uassertStatusOKWithContext(dbStatus, str::stream() << "Database " << dbName << " not found");
}
std::set<ShardId> getTargetedShardsForQuery(OperationContext* opCtx,