Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

custom out db for m/r doesn't work sharded with non-sharded db

  • Loading branch information...
commit 279d61cce49b981ff8d44d50b66a5fe0e79da7b1 1 parent 29f2a72
@erh erh authored
View
9 jstests/mr_replaceIntoDB.js
@@ -23,22 +23,23 @@ function tos( o ){
print("Testing mr replace into other DB")
res = t.mapReduce( m , r , { out : { replace: outCollStr, db: outDbStr } } )
+printjson( res );
expected = { "1" : 1 , "2" : 2 , "3" : 2 , "4" : 1 };
outDb = db.getMongo().getDB(outDbStr);
outColl = outDb[outCollStr];
str = tos( outColl.convertToSingleObject("value") )
print("Received result: " + str);
-assert.eq( tos( expected ) , str , "Received wrong result " + str );
+assert.eq( tos( expected ) , str , "A Received wrong result " + str );
print("checking result field");
-assert.eq(res.result.collection, outCollStr, "Wrong collection " + res.result.collection)
-assert.eq(res.result.db, outDbStr, "Wrong db " + res.result.db)
+assert.eq(res.result.collection, outCollStr, "B1 Wrong collection " + res.result.collection)
+assert.eq(res.result.db, outDbStr, "B2 Wrong db " + res.result.db)
print("Replace again and check");
outColl.save({_id: "5", value : 1});
t.mapReduce( m , r , { out : { replace: outCollStr, db: outDbStr } } )
str = tos( outColl.convertToSingleObject("value") )
print("Received result: " + str);
-assert.eq( tos( expected ) , str , "Received wrong result " + str );
+assert.eq( tos( expected ) , str , "C1 Received wrong result " + str );
View
2  jstests/slowNightly/sharding_passthrough.js
@@ -73,7 +73,7 @@ files.forEach(
return;
}
// These aren't supposed to get run under sharding:
- if (/[\/\\](dbadmin|error1|fsync|fsync2|geo.*|indexh|remove5|update4|notablescan|check_shard_index)\.js$/.test(x.name)) {
+ if (/[\/\\](dbadmin|error1|fsync|fsync2|geo.*|indexh|remove5|update4|notablescan|check_shard_index|mr_replaceIntoDB)\.js$/.test(x.name)) {
print(" >>>>>>>>>>>>>>> skipping test that would fail under sharding " + x.name)
return;
}
View
17 s/commands_public.cpp
@@ -868,9 +868,19 @@ namespace mongo {
string collection = cmdObj.firstElement().valuestrsafe();
string fullns = dbName + "." + collection;
+ const string shardedOutputCollection = getTmpName( collection );
+ BSONObj customOut;
+ BSONObj shardedCommand = fixForShards( cmdObj , shardedOutputCollection, customOut );
+
+ bool customOutDB = ! customOut.isEmpty() && customOut.hasField( "db" );
+
DBConfigPtr conf = grid.getDBConfig( dbName , false );
if ( ! conf || ! conf->isShardingEnabled() || ! conf->isSharded( fullns ) ) {
+ if ( customOutDB ) {
+ errmsg = "can't use out 'db' with non-sharded db";
+ return false;
+ }
return passthrough( conf , cmdObj , result );
}
@@ -886,9 +896,6 @@ namespace mongo {
set<Shard> shards;
cm->getShardsForQuery( shards , q );
- const string shardedOutputCollection = getTmpName( collection );
- BSONObj customOut;
- BSONObj shardedCommand = fixForShards( cmdObj , shardedOutputCollection, customOut );
BSONObjBuilder finalCmd;
finalCmd.append( "mapreduce.shardedfinish" , cmdObj );
@@ -918,7 +925,7 @@ namespace mongo {
// by default the target database is same as input
Shard outServer = conf->getPrimary();
string outns = fullns;
- if (!customOut.isEmpty() && customOut.hasField("db")) {
+ if ( customOutDB ) {
// have to figure out shard for the output DB
BSONElement elmt = customOut.getField("db");
string outdb = elmt.valuestrsafe();
@@ -926,6 +933,8 @@ namespace mongo {
DBConfigPtr conf2 = grid.getDBConfig( outdb , true );
outServer = conf2->getPrimary();
}
+ log() << "customOut: " << customOut << " outServer: " << outServer << endl;
+
ShardConnection conn( outServer , outns );
BSONObj finalResult;
bool ok = conn->runCommand( dbName , finalCmd.obj() , finalResult );

0 comments on commit 279d61c

Please sign in to comment.
Something went wrong with that request. Please try again.