Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 378 lines (337 sloc) 13.598 kb
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
1 require 'monitor'
50cd4bd @nicksieger Introduce synchronization around connection pool access
nicksieger authored
2 require 'set'
e8550ee @jeremy Cherry-pick core extensions
jeremy authored
3 require 'active_support/core_ext/module/synchronization'
50cd4bd @nicksieger Introduce synchronization around connection pool access
nicksieger authored
4
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
5 module ActiveRecord
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
6 # Raised when a connection could not be obtained within the connection
7 # acquisition timeout period.
8 class ConnectionTimeoutError < ConnectionNotEstablished
9 end
10
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
11 module ConnectionAdapters
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
12 # Connection pool base class for managing Active Record database
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
13 # connections.
14 #
a293278 @lifo Merge docrails
lifo authored
15 # == Introduction
16 #
17 # A connection pool synchronizes thread access to a limited number of
18 # database connections. The basic idea is that each thread checks out a
19 # database connection from the pool, uses that connection, and checks the
20 # connection back in. ConnectionPool is completely thread-safe, and will
21 # ensure that a connection cannot be used by two threads at the same time,
22 # as long as ConnectionPool's contract is correctly followed. It will also
23 # handle cases in which there are more threads than connections: if all
24 # connections have been checked out, and a thread tries to checkout a
25 # connection anyway, then ConnectionPool will wait until some other thread
26 # has checked in a connection.
27 #
28 # == Obtaining (checking out) a connection
29 #
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
30 # Connections can be obtained and used from a connection pool in several
31 # ways:
32 #
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
33 # 1. Simply use ActiveRecord::Base.connection as with Active Record 2.1 and
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
34 # earlier (pre-connection-pooling). Eventually, when you're done with
35 # the connection(s) and wish it to be returned to the pool, you call
36 # ActiveRecord::Base.clear_active_connections!. This will be the
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
37 # default behavior for Active Record when used in conjunction with
38 # Action Pack's request handling cycle.
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
39 # 2. Manually check out a connection from the pool with
40 # ActiveRecord::Base.connection_pool.checkout. You are responsible for
41 # returning this connection to the pool when finished by calling
42 # ActiveRecord::Base.connection_pool.checkin(connection).
43 # 3. Use ActiveRecord::Base.connection_pool.with_connection(&block), which
44 # obtains a connection, yields it as the sole argument to the block,
45 # and returns it to the pool after the block completes.
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
46 #
a293278 @lifo Merge docrails
lifo authored
47 # Connections in the pool are actually AbstractAdapter objects (or objects
48 # compatible with AbstractAdapter's interface).
49 #
50 # == Options
51 #
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
52 # There are two connection-pooling-related options that you can add to
53 # your database connection configuration:
54 #
55 # * +pool+: number indicating size of connection pool (default 5)
56 # * +wait_timeout+: number of seconds to block and wait for a connection
57 # before giving up and raising a timeout error (default 5 seconds).
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
58 class ConnectionPool
cccb998 @josevalim Expose connections available in the connection pool.
josevalim authored
59 attr_reader :spec, :connections
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
60
a293278 @lifo Merge docrails
lifo authored
61 # Creates a new ConnectionPool object. +spec+ is a ConnectionSpecification
62 # object which describes database connection information (e.g. adapter,
63 # host name, username, password, etc), as well as the maximum size for
64 # this ConnectionPool.
65 #
66 # The default ConnectionPool maximum size is 5.
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
67 def initialize(spec)
68 @spec = spec
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
69
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
70 # The cache of reserved connections mapped to threads
71 @reserved_connections = {}
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
72
cab76ce @nicksieger Add synchronization to connection pool also
nicksieger authored
73 # The mutex used to synchronize pool access
74 @connection_mutex = Monitor.new
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
75 @queue = @connection_mutex.new_cond
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
76
77 # default 5 second timeout unless on ruby 1.9
78 @timeout =
79 if RUBY_VERSION < '1.9'
80 spec.config[:wait_timeout] || 5
81 end
82
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
83 # default max pool size to 5
84 @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
85
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
86 @connections = []
87 @checked_out = []
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
88 end
89
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
90 # Retrieve the connection associated with the current thread, or call
91 # #checkout to obtain one if necessary.
92 #
93 # #connection can be called any number of times; the connection is
94 # held in a hash keyed by the thread id.
95 def connection
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
96 if conn = @reserved_connections[current_connection_id]
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
97 conn
98 else
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
99 @reserved_connections[current_connection_id] = checkout
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
100 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
101 end
102
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
103 # Signal that the thread is finished with the current connection.
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
104 # #release_connection releases the connection-thread association
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
105 # and returns the connection to the pool.
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
106 def release_connection
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
107 conn = @reserved_connections.delete(current_connection_id)
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
108 checkin conn if conn
109 end
110
5501b99 @coderrr Ensure ActiveRecord::Base.connection_pool.with_connection creates a n…
coderrr authored
111 # If a connection already exists yield it to the block. If no connection
112 # exists checkout a connection, yield it to the block, and checkin the
113 # connection when finished.
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
114 def with_connection
5501b99 @coderrr Ensure ActiveRecord::Base.connection_pool.with_connection creates a n…
coderrr authored
115 fresh_connection = true unless @reserved_connections[current_connection_id]
116 yield connection
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
117 ensure
5501b99 @coderrr Ensure ActiveRecord::Base.connection_pool.with_connection creates a n…
coderrr authored
118 release_connection if fresh_connection
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
119 end
120
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
121 # Returns true if a connection has already been opened.
122 def connected?
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
123 !@connections.empty?
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
124 end
125
a293278 @lifo Merge docrails
lifo authored
126 # Disconnects all connections in the pool, and clears the pool.
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
127 def disconnect!
128 @reserved_connections.each do |name,conn|
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
129 checkin conn
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
130 end
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
131 @reserved_connections = {}
132 @connections.each do |conn|
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
133 conn.disconnect!
134 end
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
135 @connections = []
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
136 end
137
50cd4bd @nicksieger Introduce synchronization around connection pool access
nicksieger authored
138 # Clears the cache which maps classes
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
139 def clear_reloadable_connections!
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
140 @reserved_connections.each do |name, conn|
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
141 checkin conn
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
142 end
143 @reserved_connections = {}
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
144 @connections.each do |conn|
145 conn.disconnect! if conn.requires_reloading?
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
146 end
62c4e4d @ebeigarts Fix connection reloading in development mode. [#4929 state:resolved]
ebeigarts authored
147 @connections.delete_if do |conn|
148 conn.requires_reloading?
149 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
150 end
151
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
152 # Verify active connections and remove and disconnect connections
153 # associated with stale threads.
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
154 def verify_active_connections! #:nodoc:
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
155 clear_stale_cached_connections!
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
156 @connections.each do |connection|
7ba2872 @nicksieger Deprecate verification_timeout and verify before reset
nicksieger authored
157 connection.verify!
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
158 end
159 end
160
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
161 # Return any checked-out connections back to the pool by threads that
162 # are no longer alive.
163 def clear_stale_cached_connections!
164 remove_stale_cached_threads!(@reserved_connections) do |name, conn|
165 checkin conn
166 end
167 end
168
a293278 @lifo Merge docrails
lifo authored
169 # Check-out a database connection from the pool, indicating that you want
170 # to use it. You should call #checkin when you no longer need this.
171 #
172 # This is done by either returning an existing connection, or by creating
173 # a new connection. If the maximum number of connections for this pool has
174 # already been reached, but the pool is empty (i.e. they're all being used),
175 # then this method will wait until a thread has checked in a connection.
176 # The wait time is bounded however: if no connection can be checked out
177 # within the timeout specified for this pool, then a ConnectionTimeoutError
178 # exception will be raised.
179 #
180 # Returns: an AbstractAdapter object.
181 #
182 # Raises:
183 # - ConnectionTimeoutError: no connection can be obtained from the pool
184 # within the timeout period.
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
185 def checkout
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
186 # Checkout an available connection
187 @connection_mutex.synchronize do
21eb18a @alk Fix race in ConnectionPool#checkout
alk authored
188 loop do
189 conn = if @checked_out.size < @connections.size
190 checkout_existing_connection
191 elsif @connections.size < @size
192 checkout_new_connection
193 end
194 return conn if conn
195 # No connections available; wait for one
196 if @queue.wait(@timeout)
197 next
198 else
8343611 @alk made ConnectionPool#checkout more robust by trying to loot dead threa…
alk authored
199 # try looting dead threads
200 clear_stale_cached_connections!
201 if @size == @checked_out.size
dd77733 @jeremy Timeout the connection pool monitor on ruby 1.8 only
jeremy authored
202 raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it."
8343611 @alk made ConnectionPool#checkout more robust by trying to loot dead threa…
alk authored
203 end
21eb18a @alk Fix race in ConnectionPool#checkout
alk authored
204 end
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
205 end
206 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
207 end
208
a293278 @lifo Merge docrails
lifo authored
209 # Check-in a database connection back into the pool, indicating that you
210 # no longer need this connection.
211 #
212 # +conn+: an AbstractAdapter object, which was obtained by earlier by
213 # calling +checkout+ on this pool.
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
214 def checkin(conn)
215 @connection_mutex.synchronize do
a260e02 @wycats Whoops. _run_*_callbacks is private
wycats authored
216 conn.send(:_run_checkin_callbacks) do
471a394 @nicksieger Modify connection pool callbacks to be compatible w/ new style
nicksieger authored
217 @checked_out.delete conn
218 @queue.signal
219 end
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
220 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
221 end
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
222
113cc4e @nicksieger Remove some synchronization that's probably overkill, assuming one do…
nicksieger authored
223 synchronize :clear_reloadable_connections!, :verify_active_connections!,
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
224 :connected?, :disconnect!, :with => :@connection_mutex
225
226 private
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
227 def new_connection
a3f12f5 @nicksieger Default connection allow_concurrency to false (for PostgreSQL)
nicksieger authored
228 ActiveRecord::Base.send(spec.adapter_method, spec.config)
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
229 end
230
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
231 def current_connection_id #:nodoc:
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
232 Thread.current.object_id
233 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
234
029952e @nicksieger Extract a base class for connection pools, start to flesh out reserve…
nicksieger authored
235 # Remove stale threads from the cache.
236 def remove_stale_cached_threads!(cache, &block)
237 keys = Set.new(cache.keys)
238
239 Thread.list.each do |thread|
240 keys.delete(thread.object_id) if thread.alive?
241 end
242 keys.each do |key|
243 next unless cache.has_key?(key)
244 block.call(key, cache[key])
245 cache.delete(key)
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
246 end
247 end
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
248
249 def checkout_new_connection
250 c = new_connection
251 @connections << c
a96b7d4 @nicksieger Add connection reset and verification upon each connection checkout
nicksieger authored
252 checkout_and_verify(c)
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
253 end
254
255 def checkout_existing_connection
d7d2d73 @nicksieger Fix typo: was using brackets instead of parens. Must need more sleep.
nicksieger authored
256 c = (@connections - @checked_out).first
a96b7d4 @nicksieger Add connection reset and verification upon each connection checkout
nicksieger authored
257 checkout_and_verify(c)
258 end
259
260 def checkout_and_verify(c)
471a394 @nicksieger Modify connection pool callbacks to be compatible w/ new style
nicksieger authored
261 c.run_callbacks :checkout do
262 c.verify!
263 @checked_out << c
264 end
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
265 c
266 end
267 end
268
a293278 @lifo Merge docrails
lifo authored
269 # ConnectionHandler is a collection of ConnectionPool objects. It is used
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
270 # for keeping separate connection pools for Active Record models that connect
a293278 @lifo Merge docrails
lifo authored
271 # to different databases.
272 #
273 # For example, suppose that you have 5 models, with the following hierarchy:
274 #
275 # |
276 # +-- Book
277 # | |
278 # | +-- ScaryBook
279 # | +-- GoodBook
280 # +-- Author
281 # +-- BankAccount
282 #
283 # Suppose that Book is to connect to a separate database (i.e. one other
284 # than the default database). Then Book, ScaryBook and GoodBook will all use
285 # the same connection pool. Likewise, Author and BankAccount will use the
286 # same connection pool. However, the connection pool used by Author/BankAccount
287 # is not the same as the one used by Book/ScaryBook/GoodBook.
288 #
289 # Normally there is only a single ConnectionHandler instance, accessible via
f17159b @fxn edit pass: the names of Rails components have a space, ie, "Active Re…
fxn authored
290 # ActiveRecord::Base.connection_handler. Active Record models use this to
a293278 @lifo Merge docrails
lifo authored
291 # determine that connection pool that they should use.
ca6d717 @nicksieger Deprecate allow_concurrency and make it have no effect
nicksieger authored
292 class ConnectionHandler
b952470 @tenderlove use an attr_reader for performance
tenderlove authored
293 attr_reader :connection_pools
294
72d959d @nicksieger Split connection handler into single- and multiple-thread versions.
nicksieger authored
295 def initialize(pools = {})
296 @connection_pools = pools
297 end
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
298
299 def establish_connection(name, spec)
8e5e02b @nicksieger Collapse connection pool class hierarchy; YAGNI.
nicksieger authored
300 @connection_pools[name] = ConnectionAdapters::ConnectionPool.new(spec)
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
301 end
302
d07a6b1 @nicksieger Make clear_active_connections! also return stale connections back to …
nicksieger authored
303 # Returns any connections in use by the current thread back to the pool,
304 # and also returns connections to the pool cached by threads that are no
305 # longer alive.
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
306 def clear_active_connections!
529c271 @nicksieger Simplify dispatcher callbacks to eliminate unnecessary stale thread p…
nicksieger authored
307 @connection_pools.each_value {|pool| pool.release_connection }
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
308 end
309
310 # Clears the cache which maps classes
311 def clear_reloadable_connections!
312 @connection_pools.each_value {|pool| pool.clear_reloadable_connections! }
313 end
314
315 def clear_all_connections!
72d959d @nicksieger Split connection handler into single- and multiple-thread versions.
nicksieger authored
316 @connection_pools.each_value {|pool| pool.disconnect! }
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
317 end
318
319 # Verify active connections.
320 def verify_active_connections! #:nodoc:
817a07b @nicksieger More doco and class/method renames. Now have a strategy for integrati…
nicksieger authored
321 @connection_pools.each_value {|pool| pool.verify_active_connections! }
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
322 end
323
324 # Locate the connection of the nearest super class. This can be an
325 # active or defined connection: if it is the latter, it will be
326 # opened and set as the active connection for the class it was defined
327 # for (not necessarily the current class).
328 def retrieve_connection(klass) #:nodoc:
329 pool = retrieve_connection_pool(klass)
330 (pool && pool.connection) or raise ConnectionNotEstablished
331 end
332
82fcd9d @nicksieger Clean up the code, get rid of reserve/release, add some more docs
nicksieger authored
333 # Returns true if a connection that's accessible to this class has
334 # already been opened.
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
335 def connected?(klass)
0832bc6 @lifo Make sure ActiveRecord::Base.connected? doesn't raise an exception fo…
lifo authored
336 conn = retrieve_connection_pool(klass)
337 conn ? conn.connected? : false
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
338 end
339
340 # Remove the connection for this class. This will close the active
341 # connection and the defined connection (if they exist). The result
342 # can be used as an argument for establish_connection, for easily
343 # re-establishing the connection.
344 def remove_connection(klass)
345 pool = @connection_pools[klass.name]
04ef434 @tenderlove only test for existence of +pool+ once
tenderlove authored
346 return nil unless pool
347
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
348 @connection_pools.delete_if { |key, value| value == pool }
04ef434 @tenderlove only test for existence of +pool+ once
tenderlove authored
349 pool.disconnect!
350 pool.spec.config
ff97e9d @nicksieger Connection handling methods extracted out into separate ConnectionHan…
nicksieger authored
351 end
352
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
353 def retrieve_connection_pool(klass)
3007545 @nicksieger Minor tweak to retrieve_connection_pool -- recurse instead of loop
nicksieger authored
354 pool = @connection_pools[klass.name]
355 return pool if pool
356 return nil if ActiveRecord::Base == klass
357 retrieve_connection_pool klass.superclass
fe575dd @nicksieger Nearing the finish line. Initial fixed-size connection pool implement…
nicksieger authored
358 end
72d959d @nicksieger Split connection handler into single- and multiple-thread versions.
nicksieger authored
359 end
1b22071 @josh Ensure ActiveRecord session store's connections are checked in after …
josh authored
360
361 class ConnectionManagement
362 def initialize(app)
363 @app = app
364 end
365
366 def call(env)
367 @app.call(env)
368 ensure
e033b5d @lifo Merge docrails
lifo authored
369 # Don't return connection (and perform implicit rollback) if
1b22071 @josh Ensure ActiveRecord session store's connections are checked in after …
josh authored
370 # this request is a part of integration test
371 unless env.key?("rack.test")
372 ActiveRecord::Base.clear_active_connections!
373 end
374 end
375 end
6edaa26 @nicksieger Initial conversion to connection pool
nicksieger authored
376 end
21eb18a @alk Fix race in ConnectionPool#checkout
alk authored
377 end
Something went wrong with that request. Please try again.