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

MongoS doesn't pass maxTimeMS to shards for write commands

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.7.0
    • Affects Version/s: None
    • Component/s: Sharding
    • None
    • Fully Compatible
    • ALL
    • Hide
      //
      // Test maxTimeMS in sharded cluster.
      //
      
      const dbName = "test";
      const collName = "coll";
      
      const st = new ShardingTest({shards: 1, mongos: 1, config: 1});
      const mongosDB = st.s0.getDB(dbName);
      let coll = mongosDB.getCollection(collName);
      
      const sessionOptions = {
          causalConsistency: false
      };
      const session = mongosDB.getMongo().startSession(sessionOptions);
      const sessionDb = session.getDatabase(dbName);
      const sessionColl = sessionDb[collName];
      
      jsTestLog("Creating collection with insert.");
      assert.commandWorked(sessionColl.insert({_id: 0}));
      
      jsTestLog("Starting the transaction.");
      session.startTransaction();
      assert.commandWorked(sessionColl.insert({_id: 1}));
      
      jsTestLog("Run a separate write.");
      assert.commandFailedWithCode(coll.runCommand(
          {insert: collName, documents: [{_id: 1, nonTxn: 1}], maxTimeMS: 100}), ErrorCodes.MaxTimeMSExpired);
      
      jsTestLog("Aborting the transaction.");
      session.abortTransaction();
      
      jsTestLog("Checking document set.");
      // We would expect only document {_id: 0} to be present in the database, since the transaction above
      // was aborted and the write to insert {_id: 1, nonTxn: 1} failed with a MaxTimeMS error. We see
      // both the {_id: 1, nonTxn: 1} and {_id: 0} document present, though.
      let docs = sessionColl.find().toArray();
      assert.sameMembers(docs, [{_id: 0}]);
      
      st.stop();
      
      Show
      // // Test maxTimeMS in sharded cluster. // const dbName = "test" ; const collName = "coll" ; const st = new ShardingTest({shards: 1, mongos: 1, config: 1}); const mongosDB = st.s0.getDB(dbName); let coll = mongosDB.getCollection(collName); const sessionOptions = { causalConsistency: false }; const session = mongosDB.getMongo().startSession(sessionOptions); const sessionDb = session.getDatabase(dbName); const sessionColl = sessionDb[collName]; jsTestLog( "Creating collection with insert." ); assert.commandWorked(sessionColl.insert({_id: 0})); jsTestLog( "Starting the transaction." ); session.startTransaction(); assert.commandWorked(sessionColl.insert({_id: 1})); jsTestLog( "Run a separate write." ); assert.commandFailedWithCode(coll.runCommand( {insert: collName, documents: [{_id: 1, nonTxn: 1}], maxTimeMS: 100}), ErrorCodes.MaxTimeMSExpired); jsTestLog( "Aborting the transaction." ); session.abortTransaction(); jsTestLog( "Checking document set." ); // We would expect only document {_id: 0} to be present in the database, since the transaction above // was aborted and the write to insert {_id: 1, nonTxn: 1} failed with a MaxTimeMS error. We see // both the {_id: 1, nonTxn: 1} and {_id: 0} document present, though. let docs = sessionColl.find().toArray(); assert.sameMembers(docs, [{_id: 0}]); st.stop();
    • Service arch 2020-05-04, Service arch 2020-05-18, Service arch 2020-06-01, Service arch 2020-06-15, Service arch 2020-06-29, Service arch 2020-07-13, Service Arch 2020-07-27, Service Arch 2020-08-10, Service Arch 2020-08-24, Service arch 2020-09-07
    • 0

      When running an insert through a mongoS it appears that a MaxTimeMSExpired error can be returned to the client even if the operation is still running on a shard mongod. This behavior seems unexpected and undesirable if a client expects that a maxTimeMS timeout error implies an operation has failed with no effect.

            Assignee:
            spencer@mongodb.com Spencer Brody (Inactive)
            Reporter:
            william.schultz@mongodb.com Will Schultz
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: