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

In mapReduce map function emitting a document with 'undefined' or 'null' key in sharded collection fails

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.5.4
    • Component/s: MapReduce, Querying
    • Labels:
      None
    • ALL
    • Hide

      This test is modified from the mr_undef.js file.

      t = db.mr_undef;
      t.drop();
      
      outname = "mr_undef_out";
      out = db[outname];
      out.drop();
      
      t.insert({x: 0});
      
      var m = function() {
          emit(undefined, this.x);
      };
      var r = function(k, v) {
          total = 0;
          for (i in v) {
              total += v[i];
          }
          return total;
      };
      
      res = t.mapReduce(m, r,  {out: outname});
      printjson(res);
      printjson(out.find().toArray());
      assert.eq(1, out.find({_id: {$type: 10}}).itcount(), "A2");
      
      
      Show
      This test is modified from the mr_undef.js file. t = db.mr_undef; t.drop(); outname = "mr_undef_out" ; out = db[outname]; out.drop(); t.insert({x: 0}); var m = function () { emit(undefined, this .x); }; var r = function (k, v) { total = 0; for (i in v) { total += v[i]; } return total; }; res = t.mapReduce(m, r, {out: outname}); printjson(res); printjson(out.find().toArray()); assert.eq(1, out.find({_id: {$type: 10}}).itcount(), "A2" );

      This fails with the code modifications to implicitly_shard_accessed_collections.js introduced by SERVER-26315. In that code, we are over-riding the DBCollection.prototype.drop() function to re-shard collections after they are dropped, in sharded cluster environments.

      Note: This does not fail in non-sharded collections.

      t = db.mr_undef;
      t.drop();
      
      outname = "mr_undef_out";
      out = db[outname];
      out.drop();
      
      t.insert({x: 0});
      
      var m = function() {
          emit(undefined, this.x);  // the key can be 'null' also
      };
      var r = function(k, v) {
          total = 0;
          for (i in v) {
              total += v[i];
          }
          return total;
      };
      
      res = t.mapReduce(m, r,  {out: outname});
      printjson(res);
      printjson(out.find().toArray());
      assert.eq(1, out.find({_id: {$type: 10}}).itcount(), "A2");
      
      

      It fails because there are no documents in the out collection even though the res object shows there was an output document.

      [js_test:mr_undef] 2017-03-15T03:59:11.699-0400 {       
      [js_test:mr_undef] 2017-03-15T03:59:11.699-0400         "result" : "mr_undef_out",
      [js_test:mr_undef] 2017-03-15T03:59:11.699-0400         "counts" : {
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400                 "input" : NumberLong(1),
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400                 "emit" : NumberLong(1),
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400                 "reduce" : NumberLong(0),
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400                 "output" : NumberLong(0)
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400         },
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400         "timeMillis" : 51,
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400         "timing" : {
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400                 "shardProcessing" : 24,
      [js_test:mr_undef] 2017-03-15T03:59:11.700-0400                 "postProcessing" : 26
      [js_test:mr_undef] 2017-03-15T03:59:11.701-0400         },
      [js_test:mr_undef] 2017-03-15T03:59:11.701-0400         "shardCounts" : {   
      [js_test:mr_undef] 2017-03-15T03:59:11.701-0400                 "huracan:20003" : {
      [js_test:mr_undef] 2017-03-15T03:59:11.702-0400                         "input" : 1, 
      [js_test:mr_undef] 2017-03-15T03:59:11.702-0400                         "emit" : 1,
      [js_test:mr_undef] 2017-03-15T03:59:11.702-0400                         "reduce" : 0,
      [js_test:mr_undef] 2017-03-15T03:59:11.702-0400                         "output" : 1     <---------------this suggests there was an output document.
      [js_test:mr_undef] 2017-03-15T03:59:11.703-0400                 }
      [js_test:mr_undef] 2017-03-15T03:59:11.703-0400         },
      [js_test:mr_undef] 2017-03-15T03:59:11.703-0400         "postProcessCounts" : { 
      [js_test:mr_undef] 2017-03-15T03:59:11.703-0400                 "huracan:20003" : {
      [js_test:mr_undef] 2017-03-15T03:59:11.703-0400                         "input" : NumberLong(0),
      [js_test:mr_undef] 2017-03-15T03:59:11.703-0400                         "reduce" : NumberLong(0),
      [js_test:mr_undef] 2017-03-15T03:59:11.704-0400                         "output" : NumberLong(0)
      [js_test:mr_undef] 2017-03-15T03:59:11.704-0400                 }
      [js_test:mr_undef] 2017-03-15T03:59:11.704-0400         },
      [js_test:mr_undef] 2017-03-15T03:59:11.704-0400         "ok" : 1
      [js_test:mr_undef] 2017-03-15T03:59:11.704-0400 }
      [js_test:mr_undef] 2017-03-15T03:59:11.704-0400 [ ]    <------- this is from the "printjson(out.find().toArray());" which shows no output document.
      ....
      [js_test:mr_undef] 2017-03-15T03:59:11.707-0400 assert: [1] != [0] are not equal : A2
      [js_test:mr_undef] 2017-03-15T03:59:11.707-0400 doassert@src/mongo/shell/assert.js:18:14
      [js_test:mr_undef] 2017-03-15T03:59:11.707-0400 assert.eq@src/mongo/shell/assert.js:54:5
      [js_test:mr_undef] 2017-03-15T03:59:11.707-0400 @jstests/core/mr_undef.js:26:1
      [js_test:mr_undef] 2017-03-15T03:59:11.707-0400
      [js_test:mr_undef] 2017-03-15T03:59:11.707-0400 2017-03-15T03:59:11.707-0400 E QUERY    [thread1] Error: [1] != [0] are not equal : A2 :
      [js_test:mr_undef] 2017-03-15T03:59:11.708-0400 doassert@src/mongo/shell/assert.js:18:14
      [js_test:mr_undef] 2017-03-15T03:59:11.708-0400 assert.eq@src/mongo/shell/assert.js:54:5
      [js_test:mr_undef] 2017-03-15T03:59:11.708-0400 @jstests/core/mr_undef.js:26:1
      [js_test:mr_undef] 2017-03-15T03:59:11.708-0400 failed to load: jstests/core/mr_undef.js
      

            Assignee:
            tess.avitabile@mongodb.com Tess Avitabile (Inactive)
            Reporter:
            eddie.louie Eddie Louie
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: