123456789_123456789_123456789_123456789_123456789_

Class: Mongo::ServerSelector::Nearest

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Base
Instance Chain:
self, Base
Inherits: Mongo::ServerSelector::Base
Defined in: lib/mongo/server_selector/nearest.rb

Overview

Encapsulates specifications for selecting near servers given a list

of candidates.

Since:

  • 2.0.0

Constant Summary

Class Method Summary

Base - Inherited

.new

Initialize the server selector.

Instance Attribute Summary

Base - Inherited

Instance Method Summary

Base - Inherited

#==

Check equality of two server selectors.

#candidates

Returns servers of acceptable types from the cluster.

#inspect

Inspect the server selector.

#local_threshold

Get the local threshold boundary for nearest selection in seconds.

#local_threshold_with_cluster,
#select_server

Select a server from the specified cluster, taking into account mongos pinning for the specified session.

#server_selection_timeout

Get the timeout for server selection.

#suitable_servers

Returns servers satisfying the server selector from the cluster.

#try_select_server

Tries to find a suitable server, returns the server if one is available or nil if there isn’t a suitable server.

#filter_stale_servers,
#full_doc

Convert this server preference definition into a format appropriate.

#match_tag_sets

Select the servers matching the defined tag sets.

#near_servers

Select the near servers from a list of provided candidates, taking the.

#primary

Select the primary from a list of provided candidates.

#secondaries

Select the secondaries from a list of provided candidates.

#select_server_impl

Parameters and return values are the same as for select_server, only the timeout param is renamed to csot_timeout.

#server_selection_diagnostic_message

Creates a diagnostic message when server selection fails.

#suitable_server

Returns a server from the list of servers that is suitable for executing the operation.

#validate!, #validate_max_staleness_support!, #validate_max_staleness_value!, #validate_max_staleness_value_early!,
#wait_for_server_selection

Waits for server state changes in the specified cluster.

Instance Attribute Details

#hedge_allowed?true (readonly)

Whether the hedge option is allowed to be defined for this server preference.

Returns:

  • (true)

    true

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector/nearest.rb', line 65

def hedge_allowed?
  true
end

#max_staleness_allowed?Boolean (readonly, private)

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector/nearest.rb', line 105

def max_staleness_allowed?
  true
end

#secondary_ok?true (readonly)

This method is for internal use only.

Whether the secondaryOk bit should be set on wire protocol messages.

I.e. whether the operation can be performed on a secondary server.

Returns:

  • (true)

    true

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector/nearest.rb', line 49

def secondary_ok?
  true
end

#tags_allowed?true (readonly)

Whether tag sets are allowed to be defined for this server preference.

Returns:

  • (true)

    true

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector/nearest.rb', line 58

def tags_allowed?
  true
end

Instance Method Details

#nameSymbol

Get the name of the server mode type.

Examples:

Get the name of the server mode for this preference.

preference.name

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector/nearest.rb', line 40

def name
  :nearest
end

#select_in_replica_set(candidates) ⇒ Array (private)

Select the near servers taking into account any defined tag sets and

local threshold between the nearest server and other servers.

Returns:

  • (Array)

    The nearest servers from the list of candidates.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector/nearest.rb', line 99

def select_in_replica_set(candidates)
  matching_servers = filter_stale_servers(candidates, primary(candidates).first)
  matching_servers = match_tag_sets(matching_servers) unless tag_sets.empty?
  near_servers(matching_servers)
end

#to_docHash Also known as: #to_mongos

Convert this server preference definition into a format appropriate

for sending to a MongoDB server (i.e., as a command field).

Returns:

  • (Hash)

    The server preference formatted as a command field value.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server_selector/nearest.rb', line 75

def to_doc
  full_doc
end

#to_mongos

Alias for #to_doc.

[ GitHub ]

  
# File 'lib/mongo/server_selector/nearest.rb', line 89

alias :to_mongos :to_doc