Retrieving the connection pool happens a lot, so we cache it in
@connection_name_to_pool_manager. This makes retrieving the connection pool
O(1) once the process is warm. When a connection is established or removed,
we invalidate the cache.
# File activerecord/lib/active_record/connection_adapters/abstract/connection_handler.rb, line 212
def retrieve_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard, strict: false)
pool = get_pool_manager(connection_name)&.get_pool_config(role, shard)&.pool
if strict && !pool
if shard != ActiveRecord::Base.default_shard
message = "No connection pool for '#{connection_name}' found for the '#{shard}' shard."
elsif role != ActiveRecord::Base.default_role
message = "No connection pool for '#{connection_name}' found for the '#{role}' role."
else
message = "No connection pool for '#{connection_name}' found."
end
raise ConnectionNotEstablished, message
end
pool
end