Class: Mongo::ShardingPoolManager

Inherits:
PoolManager show all
Defined in:
lib/mongo/util/sharding_pool_manager.rb

Instance Attribute Summary collapse

Attributes inherited from PoolManager

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

Instance Method Summary collapse

Methods inherited from PoolManager

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

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.



52
53
54
# File 'lib/mongo/util/sharding_pool_manager.rb', line 52

def initialize(client, seeds=[])
  super
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



42
43
44
# File 'lib/mongo/util/sharding_pool_manager.rb', line 42

def client
  @client
end

#hostsObject (readonly)

Returns the value of attribute hosts.



42
43
44
# File 'lib/mongo/util/sharding_pool_manager.rb', line 42

def hosts
  @hosts
end

#max_bson_sizeObject (readonly)

Returns the value of attribute max_bson_size.



42
43
44
# File 'lib/mongo/util/sharding_pool_manager.rb', line 42

def max_bson_size
  @max_bson_size
end

#membersObject (readonly)

Returns the value of attribute members.



42
43
44
# File 'lib/mongo/util/sharding_pool_manager.rb', line 42

def members
  @members
end

#nodesObject (readonly)

Returns the value of attribute nodes.



42
43
44
# File 'lib/mongo/util/sharding_pool_manager.rb', line 42

def nodes
  @nodes
end

#primaryObject (readonly)

Returns the value of attribute primary.



42
43
44
# File 'lib/mongo/util/sharding_pool_manager.rb', line 42

def primary
  @primary
end

#primary_poolObject (readonly)

Returns the value of attribute primary_pool.



42
43
44
# File 'lib/mongo/util/sharding_pool_manager.rb', line 42

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



62
63
64
# File 'lib/mongo/util/sharding_pool_manager.rb', line 62

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



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/mongo/util/sharding_pool_manager.rb', line 82

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



66
67
68
69
70
71
72
73
74
75
# File 'lib/mongo/util/sharding_pool_manager.rb', line 66

def connect
  close if @previously_connected

  initialize_data
  members = connect_to_members
  initialize_pools(best(members))

  @members = members
  @previously_connected = true
end

#inspectObject



56
57
58
# File 'lib/mongo/util/sharding_pool_manager.rb', line 56

def inspect
  "<Mongo::ShardingPoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>"
end