File tree Expand file tree Collapse file tree 1 file changed +10
-4
lines changed
lib/active_record/connection_adapters/cockroachdb Expand file tree Collapse file tree 1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -8,16 +8,22 @@ module TransactionManagerMonkeyPatch
88 # transactions that fail due to serialization errors. Failed
99 # transactions will be retried until they pass or the max retry limit is
1010 # exceeded.
11- def within_new_transaction ( options = { } )
12- attempts = options . fetch ( :attempts , 0 )
11+ def within_new_transaction ( isolation : nil , joinable : true , attempts : 0 )
1312 super
14- rescue ActiveRecord ::SerializationFailure => error
13+ rescue ActiveRecord ::StatementInvalid => error
14+ raise unless retryable? error
1515 raise if attempts >= @connection . max_transaction_retries
1616
1717 attempts += 1
1818 sleep_seconds = ( 2 ** attempts + rand ) / 10
1919 sleep ( sleep_seconds )
20- within_new_transaction ( options . merge ( attempts : attempts ) ) { yield }
20+ within_new_transaction ( isolation : isolation , joinable : joinable , attempts : attempts ) { yield }
21+ end
22+
23+ def retryable? ( error )
24+ return true if error . is_a? ActiveRecord ::SerializationFailure
25+ return retryable? error . cause if error . cause
26+ false
2127 end
2228 end
2329 end
You can’t perform that action at this time.
0 commit comments