Class: ActiveRecord::ConnectionAdapters::RactorConnectionHandler
Do not use. This class is for internal use only.
Overview
Worker-Ractor stand-in for ConnectionHandler
Class Method Summary
Instance Method Summary
- #active_connections?(role = nil) ⇒ Boolean
- #clear_active_connections!(role = nil)
- #clear_all_connections!(role = nil)
- #clear_reloadable_connections!(role = nil)
- #connected?(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard) ⇒ Boolean
-
#connection_pool_list(role = nil)
(also: #connection_pools)
Blocks handed to main_operation may only capture single-assignment locals.
- #connection_pool_names
-
#connection_pools(role = nil)
Alias for #connection_pool_list.
- #each_connection_pool(role = nil, &block)
- #establish_connection(config, owner_name: Base, role: Base.current_role, shard: Base.current_shard, clobber: false)
- #flush_idle_connections!(role = nil)
- #main_ractor_handler
- #remove_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard)
- #retrieve_connection(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard)
- #retrieve_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard, strict: false)
Proxy - Included
| #boundary_safe_bind | Attribute types may close over procs, so the database value is resolved locally. |
| #checkin_all_connections | For supervisors tearing down worker Ractors, which cannot release their own tokens when they die. |
| #checkin_token, #connection_pinned?, #discard_token, #dump_binds, #dump_column_types, #dump_object, | |
| #main_operation |
|
| #remove_token | |
Class Method Details
.instance
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 18
def self.instance ActiveSupport::Ractors[:active_record_ractor_connection_handler_instance] ||= new end
Instance Method Details
#active_connections?(role = nil) ⇒ Boolean
# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 70
def active_connections?(role = nil) each_connection_pool(role).any?(&:active_connection?) end
#clear_active_connections!(role = nil)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 74
def clear_active_connections!(role = nil) each_connection_pool(role).each do |pool| pool.release_connection pool.disable_query_cache! end end
#clear_all_connections!(role = nil)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 85
def clear_all_connections!(role = nil) each_connection_pool(role).each(&:disconnect!) end
#clear_reloadable_connections!(role = nil)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 81
def clear_reloadable_connections!(role = nil) clear_active_connections!(role) end
#connected?(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard) ⇒ Boolean
# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 65
def connected?(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard) pool = retrieve_connection_pool(connection_name, role: role, shard: shard) pool && pool.connected? end
#connection_pool_list(role = nil) Also known as: #connection_pools
Blocks handed to main_operation may only capture single-assignment locals
# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 23
def connection_pool_list(role = nil) connection_role = role pool_specs = main_operation do specs = main_connection_handler.connection_pool_list(connection_role).map { |pool| pool.pool_config.pool_spec } ActiveSupport::Ractors.make_shareable(specs, copy: false) end pool_specs.map { |pool_spec| ProxyConnectionPool.for_spec(pool_spec) } end
#connection_pool_names
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 33
def connection_pool_names connection_pool_list.map { |pool| pool.connection_descriptor.name }.uniq end
#connection_pools(role = nil)
Alias for #connection_pool_list.
# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 31
alias :connection_pools :connection_pool_list
#each_connection_pool(role = nil, &block)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 37
def each_connection_pool(role = nil, &block) return enum_for(__method__, role) unless block_given? connection_pool_list(role).each(&block) end
#establish_connection(config, owner_name: Base, role: Base.current_role, shard: Base.current_shard, clobber: false)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 93
def establish_connection(config, owner_name: Base, role: Base.current_role, shard: Base.current_shard, clobber: false) connection_owner_name = owner_name db_config = ActiveSupport::Ractors.make_shareable(config) connection_role = role connection_shard = shard clobber_existing = clobber pool_spec = main_operation do pool = main_connection_handler.establish_connection( db_config.dup, owner_name: connection_owner_name, role: connection_role, shard: connection_shard, clobber: clobber_existing, ) pool.pool_config.pool_spec end ProxyConnectionPool.for_spec(pool_spec) end
#flush_idle_connections!(role = nil)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 89
def flush_idle_connections!(role = nil) each_connection_pool(role).each(&:flush!) end
#main_ractor_handler
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 126
def main_ractor_handler Proxy.main_connection_handler end
#remove_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 114
def remove_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard) shareable_connection_name = ActiveSupport::Ractors.make_shareable(connection_name.to_s) connection_role = role connection_shard = shard main_operation do main_connection_handler.remove_connection_pool( shareable_connection_name, role: connection_role, shard: connection_shard ) end end
#retrieve_connection(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 43
def retrieve_connection(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard) retrieve_connection_pool(connection_name, role: role, shard: shard, strict: true).lease_connection end
#retrieve_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard, strict: false)
[ GitHub ]# File 'activerecord/lib/active_record/connection_adapters/ractor_connection_handler.rb', line 47
def retrieve_connection_pool(connection_name, role: ActiveRecord::Base.current_role, shard: ActiveRecord::Base.current_shard, strict: false) shareable_connection_name = ActiveSupport::Ractors.make_shareable(connection_name.to_s) connection_role = role connection_shard = shard strict_lookup = strict pool_spec = main_operation do pool = main_connection_handler.retrieve_connection_pool( shareable_connection_name, role: connection_role, shard: connection_shard, strict: strict_lookup, ) pool && pool.pool_config.pool_spec end pool_spec && ProxyConnectionPool.for_spec(pool_spec) end