class ActiveRecord::Bogacs::ShareablePool
Constants
- AtomicReference
- DEBUG
- DEFAULT_SHARED_POOL
- MAX_THREAD_SHARING
Attributes
Public Class Methods
new(spec)
click to toggle source
@override
Calls superclass method
ActiveRecord::Bogacs::DefaultPool::new
# File lib/active_record/bogacs/shareable_pool.rb, line 29 def initialize(spec) super(spec) shared_size = spec.config[:shared_pool] shared_size = shared_size ? shared_size.to_f : DEFAULT_SHARED_POOL # size 0.0 - 1.0 assumes percentage of the pool size shared_size = ( @size * shared_size ).round if shared_size <= 1.0 @shared_size = shared_size.to_i @shared_connections = ThreadSafe::Map.new # initial_capacity: @shared_size end
Public Instance Methods
active_connection?()
click to toggle source
@override
# File lib/active_record/bogacs/shareable_pool.rb, line 45 def active_connection? return true if current_thread[shared_connection_key] has_active_connection? # super end
clear_reloadable_connections!()
click to toggle source
@override
Calls superclass method
ActiveRecord::Bogacs::DefaultPool#clear_reloadable_connections!
# File lib/active_record/bogacs/shareable_pool.rb, line 74 def clear_reloadable_connections! synchronize { @shared_connections.clear; super } end
connection()
click to toggle source
@override
Calls superclass method
ActiveRecord::Bogacs::DefaultPool#connection
# File lib/active_record/bogacs/shareable_pool.rb, line 40 def connection current_thread[shared_connection_key] || super end
disconnect!()
click to toggle source
@override
Calls superclass method
ActiveRecord::Bogacs::DefaultPool#disconnect!
# File lib/active_record/bogacs/shareable_pool.rb, line 69 def disconnect! synchronize { @shared_connections.clear; super } end
release_connection(owner_thread = Thread.current)
click to toggle source
@override called from ConnectionManagement middle-ware (when finished)
# File lib/active_record/bogacs/shareable_pool.rb, line 51 def release_connection(owner_thread = Thread.current) conn_id = connection_cache_key(owner_thread) if reserved_conn = @thread_cached_conns.delete(conn_id) if shared_count = @shared_connections[reserved_conn] cheap_synchronize do # lock due #get_shared_connection ... not needed ?! # NOTE: the other option is to not care about shared here at all ... if shared_count.get == 0 # releasing a shared connection release_shared_connection(reserved_conn, owner_thread) #else return false end end else # check back-in non-shared connections checkin reserved_conn # (what super does) end end end
remove(conn)
click to toggle source
@override @note called from reap
thus the pool should work with reaper
Calls superclass method
ActiveRecord::Bogacs::DefaultPool#remove
# File lib/active_record/bogacs/shareable_pool.rb, line 80 def remove(conn) synchronize { @shared_connections.delete(conn); super } end
Private Instance Methods
acquire_connection_no_wait?()
click to toggle source
# File lib/active_record/bogacs/shareable_pool.rb, line 161 def acquire_connection_no_wait? synchronize do @connections.size < @size || @available.send(:can_remove_no_wait?) #return true if @connections.size < @size # @connections.size < @size || Queue#can_remove_no_wait? : #queue = @available.instance_variable_get(:@queue) #num_waiting = @available.instance_variable_get(:@num_waiting) #queue.size > num_waiting end end
debug(msg)
click to toggle source
# File lib/active_record/bogacs/shareable_pool.rb, line 274 def debug(msg); DEBUG.debug msg end
emulated_checkin(connection)
click to toggle source
# File lib/active_record/bogacs/shareable_pool.rb, line 233 def emulated_checkin(connection) # NOTE: not sure we'd like to run `run_callbacks :checkin {}` here ... connection.expire if connection.owner.equal? Thread.current end
emulated_checkout(connection)
click to toggle source
# File lib/active_record/bogacs/shareable_pool.rb, line 238 def emulated_checkout(connection) # NOTE: not sure we'd like to run `run_callbacks :checkout {}` here ... connection.lease unless connection.in_use? # connection.verify! auto-reconnect should do this end
has_active_connection?()
click to toggle source
# File lib/active_record/bogacs/shareable_pool.rb, line 157 def has_active_connection? # super.active_connection? @thread_cached_conns.fetch(connection_cache_key(current_thread), nil) end