1. 13 7月, 2016 1 次提交
    • J
      Create connection.active_record notification and use that to ensure that lazy- · 31a8588a
      Jeremy Wadsack 提交于
      loaded model classes have their connections wrapped in transactions.
      
      See #17776
      
      In Rails 4 config.eager_load was changed to false in the test environment. This
      means that model classes that connect to alternate databases with
      establish_connection are not loaded at start up. If use_transactional_fixtures
      is enabled, transactions are wrapped around the connections that have been
      established only at the start of the test suite. So model classes loaded later
      don't have transactions causing data created in the alternate database not to
      be removed.
      
      This change resolves that by creating a new connection.active_record
      notification that gets fired whenever a connection is established. I then added
      a subscriber after we set up transactions in the test environment to listen for
      additional connections and wrap those in transactions as well.
      31a8588a
  2. 06 7月, 2016 1 次提交
  3. 06 5月, 2016 2 次提交
    • A
      fix test · 98729053
      Arthur Neves 提交于
      98729053
    • A
      Refactor connection handler · b83fb847
      Arthur Neves 提交于
      ConnectionHandler will not have any knowlodge of AR models now, it will
      only know about the specs.
      Like that we can decouple the two, and allow the same model to use more
      than one connection.
      
      Historically, folks used to create abstract AR classes on the fly in
      order to have multiple connections for the same model, and override the
      connection methods.
      
      With this, now we can override the `specificiation_id` method in the
      model, to return a key, that will be used to find the connection_pool
      from the handler.
      b83fb847
  4. 05 11月, 2015 1 次提交
  5. 14 7月, 2015 1 次提交
    • J
      Replaced `ActiveSupport::Concurrency::Latch` with concurrent-ruby. · 284a9ba8
      Jerry D'Antonio 提交于
      The concurrent-ruby gem is a toolset containing many concurrency
      utilities. Many of these utilities include runtime-specific
      optimizations when possible. Rather than clutter the Rails codebase with
      concurrency utilities separate from the core task, such tools can be
      superseded by similar tools in the more specialized gem. This commit
      replaces `ActiveSupport::Concurrency::Latch` with
      `Concurrent::CountDownLatch`, which is functionally equivalent.
      284a9ba8
  6. 18 5月, 2015 1 次提交
  7. 14 5月, 2015 2 次提交
    • T
      AR::ConPool - remove synchronization around connection cache. · 603fe20c
      thedarkone 提交于
      Renamed `@reserved_connections` -> `@thread_cached_conns`. New name
      clearly conveys the purpose of the cache, which is to speed-up
      `#connection` method.
      
      The new `@thread_cached_conns` now also uses `Thread` objects as keys
      (instead of previously `Thread.current.object_id`).
      
      Since there is no longer any synchronization around
      `@thread_cached_conns`, `disconnect!` and `clear_reloadable_connections!`
      methods now pre-emptively obtain ownership (via `checkout`) of all
      existing connections, before modifying internal data structures.
      
      A private method `release` has been renamed `thread_conn_uncache` to
      clear-up its purpose.
      
      Fixed some brittle `thread.status == "sleep"` tests (threads can go
      into sleep even without locks).
      603fe20c
    • T
      e92f5a99
  8. 29 4月, 2015 1 次提交
    • E
      Apply schema cache dump when creating connections · 33fe7cc8
      Eugene Kenny 提交于
      The `db:schema:cache:dump` rake task dumps the database schema structure
      to `db/schema_cache.dump`. If this file is present, the schema details
      are loaded into the currently checked out connection by a railtie while
      Rails is booting, to avoid having to query the database for its schema.
      
      The schema cache dump is only applied to the initial connection used to
      boot the application though; other connections from the same pool are
      created with an empty schema cache, and still have to load the structure
      of each table directly from the database.
      
      With this change, a copy of the schema cache is associated with the
      connection pool and applied to connections as they are created.
      33fe7cc8
  9. 15 4月, 2015 1 次提交
    • J
      Fix typos and improve the documentation · 6345f31f
      Jon Atack 提交于
      This is a squash of the following commits, from first to last:
      
      -
      
      Fix minor, random things I’ve come across lately that individually
      did not seem worth making a PR for, so I saved them for one commit.
      
      One common error is using “it’s” (which is an abbreviation of “it is”)
      when the possessive “its” should be used for indicating possession.
      
      -
      
      Changes include the name of a test, so remove the `[skip ci]` (thanks @senny).
      
      -
      
      Line wrap the changes at 80 chars and add one more doc fix.
      
      -
      
      Add a missing line wrap in the Contributing to Ruby on Rails Guide.
      
      -
      
      Line wrap the `TIP` section in the Contributing to Ruby on Rails Guide as well.
      
      Rendering the guide locally with `bundle exec rake guides:generate` did
      not show any change in on-screen formatting after adding the line wrap.
      
      The HTML generated is (extra line added to illustrate where the line
      wrap takes place):
      
          <div class="info"><p>Please squash your commits into a single commit
      when appropriate. This
      
          simplifies future cherry picks and also keeps the git log
      clean.</p></div>
      
      -
      
      Squash commits.
      6345f31f
  10. 18 3月, 2014 3 次提交
    • A
      test should only pass if the pool.size+1 checkout fails · 34e54fa0
      Aaron Patterson 提交于
      Previously, any of the connection checkouts could have failed, and this
      test would pass.
      34e54fa0
    • A
      use a latch to avoid busy loops · 4db4f909
      Aaron Patterson 提交于
      4db4f909
    • M
      Reap connections based on owning-thread death · 9e457a86
      Matthew Draper 提交于
      .. not a general timeout.
      
      Now, if a thread checks out a connection then dies, we can immediately
      recover that connection and re-use it.
      
      This should alleviate the pool exhaustion discussed in #12867. More
      importantly, it entirely avoids the potential issues of the reaper
      attempting to check whether connections are still active: as long as the
      owning thread is alive, the connection is its business alone.
      
      As a no-op reap is now trivial (only entails checking a thread status
      per connection), we can also perform one in-line any time we decide to
      sleep for a connection.
      9e457a86
  11. 15 3月, 2014 1 次提交
  12. 09 2月, 2014 1 次提交
  13. 09 7月, 2013 1 次提交
  14. 15 6月, 2013 1 次提交
  15. 14 3月, 2013 1 次提交
  16. 22 1月, 2013 1 次提交
  17. 20 1月, 2013 1 次提交
  18. 11 9月, 2012 1 次提交
    • J
      ConnectionPool, unify exceptions, ConnectionTimeoutError · 5b7cfc5e
      Jonathan Rochkind 提交于
      As a result of different commits, ConnectionPool had become
      of two minds about exceptions, sometimes using PoolFullError
      and sometimes using ConnectionTimeoutError. In fact, it was
      using ConnectionTimeoutError internally, but then recueing
      and re-raising as a PoolFullError.
      
      There's no reason for this bifurcation, standardize on
      ConnectionTimeoutError, which is the rails2 name and still
      accurately describes semantics at this point.
      
      History
      
      In Rails2, ConnectionPool raises a ConnectionTimeoutError if
      it can't get a connection within timeout.
      
      Originally in master/rails3, @tenderlove had planned on removing
      wait/blocking in connectionpool entirely, at that point he changed
      exception to PoolFullError.
      
      But then later wait/blocking came back, but exception remained
      PoolFullError.
      
      Then in 02b23355 pmahoney introduced fair waiting logic, and
      brought back ConnectionTimeoutError, introducing the weird bifurcation.
      
      ConnectionTimeoutError accurately describes semantics as of this
      point, and is backwards compat with rails2, there's no reason
      for PoolFullError to be introduced, and no reason for two
      different exception types to be used internally, no reason
      to rescue one and re-raise as another.  Unify!
      5b7cfc5e
  19. 12 6月, 2012 1 次提交
  20. 26 5月, 2012 1 次提交
    • P
      Make connection pool fair with respect to waiting threads. · 02b23355
      Patrick Mahoney 提交于
      The core of this fix is a threadsafe, fair Queue class.  It is
      very similar to Queue in stdlib except that it supports waiting
      with a timeout.
      
      The issue this solves is that if several threads are contending for
      database connections, an unfair queue makes is possible that a thread
      will timeout even while other threads successfully acquire and release
      connections.  A fair queue means the thread that has been waiting the
      longest will get the next available connection.
      
      This includes a few test fixes to avoid test ordering issues that
      cropped up during development of this patch.
      02b23355
  21. 24 5月, 2012 1 次提交
    • J
      ConnectionPool wait_timeout no longer used for different types of timeouts. #6441 · cb6f8393
      Jonathan Rochkind 提交于
      An AR ConnectionSpec `wait_timeout` is pre-patch used for three
      different things:
      
      * mysql2 uses it for MySQL's own wait_timeout (how long MySQL
        should allow an idle connection before closing it), and
        defaults to 2592000 seconds.
      * ConnectionPool uses it for "number of seconds to block and
        wait for a connection before giving up and raising a timeout error",
        default 5 seconds.
      * ConnectionPool uses it for the Reaper, for deciding if a 'dead'
        connection can be reaped. Default 5 seconds.
      
      Previously, if you want to change these from defaults, you need
      to change them all together. This is problematic _especially_
      for the mysql2/ConnectionPool conflict, you will generally _not_
      want them to be the same, as evidenced by their wildly different
      defaults. This has caused real problems for people #6441 #2894
      
      But as long as we're changing this, forcing renaming the
      ConnectionPool key to be more specific, it made sense
      to seperate the two ConnectionPool uses too -- these two
      types of ConnectionPool timeouts ought to be able to be
      changed independently, you won't neccesarily want them
      to be the same, even though the defaults are (currently)
      the same.
      cb6f8393
  22. 23 5月, 2012 1 次提交
  23. 22 5月, 2012 1 次提交
  24. 21 5月, 2012 1 次提交
  25. 16 4月, 2012 1 次提交
  26. 13 3月, 2012 1 次提交
  27. 09 3月, 2012 2 次提交
  28. 04 1月, 2012 1 次提交
  29. 31 12月, 2011 6 次提交
  30. 30 11月, 2011 1 次提交
    • A
      Automatic closure of connections in threads is deprecated. For example · 0e2477b6
      Aaron Patterson 提交于
      the following code is deprecated:
      
      Thread.new { Post.find(1) }.join
      
      It should be changed to close the database connection at the end of
      the thread:
      
      Thread.new {
        Post.find(1)
        Post.connection.close
      }.join
      
      Only people who spawn threads in their application code need to worry
      about this change.
      0e2477b6