Changeset 3001
- Timestamp:
- 11/13/05 10:03:03 (3 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r3000 r3001 1 1 *SVN* 2 2 3 * When AbstractAdapter#log rescues an exception, attempt to detect and reconnect to an inactive database connection. Connection adapter must respond to the active? and reconnect! instance methods. Initial support for PostgreSQL .[Jeremy Kemper]3 * When AbstractAdapter#log rescues an exception, attempt to detect and reconnect to an inactive database connection. Connection adapter must respond to the active? and reconnect! instance methods. Initial support for PostgreSQL, MySQL, and SQLite. Make certain that all statements which may need reconnection are performed within a logged block: for example, this means no avoiding log(sql, name) { } if @logger.nil? [Jeremy Kemper] 4 4 5 5 * Much faster Oracle column reflection. #2848 [Michael Schoen <schoenm@earthlink.net>] trunk/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
r3000 r3001 23 23 @@row_even = true 24 24 25 @@reconnect_success = 0 26 @@reconnect_failure = 0 27 def self.reconnect_success_rate 28 @@reconnect_success.to_f / (@@reconnect_success + @@reconnect_failure) 29 end 30 25 31 def initialize(connection, logger = nil) #:nodoc: 26 32 @connection, @logger = connection, logger … … 41 47 42 48 def reset_runtime #:nodoc: 43 rt = @runtime 44 @runtime = 0 45 return rt 49 rt, @runtime = @runtime, 0 50 rt 46 51 end 47 52 … … 101 106 if respond_to?(:active?) and respond_to?(:reconnect!) 102 107 reconnect! unless active? 103 raise ActiveRecord::ConnectionFailed unless active? 108 if active? 109 @@reconnect_success += 1 110 @logger.info "#{adapter_name} automatically reconnected. Success rate: #{'%.2f' % self.class.reconnect_success_rate}%" if @logger 111 else 112 @@reconnect_failure += 1 113 @logger.warn "#{adapter_name} automatic reconnection failed. Success rate: #{'%.2f' % self.class.reconnect_success_rate}%" if @logger 114 raise ActiveRecord::ConnectionFailed 115 end 104 116 else 105 117 @logger.warn "#{adapter_name} does not yet support automatic reconnection." if @logger trunk/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb
r2947 r3001 137 137 138 138 139 # CONNECTION MANAGEMENT ==================================== 140 141 def active? 142 @connection.stat if @connection.respond_to?(:stat) 143 true 144 rescue Mysql::Error 145 false 146 end 147 148 def reconnect! 149 if @connection.respond_to?(:ping) 150 @connection.ping 151 else 152 @connection.close rescue nil 153 @connection.real_connect(*@connection_options) 154 end 155 end 156 157 139 158 # DATABASE STATEMENTS ====================================== 140 159 … … 149 168 150 169 def execute(sql, name = nil, retries = 2) #:nodoc: 151 unless @logger 152 @connection.query(sql) 153 else 154 log(sql, name) { @connection.query(sql) } 155 end 170 log(sql, name) { @connection.query(sql) } 156 171 rescue ActiveRecord::StatementInvalid => exception 157 if LOST_CONNECTION_ERROR_MESSAGES.any? { |msg| exception.message.split(":").first =~ /^#{msg}/ } 158 @connection.real_connect(*@connection_options) 159 unless @logger 160 @connection.query(sql) 161 else 162 @logger.info "Retrying invalid statement with reopened connection" 163 log(sql, name) { @connection.query(sql) } 164 end 165 elsif exception.message.split(":").first =~ /Packets out of order/ 166 raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem update mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information." 172 if exception.message.split(":").first =~ /Packets out of order/ 173 raise ActiveRecord::StatementInvalid, "'Packets out of order' error was received from the database. Please update your mysql bindings (gem install mysql) and read http://dev.mysql.com/doc/mysql/en/password-hashing.html for more information. If you're on Windows, use the Instant Rails installer to get the updated mysql bindings." 167 174 else 168 175 raise trunk/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
r2962 r3001 128 128 129 129 130 # CONNECTION MANAGEMENT ==================================== 131 132 def active? 133 # TODO: SQLite is an embedded db, it doesn't lose connections, 134 # but perhaps some of its exceptions merit a retry, such as 135 # LockedException. 136 true 137 end 138 139 def reconnect! 140 end 141 142 130 143 # DATABASE STATEMENTS ====================================== 131 144