Changeset 3096
- Timestamp:
- 11/19/05 10:55:11 (3 years ago)
- Files:
-
- trunk/activerecord/lib/active_record/base.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb (modified) (3 diffs)
- trunk/railties/lib/dispatcher.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/lib/active_record/base.rb
r3089 r3096 248 248 # to any of the specific Active Records. 249 249 def self.connection 250 if allow_concurrency 251 retrieve_connection 252 else 253 @connection ||= retrieve_connection 254 end 250 retrieve_connection 255 251 end 256 252 trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
r3053 r3096 20 20 # SchemaStatements#remove_column are very useful. 21 21 class AbstractAdapter 22 include Quoting, DatabaseStatements, SchemaStatements 22 include Quoting, DatabaseStatements, SchemaStatements, ConnectionManagement 23 23 @@row_even = true 24 25 @@reconnect_success = 026 @@reconnect_failure = 027 def self.reconnect_success_rate28 (100.0 * @@reconnect_success / (@@reconnect_success + @@reconnect_failure)).to_i29 end30 24 31 25 def initialize(connection, logger = nil) #:nodoc: … … 76 70 end 77 71 rescue Exception => e 72 # Flag connection as possibly dirty; needs verification before use. 73 self.needs_verification! 74 75 # Log message and raise exception. 78 76 message = "#{e.class.name}: #{e.message}: #{sql}" 79 unless reconnect_if_inactive!80 message = "(reconnect failed) #{message}"81 end82 77 log_info(message, name, 0) 83 78 raise ActiveRecord::StatementInvalid, message … … 112 107 end 113 108 end 114 115 private116 def reconnect_if_inactive!117 if respond_to?(:active?) and respond_to?(:reconnect!)118 reconnect! unless active?119 if active?120 @@reconnect_success += 1121 @logger.info "#{adapter_name} automatically reconnected. Success rate: #{self.class.reconnect_success_rate}%" if @logger122 true123 else124 @@reconnect_failure += 1125 @logger.warn "#{adapter_name} automatic reconnection failed. Success rate: #{self.class.reconnect_success_rate}%" if @logger126 false127 end128 else129 @logger.warn "#{adapter_name} does not yet support automatic reconnection." if @logger130 end131 end132 109 end 133 110 end trunk/activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb
r2825 r3096 1 1 module ActiveRecord 2 module ConnectionAdapters 3 module ConnectionManagement 4 # Check whether the connection should be checked for activity before use. 5 def needs_verification? 6 @needs_verification == true 7 end 8 9 # Flag the connection for an activity check before use. 10 def needs_verification! 11 @needs_verification = true 12 end 13 14 # If the connection is flagged for an activity check, check whether 15 # it is active and reconnect if not. 16 def verify! 17 if needs_verification? 18 reconnect! unless active? 19 @needs_verification = false 20 end 21 self 22 end 23 end 24 end 25 2 26 # The root class of all active record objects. 3 27 class Base … … 79 103 until klass == ar_super 80 104 if conn = active_connections[klass] 105 # Validate the active connection before returning it. 106 conn.verify! 81 107 return conn 82 108 elsif conn = @@defined_connections[klass] 109 # Activate this connection specification. 83 110 klass.connection = conn 84 111 return self.connection … … 126 153 end 127 154 end 155 156 # Mark active connections for verification on next retrieve_connection. 157 def self.mark_active_connections_for_verification! #:nodoc: 158 active_connections.values.each { |conn| conn.needs_verification! } 159 end 128 160 end 129 161 end trunk/railties/lib/dispatcher.rb
r2841 r3096 74 74 def reset_after_dispatch 75 75 reset_application! if Dependencies.load? 76 ActiveRecord::Base.mark_active_connections_for_verification! 76 77 Breakpoint.deactivate_drb if defined?(BREAKPOINT_SERVER_PORT) 77 78 end