Skip to content

PHPLIB-1115: Fix waitForSnapshot() for MongoDB 7.0+ #1083

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 30, 2023

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented May 29, 2023

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

Using find instead of aggregate should ensure documents are available in the calling test case on 7.0+ servers.

@jmikola jmikola requested a review from GromNaN May 29, 2023 04:42
@jmikola jmikola marked this pull request as draft May 29, 2023 06:58
@jmikola jmikola marked this pull request as ready for review May 29, 2023 15:31
@jmikola
Copy link
Member Author

jmikola commented May 30, 2023

Note: test failures on mongodb-latest are due to PHPLIB-1071.

/* Retry until a snapshot query succeeds or ten seconds elapse,
* whichwever comes first.
*
* TODO: use hrtime() once the library requires PHP 7.3+ */
Copy link
Member

Choose a reason for hiding this comment

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

This todo makes sense.
You can also remove the microtime calls and count 10000 iterations with 1ms sleep.

Copy link
Member Author

Choose a reason for hiding this comment

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

count 10000 iterations with 1ms sleep.

Doing so wouldn't consider the time spent executing the FindOne operation.

This todo makes sense

I don't recall my original intention behind adding a TODO for hrtime() (it wasn't discussed in #900), but I gave this some thought when implementing this PR and couldn't see any reason to use it:

  • microtime() isn't deprecated and we don't need the precision offered by hrtime()
  • The variable return types for hrtime() seemed more complicated to work with
  • A monotonic timer is nice, but not necessary for a rarely used test method where we also don't need to worry about system clock changes

Side note: I did review the 7.3 polyfill while working on this PR.

Having said all that, we do have many uses of microtime() in the test suite:

  • DocumentationExamplesTest
  • FindFunctionalTest
  • WatchFunctionalTest
  • UnifiedSpecTests/EventCollector and Loop (these should remain as-is)

The first three instances all pertain to calculating durations (actual timestamp isn't relevant) so I wouldn't object if you want to create a ticket to integrate hrtime() there.

This fixes a bug in the original implementation where the method would return even if the query did not match a document. Instead, we should retry if either the query fails to match or a SnapshotUnavailable error is raised.

This issue was only discovered due to increased snapshot latency in MongoDB 7.0-dev. In previous versions, the snapshot was always available by the subsequent queries in testSnapshotQueries(), which uses waitForSnapshot().

Additionally, usleep() is added to avoid spamming the server with retry attempts. The TODO item for hrtime() was also removed, as there's no significant benefit to using it in this context and it's return types are not as convenient as microtime().
@jmikola jmikola merged commit 3052d1a into mongodb:master May 30, 2023
@jmikola jmikola deleted the phplib-1115 branch May 30, 2023 14:29
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