Module: Mongo::ServerSelector

Extended by:
ServerSelector
Included in:
ServerSelector
Defined in:
lib/mongo/server_selector.rb,
lib/mongo/server_selector/primary.rb,
lib/mongo/server_selector/nearest.rb,
lib/mongo/server_selector/secondary.rb,
lib/mongo/server_selector/selectable.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.

Since:

  • 2.0.0

Defined Under Namespace

Modules: Selectable Classes: Nearest, Primary, PrimaryPreferred, Secondary, SecondaryPreferred

Constant Summary

LOCAL_THRESHOLD =

The max latency in seconds between the closest server and other servers considered for selection.

Since:

  • 2.0.0

0.015.freeze
SERVER_SELECTION_TIMEOUT =

How long to block for server selection before throwing an exception.

Since:

  • 2.0.0

30.freeze
SMALLEST_MAX_STALENESS_SECONDS =

The smallest allowed max staleness value, in seconds.

Since:

  • 2.4.0

90
PRIMARY =

Primary read preference.

Since:

  • 2.1.0

Options::Redacted.new(mode: :primary).freeze
PREFERENCES =

Hash lookup for the selector classes based off the symbols

provided in configuration.

Since:

  • 2.0.0

{
  nearest: Nearest,
  primary: Primary,
  primary_preferred: PrimaryPreferred,
  secondary: Secondary,
  secondary_preferred: SecondaryPreferred
}.freeze

Instance Method Summary collapse

Instance Method Details

#get(preference = {}) ⇒ Object

Create a server selector object.

Examples:

Get a server selector object for selecting a secondary with

specific tag sets.
Mongo::ServerSelector.get(:mode => :secondary, :tag_sets => [{'dc' => 'nyc'}])

Parameters:

  • preference (Hash) (defaults to: {})

    The server preference.

Since:

  • 2.0.0



72
73
74
75
# File 'lib/mongo/server_selector.rb', line 72

def get(preference = {})
  return preference if PREFERENCES.values.include?(preference.class)
  PREFERENCES.fetch(preference[:mode] || :primary).new(preference)
end