-
Notifications
You must be signed in to change notification settings - Fork 266
PHPLIB-342: Change streams should use the same session when resuming #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/ChangeStream.php
Outdated
// resume and we can therefore unset the resumeCallable, which will | ||
// free any reference to Watch. This will also free the only | ||
// reference to an implicit session, since any such reference | ||
// belongs to Watch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* Feel free to
* use multi-line
* comments. */
src/ChangeStream.php
Outdated
// resume and we can therefore unset the resumeCallable, which will | ||
// free any reference to Watch. This will also free the only | ||
// reference to an implicit session, since any such reference | ||
// belongs to Watch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose pointing to the earlier extended comment for next()
rather than reproducing the full explanation:
// As with next(), free the callable once we know it will never be used
); | ||
|
||
$changeStream->rewind(); | ||
$this->killChangeStreamCursor($changeStream); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test this against a replica set with auth if possible. That should highlight whether killChangeStreamCursor()
will need to also take the same implicit session created within the Watch class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After testing with auth, it looks like killChangeStreamCursor()
does not need to take the same implicit session created within the Watch class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. That answers my question in mongodb/mongo-php-driver#803 (comment).
}, | ||
function($changeStream) use (&$originalSession) { | ||
if (isset($changeStream->aggregate)) { | ||
$originalSession = $changeStream->lsid; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK lsid
may include other fields, so you may want to only capture lsid->id
(and/or possibly cast it to a hex string as I'm doing in the PHPC tests:
bin2hex((string) $command->lsid->id);
This makes output easier to digest if comparisons fail, since you're no longer dealing with raw binary strings and MongoDB\BSON\Binary
objects.
|
||
$this->assertSame($expectedCommands, $commands); | ||
|
||
foreach ($sessionAfterResume as $session) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice :)
src/ChangeStream.php
Outdated
* free any reference to Watch. This will also free the only | ||
* reference to an implicit session, since any such reference | ||
* belongs to Watch. */ | ||
if ($this->getCursorId() === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getCursorId()
returns a MongoDB\Driver\CursorId
, so this will never evaluate to true. You may need to cast the CursorId to a string and compare with '0'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Let's rebase on v1.3 tomorrow before you merge this. |
https://jira.mongodb.org/browse/PHPLIB-342
I marked this [WIP] because I'll update
WatchFunctionalTest
to verify that thelsid
s of all aggregates and getMores are the same after PHPC-1152 is merged.