Module: Mongo::ServerSelector
- Extended by:
- ServerSelector
- Included in:
- ServerSelector
- Defined in:
- lib/mongo/server_selector.rb,
lib/mongo/server_selector/base.rb,
lib/mongo/server_selector/nearest.rb,
lib/mongo/server_selector/primary.rb,
lib/mongo/server_selector/secondary.rb,
lib/mongo/server_selector/primary_preferred.rb,
lib/mongo/server_selector/secondary_preferred.rb
Overview
Functionality for getting an object able to select a server, given a preference.
Defined Under Namespace
Classes: Base, Nearest, Primary, PrimaryPreferred, Secondary, SecondaryPreferred
Constant Summary collapse
- LOCAL_THRESHOLD =
The max latency in seconds between the closest server and other servers considered for selection.
0.015.freeze
- SERVER_SELECTION_TIMEOUT =
How long to block for server selection before throwing an exception.
30.freeze
- SMALLEST_MAX_STALENESS_SECONDS =
The smallest allowed max staleness value, in seconds.
90
- PRIMARY =
Primary read preference.
Options::Redacted.new(mode: :primary).freeze
- PREFERENCES =
Hash lookup for the selector classes based off the symbols
provided in configuration.
{ nearest: Nearest, primary: Primary, primary_preferred: PrimaryPreferred, secondary: Secondary, secondary_preferred: SecondaryPreferred }.freeze
Instance Method Summary collapse
-
#get(preference = {}) ⇒ Object
Create a server selector object.
-
#primary ⇒ Object
private
Returns the primary server selector.
Instance Method Details
#get(preference = {}) ⇒ Object
Create a server selector object.
75 76 77 78 79 |
# File 'lib/mongo/server_selector.rb', line 75 def get(preference = {}) return preference if PREFERENCES.values.include?(preference.class) Mongo::Lint.validate_underscore_read_preference(preference) PREFERENCES.fetch((preference[:mode] || :primary).to_sym).new(preference) end |
#primary ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the primary server selector.
A call to this method is equivalent to ‘get(mode: :primary)`, except the resulting server selector object is cached and not recreated each time.
87 88 89 |
# File 'lib/mongo/server_selector.rb', line 87 def primary @primary ||= get(mode: :primary) end |