class ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter::ActiveRecordPoolControl

Attributes

in_use?[R]
owner[R]

Public Class Methods

new(proxy) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 190
def initialize(proxy)
  @proxy = proxy
  @owner = nil
  @pool = nil
  @schema_cache = ActiveRecord::ConnectionAdapters::SchemaCache.new @proxy
  @idle_since = Concurrent.monotonic_time
  @adapter = ActiveRecord::ConnectionAdapters::AbstractAdapter.new(@proxy)
end

Public Instance Methods

==(*args) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 283
def ==(*args)
  @proxy.object_id == args[0].object_id
end
close(*args) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 199
def close(*args)
  @pool.checkin @proxy
end
expire(*args) click to toggle source

this method must only be called while holding connection pool's mutex

# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 219
def expire(*args)
  if in_use?
    if @owner != Thread.current
      raise ActiveRecordError, "Cannot expire connection, " \
        "it is owned by a different thread: #{@owner}. " \
        "Current thread: #{Thread.current}."
    end

    @idle_since = Concurrent.monotonic_time
    @owner = nil
  else
    raise ActiveRecordError, "Cannot expire connection, it is not currently leased."
  end
end
lease(*args) click to toggle source

this method must only be called while holding connection pool's mutex

# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 204
def lease(*args)
  if in_use?
    msg = +"Cannot lease connection, "
    if @owner == Thread.current
      msg << "it is already leased by the current thread."
    else
      msg << "it is already in use by a different thread: #{@owner}. " \
            "Current thread: #{Thread.current}."
    end
    raise ActiveRecordError, msg
  end
  @owner = Thread.current
end
lock(*args) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 271
def lock(*args)
  @adapter.lock
end
pool(*args) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 279
def pool(*args)
  @pool
end
pool=(*args) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 275
def pool=(*args)
  @pool = args[0]
end
schema_cache(*args) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 253
def schema_cache(*args)
  if @pool.respond_to?(:get_schema_cache) # AR6
    @pool.get_schema_cache(@proxy)
  else
    @schema_cache
  end
end
schema_cache=(*args) click to toggle source
# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 261
def schema_cache=(*args)
  cache = args[0]
  cache.connection = @proxy
  if @pool.respond_to?(:set_schema_cache) # AR6
    @pool.set_schema_cache(cache)
  else
    @schema_cache = cache
  end
end
seconds_idle(*args) click to toggle source

Seconds since this connection was returned to the pool

# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 235
def seconds_idle(*args)
  return 0 if in_use?

  Concurrent.monotonic_time - @idle_since
end
steal!(*args) click to toggle source

this method must only be called while holding connection pool's mutex (and a desire for segfaults)

# File lib/active_record/connection_adapters/makara_abstract_adapter.rb, line 242
def steal!(*args)
  if in_use?
    if @owner != Thread.current
      @pool.send :remove_connection_from_thread_cache, @proxy, @owner
      @owner = Thread.current
    end
  else
    raise ActiveRecordError, "Cannot steal connection, it is not currently leased."
  end
end