Created
September 4, 2008 12:33
-
-
Save nicksieger/8765 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 662a9ed4286e1cf3118ad333955e16ab761cd350 Mon Sep 17 00:00:00 2001 | |
From: Nick Sieger <[email protected]> | |
Date: Thu, 4 Sep 2008 14:03:19 +0200 | |
Subject: [PATCH] Deprecate verification_timeout and verify before reset | |
--- | |
.../abstract/connection_pool.rb | 6 ++---- | |
.../abstract/connection_specification.rb | 15 ++++++++++----- | |
.../connection_adapters/abstract_adapter.rb | 12 ++++-------- | |
activerecord/test/cases/base_test.rb | 2 +- | |
activerecord/test/cases/connection_test_mysql.rb | 2 +- | |
5 files changed, 18 insertions(+), 19 deletions(-) | |
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | |
index 838b043..6b4bc25 100644 | |
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | |
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb | |
@@ -35,7 +35,6 @@ module ActiveRecord | |
# * +wait_timeout+: number of seconds to block and wait for a connection | |
# before giving up and raising a timeout error (default 5 seconds). | |
class ConnectionPool | |
- delegate :verification_timeout, :to => "::ActiveRecord::Base" | |
attr_reader :spec | |
def initialize(spec) | |
@@ -60,7 +59,6 @@ module ActiveRecord | |
# held in a hash keyed by the thread id. | |
def connection | |
if conn = @reserved_connections[current_connection_id] | |
- conn.verify!(verification_timeout) | |
conn | |
else | |
@reserved_connections[current_connection_id] = checkout | |
@@ -118,7 +116,7 @@ module ActiveRecord | |
def verify_active_connections! #:nodoc: | |
clear_stale_cached_connections! | |
@connections.each do |connection| | |
- connection.verify!(verification_timeout) | |
+ connection.verify! | |
end | |
end | |
@@ -200,8 +198,8 @@ module ActiveRecord | |
end | |
def checkout_and_verify(c) | |
+ c.verify! | |
c.run_callbacks :checkout | |
- c.verify!(verification_timeout) | |
@checked_out << c | |
c | |
end | |
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb | |
index 417a333..a968fc0 100644 | |
--- a/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb | |
+++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb | |
@@ -7,11 +7,6 @@ module ActiveRecord | |
end | |
end | |
- # Check for activity after at least +verification_timeout+ seconds. | |
- # Defaults to 0 (always check.) | |
- cattr_accessor :verification_timeout, :instance_writer => false | |
- @@verification_timeout = 0 | |
- | |
# The connection handler | |
cattr_accessor :connection_handler, :instance_writer => false | |
@@connection_handler = ConnectionAdapters::ConnectionHandler.new | |
@@ -101,6 +96,16 @@ module ActiveRecord | |
ActiveSupport::Deprecation.warn("ActiveRecord::Base.allow_concurrency= has been deprecated and no longer has any effect. Please remove all references to allow_concurrency=.") | |
end | |
+ # Deprecated and no longer has any effect. | |
+ def verification_timeout | |
+ ActiveSupport::Deprecation.warn("ActiveRecord::Base.verification_timeout has been deprecated and no longer has any effect. Please remove all references to verification_timeout.") | |
+ end | |
+ | |
+ # Deprecated and no longer has any effect. | |
+ def verification_timeout=(flag) | |
+ ActiveSupport::Deprecation.warn("ActiveRecord::Base.verification_timeout= has been deprecated and no longer has any effect. Please remove all references to verification_timeout=.") | |
+ end | |
+ | |
# Returns the connection currently associated with the class. This can | |
# also be used to "borrow" the connection to do database work unrelated | |
# to any of the specific Active Records. | |
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | |
index 005be9d..ad6e217 100755 | |
--- a/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | |
+++ b/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb | |
@@ -123,14 +123,10 @@ module ActiveRecord | |
false | |
end | |
- # Lazily verify this connection, calling <tt>active?</tt> only if it | |
- # hasn't been called for +timeout+ seconds. | |
- def verify!(timeout) | |
- now = Time.now.to_i | |
- if (now - @last_verification) > timeout | |
- reconnect! unless active? | |
- @last_verification = now | |
- end | |
+ # Verify this connection by calling <tt>active?</tt> and reconnecting if | |
+ # the connection is no longer active. | |
+ def verify!(*ignored) | |
+ reconnect! unless active? | |
end | |
# Provides access to the underlying database connection. Useful for | |
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb | |
index ac9081e..67358fe 100644 | |
--- a/activerecord/test/cases/base_test.rb | |
+++ b/activerecord/test/cases/base_test.rb | |
@@ -880,7 +880,7 @@ class BasicsTest < ActiveRecord::TestCase | |
def test_mass_assignment_protection_against_class_attribute_writers | |
[:logger, :configurations, :primary_key_prefix_type, :table_name_prefix, :table_name_suffix, :pluralize_table_names, :colorize_logging, | |
- :default_timezone, :schema_format, :verification_timeout, :lock_optimistically, :record_timestamps].each do |method| | |
+ :default_timezone, :schema_format, :lock_optimistically, :record_timestamps].each do |method| | |
assert Task.respond_to?(method) | |
assert Task.respond_to?("#{method}=") | |
assert Task.new.respond_to?(method) | |
diff --git a/activerecord/test/cases/connection_test_mysql.rb b/activerecord/test/cases/connection_test_mysql.rb | |
index 1adbf18..40ddcf5 100644 | |
--- a/activerecord/test/cases/connection_test_mysql.rb | |
+++ b/activerecord/test/cases/connection_test_mysql.rb | |
@@ -24,7 +24,7 @@ class MysqlConnectionTest < ActiveRecord::TestCase | |
assert @connection.active? | |
@connection.update('set @@wait_timeout=1') | |
sleep 2 | |
- @connection.verify!(0) | |
+ @connection.verify! | |
assert @connection.active? | |
end | |
end | |
-- | |
1.5.6 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment