Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-342

Change streams should use the same session when resuming

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.3.2
    • Affects Version/s: 1.3.0
    • Component/s: None
    • None

      Below, I refer to three types of sessions:

      • Explicit, where the user has provided a "session" option
      • Implicit, where neither the user nor PHPC have provided a session to libmongoc
      • "Implicit from the user's perspective", where the user hasn't provided a "session" option but the PHP driver needs to create one. This session is explicit from libmongoc's perspective.

      When resuming a change stream, we should ensure that the new cursor uses the same session, regardless of whether it was explicit or implicit. The assurance for the implicit case relates to 490306b from CDRIVER-2578.

      PHPC-1152 will ensure that a command cursor (on which getMore is called) will use the same session as its originating command (e.g. aggregate) for both explicit and implicit sessions. This will be done by having PHPC create an explicit session internally even when no session option is specified (i.e. implicit from the user's perspective).

      The case where the user provides an explicit session is trivial. We simply need to use that session for both the original command and ensure that it is saved and accessible to the resume callback.

      The implicit session case is more complicated. PHPC-1151 coincidentally added a reference to the explicit/implicit Session object on the Cursor (to ensure it is ref-counted and is not freed before the mongoc_cursor_t using it). Ideally, we could access that object and use it for resuming; however, introducing a getSession() accessor method on the Cursor would not be possible until PHPC 1.5.0 (likely PHPLIB 1.4.0).

      The implicit session case will therefore require an alternative solution if we're to address this in PHPLIB 1.3.x. I propose we follow PHPC's lead (with respect to libmongoc) and have the ChangeStream operation in PHPLIB always create a Session object (even for the implicit case where the user hasn't specified the "session" option).

      As is done in libmongoc, some special logic may be necessary to ensure that an "implicit from the user's perspective" session is freed immediately once a getMore indicates that the cursor's results have been exhausted. That may be particularly tricky unless PHPC can provide some API for PHPLIB to indicate that the Session object it's passing should be considered "implicit from the user's perspective" instead of "explicit". It's quite possible we won't be able to accomplish this in PHPLIB 1.3.x without introducing a new API in PHPC 1.5.0.

            Assignee:
            katherine.walker@mongodb.com Katherine Walker (Inactive)
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: