Skip to content

PHPLIB-802: Send readConcern but not writeConcern to explain commands #1080

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
May 29, 2023

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented May 25, 2023

Fix PHPLIB-802

ReadConcern is relevant for query plan evaluation, not WriteConcern (comment)

This should be covered by unit tests PHPLIB-1144.

@GromNaN GromNaN requested a review from jmikola May 25, 2023 23:07
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.

I noted the discussion in SERVER-28678 that readConcern might be relevant but writeConcern is not. Feel free to amend the original title/description of PHPLIB-802 to accurately reflect the change.

@@ -322,7 +322,7 @@ private function createCommandDocument(): array
'pipeline' => $this->pipeline,
];

foreach (['allowDiskUse', 'bypassDocumentValidation', 'comment', 'explain', 'maxTimeMS'] as $option) {
foreach (['allowDiskUse', 'bypassDocumentValidation', 'comment', 'explain', 'maxTimeMS', 'readConcern'] as $option) {
Copy link
Member

Choose a reason for hiding this comment

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

readConcern should not be added directly to the command document. The option is already handled in executeCommand() along with other options for the execute method.

That code path allows for sensible inheritance of client-level options. I'd have to double-check libmongoc internals to confirm, but I think directly adding it in a command document here might result in duplicate BSON fields being sent to the server. I know that's possible if you were to manually inject a session ID in the lsid field.

Instead, I think you should add this option in getCommandDocument(). You can use the array union operator to do so and just add ['readConcern' => ...] to $this->createCommandDocument() before returning. A more verbose approach with an assigned variable is fine as well.


Likewise for other Explainable commands where you modified the value used to construct the Command object instead of the Explainable::getCommandDocument() implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

I understand better how it works now.
I opted for the more verbose way to add the readConcern option when available: its easier to read and better for code analysis.

@@ -349,6 +349,9 @@ private function createCommandDocument(): array
// maxAwaitTimeMS is a Query level option so should not be considered here
unset($options['maxAwaitTimeMS']);

// writeConcern is not relevant to evaluating the query plan
unset($options['writeConcern']);
Copy link
Member

Choose a reason for hiding this comment

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

The Find operation has never documented a writeConcern option. Moreover, createQueryOptions() never creates a writeConcern key in its return array. This can be removed.

@GromNaN GromNaN requested a review from jmikola May 26, 2023 12:43
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 after removing the change to FindAndModify.php.

You may also want to rebase and regenerate the psalm baseline before merging, rather than attempt to resolve that conflict through GitHub's UI.

@GromNaN GromNaN merged commit 118f084 into mongodb:master May 29, 2023
@GromNaN GromNaN deleted the PHPLIB-802 branch May 29, 2023 16:58
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