GODRIVER-2689 (POC) Simplify the "readpref" API#1733
GODRIVER-2689 (POC) Simplify the "readpref" API#1733prestonvasquez wants to merge 7 commits intomongodb:masterfrom
Conversation
API Change Report./v2/eventincompatible changes##ServerDescription.Tags: changed from ./v2/tag.Set to ./v2/mongo/readpref.TagSet ./v2/mongo/readprefincompatible changes(*ReadPref).MaxStaleness: changed from func() (time.Duration, bool) to func() *time.Duration compatible changesBuilder: added ./v2/tagincompatible changespackage removed ./v2/x/mongo/driver/descriptionincompatible changes##SelectedServer.Tags: changed from ./v2/tag.Set to ./v2/mongo/readpref.TagSet |
| type ReadPref struct { | ||
| Mode Mode | ||
|
|
||
| maxStaleness *time.Duration |
There was a problem hiding this comment.
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.
GODRIVER-2689
Summary
Background & Motivation