Class: Mongo::ShardingPoolManager

Inherits:
PoolManager show all
Defined in:
lib/mongo/util/sharding_pool_manager.rb

Instance Attribute Summary

Attributes inherited from PoolManager

#arbiters, #client, #hosts, #max_bson_size, #max_message_size, #pools, #primary, #primary_pool, #secondaries, #secondary_pools, #seeds

Instance Method Summary collapse

Methods inherited from PoolManager

#close, #closed?, #initialize, #read, #refresh!, #refresh_required?

Methods included from ThreadLocalVariableManager

#thread_local

Constructor Details

This class inherits a constructor from Mongo::PoolManager

Instance Method Details

#best(members) ⇒ Object

“Best” should be the member with the fastest ping time but connect/connect_to_members reinitializes @members



23
24
25
# File 'lib/mongo/util/sharding_pool_manager.rb', line 23

def best(members)
  Array(members.first)
end

#check_connection_healthBoolean

Checks that each node is healthy (via check_is_master) and that each node is in fact a mongos. If either criteria are not true, a refresh is set to be triggered and close() is called on the node.

Returns:

  • (Boolean)

    indicating if a refresh is required.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/mongo/util/sharding_pool_manager.rb', line 48

def check_connection_health
  @refresh_required = false
  @members.each do |member|
    begin
      config = @client.check_is_master([member.host, member.port])
      unless config && config.has_key?('msg')
        @refresh_required = true
        member.close
      end
    rescue OperationTimeout
      @refresh_required = true
      member.close
    end
    break if @refresh_required
  end
  @refresh_required
end

#connectObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mongo/util/sharding_pool_manager.rb', line 27

def connect
  @connect_mutex.synchronize do
    begin
      thread_local[:locks][:connecting_manager] = true
      @refresh_required = false
      disconnect_old_members
      connect_to_members
      initialize_pools best(@members)
      update_max_sizes
      @seeds = discovered_seeds
    ensure
      thread_local[:locks][:connecting_manager] = false
    end
  end
end

#inspectObject



17
18
19
# File 'lib/mongo/util/sharding_pool_manager.rb', line 17

def inspect
  "<Mongo::ShardingPoolManager:0x#{self.object_id.to_s(16)} @seeds=#{@seeds}>"
end