diff options
author | Spencer T Brody <spencer@mongodb.com> | 2016-06-15 14:45:15 -0400 |
---|---|---|
committer | Spencer T Brody <spencer@mongodb.com> | 2016-06-22 17:39:56 -0400 |
commit | ef34ca10813a2fa779b2693f6566e354b09b063b (patch) | |
tree | 756f6a5c663409071112e2b6363e5f62212e9599 | |
parent | e90b12837bf13891da5153173dff8a4f36d347cd (diff) | |
download | mongo-ef34ca10813a2fa779b2693f6566e354b09b063b.tar.gz |
SERVER-24597 Fix check that prevents sending mapreduce output to config servers
-rw-r--r-- | buildscripts/resmokeconfig/suites/sharding_last_stable_mongos.yml | 2 | ||||
-rw-r--r-- | jstests/sharding/map_reduce_validation.js | 10 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_map_reduce_cmd.cpp | 10 |
4 files changed, 21 insertions, 7 deletions
diff --git a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos.yml b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos.yml index c7b49a27e4f..1d75bab8814 100644 --- a/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos.yml +++ b/buildscripts/resmokeconfig/suites/sharding_last_stable_mongos.yml @@ -24,6 +24,8 @@ selector: - jstests/sharding/shard_collection_verify_initial_chunks.js # TODO: Enable when SERVER-22672 is complete - jstests/sharding/printShardingStatus.js + # TODO: Change in error reporting, enable when 3.4 becomes 'last-stable'. + - jstests/sharding/map_reduce_validation.js executor: js_test: diff --git a/jstests/sharding/map_reduce_validation.js b/jstests/sharding/map_reduce_validation.js index 7ccbf6130ee..89aec1820fa 100644 --- a/jstests/sharding/map_reduce_validation.js +++ b/jstests/sharding/map_reduce_validation.js @@ -13,7 +13,7 @@ assert.commandFailed(testDB.runCommand( {mapReduce: 'user', map: mapFunc, reduce: reduceFunc, out: {inline: 1, sharded: true}})); testDB.bar.insert({i: 1}); -assert.commandFailed(testDB.runCommand({ +assert.commandFailedWithCode(testDB.runCommand({ mapReduce: 'bar', map: function() { emit(this.i, this.i * 3); @@ -22,9 +22,10 @@ assert.commandFailed(testDB.runCommand({ return Array.sum(values); }, out: {replace: "foo", db: "admin"} -})); +}), + ErrorCodes.CommandNotSupported); -assert.commandFailed(testDB.runCommand({ +assert.commandFailedWithCode(testDB.runCommand({ mapReduce: 'bar', map: function() { emit(this.i, this.i * 3); @@ -33,7 +34,8 @@ assert.commandFailed(testDB.runCommand({ return Array.sum(values); }, out: {replace: "foo", db: "config"} -})); +}), + ErrorCodes.CommandNotSupported); assert.commandWorked(testDB.runCommand({ mapReduce: 'bar', diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index 7ce01758d8b..ade9ae9225e 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -1670,12 +1670,12 @@ public: int, string& errmsg, BSONObjBuilder& result) { - if (!grid.shardRegistry()) { + if (serverGlobalParams.clusterRole == ClusterRole::ConfigServer) { return appendCommandStatus( result, Status(ErrorCodes::CommandNotSupported, - str::stream() << "Can not execute mapReduce with output database " - << dbname)); + str::stream() << "Can not execute mapReduce with output database " << dbname + << " which lives on config servers")); } boost::optional<DisableDocumentValidation> maybeDisableValidation; diff --git a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp index b69b5ea4add..b8e7bb9e0c9 100644 --- a/src/mongo/s/commands/cluster_map_reduce_cmd.cpp +++ b/src/mongo/s/commands/cluster_map_reduce_cmd.cpp @@ -195,6 +195,7 @@ public: bool shardedOutput = false; NamespaceString outputCollNss; bool customOutDB = false; + bool inlineOutput = false; string outDB = dbname; @@ -205,6 +206,7 @@ public: shardedOutput = customOut.getBoolField("sharded"); if (customOut.hasField("inline")) { + inlineOutput = true; uassert(ErrorCodes::InvalidOptions, "cannot specify inline and sharded output at the same time", !shardedOutput); @@ -243,6 +245,14 @@ public: confOut = confIn; } + if (confOut->getPrimaryId() == "config" && !inlineOutput) { + return appendCommandStatus( + result, + Status(ErrorCodes::CommandNotSupported, + str::stream() << "Can not execute mapReduce with output database " << outDB + << " which lives on config servers")); + } + const bool shardedInput = confIn && confIn->isShardingEnabled() && confIn->isSharded(nss.ns()); |