summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands
diff options
context:
space:
mode:
authorMihai Andrei <mihai.andrei@mongodb.com>2019-11-01 21:47:44 +0000
committerevergreen <evergreen@mongodb.com>2019-11-01 21:47:44 +0000
commite5340534df81238e454ce7d3afbb7883115f2c53 (patch)
treef2176e41aa558a45af9ef576329ad7abf4e8702a /src/mongo/db/commands
parent8191b9a55df49629d7f8aec22a4e9c9414e9e914 (diff)
downloadmongo-e5340534df81238e454ce7d3afbb7883115f2c53.tar.gz
SERVER-43578 M/R Agg: Reject mapreduce command sent to mongos which is expected to drop and re-shard the output collection
Diffstat (limited to 'src/mongo/db/commands')
-rw-r--r--src/mongo/db/commands/map_reduce_agg_test.cpp23
-rw-r--r--src/mongo/db/commands/map_reduce_out_options.h4
-rw-r--r--src/mongo/db/commands/mr_common.cpp8
3 files changed, 35 insertions, 0 deletions
diff --git a/src/mongo/db/commands/map_reduce_agg_test.cpp b/src/mongo/db/commands/map_reduce_agg_test.cpp
index 98a237d7d3f..8cdbbe439a3 100644
--- a/src/mongo/db/commands/map_reduce_agg_test.cpp
+++ b/src/mongo/db/commands/map_reduce_agg_test.cpp
@@ -267,5 +267,28 @@ TEST(MapReduceAggTest, testSourceDestinationCollectionsNotEqualMergeDoesNotFail)
ASSERT_DOES_NOT_THROW(map_reduce_common::translateFromMR(mr, expCtx));
}
+TEST(MapReduceAggTest, testShardedTrueWithReplaceActionFailsOnMongos) {
+ auto nss = NamespaceString{"db", "coll"};
+ auto mr = MapReduce{
+ nss,
+ MapReduceJavascriptCode{mapJavascript.toString()},
+ MapReduceJavascriptCode{reduceJavascript.toString()},
+ MapReduceOutOptions{boost::make_optional("db"s), "coll2", OutputType::Replace, true}};
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest(nss));
+ expCtx->inMongos = true;
+ ASSERT_THROWS_CODE(map_reduce_common::translateFromMR(mr, expCtx), DBException, 31327);
+}
+
+TEST(MapReduceAggTest, testShardedTrueWithReplaceActionDoesNotFailOnMongod) {
+ auto nss = NamespaceString{"db", "coll"};
+ auto mr = MapReduce{
+ nss,
+ MapReduceJavascriptCode{mapJavascript.toString()},
+ MapReduceJavascriptCode{reduceJavascript.toString()},
+ MapReduceOutOptions{boost::make_optional("db"s), "coll2", OutputType::Replace, true}};
+ boost::intrusive_ptr<ExpressionContextForTest> expCtx(new ExpressionContextForTest(nss));
+ ASSERT_DOES_NOT_THROW(map_reduce_common::translateFromMR(mr, expCtx));
+}
+
} // namespace
} // namespace mongo
diff --git a/src/mongo/db/commands/map_reduce_out_options.h b/src/mongo/db/commands/map_reduce_out_options.h
index b7d25fd7840..d62f632dae8 100644
--- a/src/mongo/db/commands/map_reduce_out_options.h
+++ b/src/mongo/db/commands/map_reduce_out_options.h
@@ -94,6 +94,10 @@ public:
return _databaseName;
}
+ const bool isSharded() const {
+ return _sharded;
+ }
+
private:
boost::optional<std::string> _databaseName;
std::string _collectionName;
diff --git a/src/mongo/db/commands/mr_common.cpp b/src/mongo/db/commands/mr_common.cpp
index 8eece3727a0..16269873593 100644
--- a/src/mongo/db/commands/mr_common.cpp
+++ b/src/mongo/db/commands/mr_common.cpp
@@ -331,6 +331,14 @@ std::unique_ptr<Pipeline, PipelineDeleter> translateFromMR(
shardKey == std::set<FieldPath>{FieldPath("_id"s)});
}
+ // If sharded option is set to true and the replace action is specified, verify that this isn't
+ // running on mongos.
+ if (outType == OutputType::Replace && parsedMr.getOutOptions().isSharded()) {
+ uassert(31327,
+ "Cannot replace output collection when specifying sharded: true",
+ !expCtx->inMongos);
+ }
+
// 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.
auto pipeline = uassertStatusOK(Pipeline::create(