-
Notifications
You must be signed in to change notification settings - Fork 266
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
Conversation
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 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.
src/Operation/Aggregate.php
Outdated
@@ -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) { |
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.
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.
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 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.
src/Operation/Find.php
Outdated
@@ -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']); |
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.
The Find operation has never documented a writeConcern
option. Moreover, createQueryOptions()
never creates a writeConcern
key in its return array. This can be removed.
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 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.
Fix PHPLIB-802
ReadConcern
is relevant for query plan evaluation, notWriteConcern
(comment)This should be covered by unit tests PHPLIB-1144.