summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
authorJamie Heppenstall <jamie.heppenstall@mongodb.com>2019-06-06 15:00:55 -0400
committerJamie Heppenstall <jamie.heppenstall@mongodb.com>2019-07-03 10:13:52 -0400
commit6792520dc6a2a0c430c11fc264faa1e061903fbd (patch)
treed22fcc215ec30f1e38c2a2e4fd6a8b7c7071aff8 /src/mongo/s
parent037a9b1a9e841fa7c221346c6efe280807b90c0a (diff)
downloadmongo-6792520dc6a2a0c430c11fc264faa1e061903fbd.tar.gz
SERVER-39659 Reformat createShardDatabase to return void and call uasserts on all relevant statuses
(cherry picked from commit 0863aca0c6ad060ad241b7fa75fb03db06beccb0)
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/cluster_commands_helpers.cpp36
-rw-r--r--src/mongo/s/cluster_commands_helpers.h6
-rw-r--r--src/mongo/s/commands/cluster_create_cmd.cpp2
-rw-r--r--src/mongo/s/commands/cluster_create_indexes_cmd.cpp2
-rw-r--r--src/mongo/s/commands/cluster_find_and_modify_cmd.cpp2
-rw-r--r--src/mongo/s/commands/cluster_map_reduce_cmd.cpp2
-rw-r--r--src/mongo/s/write_ops/chunk_manager_targeter.cpp7
7 files changed, 28 insertions, 29 deletions
diff --git a/src/mongo/s/cluster_commands_helpers.cpp b/src/mongo/s/cluster_commands_helpers.cpp
index 372da718964..3cf00aba6dd 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,
diff --git a/src/mongo/s/cluster_commands_helpers.h b/src/mongo/s/cluster_commands_helpers.h
index c1dcc2f1050..433013c76b6 100644
--- a/src/mongo/s/cluster_commands_helpers.h
+++ b/src/mongo/s/cluster_commands_helpers.h
@@ -198,10 +198,10 @@ bool appendEmptyResultSet(OperationContext* opCtx,
const std::string& ns);
/**
- * If the specified database exists already, loads it in the cache (if not already there) and
- * returns it. Otherwise, if it does not exist, this call will implicitly create it as non-sharded.
+ * If the specified database exists already, loads it in the cache (if not already there).
+ * Otherwise, if it does not exist, this call will implicitly create it as non-sharded.
*/
-StatusWith<CachedDatabaseInfo> createShardDatabase(OperationContext* opCtx, StringData dbName);
+void createShardDatabase(OperationContext* opCtx, StringData dbName);
/**
* Returns the shards that would be targeted for the given query according to the given routing
diff --git a/src/mongo/s/commands/cluster_create_cmd.cpp b/src/mongo/s/commands/cluster_create_cmd.cpp
index a5c71dcb1e0..9b9ebab29e3 100644
--- a/src/mongo/s/commands/cluster_create_cmd.cpp
+++ b/src/mongo/s/commands/cluster_create_cmd.cpp
@@ -73,7 +73,7 @@ public:
BSONObjBuilder& result) override {
const NamespaceString nss(parseNs(dbName, cmdObj));
- uassertStatusOK(createShardDatabase(opCtx, dbName));
+ createShardDatabase(opCtx, dbName);
uassert(ErrorCodes::InvalidOptions,
"specify size:<n> when capped is true",
diff --git a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp
index 65ac1d1abcc..31e0d36625a 100644
--- a/src/mongo/s/commands/cluster_create_indexes_cmd.cpp
+++ b/src/mongo/s/commands/cluster_create_indexes_cmd.cpp
@@ -71,7 +71,7 @@ public:
const NamespaceString nss(CommandHelpers::parseNsCollectionRequired(dbName, cmdObj));
LOG(1) << "createIndexes: " << nss << " cmd:" << redact(cmdObj);
- uassertStatusOK(createShardDatabase(opCtx, dbName));
+ createShardDatabase(opCtx, dbName);
auto shardResponses = scatterGatherOnlyVersionIfUnsharded(
opCtx,
diff --git a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp
index fb147d54a06..1f70c6080a0 100644
--- a/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp
+++ b/src/mongo/s/commands/cluster_find_and_modify_cmd.cpp
@@ -228,7 +228,7 @@ public:
// findAndModify should only be creating database if upsert is true, but this would require
// that the parsing be pulled into this function.
- uassertStatusOK(createShardDatabase(opCtx, nss.db()));
+ createShardDatabase(opCtx, nss.db());
// Append mongoS' runtime constants to the command object before forwarding it to the shard.
auto cmdObjForShard = appendRuntimeConstantsToCommandObject(opCtx, cmdObj);
diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
index 3a9cfddcdf6..6f169e55140 100644
--- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
+++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp
@@ -244,7 +244,7 @@ public:
// Create the output database implicitly if we have a custom output requested
if (customOutDB) {
- uassertStatusOK(createShardDatabase(opCtx, outDB));
+ createShardDatabase(opCtx, outDB);
}
// Ensure that the output database doesn't reside on the config server
diff --git a/src/mongo/s/write_ops/chunk_manager_targeter.cpp b/src/mongo/s/write_ops/chunk_manager_targeter.cpp
index 7cf36798a16..d723f59d70c 100644
--- a/src/mongo/s/write_ops/chunk_manager_targeter.cpp
+++ b/src/mongo/s/write_ops/chunk_manager_targeter.cpp
@@ -348,9 +348,10 @@ ChunkManagerTargeter::ChunkManagerTargeter(const NamespaceString& nss,
Status ChunkManagerTargeter::init(OperationContext* opCtx) {
- auto shardDbStatus = createShardDatabase(opCtx, _nss.db());
- if (!shardDbStatus.isOK()) {
- return shardDbStatus.getStatus();
+ try {
+ createShardDatabase(opCtx, _nss.db());
+ } catch (const DBException& e) {
+ return e.toStatus();
}
const auto routingInfoStatus = getCollectionRoutingInfoForTxnCmd(opCtx, _nss);