module ActiveRecord::ConnectionAdapters::CockroachDB::TransactionManagerMonkeyPatch

Public Instance Methods

retryable?(error) click to toggle source
# File lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb, line 23
def retryable?(error)
  return true if error.is_a? ActiveRecord::SerializationFailure
  return retryable? error.cause if error.cause
  false
end
within_new_transaction(isolation: nil, joinable: true, attempts: 0) { || ... } click to toggle source

Capture ActiveRecord::SerializationFailure errors caused by transactions that fail due to serialization errors. Failed transactions will be retried until they pass or the max retry limit is exceeded.

Calls superclass method
# File lib/active_record/connection_adapters/cockroachdb/transaction_manager.rb, line 11
def within_new_transaction(isolation: nil, joinable: true, attempts: 0)
  super(isolation: isolation, joinable: joinable)
rescue ActiveRecord::StatementInvalid => error
  raise unless retryable? error
  raise if attempts >= @connection.max_transaction_retries

  attempts += 1
  sleep_seconds = (2 ** attempts + rand) / 10
  sleep(sleep_seconds)
  within_new_transaction(isolation: isolation, joinable: joinable, attempts: attempts) { yield }
end