Parent

Mongo::PoolManager

Attributes

arbiters[R]
client[R]
hosts[R]
max_bson_size[R]
members[R]
nodes[R]
primary[R]
primary_pool[R]
secondaries[R]
secondary_pool[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/util/pool_manager.rb, line 17
def initialize(client, seeds=[])
  @client               = client
  @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 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={}) click to toggle source
# File lib/mongo/util/pool_manager.rb, line 90
def close(opts={})
  begin
    pools.each { |pool| pool.close(opts) }
  rescue ConnectionFailure
  end
end
closed?() click to toggle source
# File lib/mongo/util/pool_manager.rb, line 86
def closed?
  pools.all? { |pool| pool.closed? }
end
connect() click to toggle source
# 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() click to toggle source
# File lib/mongo/util/pool_manager.rb, line 23
def inspect
  "<Mongo::PoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>"
end
pools() click to toggle source
# File lib/mongo/util/pool_manager.rb, line 121
def pools
  [@primary_pool, *@secondary_pools].compact
end
read() click to toggle source
# 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) click to toggle source
# File lib/mongo/util/pool_manager.rb, line 101
def read_pool(mode=@client.read,
              tags=@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(tags) && pinned.up?
    pool = pinned
  else
    pool = select_pool(mode, tags, acceptable_latency)
  end

  unless pool
    raise ConnectionFailure, "No replica set member available for query " +
      "with read preference matching mode #{mode} and tags matching #{tags}."
  end

  pool
end
refresh_required?() click to toggle source

The replica set connection should initiate a full refresh.

# File lib/mongo/util/pool_manager.rb, line 82
def refresh_required?
  @refresh_required
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.