From: Tom Hughes Date: Sat, 21 Jan 2012 15:00:56 +0000 (+0000) Subject: Switch to using deadlock_retry as a gem X-Git-Tag: live~5800 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/682ccc18df1911dbf737da87fc48d40705c72f40 Switch to using deadlock_retry as a gem --- diff --git a/Gemfile b/Gemfile index fb3f7c847..e2e822ba4 100644 --- a/Gemfile +++ b/Gemfile @@ -20,6 +20,7 @@ gem 'validates_email_format_of', '>= 1.5.1' gem 'composite_primary_keys', '>= 4.1.2' gem 'http_accept_language', '>= 1.0.2' gem 'paperclip', '~> 2.0' +gem 'deadlock_retry', '>= 1.1.2' # Character conversion support for ruby 1.8 gem 'iconv', :platforms => :ruby_18 diff --git a/Gemfile.lock b/Gemfile.lock index 27e164ebe..2291fc0d9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -42,6 +42,7 @@ GEM coffee-script-source (1.2.0) composite_primary_keys (4.1.2) activerecord (~> 3.1) + deadlock_retry (1.1.2) dynamic_form (1.1.4) erubis (2.7.0) execjs (1.3.0) @@ -157,6 +158,7 @@ DEPENDENCIES SystemTimer (>= 1.1.3) coffee-rails (~> 3.2.1) composite_primary_keys (>= 4.1.2) + deadlock_retry (>= 1.1.2) dynamic_form http_accept_language (>= 1.0.2) httpclient diff --git a/vendor/plugins/deadlock_retry/README b/vendor/plugins/deadlock_retry/README deleted file mode 100644 index b5937ce0e..000000000 --- a/vendor/plugins/deadlock_retry/README +++ /dev/null @@ -1,10 +0,0 @@ -Deadlock Retry -============== - -Deadlock retry allows the database adapter (currently only tested with the -MySQLAdapter) to retry transactions that fall into deadlock. It will retry -such transactions three times before finally failing. - -This capability is automatically added to ActiveRecord. No code changes or otherwise are required. - -Copyright (c) 2005 Jamis Buck, released under the MIT license \ No newline at end of file diff --git a/vendor/plugins/deadlock_retry/Rakefile b/vendor/plugins/deadlock_retry/Rakefile deleted file mode 100644 index 8063a6ed4..000000000 --- a/vendor/plugins/deadlock_retry/Rakefile +++ /dev/null @@ -1,10 +0,0 @@ -require 'rake' -require 'rake/testtask' - -desc "Default task" -task :default => [ :test ] - -Rake::TestTask.new do |t| - t.test_files = Dir["test/**/*_test.rb"] - t.verbose = true -end diff --git a/vendor/plugins/deadlock_retry/init.rb b/vendor/plugins/deadlock_retry/init.rb deleted file mode 100644 index 2d7c5f36e..000000000 --- a/vendor/plugins/deadlock_retry/init.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'deadlock_retry' - -if defined?(ActiveRecord::Base) - ActiveRecord::Base.send :include, DeadlockRetry -end diff --git a/vendor/plugins/deadlock_retry/lib/deadlock_retry.rb b/vendor/plugins/deadlock_retry/lib/deadlock_retry.rb deleted file mode 100644 index f287c4e67..000000000 --- a/vendor/plugins/deadlock_retry/lib/deadlock_retry.rb +++ /dev/null @@ -1,60 +0,0 @@ -# Copyright (c) 2005 Jamis Buck -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -module DeadlockRetry - def self.append_features(base) - super - base.extend(ClassMethods) - base.class_eval do - class < error - raise unless connection.open_transactions.zero? - if DEADLOCK_ERROR_MESSAGES.any? { |msg| error.message =~ /#{Regexp.escape(msg)}/ } - raise if retry_count >= MAXIMUM_RETRIES_ON_DEADLOCK - retry_count += 1 - logger.info "Deadlock detected on retry #{retry_count}, restarting transaction" - retry - else - raise - end - end - end - end -end diff --git a/vendor/plugins/deadlock_retry/test/deadlock_retry_test.rb b/vendor/plugins/deadlock_retry/test/deadlock_retry_test.rb deleted file mode 100644 index 7124391f8..000000000 --- a/vendor/plugins/deadlock_retry/test/deadlock_retry_test.rb +++ /dev/null @@ -1,95 +0,0 @@ -begin - require 'active_record' -rescue LoadError - if ENV['ACTIVERECORD_PATH'].nil? - abort < 3 - end - end - end - - assert_equal 4, tries - end -end