Class: Mongo::PoolManager
- Includes:
- ReadPreference, ThreadLocalVariableManager
- Defined in:
- lib/mongo/util/pool_manager.rb
Direct Known Subclasses
Constant Summary
Constants included from ReadPreference
ReadPreference::MONGOS_MODES, ReadPreference::READ_PREFERENCES
Instance Attribute Summary collapse
-
#arbiters ⇒ Object
readonly
Returns the value of attribute arbiters.
-
#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.
-
#secondaries ⇒ Object
readonly
Returns the value of attribute secondaries.
-
#secondary_pool ⇒ Object
readonly
Returns the value of attribute secondary_pool.
-
#secondary_pools ⇒ Object
readonly
Returns the value of attribute secondary_pools.
-
#seeds ⇒ Object
readonly
Returns the value of attribute seeds.
Instance Method Summary collapse
-
#check_connection_health ⇒ Object
We’re healthy if all members are pingable and if the view of the replica set returned by isMaster is equivalent to our view.
- #close(opts = {}) ⇒ Object
- #closed? ⇒ Boolean
- #connect ⇒ Object
-
#initialize(client, seeds = []) ⇒ PoolManager
constructor
Create a new set of connection pools.
- #inspect ⇒ Object
- #pools ⇒ Object
- #read ⇒ Object
- #read_pool(mode = @client.read, tags = @client.tag_sets, acceptable_latency = @client.acceptable_latency) ⇒ Object
-
#refresh_required? ⇒ Boolean
The replica set connection should initiate a full refresh.
Methods included from ThreadLocalVariableManager
Methods included from ReadPreference
mongos, #select_near_pool, #select_pool, #select_secondary_pool, validate
Constructor Details
#initialize(client, seeds = []) ⇒ PoolManager
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.
17 18 19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 17 def initialize(client, seeds=[]) @client = client @seeds = seeds @previously_connected = false end |
Instance Attribute Details
#arbiters ⇒ Object (readonly)
Returns the value of attribute arbiters.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def arbiters @arbiters end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def client @client end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def hosts @hosts end |
#max_bson_size ⇒ Object (readonly)
Returns the value of attribute max_bson_size.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def max_bson_size @max_bson_size end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def members @members end |
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def nodes @nodes end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def primary @primary end |
#primary_pool ⇒ Object (readonly)
Returns the value of attribute primary_pool.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def primary_pool @primary_pool end |
#secondaries ⇒ Object (readonly)
Returns the value of attribute secondaries.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def secondaries @secondaries end |
#secondary_pool ⇒ Object (readonly)
Returns the value of attribute secondary_pool.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def secondary_pool @secondary_pool end |
#secondary_pools ⇒ Object (readonly)
Returns the value of attribute secondary_pools.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def secondary_pools @secondary_pools end |
#seeds ⇒ Object (readonly)
Returns the value of attribute seeds.
6 7 8 |
# File 'lib/mongo/util/pool_manager.rb', line 6 def seeds @seeds end |
Instance Method Details
#check_connection_health ⇒ Object
We’re healthy if all members are pingable and if the view of the replica set returned by isMaster is equivalent to our view. If any of these isn’t the case, set @refresh_required to true, and return.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mongo/util/pool_manager.rb', line 43 def check_connection_health begin seed = get_valid_seed_node rescue ConnectionFailure @refresh_required = true return end config = seed.config if config @refresh_required = true seed.close return end if config['hosts'].length != @members.length @refresh_required = true seed.close return end config['hosts'].each do |host| member = @members.detect do |m| m.address == host end if member && validate_existing_member(member) next else @refresh_required = true seed.close return false end end seed.close end |
#close(opts = {}) ⇒ Object
90 91 92 93 94 95 |
# File 'lib/mongo/util/pool_manager.rb', line 90 def close(opts={}) begin pools.each { |pool| pool.close(opts) } rescue ConnectionFailure end end |
#closed? ⇒ Boolean
86 87 88 |
# File 'lib/mongo/util/pool_manager.rb', line 86 def closed? pools.all? { |pool| pool.closed? } end |
#connect ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mongo/util/pool_manager.rb', line 27 def connect close if @previously_connected initialize_data members = connect_to_members initialize_pools(members) cache_discovered_seeds(members) @members = members @previously_connected = true end |
#inspect ⇒ Object
23 24 25 |
# File 'lib/mongo/util/pool_manager.rb', line 23 def inspect "<Mongo::PoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>" end |
#pools ⇒ Object
121 122 123 |
# File 'lib/mongo/util/pool_manager.rb', line 121 def pools [@primary_pool, *@secondary_pools].compact end |
#read ⇒ Object
97 98 99 |
# File 'lib/mongo/util/pool_manager.rb', line 97 def read read_pool.host_port end |
#read_pool(mode = @client.read, tags = @client.tag_sets, acceptable_latency = @client.acceptable_latency) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/mongo/util/pool_manager.rb', line 101 def read_pool(mode=@client.read, =@client.tag_sets, acceptable_latency=@client.acceptable_latency) pinned = thread_local[:pinned_pools][self.object_id] if pinned && pinned.matches_mode(mode) && pinned.matches_tag_sets() && pinned.up? pool = pinned else pool = select_pool(mode, , acceptable_latency) end unless pool raise ConnectionFailure, "No replica set member available for query " + "with read preference matching mode #{mode} and tags matching #{}." end pool end |
#refresh_required? ⇒ Boolean
The replica set connection should initiate a full refresh.
82 83 84 |
# File 'lib/mongo/util/pool_manager.rb', line 82 def refresh_required? @refresh_required end |