Skip to content

RUBY-3628 Deprecate hedged reads option#3036

Open
comandeo-mongo wants to merge 1 commit intomongodb:masterfrom
comandeo-mongo:3628-deprecate-hedge
Open

RUBY-3628 Deprecate hedged reads option#3036
comandeo-mongo wants to merge 1 commit intomongodb:masterfrom
comandeo-mongo:3628-deprecate-hedge

Conversation

@comandeo-mongo
Copy link
Copy Markdown
Contributor

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 hedge parameter SHOULD be annotated and documented as deprecated. If static annotations are not used, drivers MUST emit a runtime deprecation warning if a hedge parameter is specified."

Ruby has no static deprecation annotation, so this PR does both: it adds YARD @deprecated tags everywhere hedge is exposed, and it emits a one-time runtime warning via the existing Mongo::Deprecations helper (same pattern as :map_reduce).

Changes

  • lib/mongo/server_selector/base.rb — annotate the :hedge option, the hedge attr_reader, and emit a runtime Mongo::Deprecations.warn(:hedge_read_preference, ...) when a selector is constructed with a non-nil hedge.
  • lib/mongo/server_selector/{primary,secondary,primary_preferred,secondary_preferred,nearest}.rb — annotate the per-selector hedge_allowed? methods.
  • lib/mongo/error/invalid_server_preference.rb — annotate the NO_HEDGE_SUPPORT constant.

No behavioral change. The hedge option still serializes to the wire and the existing validation still raises Error::InvalidServerPreference for invalid shapes.

Cross-driver references

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 rubocop clean 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.
  • Deprecation warning observed once per process when constructing a selector with hedge: { ... }.

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.
@comandeo-mongo comandeo-mongo marked this pull request as ready for review April 30, 2026 16:29
@comandeo-mongo comandeo-mongo requested a review from a team as a code owner April 30, 2026 16:29
@comandeo-mongo comandeo-mongo requested review from Copilot and jamis April 30, 2026 16:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 @deprecated annotations around hedge-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_SUPPORT error 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.'
)
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.

3 participants