Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

  • Loading branch information...
commit 279d61cce49b981ff8d44d50b66a5fe0e79da7b1 1 parent 29f2a72
Eliot erh authored
9 jstests/mr_replaceIntoDB.js
@@ -23,22 +23,23 @@ function tos( o ){
23 23
24 24 print("Testing mr replace into other DB")
25 25 res = t.mapReduce( m , r , { out : { replace: outCollStr, db: outDbStr } } )
  26 +printjson( res );
26 27 expected = { "1" : 1 , "2" : 2 , "3" : 2 , "4" : 1 };
27 28 outDb = db.getMongo().getDB(outDbStr);
28 29 outColl = outDb[outCollStr];
29 30 str = tos( outColl.convertToSingleObject("value") )
30 31 print("Received result: " + str);
31   -assert.eq( tos( expected ) , str , "Received wrong result " + str );
  32 +assert.eq( tos( expected ) , str , "A Received wrong result " + str );
32 33
33 34 print("checking result field");
34   -assert.eq(res.result.collection, outCollStr, "Wrong collection " + res.result.collection)
35   -assert.eq(res.result.db, outDbStr, "Wrong db " + res.result.db)
  35 +assert.eq(res.result.collection, outCollStr, "B1 Wrong collection " + res.result.collection)
  36 +assert.eq(res.result.db, outDbStr, "B2 Wrong db " + res.result.db)
36 37
37 38 print("Replace again and check");
38 39 outColl.save({_id: "5", value : 1});
39 40 t.mapReduce( m , r , { out : { replace: outCollStr, db: outDbStr } } )
40 41 str = tos( outColl.convertToSingleObject("value") )
41 42 print("Received result: " + str);
42   -assert.eq( tos( expected ) , str , "Received wrong result " + str );
  43 +assert.eq( tos( expected ) , str , "C1 Received wrong result " + str );
43 44
44 45
2  jstests/slowNightly/sharding_passthrough.js
@@ -73,7 +73,7 @@ files.forEach(
73 73 return;
74 74 }
75 75 // These aren't supposed to get run under sharding:
76   - if (/[\/\\](dbadmin|error1|fsync|fsync2|geo.*|indexh|remove5|update4|notablescan|check_shard_index)\.js$/.test(x.name)) {
  76 + if (/[\/\\](dbadmin|error1|fsync|fsync2|geo.*|indexh|remove5|update4|notablescan|check_shard_index|mr_replaceIntoDB)\.js$/.test(x.name)) {
77 77 print(" >>>>>>>>>>>>>>> skipping test that would fail under sharding " + x.name)
78 78 return;
79 79 }
17 s/commands_public.cpp
@@ -868,9 +868,19 @@ namespace mongo {
868 868 string collection = cmdObj.firstElement().valuestrsafe();
869 869 string fullns = dbName + "." + collection;
870 870
  871 + const string shardedOutputCollection = getTmpName( collection );
  872 + BSONObj customOut;
  873 + BSONObj shardedCommand = fixForShards( cmdObj , shardedOutputCollection, customOut );
  874 +
  875 + bool customOutDB = ! customOut.isEmpty() && customOut.hasField( "db" );
  876 +
871 877 DBConfigPtr conf = grid.getDBConfig( dbName , false );
872 878
873 879 if ( ! conf || ! conf->isShardingEnabled() || ! conf->isSharded( fullns ) ) {
  880 + if ( customOutDB ) {
  881 + errmsg = "can't use out 'db' with non-sharded db";
  882 + return false;
  883 + }
874 884 return passthrough( conf , cmdObj , result );
875 885 }
876 886
@@ -886,9 +896,6 @@ namespace mongo {
886 896 set<Shard> shards;
887 897 cm->getShardsForQuery( shards , q );
888 898
889   - const string shardedOutputCollection = getTmpName( collection );
890   - BSONObj customOut;
891   - BSONObj shardedCommand = fixForShards( cmdObj , shardedOutputCollection, customOut );
892 899
893 900 BSONObjBuilder finalCmd;
894 901 finalCmd.append( "mapreduce.shardedfinish" , cmdObj );
@@ -918,7 +925,7 @@ namespace mongo {
918 925 // by default the target database is same as input
919 926 Shard outServer = conf->getPrimary();
920 927 string outns = fullns;
921   - if (!customOut.isEmpty() && customOut.hasField("db")) {
  928 + if ( customOutDB ) {
922 929 // have to figure out shard for the output DB
923 930 BSONElement elmt = customOut.getField("db");
924 931 string outdb = elmt.valuestrsafe();
@@ -926,6 +933,8 @@ namespace mongo {
926 933 DBConfigPtr conf2 = grid.getDBConfig( outdb , true );
927 934 outServer = conf2->getPrimary();
928 935 }
  936 + log() << "customOut: " << customOut << " outServer: " << outServer << endl;
  937 +
929 938 ShardConnection conn( outServer , outns );
930 939 BSONObj finalResult;
931 940 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.