method
try_to_checkout_new_connection
v8.0.0 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::ConnectionPool
try_to_checkout_new_connection()private
If the pool is not at a @size limit, establish new connection. Connecting to the DB is done outside main synchronized section.
# File activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb, line 886
def try_to_checkout_new_connection
# first in synchronized section check if establishing new conns is allowed
# and increment @now_connecting, to prevent overstepping this pool's @size
# constraint
do_checkout = synchronize do
if @threads_blocking_new_connections.zero? && (@connections.size + @now_connecting) < @size
@now_connecting += 1
end
end
if do_checkout
begin
# if successfully incremented @now_connecting establish new connection
# outside of synchronized section
conn = checkout_new_connection
ensure
synchronize do
if conn
adopt_connection(conn)
# returned conn needs to be already leased
conn.lease
end
@now_connecting -= 1
end
end
end
end Related methods
- Instance methods
- active_connection
- active_connection?
- checkin
- checkout
- clear_reloadable_connections
- clear_reloadable_connections!
- connected?
- connection_class
- connections
- discard!
- discarded?
- disconnect
- disconnect!
- flush
- flush!
- inspect
- internal_metadata
- lease_connection
- migration_context
- migrations_paths
- num_waiting_in_queue
- permanent_lease?
- pin_connection!
- reap
- release_connection
- remove
- schedule_query
- schema_cache
- schema_migration
- schema_reflection=
- stat
- unpin_connection!
- with_connection
- Class methods
- install_executor_hooks
- new
- Private methods
-
acquire_connection -
adopt_connection -
attempt_to_checkout_all_existing_connections -
build_async_executor -
bulk_make_new_connections -
checkout_and_verify -
checkout_for_exclusive_access -
checkout_new_connection -
connection_lease -
new_connection -
release -
remove_connection_from_thread_cache -
try_to_checkout_new_connection -
with_exclusively_acquired_all_connections -
with_new_connections_blocked