Class: Mongo::ShardingPoolManager

Inherits:
PoolManager show all
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

Attributes inherited from PoolManager

#arbiters, #secondaries, #secondary_pool, #secondary_pools, #seeds

Instance Method Summary collapse

Methods inherited from PoolManager

#close, #closed?, #pools, #read, #read_pool, #refresh_required?

Methods included from ThreadLocalVariableManager

#thread_local

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

#clientObject (readonly)

Returns the value of attribute client.



5
6
7
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5

def client
  @client
end

#hostsObject (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_sizeObject (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

#membersObject (readonly)

Returns the value of attribute members.



5
6
7
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5

def members
  @members
end

#nodesObject (readonly)

Returns the value of attribute nodes.



5
6
7
# File 'lib/mongo/util/sharding_pool_manager.rb', line 5

def nodes
  @nodes
end

#primaryObject (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_poolObject (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_healthObject

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

#connectObject



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

#inspectObject



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