Class: Mongo::ShardingPoolManager
- Inherits:
-
PoolManager
- Object
- PoolManager
- Mongo::ShardingPoolManager
- Defined in:
- lib/mongo/util/sharding_pool_manager.rb
Constant Summary
Constants included from ReadPreference
ReadPreference::MONGOS_MODES, ReadPreference::READ_PREFERENCES
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#hosts ⇒ Object
readonly
Returns the value of attribute hosts.
-
#max_bson_size ⇒ Object
readonly
Returns the value of attribute max_bson_size.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#primary ⇒ Object
readonly
Returns the value of attribute primary.
-
#primary_pool ⇒ Object
readonly
Returns the value of attribute primary_pool.
Attributes inherited from PoolManager
#arbiters, #secondaries, #secondary_pool, #secondary_pools, #seeds
Instance Method Summary collapse
-
#best(members) ⇒ Object
“Best” should be the member with the fastest ping time but connect/connect_to_members reinitializes @members.
-
#check_connection_health ⇒ Object
We want to refresh to the member with the fastest ping time but also want to minimize refreshes We’re healthy if the primary is pingable.
- #connect ⇒ Object
-
#initialize(client, seeds = []) ⇒ ShardingPoolManager
constructor
Create a new set of connection pools.
- #inspect ⇒ Object
Methods inherited from PoolManager
#close, #closed?, #pools, #read, #read_pool, #refresh_required?
Methods included from ThreadLocalVariableManager
Methods included from ReadPreference
mongos, #select_near_pool, #select_pool, #select_secondary_pool, validate
Constructor Details
#initialize(client, seeds = []) ⇒ ShardingPoolManager
Create a new set of connection pools.
The pool manager will by default use the original seed list passed to the connection objects, accessible via connection.seeds. In addition, the user may pass an additional list of seeds nodes discovered in real time. The union of these lists will be used when attempting to connect, with the newly-discovered nodes being used first.
15 16 17 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 15 def initialize(client, seeds=[]) super end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5 def client @client end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
5 6 7 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5 def hosts @hosts end |
#max_bson_size ⇒ Object (readonly)
Returns the value of attribute max_bson_size.
5 6 7 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5 def max_bson_size @max_bson_size end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
5 6 7 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5 def members @members end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
5 6 7 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5 def nodes @nodes end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
5 6 7 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5 def primary @primary end |
#primary_pool ⇒ Object (readonly)
Returns the value of attribute primary_pool.
5 6 7 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5 def primary_pool @primary_pool end |
Instance Method Details
#best(members) ⇒ Object
“Best” should be the member with the fastest ping time but connect/connect_to_members reinitializes @members
25 26 27 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 25 def best(members) Array(members.first) end |
#check_connection_health ⇒ Object
We want to refresh to the member with the fastest ping time but also want to minimize refreshes We’re healthy if the primary is pingable. If this isn’t the case, or the members have changed, set @refresh_required to true, and return. The config.mongos find can’t be part of the connect call chain due to infinite recursion
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 45 def check_connection_health begin seeds = @client['config']['mongos'].find.to_a.map{|doc| doc['_id']} if @seeds != seeds @seeds = seeds @refresh_required = true end rescue Mongo::OperationFailure @refresh_required = true end end |
#connect ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 29 def connect close if @previously_connected initialize_data members = connect_to_members initialize_pools(best(members)) @members = members @previously_connected = true end |
#inspect ⇒ Object
19 20 21 |
# File 'lib/mongo/util/sharding_pool_manager.rb', line 19 def inspect "<Mongo::ShardingPoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>" end |