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

findAndModify with sort exceeds internal sort memory limit, silently fails

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.8.0-rc3
    • Affects Version/s: None
    • Component/s: Concurrency
    • Fully Compatible
    • ALL
    • Hide

      Start up a mongod (with mmapv1 or wiredtiger) and run the following script:

      function insert() {
          // Use 32-bit integer for representing 'length' property
          var doc = { tid: 0, length: new NumberInt(2 * 1024 * 1024 /* 2MB */) };
          doc.field = new Array(doc.length + 1).join('x');
      
          var res = db.foo.insert(doc);
          assert.writeOK(res);
          assert.eq(1, res.nInserted);
      }
      
      function findAndModify() {
          var res = db.runCommand({
              findandmodify: db.foo.getName(),
              query: { tid: 0 },
              sort: { length: 1 }, // NOTE: this seems necessary for the repro
              update: { $mul: { length: 1 } },
              new: true
          });
          assert.commandWorked(res);
      
          var doc = res.value;
          assert(doc !== null, 'query spec should have matched a document');
      }
      
      db.foo.drop();
      while (true) {
          insert();
          findAndModify();
      }
      
      Show
      Start up a mongod (with mmapv1 or wiredtiger) and run the following script: function insert() { // Use 32-bit integer for representing 'length' property var doc = { tid: 0, length: new NumberInt(2 * 1024 * 1024 /* 2MB */ ) }; doc.field = new Array(doc.length + 1).join( 'x' ); var res = db.foo.insert(doc); assert .writeOK(res); assert .eq(1, res.nInserted); } function findAndModify() { var res = db.runCommand({ findandmodify: db.foo.getName(), query: { tid: 0 }, sort: { length: 1 }, // NOTE: this seems necessary for the repro update: { $mul: { length: 1 } }, new : true }); assert .commandWorked(res); var doc = res.value; assert (doc !== null , 'query spec should have matched a document' ); } db.foo.drop(); while ( true ) { insert(); findAndModify(); }

      When performing insert operations between findAndModify commands, a findAndModify will eventually fail to find a document to update, even though the query predicate remains the same. This failure only seems to occur when a sort specification is supplied.


      git version
      a6788ec72a9dabb38bd92a8ab653e32034e9e02e

            Assignee:
            rassi J Rassi
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: