Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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