Skip to content

PHPC-1152, PHPC-1161: Emulate implicit sessions for command cursors #803

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 4 commits into from
Apr 18, 2018

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Apr 12, 2018

https://jira.mongodb.org/browse/PHPC-1152
https://jira.mongodb.org/browse/PHPC-1161

Tests for this patch depend on #811, although I've included a temporary commit with the patch (sans the full patch and tests in #811) to give this PR's own tests a chance at passing.

@jmikola jmikola force-pushed the 1.4-phpc-1152 branch 2 times, most recently from 2c001f4 to 393d274 Compare April 13, 2018 20:40
@jmikola jmikola force-pushed the 1.4-phpc-1152 branch 3 times, most recently from d8b9fd2 to 04c50b5 Compare April 16, 2018 21:00
@jmikola jmikola changed the title [WIP] PHPC-1152: Command cursors should use same session as originating command PHPC-1152: Command cursors should use same session as originating command Apr 16, 2018
@jmikola jmikola changed the title PHPC-1152: Command cursors should use same session as originating command PHPC-1152, PHPC-1161: Command cursors should use same session as originating command Apr 16, 2018
@jmikola jmikola changed the title PHPC-1152, PHPC-1161: Command cursors should use same session as originating command PHPC-1152, PHPC-1161: Emulate implicit sessions for command cursors Apr 16, 2018
@jmikola jmikola requested review from derickr and kvwalker April 16, 2018 21:02
Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

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

LGTM, but I have some comments.

int result;
bool result = false;
bool free_reply = false;
bool free_zsession = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Before you merge this into master, you should run clang-format on this.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is in the v1.4 branch, which isn't formatted. I intend to run it through clang-format after (or during) the merge to master. Does that work?

php_phongo.c Outdated
/* If an explicit session was not provided, attempt to create an implicit
* client session (ignoring any errors).
*
* TODO: Ensure that this doesn't conflict with any commands users may run
Copy link
Contributor

Choose a reason for hiding this comment

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

How are you going to "ensure" this? Right now, it just looks like a comment that we're going to forget about :-)

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed. This is something I wanted to check manually but running through a few cases in Exceptions to sending the session ID to the server on all commands. In particular, I'd like to test:

  • isMaster
  • executeWriteCommand() with an unacknowledged write concern

I'm also curious about killCursors. The spec says that an LSID is optional, but testing in PHPC-1152 demonstrated that killCursors wasn't always using the LSID of the command from which the cursor originated. I want to confirm that the exceptions for mismatched LSIDs only applied to getMore and that killCursors truly doesn't care. If that's not the case, I think the spec language may need some corrections.

Copy link
Member Author

Choose a reason for hiding this comment

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

@kvwalker answered the killCursors question in mongodb/mongo-php-library#528 (comment).

Copy link
Member Author

Choose a reason for hiding this comment

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

isMaster isn't a problem.

Unacknowledged write concerns is a legitimate issue, and may also affect libmongoc. I've opened PHPC-1163 to track that.

Copy link
Contributor

@kvwalker kvwalker left a comment

Choose a reason for hiding this comment

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

LGTM. I tested this locally with PHPLIB-324 and verified that resumeCallable is unset after the cursor is invalidated, which I tested using DropDatabase before calling $changeStream->next().

jmikola added 4 commits April 18, 2018 13:37
This corrects the function signatures to return a boolean indicating success instead of an integer (which was cast from a boolean).

Additionally, it restructures phongo_execute_command() to use a cleanup label, in anticipation of implicit session changes.
This ensures that phongo_execute_command creates an implicit session (if supported and not explicit session was provided). In turn, this ensures that any command cursor shares the same session as its originating command.

By creating a Session object, we can ensure that the implicit session is destroyed during garbage collection when the last reference is removed.
@jmikola jmikola merged commit 1f222d0 into mongodb:v1.4 Apr 18, 2018
jmikola added a commit that referenced this pull request Apr 18, 2018
@jmikola jmikola deleted the 1.4-phpc-1152 branch April 18, 2018 19:38
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.

3 participants