Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-44238

mapReduce fails to merge with sharded output in different database

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: MapReduce
    • Labels:
      None
    • ALL
    • Hide
      (function() {
      "use strict";
      const st = new ShardingTest({shards: 2});
      const db = st.s.getDB("test");
      assert.commandWorked(db.adminCommand({enableSharding: "test"}));
      assert.commandWorked(db.adminCommand({enableSharding: "foreign"}));
      const inputColl = db.input;
      const outputCollOtherDB = db.getSiblingDB("foreign").output;
      assert.commandWorked(
          db.adminCommand({shardCollection: inputColl.getFullName(), key: {_id: "hashed"}}));
      assert.commandWorked(
          db.adminCommand({shardCollection: outputCollOtherDB.getFullName(), key: {_id: "hashed"}}));
      
      assert.commandWorked(inputColl.insert([{_id: 1}, {_id: 2}, {_id: 3}]));
      assert.commandWorked(outputCollOtherDB.insert({_id: 1, value: 0}));
      function mapFn() {
          emit(this._id, 1);
      }
      function reduceFn(key, values) {
          return Array.sum(values);
      }
      
      assert.commandWorked(inputColl.mapReduce(mapFn, reduceFn, {
          out:
              {merge: outputCollOtherDB.getName(), db: outputCollOtherDB.getDB().getName(), sharded: true}
      }));
      
      st.stop();
      }());
      
      Show
      ( function () { "use strict" ; const st = new ShardingTest({shards: 2}); const db = st.s.getDB( "test" ); assert.commandWorked(db.adminCommand({enableSharding: "test" })); assert.commandWorked(db.adminCommand({enableSharding: "foreign" })); const inputColl = db.input; const outputCollOtherDB = db.getSiblingDB( "foreign" ).output; assert.commandWorked( db.adminCommand({shardCollection: inputColl.getFullName(), key: {_id: "hashed" }})); assert.commandWorked( db.adminCommand({shardCollection: outputCollOtherDB.getFullName(), key: {_id: "hashed" }})); assert.commandWorked(inputColl.insert([{_id: 1}, {_id: 2}, {_id: 3}])); assert.commandWorked(outputCollOtherDB.insert({_id: 1, value: 0})); function mapFn() { emit( this ._id, 1); } function reduceFn(key, values) { return Array.sum(values); } assert.commandWorked(inputColl.mapReduce(mapFn, reduceFn, { out: {merge: outputCollOtherDB.getName(), db: outputCollOtherDB.getDB().getName(), sharded: true } })); st.stop(); }());

      The attached reproduction script fails with:

      [js_test:repro] 2019-10-24T18:52:40.920-0400 2019-10-24T18:52:40.920-0400 E  QUERY    [js] uncaught exception: Error: map reduce failed:{
      [js_test:repro] 2019-10-24T18:52:40.921-0400 	"ok" : 0,
      [js_test:repro] 2019-10-24T18:52:40.921-0400 	"errmsg" : "MR post processing failed: { operationTime: Timestamp(1571957560, 122), ok: 0.0, errmsg: \"The upsert document could not be inserted onto the shard targeted by the query, since its shard key belongs on a different shard. Cross-shard upserts ...\", code: 20, codeName: \"IllegalOperation\", $gleStats: { lastOpTime: { ts: Timestamp(1571957560, 122), t: 1 }, electionId: ObjectId('7fffffff0000000000000001') }, lastCommittedOpTime: Timestamp(1571957560, 113), $configServerState: { opTime: { ts: Timestamp(1571957560, 114), t: 1 } }, $clusterTime: { clusterTime: Timestamp(1571957560, 123), signature: { hash: BinData(0, 0000000000000000000000000000000000000000), keyId: 0 } } }",
      [js_test:repro] 2019-10-24T18:52:40.921-0400 	"operationTime" : Timestamp(1571957560, 124),
      [js_test:repro] 2019-10-24T18:52:40.921-0400 	"$clusterTime" : {
      [js_test:repro] 2019-10-24T18:52:40.921-0400 		"clusterTime" : Timestamp(1571957560, 124),
      [js_test:repro] 2019-10-24T18:52:40.921-0400 		"signature" : {
      [js_test:repro] 2019-10-24T18:52:40.921-0400 			"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
      [js_test:repro] 2019-10-24T18:52:40.921-0400 			"keyId" : NumberLong(0)
      [js_test:repro] 2019-10-24T18:52:40.921-0400 		}
      [js_test:repro] 2019-10-24T18:52:40.921-0400 	}
      [js_test:repro] 2019-10-24T18:52:40.921-0400 } :
      [js_test:repro] 2019-10-24T18:52:40.921-0400 _getErrorWithCode@src/mongo/shell/utils.js:25:13
      [js_test:repro] 2019-10-24T18:52:40.921-0400 DBCollection.prototype.mapReduce@src/mongo/shell/collection.js:1085:15
      [js_test:repro] 2019-10-24T18:52:40.921-0400 @repro.js:23:22
      [js_test:repro] 2019-10-24T18:52:40.921-0400 @repro.js:1:2
      

            Assignee:
            charlie.swanson@mongodb.com Charlie Swanson
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: