Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-2192

Implement Driver Sessions API

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.9.0
    • Affects Version/s: None
    • Component/s: libmongoc
    • None
    • Fully Compatible

      Conform to the Driver Session Spec. Start and end a client-side session, and gossip the clusterTime.

      • Done in 1.8: Bundle all the data needed to run a command into a mongoc_cmd_parts_t struct and pass that around instead of adding a "session" parameter everywhere
      • Done: Implement the second part of the spec's test plan: prove that a database or collection stores a pointer to the session it came from
      • Done: Write a live test that any command sent to a 3.6 mongos includes $clusterTime
      • Done: Implement mongoc_session_opts_clone().
      • Done: Ensure that executing an empty command "{}" is still an error. Check in mongoc_cmd_parts_assemble / mongoc_cmd_parts_assemble_simple that the command name is non-NULL, before adding "$clusterTime". Update their signatures to take an error pointer and return bool. Save the command name on the mongoc_cmd_t.
      • Done: Append $clusterTime to commands in mongoc-cursor.c.
      • Done: Parse $clusterTime from all command replies
      • Done: Send and receive $clusterTime in topology scanner
      • Done: Complete clusterTime tests from Driver Sessions Spec
      • Done: Add a "session" field to mongoc_cmd_t and ensure all commands on a mongoc_session_t, mongoc_database_t, or mongoc_collection_t set it correctly.
      • Done: For most of the non-deprecated functions on a mongoc_client_t, add functions for mongoc_session_t. E.g., mongoc_session_drop_database, mongoc_session_read_write_command_with_opts, get read preference, read concern, write concern.
      • Done: Generate session ids and pass them with all commands.
      • Cancelled: mongoc_session_get_database_names and mongoc_session_find_databases.
      • Done: Get localLogicalSessionTimeoutMinutes from ismaster response.
      • Done: Delete code that adds "lsid" to OP_QUERY commands in mongoc_cmd_assemble and _mongoc_write_opquery; all commands sent to servers that support sessions will use OP_MSG (may depend on CDRIVER-2306)
      • Moved to CDRIVER-2355: Refactor mongoc_cmd_parts_assemble, $readPreference handling is particularly duplicative.

      Respond to spec changes. The spec had said that we associate db / collection / gridfs objects with sessions, but now we're going to keep sessions separate, and pass a session as a parameter to each non-deprecated function that can use a session. Luckily, I think our "with_opts" functions will handle this without requiring a large number of new functions.

      The spec had made retryWrites a session option, now it's a client option.

      We had chosen not to implement session pooling, but pooling is practically a requirement now, because every command must be associated with some session (whether the user passes a session or not).

      Required changes:

      • Done: Temporarily disable compilation of example-session.c
      • Done: Remove the functions that create a database, collection or gridfs struct that is associated with a session. We're not associating these structs with sessions anymore. Keep the session field in bulk operation and cursor structs, however.
      • Done: Remove the session field from the db / collection / gridfs structs.
      • Done: Remove read concern, write concern, and read preferences from session.
      • Done: Remove documentation of the relationship among db / collection / gridfs and sessions.
      • Done: Remove retryWrites from mongoc_session_opts_t
      • Done: Remove mongoc_session_read_command_with_opts and similar functions - we're not executing commands on a session anymore, we pass the session to the command function
      • Done: Rename mongoc_session_t to mongoc_client_session_t
      • Done: Replace term "causally consistent reads" with "causal consistency".
      • Done: Add mongoc_client_session_append, analogous to mongoc_write_concern_append: it will add an "lsid" to a bson_t "opts"
      • In CDRIVER-2331: Test that all "with_opts" functions properly handle the "lsid" field.
      • In CDRIVER-2331: Add "with_opts" functions as necessary to support sessions everywhere: CDRIVER-2331
      • Done: Update example-session.c to not show retryable writes, only causally consistent reads, and to use new API. Re-enable compilation and re-enable the literalinclude in mongoc_session_t.rst
      • Done: Implement a server session pool, and move txn_num field from mongoc_client_session_t to a new internal struct mongoc_server_session_t. Use logicalSessionTimeoutMinutes to determine whether sessions are supported in the topology, and return an error from mongoc_client_start_session otherwise. _mongoc_topology_pop_server_session must trigger topology discovery if there are no known servers, so it can detect whether the topology supports sessions (logical_session_timeout_minutes is not -1).
      • Done: Call endSessions when destroying a client or client pool.
      • Done: Update sessions API for recent changes: set the clusterTime on a mongoc_client_session_t (operationTime will be handled in CDRIVER-2229)
      • Done: Implement compute the $clusterTime to send to a server from the spec
      • Done: Include "lsid" with all commands, even if no explicit session is passed. Add a section to run_session_test() that executes the command with no "sessionId" and ensure all commands include the same lsid anyway. Make sure not to send lsid with "endSessions".
      • Done: Use random numbers, instead of consecutive ones, for sessionIds. This ensures that a session from the wrong client really is prohibited.
      • Done: Update server session's last_used.

            Assignee:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Reporter:
            jesse@mongodb.com A. Jesse Jiryu Davis
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: