Parent

Mongo::PoolManager

Attributes

arbiters[R]
client[R]
hosts[R]
max_bson_size[R]
max_message_size[R]
max_wire_version[R]
min_wire_version[R]
pools[R]
primary[R]
primary_pool[R]
secondaries[R]
secondary_pools[R]
seeds[R]

Public Class Methods

new(client, seeds=[]) click to toggle source

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.

# File lib/mongo/connection/pool_manager.rb, line 40
def initialize(client, seeds=[])
  @client                                   = client
  @seeds                                    = seeds

  initialize_immutable_state
  initialize_mutable_state

  @pools                                    = Set.new
  @primary                                  = nil
  @primary_pool                             = nil
  @members                                  = Set.new
  @refresh_required                         = false
  @max_bson_size                            = DEFAULT_MAX_BSON_SIZE
  @max_message_size                         = @max_bson_size * MESSAGE_SIZE_FACTOR
  @max_wire_version                         = 0
  @min_wire_version                         = 0
  @connect_mutex                            = Mutex.new
  thread_local[:locks][:connecting_manager] = false
end

Public Instance Methods

check_connection_health() click to toggle source

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.

# File lib/mongo/connection/pool_manager.rb, line 90
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={}) click to toggle source
# File lib/mongo/connection/pool_manager.rb, line 138
def close(opts={})
  begin
    pools.each { |pool| pool.close(opts) }
  rescue ConnectionFailure
  end
end
closed?() click to toggle source
# File lib/mongo/connection/pool_manager.rb, line 134
def closed?
  pools.all? { |pool| pool.closed? }
end
connect() click to toggle source
# File lib/mongo/connection/pool_manager.rb, line 64
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
  clone_state
end
inspect() click to toggle source
# File lib/mongo/connection/pool_manager.rb, line 60
def inspect
  "<Mongo::PoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>"
end
read() click to toggle source
# File lib/mongo/connection/pool_manager.rb, line 145
def read
  read_pool.host_port
end
refresh!(additional_seeds) click to toggle source
# File lib/mongo/connection/pool_manager.rb, line 81
def refresh!(additional_seeds)
  @seeds |= additional_seeds
  connect
end
refresh_required?() click to toggle source

The replica set connection should initiate a full refresh.

# File lib/mongo/connection/pool_manager.rb, line 130
def refresh_required?
  @refresh_required
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.