Module: FiberedMysql2::FiberedMysql2Adapter_6

Included in:
FiberedMysql2Adapter
Defined in:
lib/active_record/connection_adapters/fibered_mysql2_adapter.rb

Instance Method Summary collapse

Instance Method Details

#expireObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_record/connection_adapters/fibered_mysql2_adapter.rb', line 24

def expire
  if (of = owner_fiber)
    # Because we are actively releasing connections from dead fibers, we only want
    # to enforce that we're expiring the current fiber's connection, iff the owner
    # of the connection is still alive.
    if of.alive? && of != Fiber.current
      raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection; " \
        "it is owned by a different Fiber: #{of}. " \
        "Current Fiber: #{Fiber.current}."
    end

    @idle_since = ::Concurrent.monotonic_time
    @owner = nil
  else
    raise ::ActiveRecord::ActiveRecordError, "Cannot expire connection; it is not currently leased."
  end
end

#leaseObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_record/connection_adapters/fibered_mysql2_adapter.rb', line 9

def lease
  if (of = owner_fiber)
    msg = +"Cannot lease connection; "
    if of == Fiber.current
      msg << "it is already leased by the current Fiber."
    else
      msg << "it is already in use by a different Fiber: #{of}. " \
              "Current Fiber: #{Fiber.current}."
    end
    raise ::ActiveRecord::ActiveRecordError, msg
  end

  @owner = Fiber.current
end

#steal!Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/active_record/connection_adapters/fibered_mysql2_adapter.rb', line 42

def steal!
  if (of = owner_fiber)
    if of != Fiber.current
      pool.send :remove_connection_from_thread_cache, self, of

      @owner = Fiber.current
    end
  else
    raise ::ActiveRecord::ActiveRecordError, "Cannot steal connection; it is not currently leased."
  end
end