RUBY-3628 Deprecate hedged reads option#3036
Open
comandeo-mongo wants to merge 1 commit intomongodb:masterfrom
Open
RUBY-3628 Deprecate hedged reads option#3036comandeo-mongo wants to merge 1 commit intomongodb:masterfrom
comandeo-mongo wants to merge 1 commit intomongodb:masterfrom
Conversation
Hedged reads are deprecated in MongoDB Server 8.0 and will be removed in a future version. Per the server-selection spec, drivers without static deprecation annotations must emit a runtime warning when the hedge parameter is specified. - Mark the :hedge option, the hedge attr_reader, hedge_allowed? methods, and the NO_HEDGE_SUPPORT error message as @deprecated in YARD docs. - Emit a one-time Mongo::Deprecations warning when a server selector is constructed with a non-nil :hedge option.
Contributor
There was a problem hiding this comment.
Pull request overview
Implements runtime + documentation deprecation for the hedge (hedged reads) read preference option in line with the updated server selection specification for MongoDB Server 8.0+.
Changes:
- Adds YARD
@deprecatedannotations aroundhedge-related APIs in server selector classes. - Emits a one-time runtime deprecation warning when a selector is constructed with a non-nil
hedge. - Marks the
NO_HEDGE_SUPPORTerror message constant as deprecated.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/mongo/server_selector/base.rb | Adds hedge deprecation docs and emits a runtime deprecation warning when hedge is provided. |
| lib/mongo/server_selector/primary.rb | Marks hedge_allowed? as deprecated in YARD docs. |
| lib/mongo/server_selector/primary_preferred.rb | Marks hedge_allowed? as deprecated in YARD docs. |
| lib/mongo/server_selector/secondary.rb | Marks hedge_allowed? as deprecated in YARD docs. |
| lib/mongo/server_selector/secondary_preferred.rb | Marks hedge_allowed? as deprecated in YARD docs. |
| lib/mongo/server_selector/nearest.rb | Marks hedge_allowed? as deprecated in YARD docs. |
| lib/mongo/error/invalid_server_preference.rb | Marks NO_HEDGE_SUPPORT constant as deprecated in YARD docs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+40
to
+41
| # @deprecated Hedged reads are deprecated in MongoDB Server 8.0 and will | ||
| # be removed in a future version. |
Comment on lines
55
to
+63
| validate! | ||
|
|
||
| return if @hedge.nil? | ||
|
|
||
| Mongo::Deprecations.warn( | ||
| :hedge_read_preference, | ||
| 'The hedge read preference option is deprecated. Hedged reads are ' \ | ||
| 'deprecated in MongoDB Server 8.0 and will be removed in a future version.' | ||
| ) |
jamis
approved these changes
Apr 30, 2026
This file contains hidden or 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
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.
Description
RUBY-3628. Implements the server-selection spec change for DRIVERS-2929.
Hedged reads are deprecated in MongoDB Server 8.0 and will be removed in a future version. The spec requires that "Driver APIs related to the
hedgeparameter SHOULD be annotated and documented as deprecated. If static annotations are not used, drivers MUST emit a runtime deprecation warning if ahedgeparameter is specified."Ruby has no static deprecation annotation, so this PR does both: it adds YARD
@deprecatedtags everywherehedgeis exposed, and it emits a one-time runtime warning via the existingMongo::Deprecationshelper (same pattern as:map_reduce).Changes
lib/mongo/server_selector/base.rb— annotate the:hedgeoption, thehedgeattr_reader, and emit a runtimeMongo::Deprecations.warn(:hedge_read_preference, ...)when a selector is constructed with a non-nilhedge.lib/mongo/server_selector/{primary,secondary,primary_preferred,secondary_preferred,nearest}.rb— annotate the per-selectorhedge_allowed?methods.lib/mongo/error/invalid_server_preference.rb— annotate theNO_HEDGE_SUPPORTconstant.No behavioral change. The
hedgeoption still serializes to the wire and the existing validation still raisesError::InvalidServerPreferencefor invalid shapes.Cross-driver references
DeprecationWarning, no static annotations available.@Deprecatedannotation only.Deprecated:doc-comment only.Test plan
This change is annotation + a one-line runtime warning. No new specs added; per the spec change there is no behavioral surface to assert.
bundle exec rubocopclean on all modified files.MONGODB_URI=... bundle exec rspec spec/mongo/server_selector/{primary,primary_preferred,secondary,secondary_preferred,nearest}_spec.rb— 200 examples, 0 failures.MONGODB_URI=... bundle exec rspec spec/mongo/operation/read_preference_op_msg_spec.rb— 41 examples, 0 failures.hedge: { ... }.