File tree Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Expand file tree Collapse file tree 2 files changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,11 @@ class Configuration
12
12
backfill_pause
13
13
retry_delay
14
14
max_tries
15
+ max_lock_timeout
15
16
sensitive_logger
16
17
lock_timeout
17
- safe_timeout
18
18
] )
19
+ attr_reader :safe_timeout
19
20
20
21
def initialize
21
22
self . default_value_backfill_threshold = nil
@@ -27,6 +28,7 @@ def initialize
27
28
self . backfill_pause = 0.5 . second
28
29
self . retry_delay = 1 . minute
29
30
self . max_tries = 5
31
+ self . max_lock_timeout = 1 . second
30
32
self . sensitive_logger = nil
31
33
end
32
34
@@ -43,7 +45,7 @@ def lock_timeout=(value)
43
45
def safe_timeout = ( value )
44
46
raise 'Setting safe timeout to 0 disables the safe timeout and is dangerous' unless value
45
47
46
- unless lock_timeout . nil? || value > lock_timeout
48
+ unless lock_timeout . nil? || value > lock_timeout || value > max_lock_timeout
47
49
raise ArgumentError , "Safe timeout (#{ value } ) cannot be less than lock timeout (#{ lock_timeout } )"
48
50
end
49
51
Original file line number Diff line number Diff line change @@ -13,21 +13,18 @@ module StatementRetrier
13
13
private
14
14
15
15
def retry_if_lock_timeout
16
- remaining_tries = SafePgMigrations . config . max_tries
16
+ number_of_retries = 0
17
17
begin
18
- remaining_tries - = 1
18
+ number_of_retries + = 1
19
19
yield
20
20
rescue ActiveRecord ::LockWaitTimeout
21
21
raise if transaction_open? # Retrying is useless if we're inside a transaction.
22
- raise unless remaining_tries > 0
22
+ raise if number_of_retries >= SafePgMigrations . config . max_tries
23
23
24
- number_of_retries = SafePgMigrations . config . max_tries - remaining_tries
25
- if SafePgMigrations . config . max_tries - remaining_tries <= 20
24
+ if SafePgMigrations . config . lock_timeout < SafePgMigrations . config . max_lock_timeout
26
25
SafePgMigrations . config . lock_timeout = SafePgMigrations . config . lock_timeout * number_of_retries
27
- SafePgMigrations . config . safe_timeout = SafePgMigrations . config . safe_timeout * number_of_retries
28
26
else
29
- SafePgMigrations . config . lock_timeout = SafePgMigrations . config . lock_timeout * 20
30
- SafePgMigrations . config . safe_timeout = SafePgMigrations . config . safe_timeout * 20
27
+ SafePgMigrations . config . lock_timeout = SafePgMigrations . config . max_lock_timeout
31
28
end
32
29
33
30
retry_delay = SafePgMigrations . config . retry_delay
You can’t perform that action at this time.
0 commit comments