Skip to content

Commit 6b6f88d

Browse files
author
Anna
committed
Removed Retry Deadlock Victim
1 parent 97cbb09 commit 6b6f88d

File tree

6 files changed

+6
-147
lines changed

6 files changed

+6
-147
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
* 4.0.0 *
2+
3+
*Removed deadlock victim retry in favor of Isolation Level
14

25
* 3.2.12 *
36

README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,6 @@ ActiveRecord::ConnectionAdapters::SQLServerAdapter.native_string_database_type =
110110
It is important to remember that unicode types in SQL Server have approximately half the storage capacity as their counter parts. So where a normal string would max out at (8000) a unicode string will top off at (4000).
111111

112112

113-
#### Deadlock Victim Retry
114-
115-
In a config initializer, you can configure the adapter to retry deadlock victims' SQL. Note, this relies on us copying ActiveRecord's `#transaction` method and can be brittle when upgrading. If you think that our version of `#transaction` is out of sync with the version of rails in our gemspec, please open a ticket and let us know. Our custom transaction method can be found in `activerecord/connection_adapters/sqlserver/core_ext/database_statements.rb`.
116-
117-
```ruby
118-
ActiveRecord::ConnectionAdapters::SQLServerAdapter.retry_deadlock_victim = true
119-
```
120-
121-
122113
#### Force Schema To Lowercase
123114

124115
Although it is not necessary, the Ruby convention is to use lowercase method names. If your database schema is in upper or mixed case, we can force all table and column names during the schema reflection process to be lowercase. Add this to your config/initializers file for the adapter.

lib/active_record/connection_adapters/sqlserver/core_ext/database_statements.rb

Lines changed: 0 additions & 94 deletions
This file was deleted.

lib/active_record/connection_adapters/sqlserver/database_statements.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ module ConnectionAdapters
33
module Sqlserver
44
module DatabaseStatements
55

6-
include CoreExt::DatabaseStatements
7-
86
def select_rows(sql, name = nil)
97
raw_select sql, name, [], :fetch => :rows
108
end
@@ -49,14 +47,6 @@ def supports_statement_cache?
4947
true
5048
end
5149

52-
def transaction(options = {})
53-
if retry_deadlock_victim?
54-
block_given? ? transaction_with_retry_deadlock_victim(options) { yield } : transaction_with_retry_deadlock_victim(options)
55-
else
56-
block_given? ? super(options) { yield } : super(options)
57-
end
58-
end
59-
6050
def begin_db_transaction
6151
do_execute "BEGIN TRANSACTION"
6252
end

lib/active_record/connection_adapters/sqlserver_adapter.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require 'active_support/core_ext/string'
77
require 'active_record/connection_adapters/abstract_adapter'
88
require 'active_record/connection_adapters/sqlserver/core_ext/active_record'
9-
require 'active_record/connection_adapters/sqlserver/core_ext/database_statements'
109
require 'active_record/connection_adapters/sqlserver/core_ext/explain'
1110
require 'active_record/connection_adapters/sqlserver/core_ext/explain_subscriber'
1211
require 'active_record/connection_adapters/sqlserver/core_ext/relation'
@@ -186,9 +185,8 @@ class SQLServerAdapter < AbstractAdapter
186185
attr_reader :database_version, :database_year, :spid, :product_level, :product_version, :edition
187186

188187
cattr_accessor :native_text_database_type, :native_binary_database_type, :native_string_database_type,
189-
:enable_default_unicode_types, :auto_connect, :retry_deadlock_victim,
190-
:cs_equality_operator, :lowercase_schema_reflection, :auto_connect_duration,
191-
:showplan_option
188+
:enable_default_unicode_types, :auto_connect, :cs_equality_operator,
189+
:lowercase_schema_reflection, :auto_connect_duration, :showplan_option
192190

193191
self.enable_default_unicode_types = true
194192

@@ -359,11 +357,6 @@ def auto_connect_duration
359357
@@auto_connect_duration ||= 10
360358
end
361359

362-
def retry_deadlock_victim
363-
@@retry_deadlock_victim.is_a?(FalseClass) ? false : true
364-
end
365-
alias :retry_deadlock_victim? :retry_deadlock_victim
366-
367360
def native_string_database_type
368361
@@native_string_database_type || (enable_default_unicode_types ? 'nvarchar' : 'varchar')
369362
end
@@ -509,7 +502,6 @@ def with_sqlserver_error_handling
509502
rescue Exception => e
510503
case translate_exception(e,e.message)
511504
when LostConnection; retry if auto_reconnected?
512-
when DeadlockVictim; retry if retry_deadlock_victim? && open_transactions == 0
513505
end
514506
raise
515507
end

test/cases/connection_test_sqlserver.rb

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,7 @@ class ConnectionTestSqlserver < ActiveRecord::TestCase
180180
raw_conn.stubs(:execute).raises(deadlock_victim_exception(@query)).then.returns(stubbed_handle)
181181
end
182182

183-
teardown do
184-
@connection.class.retry_deadlock_victim = nil
185-
end
186-
187-
should 'retry by default' do
188-
assert_nothing_raised do
189-
assert_equal @expected, @connection.execute(@query)
190-
end
191-
end
192-
193-
should 'raise ActiveRecord::DeadlockVictim if retry is disabled' do
194-
@connection.class.retry_deadlock_victim = false
183+
should 'raise ActiveRecord::DeadlockVictim' do
195184
assert_raise(ActiveRecord::DeadlockVictim) do
196185
assert_equal @expected, @connection.execute(@query)
197186
end
@@ -228,21 +217,9 @@ def execute_with_deadlock_exception(sql, *args)
228217
remove_method :execute_without_deadlock_exception
229218
end
230219
@connection.send(:remove_instance_variable, :@raised_deadlock_exception)
231-
@connection.class.retry_deadlock_victim = nil
232-
end
233-
234-
should 'retry by default' do
235-
skip "takes too long"
236-
assert_nothing_raised do
237-
ActiveRecord::Base.transaction do
238-
assert_equal @expected, @connection.execute(@query)
239-
end
240-
end
241220
end
242221

243222
should 'raise ActiveRecord::DeadlockVictim if retry disabled' do
244-
skip "takes too long"
245-
@connection.class.retry_deadlock_victim = false
246223
assert_raise(ActiveRecord::DeadlockVictim) do
247224
ActiveRecord::Base.transaction do
248225
assert_equal @expected, @connection.execute(@query)

0 commit comments

Comments
 (0)