class Mongo::PoolManager

Attributes

arbiters[R]
connection[R]
hosts[R]
max_bson_size[R]
members[R]
nodes[R]
primary[R]
primary_pool[R]
read_pool[R]
secondaries[R]
secondary_pool[R]
secondary_pools[R]
tag_map[R]
tags_to_pools[R]

Public Class Methods

new(connection, 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/util/pool_manager.rb, line 15
def initialize(connection, seeds=[])
  @connection = connection
  @original_seeds = connection.seeds
  @seeds = seeds
  @previously_connected = 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/util/pool_manager.rb, line 44
def check_connection_health
  begin
    seed = get_valid_seed_node
  rescue ConnectionFailure
    @refresh_required = true
    return
  end

  config = seed.set_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={}) click to toggle source
# File lib/mongo/util/pool_manager.rb, line 91
def close(opts={})
  begin
    if @primary_pool
      @primary_pool.close(opts)
    end

    if @secondary_pools
      @secondary_pools.each do |pool|
        pool.close(opts)
      end
    end

    if @members
      @members.each do |member|
        member.close
      end
    end

    rescue ConnectionFailure
  end
end
closed?() click to toggle source
# File lib/mongo/util/pool_manager.rb, line 87
def closed?
  pools.all? { |pool| pool.closed? }
end
connect() click to toggle source
# File lib/mongo/util/pool_manager.rb, line 26
def connect
  close if @previously_connected

  initialize_data
  members = connect_to_members
  initialize_pools(members)
  cache_discovered_seeds(members)
  set_read_pool
  set_tag_mappings

  @members = members
  @previously_connected = true
end
inspect() click to toggle source
# File lib/mongo/util/pool_manager.rb, line 22
def inspect
  "<Mongo::PoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>"
end
refresh_required?() click to toggle source

The replica set connection should initiate a full refresh.

# File lib/mongo/util/pool_manager.rb, line 83
def refresh_required?
  @refresh_required
end
seeds() click to toggle source

The set of nodes that this class has discovered and successfully connected to.

# File lib/mongo/util/pool_manager.rb, line 115
def seeds
  @seeds || []
end