Skip to content

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

Merged
merged 1 commit into from
Apr 19, 2018

Conversation

kvwalker
Copy link
Contributor

@kvwalker kvwalker commented Apr 16, 2018

https://jira.mongodb.org/browse/PHPLIB-342

I marked this [WIP] because I'll update WatchFunctionalTest to verify that the lsids of all aggregates and getMores are the same after PHPC-1152 is merged.

@kvwalker kvwalker requested a review from jmikola April 16, 2018 18:09
// 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.
Copy link
Member

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. */

// 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.
Copy link
Member

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);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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;
Copy link
Member

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice :)

* 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) {
Copy link
Member

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'.

@kvwalker kvwalker changed the title [WIP] PHPLIB-342: Change streams should use the same session when resuming PHPLIB-342: Change streams should use the same session when resuming Apr 17, 2018
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jmikola
Copy link
Member

jmikola commented Apr 18, 2018

Let's rebase on v1.3 tomorrow before you merge this.

@kvwalker kvwalker changed the base branch from master to v1.3 April 19, 2018 14:58
@kvwalker kvwalker merged commit 5fd00fb into mongodb:v1.3 Apr 19, 2018
kvwalker added a commit that referenced this pull request Apr 19, 2018
@kvwalker kvwalker deleted the PHPLIB-342 branch April 19, 2018 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants