module Sequel::TransactionConnectionValidator
Public Instance Methods
transaction(opts=OPTS)
click to toggle source
Rescue disconnect errors raised when beginning a new transaction. If there is a disconnnect error, it should be safe to retry the transaction using a new connection, as we haven’t yielded control to the user yet.
Calls superclass method
# File lib/sequel/extensions/transaction_connection_validator.rb 38 def transaction(opts=OPTS) 39 super 40 rescue DisconnectRetry => e 41 if synchronize(opts[:server]){|conn| conn.equal?(e.connection)} 42 # If retrying would use the same connection, that means the 43 # connection was not removed from the pool, which means the caller has 44 # already checked out the connection, and retrying will not be successful. 45 # In this case, we can only reraise the exception. 46 raise e.database_error 47 end 48 49 num_retries ||= 0 50 num_retries += 1 51 retry if num_retries < 5 52 53 raise e.database_error 54 end
Private Instance Methods
begin_new_transaction(conn, opts)
click to toggle source
Reraise disconnect errors as DisconnectRetry
so they can be retried.
Calls superclass method
# File lib/sequel/extensions/transaction_connection_validator.rb 59 def begin_new_transaction(conn, opts) 60 super 61 rescue Sequel::DatabaseDisconnectError, *database_error_classes => e 62 if e.is_a?(Sequel::DatabaseDisconnectError) || disconnect_error?(e, OPTS) 63 exception = DisconnectRetry.new(e.message) 64 exception.set_backtrace([]) 65 exception.connection = conn 66 unless e.is_a?(Sequel::DatabaseError) 67 e = Sequel.convert_exception_class(e, database_error_class(e, OPTS)) 68 end 69 exception.database_error = e 70 raise exception 71 end 72 73 raise 74 end