Class: Mongo::PoolManager
- Includes:
- ThreadLocalVariableManager
- Defined in:
- lib/mongo/util/pool_manager.rb
Direct Known Subclasses
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.
-
#members ⇒ Object
readonly
Returns the value of attribute members.
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
-
#pools ⇒ Object
readonly
Returns the value of attribute pools.
-
#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_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
- #max_bson_size ⇒ Object
- #max_message_size ⇒ Object
- #read ⇒ Object
- #refresh!(additional_seeds) ⇒ Object
-
#refresh_required? ⇒ Boolean
The replica set connection should initiate a full refresh.
Methods included from ThreadLocalVariableManager
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.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongo/util/pool_manager.rb', line 24 def initialize(client, seeds=[]) @client = client @seeds = seeds @pools = Set.new @primary = nil @primary_pool = nil @secondaries = Set.new @secondary_pools = [] @hosts = Set.new @members = Set.new @refresh_required = false end |
Instance Attribute Details
#arbiters ⇒ Object (readonly)
Returns the value of attribute arbiters.
5 6 7 |
# File 'lib/mongo/util/pool_manager.rb', line 5 def arbiters @arbiters end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/mongo/util/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/pool_manager.rb', line 5 def hosts @hosts end |
#members ⇒ Object (readonly)
Returns the value of attribute members.
5 6 7 |
# File 'lib/mongo/util/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/pool_manager.rb', line 5 def nodes @nodes end |
#pools ⇒ Object (readonly)
Returns the value of attribute pools.
5 6 7 |
# File 'lib/mongo/util/pool_manager.rb', line 5 def pools @pools end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
5 6 7 |
# File 'lib/mongo/util/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/pool_manager.rb', line 5 def primary_pool @primary_pool end |
#secondaries ⇒ Object (readonly)
Returns the value of attribute secondaries.
5 6 7 |
# File 'lib/mongo/util/pool_manager.rb', line 5 def secondaries @secondaries end |
#secondary_pools ⇒ Object (readonly)
Returns the value of attribute secondary_pools.
5 6 7 |
# File 'lib/mongo/util/pool_manager.rb', line 5 def secondary_pools @secondary_pools end |
#seeds ⇒ Object (readonly)
Returns the value of attribute seeds.
5 6 7 |
# File 'lib/mongo/util/pool_manager.rb', line 5 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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mongo/util/pool_manager.rb', line 59 def check_connection_health begin seed = get_valid_seed_node rescue ConnectionFailure @refresh_required = true return end unless current_config = seed.config @refresh_required = true seed.close return end if current_config['hosts'].length != @members.length @refresh_required = true seed.close return end current_config['hosts'].each do |host| member = @members.detect do |m| m.address == host end if member && validate_existing_member(current_config, member) next else @refresh_required = true seed.close return false end end seed.close end |
#close(opts = {}) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/mongo/util/pool_manager.rb', line 105 def close(opts={}) begin pools.each { |pool| pool.close(opts) } rescue ConnectionFailure end end |
#closed? ⇒ Boolean
101 102 103 |
# File 'lib/mongo/util/pool_manager.rb', line 101 def closed? pools.all? { |pool| pool.closed? } end |
#connect ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/mongo/util/pool_manager.rb', line 42 def connect @refresh_required = false disconnect_old_members connect_to_members initialize_pools(@members) cache_discovered_seeds end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/mongo/util/pool_manager.rb', line 38 def inspect "<Mongo::PoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>" end |
#max_bson_size ⇒ Object
116 117 118 |
# File 'lib/mongo/util/pool_manager.rb', line 116 def max_bson_size @max_bson_size ||= config_min('maxBsonObjectSize', DEFAULT_MAX_BSON_SIZE) end |
#max_message_size ⇒ Object
120 121 122 |
# File 'lib/mongo/util/pool_manager.rb', line 120 def @max_message_size ||= config_min('maxMessageSizeBytes', DEFAULT_MAX_MESSAGE_SIZE) end |
#read ⇒ Object
112 113 114 |
# File 'lib/mongo/util/pool_manager.rb', line 112 def read read_pool.host_port end |
#refresh!(additional_seeds) ⇒ Object
50 51 52 53 |
# File 'lib/mongo/util/pool_manager.rb', line 50 def refresh!(additional_seeds) @seeds |= additional_seeds connect end |
#refresh_required? ⇒ Boolean
The replica set connection should initiate a full refresh.
97 98 99 |
# File 'lib/mongo/util/pool_manager.rb', line 97 def refresh_required? @refresh_required end |