Skip to content

PHPLIB-712: Allow hint for unacknowledged writes using OP_MSG when supported by the server #859

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 3 commits into from
Aug 31, 2021

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Aug 26, 2021

* to check the original error. */
if ($e instanceof BulkWriteException && $e->getPrevious() !== null) {
$e = $e->getPrevious();
}
Copy link
Member Author

Choose a reason for hiding this comment

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

libmongoc already raises an error if hint and w:0 are mixed and hint is not supported by the server (see: _mongoc_write_command_execute_idl); however, that manifests as a BulkWriteException.

I still plan to add explicitly throw UnsupportedException from PHPLIB's operation classes. In the meantime, this change was necessary to ensure tests pass as-is. And in light of PHPC-1960, this change is just generally correct since not all BulkWriteExceptions originate from server-side errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Explicit UnsupportedExceptions are now implemented and tested for Update, Delete, and FindAndModify operations.

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 addresses PHPLIB-711.

@@ -55,7 +55,10 @@ class Update implements Executable, Explainable
private static $wireVersionForDocumentLevelValidation = 4;

/** @var integer */
private static $wireVersionForHintServerSideError = 5;
private static $wireVersionForHint = 8;
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 will ultimately be used for detecting whether hint and w:0 are being used together on an unsupported server.

I also plan to add a method that detects an unacknowledged write concern. Since FindAndModify will also need to be addressed by this PR, I'll likely end up fixing PHPLIB-709 in the process.

Copy link
Member Author

Choose a reason for hiding this comment

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

Implemented is_write_concern_acknowledged, which is now used in the Update, Delete, and FindAndModify operations. PHPLIB-709 has been fixed in the process.

@jmikola jmikola force-pushed the phplib-712 branch 2 times, most recently from a0d2d65 to e0f2f9c Compare August 28, 2021 00:14
@jmikola jmikola marked this pull request as ready for review August 28, 2021 00:22
@jmikola
Copy link
Member Author

jmikola commented Aug 28, 2021

Note: mongodb/specifications#1057 (comment) explains the failing CI build. I think this will require removing outcome assertions from the tests that execute w:0 writes, but I'm waiting on some feedback in the spec PR before making that change.

@jmikola jmikola requested a review from alcaeus August 28, 2021 00:28
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

LGTM pending spec test merge.

@@ -63,6 +64,46 @@ public function testDeleteMany(): void
$this->assertSameDocuments($expected, $this->collection->find());
}

public function testHintOptionUnsupportedClientSideError(): void
Copy link
Member

Choose a reason for hiding this comment

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

Are these scenarios not covered by the automated spec tests, or did you want to ensure that the correct exception thrown?

Copy link
Member Author

Choose a reason for hiding this comment

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

Had I not implemented PHPLIB-711, we could rely on the spec tests to differentiate between PHPLIB's UnsupportedException and the BulkWriteException thrown from PHPC encountering libmongoc's client-side error. However, I think unwrapping BulkWriteExceptions is necessary to properly differentiate cilent-side and server-side errors.

With PHPLIB-711 implemented, the unwrapped BulkWriteException (in this particular case) and UnsupportedException are both considered client-side errors so the spec tests really cannot differentiate. That's where these tests come in, to explicitly assert that PHPLIB raises its own internal exception.

@jmikola jmikola force-pushed the phplib-712 branch 2 times, most recently from 399ca90 to 003c6d1 Compare August 30, 2021 17:14
Synced with mongodb/specifications@59a5dad

Note: aggregate tests are intentionally excluded since those will be synced by mongodb#854
The CRUD spec requires a client-side error if hint is used and the server would not otherwise raise an error for an unsupported option. This was already being done, but this commit renames an internal constant and adds functional tests.

A client-side error is also required if hint is used with an unacknowledged write concern and the server does not support hint for the operation (regardless of error reporting for unsupported options). This was previously done only for FindAndModify; however, it failed to detect some acknowledged write concerns (PHPLIB-712). That issue has been fixed and the commit additionally adds this behavior for update and delete operations.
@jmikola jmikola merged commit e787475 into mongodb:master Aug 31, 2021
@jmikola jmikola deleted the phplib-712 branch August 31, 2021 15:11
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