Skip to content
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

GODRIVER-2689 (POC) Simplify the "readpref" API #1733

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

prestonvasquez
Copy link
Collaborator

GODRIVER-2689

Summary

Background & Motivation

@prestonvasquez prestonvasquez changed the base branch from v1 to master August 5, 2024 23:11
@mongodb-drivers-pr-bot mongodb-drivers-pr-bot bot added the priority-3-low Low Priority PR for Review label Aug 5, 2024
Copy link
Contributor

mongodb-drivers-pr-bot bot commented Aug 6, 2024

API Change Report

./v2/event

incompatible changes

##ServerDescription.Tags: changed from ./v2/tag.Set to ./v2/mongo/readpref.TagSet

./v2/mongo/readpref

incompatible changes

(*ReadPref).MaxStaleness: changed from func() (time.Duration, bool) to func() *time.Duration
(*ReadPref).Mode: removed
##(*ReadPref).TagSets: changed from func() []./v2/tag.Set to func() []TagSet
ErrInvalidTagSet: removed
Mode.IsValid: removed
Mode.String: removed
Mode: changed from uint8 to string
Nearest: changed from func(...Option) *ReadPref to func(...*Builder) *ReadPref
NearestMode: changed from Mode to untyped string
New: changed from func(Mode, ...Option) (*ReadPref, error) to func(Mode, ...*Builder) (*ReadPref, error)
Option: removed
PrimaryMode: changed from Mode to untyped string
PrimaryPreferred: changed from func(...Option) *ReadPref to func(...*Builder) *ReadPref
PrimaryPreferredMode: changed from Mode to untyped string
Secondary: changed from func(...Option) *ReadPref to func(...*Builder) *ReadPref
SecondaryMode: changed from Mode to untyped string
SecondaryPreferred: changed from func(...Option) *ReadPref to func(...*Builder) *ReadPref
SecondaryPreferredMode: changed from Mode to untyped string
WithHedgeEnabled: removed
WithMaxStaleness: removed
WithTagSets: removed
WithTags: removed

compatible changes

Builder: added
NewTagSet: added
NewTagSetFromMap: added
NewTagSetsFromMaps: added
Options: added
ReadPref.Mode: added
Tag: added
TagSet: added

./v2/tag

incompatible changes

package removed

./v2/x/mongo/driver/description

incompatible changes

##SelectedServer.Tags: changed from ./v2/tag.Set to ./v2/mongo/readpref.TagSet
##Server.Tags: changed from ./v2/tag.Set to ./v2/mongo/readpref.TagSet

type ReadPref struct {
Mode Mode

maxStaleness *time.Duration
Copy link
Collaborator Author

@prestonvasquez prestonvasquez Aug 6, 2024

Choose a reason for hiding this comment

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

The current pattern prevents users from creating invalid read preferences, for example:

ms := 1 * time.Second
rp := readpref.ReadPref{
    Mode: readpref.PrimaryMode, 
    MaxStaleness: &ms, 
}

Concerning server selection:

If the mode field is “primary”, the tags, maxStalenessSeconds, and hedge fields MUST be absent.

Concerning max staleness:

A connection string combining a positive maxStalenessSeconds with read preference mode “primary” MUST be considered invalid; this includes connection strings with no explicit read preference mode.

The only driver I've investigated that doesn't follow the pattern of validating in the read preference constructor is C (compared to Node, Python, PHP). C uses a _mongoc_read_prefs_validate function to validate this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-3-low Low Priority PR for Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant