-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
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.
- depends on
-
PHPC-1152 Aggregate may fail to use the same session for getMore commands
- Closed
- is related to
-
PHPC-1151 Possible segfault is Session object is freed before Cursor
- Closed
-
CDRIVER-2578 mongoc_change_stream_t can send getMore with wrong lsid
- Closed
- related to
-
PHPLIB-361 Implicit session for change stream should default causalConsistency to false
- Closed
-
DRIVERS-2080 Consider hidden members to be data-bearing nodes when TopologyType is Single
- Backlog