Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add mysql 5.5 support.

  • Loading branch information...
commit 63a87d9e81f6688e38158a20ae47fd8dbc017cc0 1 parent ccea55f
@mperham mperham authored
Showing with 28 additions and 22 deletions.
  1. +2 −1  CHANGELOG
  2. +18 −17 lib/deadlock_retry.rb
  3. +8 −4 test/deadlock_retry_test.rb
View
3  CHANGELOG
@@ -1,8 +1,9 @@
deadlock_retry changes
-== HEAD
+== v1.1.2
* Exponential backoff, sleep 0, 1, 2, 4... seconds between retries.
+* Support new syntax for InnoDB status in MySQL 5.5.
== v1.1.1 (2011-05-13)
View
35 lib/deadlock_retry.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/module/attribute_accessors'
+
module DeadlockRetry
VERSION = '1.1.2'
@@ -11,15 +13,7 @@ class << self
end
end
- @@innodb_status_available = nil
-
- def self.innodb_status_available?
- @@innodb_status_available
- end
-
- def self.innodb_status_available=(bool)
- @@innodb_status_available = bool
- end
+ mattr_accessor :innodb_status_cmd
module ClassMethods
DEADLOCK_ERROR_MESSAGES = [
@@ -43,7 +37,7 @@ def transaction_with_deadlock_handling(*objects, &block)
raise if retry_count >= MAXIMUM_RETRIES_ON_DEADLOCK
retry_count += 1
logger.info "Deadlock detected on retry #{retry_count}, restarting transaction"
- log_innodb_status if DeadlockRetry.innodb_status_available?
+ log_innodb_status if DeadlockRetry.innodb_status_cmd
exponential_pause(retry_count)
retry
else
@@ -69,19 +63,26 @@ def in_nested_transaction?
end
def show_innodb_status
- self.connection.select_value("show innodb status")
+ self.connection.select_value(DeadlockRetry.innodb_status_cmd)
end
# Should we try to log innodb status -- if we don't have permission to,
# we actually break in-flight transactions, silently (!)
def check_innodb_status_available
- return unless DeadlockRetry.innodb_status_available? == nil
+ return unless DeadlockRetry.innodb_status_cmd == nil
begin
- show_innodb_status
- DeadlockRetry.innodb_status_available = true
+ mysql_version = self.connection.execute('show variables like \'version\'').to_a[0][1]
+ cmd = if mysql_version < '5.5'
+ 'show innodb status'
+ else
+ 'show engine innodb status'
+ end
+ self.connection.select_value(cmd)
+ DeadlockRetry.innodb_status_cmd = cmd
rescue
- DeadlockRetry.innodb_status_available = false
+ logger.info "Cannot log innodb status: #{$!.message}"
+ DeadlockRetry.innodb_status_cmd = false
end
end
@@ -93,9 +94,9 @@ def log_innodb_status
lines.each_line do |line|
logger.warn line
end
- rescue Exception => e
+ rescue => e
# Access denied, ignore
- logger.warn "Cannot log innodb status: #{e.message}"
+ logger.info "Cannot log innodb status: #{e.message}"
end
end
View
12 test/deadlock_retry_test.rb
@@ -37,8 +37,12 @@ def self.show_innodb_status
[]
end
- def self.reset_innodb_status_availability
- DeadlockRetry.innodb_status_availability = nil
+ def self.execute(sql)
+ [['version', '5.1.45']]
+ end
+
+ def self.select_value(sql)
+ true
end
include DeadlockRetry
@@ -85,9 +89,9 @@ def test_included_by_default
end
def test_innodb_status_availability
- DeadlockRetry.innodb_status_available = nil
+ DeadlockRetry.innodb_status_cmd = nil
MockModel.transaction {}
- assert_equal true, DeadlockRetry.innodb_status_available?
+ assert_equal "show innodb status", DeadlockRetry.innodb_status_cmd
end
Please sign in to comment.
Something went wrong with that request. Please try again.