-
Notifications
You must be signed in to change notification settings - Fork 454
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
CDRIVER-4099 Support mongos redirection during retryable operations #1529
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 tasks
kevinAlbs
reviewed
Feb 9, 2024
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.
Looks good overall. Suggested one behavior change and minor test suggestions.
kevinAlbs
reviewed
Feb 9, 2024
kevinAlbs
approved these changes
Feb 13, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves CDRIVER-4099. Verified by this patch (filtered to relevant tasks; CSE tasks are failing atm due to an unrelated issue).
This PR also implements the proposed prose test spec changes in mongodb/specifications#1504.
Description
There are five internal functions in libmongoc that each individually (re)implement retryable reads/writes:
_mongoc_client_retryable_write_command_with_stream
_mongoc_client_retryable_read_command_with_stream
mongoc_collection_find_and_modify_with_opts
_mongoc_cursor_run_command
_mongoc_write_opmsg
This PR refrains from refactoring these instances to use a comment implementation due to the complexity required. Instead, the new
mongoc_deprioritized_servers_add_if_sharded
function serves to document the instances of retry-op code paths for future reference and make a first step towards unifying the behavior of these disparate implementations in the future.The
mongoc_deprioritized_servers_add_if_sharded
is a convenient function that only adds the provided server to the set of deprioritized servers when the topology is Sharded, per spec:The
mongoc_deprioritized_servers_t
interface deliberately operates onmongoc_server_description_t
objects, rather than the underlying server IDs currently used as keys in the set, to leave the path open for changing the method used to identify servers (i.e. tohost_and_port
) or using an array instead of a set (can't use strings as keys inmongoc_set_t
) if needed without requiring a significant refactor.The bulk of changes in this PR are to accomodate the addition of a new parameter to all intermediate internal functions that must forward the deprioritized servers list aaaaall the way down to
mongoc_topology_description_suitable_servers
where it is ultimately used, per spec:This was interpreted as being most appropriately implemented in
mongoc_topology_description_suitable_servers
in the "Sharded clusters" block immediately before filtering for suitable mongoses.Trace log messages are used to verify that deprioritization code paths are being executed as intended by the prose tests. All relevant trace logs use the
deprioritization:
prefix for easy filtering in the verbose trace logs, e.g../test-libmongoc -t | grep "deprioritization"
(simplified):The
on_other_mongos
prose tests for both retryable read and retryable write are repeated several times in an effort to reduce the possibility of (incorrectly using) normal SDAM behavior happening to produce the same result as server deprioritization due to randomized server selection. Otherwise the test may occasionally succeed (false-positive) even without the implementation of server deprioritization. The loops can be removed if considered excessive/slow.A drive-by fix moves the
MONGOC_INFO
message for mock server startup to a position where the printed port number is accurate to the actual port of the running server.