summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicholas Zolnierz <nicholas.zolnierz@mongodb.com>2019-10-17 15:29:01 +0000
committerevergreen <evergreen@mongodb.com>2019-10-17 15:29:01 +0000
commita4d3270268d55c3f4839b8944a4d3eb47543e0fd (patch)
treef8302b0ecf9dd5d6c3f1d0b86f1189143685e03e /src
parent65decc93b23acf373d33d7453bb2ba745a6ef319 (diff)
downloadmongo-a4d3270268d55c3f4839b8944a4d3eb47543e0fd.tar.gz
SERVER-42916 Reject non-inline mapReduce to an existing sharded collection that is not sharded by _id
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/commands/mr_common.cpp15
-rw-r--r--src/mongo/s/commands/cluster_map_reduce.cpp5
2 files changed, 14 insertions, 6 deletions
diff --git a/src/mongo/db/commands/mr_common.cpp b/src/mongo/db/commands/mr_common.cpp
index 1621ac716cd..eab02894609 100644
--- a/src/mongo/db/commands/mr_common.cpp
+++ b/src/mongo/db/commands/mr_common.cpp
@@ -316,11 +316,22 @@ std::unique_ptr<Pipeline, PipelineDeleter> translateFromMR(
if (outType == OutputType::Merge || outType == OutputType::Reduce) {
uassert(ErrorCodes::InvalidOptions,
"Source collection cannot be the same as destination collection in MapReduce when "
- "using merge or "
- "reduce actions",
+ "using merge or reduce actions",
inNss != outNss);
}
+ // If non-inline output, verify that the target collection is *not* sharded by anything other
+ // than _id.
+ if (outType != OutputType::InMemory) {
+ auto [shardKey, targetCollectionVersion] =
+ expCtx->mongoProcessInterface->ensureFieldsUniqueOrResolveDocumentKey(
+ expCtx, boost::none, boost::none, outNss);
+ uassert(31313,
+ "The mapReduce target collection must either be unsharded or sharded by {_id: 1} "
+ "or {_id: 'hashed'}",
+ shardKey == std::set<FieldPath>{FieldPath("_id"s)});
+ }
+
// TODO: It would be good to figure out what kind of errors this would produce in the Status.
// It would be better not to produce something incomprehensible out of an internal translation.
return uassertStatusOK(Pipeline::create(
diff --git a/src/mongo/s/commands/cluster_map_reduce.cpp b/src/mongo/s/commands/cluster_map_reduce.cpp
index 9ae34eca3c5..0eadc1b8ee3 100644
--- a/src/mongo/s/commands/cluster_map_reduce.cpp
+++ b/src/mongo/s/commands/cluster_map_reduce.cpp
@@ -671,10 +671,7 @@ bool runMapReduce(OperationContext* opCtx,
outputRoutingInfo.cm());
}
- if (!ok) {
- errmsg = str::stream() << "MR post processing failed: " << singleResult.toString();
- return false;
- }
+ uassert(31311, str::stream() << "MR post processing failed: " << singleResult.toString(), ok);
// copy some elements from a single result
// annoying that we have to copy all results for inline, but no way around it