From 32089cbcc9ca3fb935f783e7a7ef2b60b7d43006 Mon Sep 17 00:00:00 2001 From: Wes Oldenbeuving Date: Wed, 5 Nov 2008 18:27:23 +0100 Subject: Ensure ActiveRecord::ConnectionPool.connected? handles undefined connections. [#936 state:resolved] Signed-off-by: Pratik Naik --- .../lib/active_record/connection_adapters/abstract/connection_pool.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') 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 432c341e6c..3016c329bd 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -324,7 +324,7 @@ module ActiveRecord # Returns true if a connection that's accessible to this class has # already been opened. def connected?(klass) - retrieve_connection_pool(klass).connected? + conn = retrieve_connection_pool(klass) ? conn.connected? : false end # Remove the connection for this class. This will close the active -- cgit v1.2.3 From 0832bc63f4047d0ad0171c411460db23450213aa Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Thu, 6 Nov 2008 01:29:09 +0530 Subject: Make sure ActiveRecord::Base.connected? doesn't raise an exception for defined connections --- .../lib/active_record/connection_adapters/abstract/connection_pool.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') 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 3016c329bd..54a17e20a9 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -324,7 +324,8 @@ module ActiveRecord # Returns true if a connection that's accessible to this class has # already been opened. def connected?(klass) - conn = retrieve_connection_pool(klass) ? conn.connected? : false + conn = retrieve_connection_pool(klass) + conn ? conn.connected? : false end # Remove the connection for this class. This will close the active -- cgit v1.2.3 From 15c077492029dcba477aad2e29339803377cc1f8 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 7 Nov 2008 16:22:28 -0500 Subject: undef abstract methods instead of raising NotImplementedError. Still need the definitions for rdoc though. --- .../connection_adapters/abstract/database_statements.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') diff --git a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb index 97c6cd4331..189c6c7b5a 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb @@ -31,13 +31,13 @@ module ActiveRecord # Returns an array of arrays containing the field values. # Order is the same as that returned by +columns+. def select_rows(sql, name = nil) - raise NotImplementedError, "select_rows is an abstract method" end + undef_method :select_rows # Executes the SQL statement in the context of this connection. - def execute(sql, name = nil) - raise NotImplementedError, "execute is an abstract method" + def execute(sql, name = nil, skip_logging = false) end + undef_method :execute # Returns the last auto-generated ID from the affected table. def insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) @@ -163,8 +163,8 @@ module ActiveRecord # Returns an array of record hashes with the column names as keys and # column values as values. def select(sql, name = nil) - raise NotImplementedError, "select is an abstract method" end + undef_method :select # Returns the last auto-generated ID from the affected table. def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil) -- cgit v1.2.3 From 529c2716992490a6eab55486788ca0d35c17e60b Mon Sep 17 00:00:00 2001 From: Nick Sieger Date: Sat, 8 Nov 2008 03:49:25 +0530 Subject: Simplify dispatcher callbacks to eliminate unnecessary stale thread purging. [Nick Sieger, Pratik Naik] Signed-off-by: Pratik Naik --- .../active_record/connection_adapters/abstract/connection_pool.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') 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 54a17e20a9..cf760e334e 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -292,10 +292,7 @@ module ActiveRecord # and also returns connections to the pool cached by threads that are no # longer alive. def clear_active_connections! - @connection_pools.each_value do |pool| - pool.release_connection - pool.clear_stale_cached_connections! - end + @connection_pools.each_value {|pool| pool.release_connection } end # Clears the cache which maps classes -- cgit v1.2.3 From dd77733f2fdb6dde2be7115fc31ad1dcbfccb5a1 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 8 Nov 2008 00:24:36 -0500 Subject: Timeout the connection pool monitor on ruby 1.8 only --- .../connection_adapters/abstract/connection_pool.rb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract') 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 cf760e334e..901b17124c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb @@ -65,15 +65,23 @@ module ActiveRecord # The default ConnectionPool maximum size is 5. def initialize(spec) @spec = spec + # The cache of reserved connections mapped to threads @reserved_connections = {} + # The mutex used to synchronize pool access @connection_mutex = Monitor.new @queue = @connection_mutex.new_cond - # default 5 second timeout - @timeout = spec.config[:wait_timeout] || 5 + + # default 5 second timeout unless on ruby 1.9 + @timeout = + if RUBY_VERSION < '1.9' + spec.config[:wait_timeout] || 5 + end + # default max pool size to 5 @size = (spec.config[:pool] && spec.config[:pool].to_i) || 5 + @connections = [] @checked_out = [] end @@ -187,7 +195,7 @@ module ActiveRecord # try looting dead threads clear_stale_cached_connections! if @size == @checked_out.size - raise ConnectionTimeoutError, "could not obtain a database connection within #{@timeout} seconds. The pool size is currently #{@size}, perhaps you need to increase it?" + raise ConnectionTimeoutError, "could not obtain a database connection#{" within #{@timeout} seconds" if @timeout}. The max pool size is currently #{@size}; consider increasing it." end end end -- cgit v1.2.3