Uploaded image for project: 'Drivers'
  1. Drivers
  2. DRIVERS-2077

Driver sessions should not require server selection on `startSession`

    • Type: Icon: Spec Change Spec Change
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Component/s: Sessions
    • Labels:
      None
    • Needed

      TLDR: "startSession MAY report an error if sessions are not supported by the deployment (see How to Check Whether a Deployment Supports Sessions)."

      The drive sessions spec currently indicates that

      startSession MUST report an error if sessions are not supported by the deployment (see How to Check Whether a Deployment Supports Sessions).
      

      I think this language constricts design, and should be loosened to a MAY. Generally, all startSession does is creates a local session id (it used to be a command, which could justify the requirement), it does not do any I/O and therefore I think we should be able to defer the potential server selection to the time of operation execution.

      For async drivers (such as node) the current prose would require that the method be asynchronous, turning this code:

      MongoClient.connect('mongodb://localhost/test').then(client => {
        const session = client.startSession({ causalConsistency: true });
        const coll = client.db('foo').collection('bar');
      
        return coll.insert({ a: 42 }, { session: session })
      });
      

      into:

      MongoClient.connect('mongodb://localhost/test').then(client => {
        client.startSession({ causalConsistency: true }).then(session => {
          const coll = client.db('foo').collection('bar');
          return coll.insert({ a: 42 }, { session: session });
        });
      });
      

      While this is purely a cosmetic complaint at this point, I think the deeper level here is the concern about locality of the session support check. Driver sessions also require that implicit sessions be created for all operations where an explicit session has not been provided. This means that the check for topology sessions support must also happen in the implicit case. If we defer the check in startSession to the point of operation execution, we can use the same path to determine session support for both explicit and implicit cases.

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.broadstone@mongodb.com Matt Broadstone
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: