Permalink
Browse files

Move MapReduce option parsing somewhere it can be accessed by mongos …

…and mongod SERVER-7122
  • Loading branch information...
1 parent e013f35 commit 965ad9961052a7dab133ca86e65c0aa210b3a71e @stbrody stbrody committed Nov 15, 2012
Showing with 98 additions and 61 deletions.
  1. +1 −0 src/mongo/SConscript
  2. +0 −60 src/mongo/db/commands/mr.cpp
  3. +8 −1 src/mongo/db/commands/mr.h
  4. +89 −0 src/mongo/db/commands/mr_common.cpp
View
1 src/mongo/SConscript
@@ -202,6 +202,7 @@ env.StaticLibrary("coredb", [
"db/commands/find_and_modify_common.cpp",
"db/commands/hashcmd.cpp",
"db/commands/isself.cpp",
+ "db/commands/mr_common.cpp",
"db/commands/server_status.cpp",
"db/commands/parameters.cpp",
"db/pipeline/pipeline.cpp",
View
60 src/mongo/db/commands/mr.cpp
@@ -216,66 +216,6 @@ namespace mongo {
_reduce( x , key , endSizeEstimate );
}
- Config::OutputOptions Config::parseOutputOptions(const string& dbname,
- const BSONObj& cmdObj) {
- Config::OutputOptions outputOptions;
-
- outputOptions.outNonAtomic = false;
- if ( cmdObj["out"].type() == String ) {
- outputOptions.collectionName = cmdObj["out"].String();
- outputOptions.outType = REPLACE;
- }
- else if ( cmdObj["out"].type() == Object ) {
- BSONObj o = cmdObj["out"].embeddedObject();
-
- BSONElement e = o.firstElement();
- string t = e.fieldName();
-
- if ( t == "normal" || t == "replace" ) {
- outputOptions.outType = REPLACE;
- outputOptions.collectionName = e.String();
- }
- else if ( t == "merge" ) {
- outputOptions.outType = MERGE;
- outputOptions.collectionName = e.String();
- }
- else if ( t == "reduce" ) {
- outputOptions.outType = REDUCE;
- outputOptions.collectionName = e.String();
- }
- else if ( t == "inline" ) {
- outputOptions.outType = INMEMORY;
- }
- else {
- uasserted( 13522 , str::stream() << "unknown out specifier [" << t << "]" );
- }
-
- if (o.hasElement("db")) {
- outputOptions.outDB = o["db"].String();
- }
-
- if (o.hasElement("nonAtomic")) {
- outputOptions.outNonAtomic = o["nonAtomic"].Bool();
- if (outputOptions.outNonAtomic)
- uassert(15895,
- "nonAtomic option cannot be used with this output type",
- (outputOptions.outType == REDUCE ||
- outputOptions.outType == MERGE));
- }
- }
- else {
- uasserted( 13606 , "'out' has to be a string or an object" );
- }
-
- if ( outputOptions.outType != INMEMORY ) {
- outputOptions.finalNamespace = str::stream() <<
- (outputOptions.outDB.empty() ? dbname : outputOptions.outDB) <<
- "." << outputOptions.collectionName;
- }
-
- return outputOptions;
- }
-
Config::Config( const string& _dbname , const BSONObj& cmdObj )
{
dbname = _dbname;
View
9 src/mongo/db/commands/mr.h
@@ -18,7 +18,14 @@
#pragma once
-#include "mongo/pch.h"
+#include <boost/scoped_ptr.hpp>
+#include <string>
+#include <vector>
+
+#include "mongo/db/curop.h"
+#include "mongo/db/instance.h"
+#include "mongo/db/jsobj.h"
+#include "mongo/scripting/engine.h"
namespace mongo {
View
89 src/mongo/db/commands/mr_common.cpp
@@ -0,0 +1,89 @@
+/**
+ * Copyright (C) 2012 10gen Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "mongo/db/commands/mr.h"
+
+#include <string>
+
+#include "mongo/db/jsobj.h"
+#include "mongo/util/mongoutils/str.h"
+
+namespace mongo {
+
+ namespace mr {
+ Config::OutputOptions Config::parseOutputOptions(const std::string& dbname,
+ const BSONObj& cmdObj) {
+ Config::OutputOptions outputOptions;
+
+ outputOptions.outNonAtomic = false;
+ if (cmdObj["out"].type() == String) {
+ outputOptions.collectionName = cmdObj["out"].String();
+ outputOptions.outType = REPLACE;
+ }
+ else if (cmdObj["out"].type() == Object) {
+ BSONObj o = cmdObj["out"].embeddedObject();
+
+ BSONElement e = o.firstElement();
+ string t = e.fieldName();
+
+ if (t == "normal" || t == "replace") {
+ outputOptions.outType = REPLACE;
+ outputOptions.collectionName = e.String();
+ }
+ else if (t == "merge") {
+ outputOptions.outType = MERGE;
+ outputOptions.collectionName = e.String();
+ }
+ else if (t == "reduce") {
+ outputOptions.outType = REDUCE;
+ outputOptions.collectionName = e.String();
+ }
+ else if (t == "inline") {
+ outputOptions.outType = INMEMORY;
+ }
+ else {
+ uasserted(13522,
+ mongoutils::str::stream() << "unknown out specifier [" << t << "]");
+ }
+
+ if (o.hasElement("db")) {
+ outputOptions.outDB = o["db"].String();
+ }
+
+ if (o.hasElement("nonAtomic")) {
+ outputOptions.outNonAtomic = o["nonAtomic"].Bool();
+ if (outputOptions.outNonAtomic)
+ uassert(15895,
+ "nonAtomic option cannot be used with this output type",
+ (outputOptions.outType == REDUCE ||
+ outputOptions.outType == MERGE));
+ }
+ }
+ else {
+ uasserted(13606 , "'out' has to be a string or an object");
+ }
+
+ if (outputOptions.outType != INMEMORY) {
+ outputOptions.finalNamespace = mongoutils::str::stream()
+ << (outputOptions.outDB.empty() ? dbname : outputOptions.outDB)
+ << "." << outputOptions.collectionName;
+ }
+
+ return outputOptions;
+ }
+ }
+
+}

0 comments on commit 965ad99

Please sign in to comment.