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.
-
#max_bson_size ⇒ Object
readonly
Returns the value of attribute max_bson_size.
-
#max_message_size ⇒ Object
readonly
Returns the value of attribute max_message_size.
-
#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
- #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.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/mongo/util/pool_manager.rb', line 38 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 @max_bson_size = DEFAULT_MAX_BSON_SIZE = @max_bson_size * MESSAGE_SIZE_FACTOR @connect_mutex = Mutex.new thread_local[:locks][:connecting_manager] = false end |
Instance Attribute Details
#arbiters ⇒ Object (readonly)
Returns the value of attribute arbiters.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def arbiters @arbiters end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def client @client end |
#hosts ⇒ Object (readonly)
Returns the value of attribute hosts.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def hosts @hosts end |
#max_bson_size ⇒ Object (readonly)
Returns the value of attribute max_bson_size.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def max_bson_size @max_bson_size end |
#max_message_size ⇒ Object (readonly)
Returns the value of attribute max_message_size.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def end |
#pools ⇒ Object (readonly)
Returns the value of attribute pools.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def pools @pools end |
#primary ⇒ Object (readonly)
Returns the value of attribute primary.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def primary @primary end |
#primary_pool ⇒ Object (readonly)
Returns the value of attribute primary_pool.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def primary_pool @primary_pool end |
#secondaries ⇒ Object (readonly)
Returns the value of attribute secondaries.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def secondaries @secondaries end |
#secondary_pools ⇒ Object (readonly)
Returns the value of attribute secondary_pools.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 def secondary_pools @secondary_pools end |
#seeds ⇒ Object (readonly)
Returns the value of attribute seeds.
19 20 21 |
# File 'lib/mongo/util/pool_manager.rb', line 19 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.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/mongo/util/pool_manager.rb', line 85 def check_connection_health return if thread_local[:locks][:connecting_manager] members = copy_members 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 end end seed.close end |
#close(opts = {}) ⇒ Object
133 134 135 136 137 138 |
# File 'lib/mongo/util/pool_manager.rb', line 133 def close(opts={}) begin pools.each { |pool| pool.close(opts) } rescue ConnectionFailure end end |
#closed? ⇒ Boolean
129 130 131 |
# File 'lib/mongo/util/pool_manager.rb', line 129 def closed? pools.all? { |pool| pool.closed? } end |
#connect ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mongo/util/pool_manager.rb', line 60 def connect @connect_mutex.synchronize do begin thread_local[:locks][:connecting_manager] = true @refresh_required = false disconnect_old_members connect_to_members initialize_pools(@members) update_max_sizes @seeds = discovered_seeds ensure thread_local[:locks][:connecting_manager] = false end end end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/mongo/util/pool_manager.rb', line 56 def inspect "<Mongo::PoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>" end |
#read ⇒ Object
140 141 142 |
# File 'lib/mongo/util/pool_manager.rb', line 140 def read read_pool.host_port end |
#refresh!(additional_seeds) ⇒ Object
76 77 78 79 |
# File 'lib/mongo/util/pool_manager.rb', line 76 def refresh!(additional_seeds) @seeds |= additional_seeds connect end |
#refresh_required? ⇒ Boolean
The replica set connection should initiate a full refresh.
125 126 127 |
# File 'lib/mongo/util/pool_manager.rb', line 125 def refresh_required? @refresh_required end |