Class: ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter::ActiveRecordPoolControl
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::MakaraAbstractAdapter::ActiveRecordPoolControl
- Defined in:
- lib/active_record/connection_adapters/makara_abstract_adapter.rb
Instance Attribute Summary collapse
-
#owner ⇒ Object
(also: #in_use?)
readonly
Returns the value of attribute owner.
Instance Method Summary collapse
- #==(*args) ⇒ Object
- #close(*args) ⇒ Object
-
#expire(*args) ⇒ Object
this method must only be called while holding connection pool’s mutex.
-
#initialize(proxy) ⇒ ActiveRecordPoolControl
constructor
A new instance of ActiveRecordPoolControl.
-
#lease(*args) ⇒ Object
this method must only be called while holding connection pool’s mutex.
- #lock(*args) ⇒ Object
- #pool(*args) ⇒ Object
- #pool=(*args) ⇒ Object
- #schema_cache(*args) ⇒ Object
- #schema_cache=(*args) ⇒ Object
-
#seconds_idle(*args) ⇒ Object
Seconds since this connection was returned to the pool.
-
#steal!(*args) ⇒ Object
this method must only be called while holding connection pool’s mutex (and a desire for segfaults).
Constructor Details
#initialize(proxy) ⇒ ActiveRecordPoolControl
Returns a new instance of ActiveRecordPoolControl.
218 219 220 221 222 223 224 225 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 218 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 |
Instance Attribute Details
#owner ⇒ Object (readonly) Also known as: in_use?
Returns the value of attribute owner.
215 216 217 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 215 def owner @owner end |
Instance Method Details
#==(*args) ⇒ Object
311 312 313 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 311 def ==(*args) @proxy.object_id == args[0].object_id end |
#close(*args) ⇒ Object
227 228 229 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 227 def close(*args) @pool.checkin @proxy end |
#expire(*args) ⇒ Object
this method must only be called while holding connection pool’s mutex
247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 247 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) ⇒ Object
this method must only be called while holding connection pool’s mutex
232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 232 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) ⇒ Object
299 300 301 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 299 def lock(*args) @adapter.lock end |
#pool(*args) ⇒ Object
307 308 309 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 307 def pool(*args) @pool end |
#pool=(*args) ⇒ Object
303 304 305 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 303 def pool=(*args) @pool = args[0] end |
#schema_cache(*args) ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 281 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) ⇒ Object
289 290 291 292 293 294 295 296 297 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 289 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) ⇒ Object
Seconds since this connection was returned to the pool
263 264 265 266 267 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 263 def seconds_idle(*args) return 0 if in_use? Concurrent.monotonic_time - @idle_since end |
#steal!(*args) ⇒ Object
this method must only be called while holding connection pool’s mutex (and a desire for segfaults)
270 271 272 273 274 275 276 277 278 279 |
# File 'lib/active_record/connection_adapters/makara_abstract_adapter.rb', line 270 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 |