Skip to content

Commit

Permalink
Fix possible thread safety issues on non-GVL ruby implementations in …
Browse files Browse the repository at this point in the history
…adapter transaction code
  • Loading branch information
jeremyevans committed Apr 27, 2012
1 parent bf76226 commit fc0a285
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/sequel/adapters/firebird.rb
Expand Up @@ -31,7 +31,7 @@ def connect(server)
def execute(sql, opts={})
begin
synchronize(opts[:server]) do |conn|
if conn.transaction_started && !@transactions.has_key?(conn)
if conn.transaction_started && !_trans(conn)
conn.rollback
raise DatabaseDisconnectError, "transaction accidently left open, rolling back and disconnecting"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sequel/adapters/jdbc/h2.rb
Expand Up @@ -48,7 +48,7 @@ def supports_savepoints?
# If the :prepare option is given and we aren't in a savepoint,
# prepare the transaction for a two-phase commit.
def commit_transaction(conn, opts={})
if (s = opts[:prepare]) && @transactions[conn][:savepoint_level] <= 1
if (s = opts[:prepare]) && _trans(conn)[:savepoint_level] <= 1
log_connection_execute(conn, "PREPARE COMMIT #{s}")
else
super
Expand Down
8 changes: 4 additions & 4 deletions lib/sequel/adapters/jdbc/transactions.rb
Expand Up @@ -24,7 +24,7 @@ def supports_releasing_savepoints?
# Use JDBC connection's setAutoCommit to false to start transactions
def begin_transaction(conn, opts={})
if supports_savepoints?
th = @transactions[conn]
th = _trans(conn)
if sps = th[:savepoints]
sps << log_yield(TRANSACTION_SAVEPOINT){conn.set_savepoint}
else
Expand All @@ -40,7 +40,7 @@ def begin_transaction(conn, opts={})
# Use JDBC connection's commit method to commit transactions
def commit_transaction(conn, opts={})
if supports_savepoints?
sps = @transactions[conn][:savepoints]
sps = _trans(conn)[:savepoints]
if sps.empty?
log_yield(TRANSACTION_COMMIT){conn.commit}
elsif supports_releasing_savepoints?
Expand All @@ -54,7 +54,7 @@ def commit_transaction(conn, opts={})
# Use JDBC connection's setAutoCommit to true to enable non-transactional behavior
def remove_transaction(conn, committed)
if supports_savepoints?
sps = @transactions[conn][:savepoints]
sps = _trans(conn)[:savepoints]
conn.setAutoCommit(true) if sps.empty?
sps.pop
else
Expand All @@ -67,7 +67,7 @@ def remove_transaction(conn, committed)
# Use JDBC connection's rollback method to rollback transactions
def rollback_transaction(conn, opts={})
if supports_savepoints?
sps = @transactions[conn][:savepoints]
sps = _trans(conn)[:savepoints]
if sps.empty?
log_yield(TRANSACTION_ROLLBACK){conn.rollback}
else
Expand Down
2 changes: 1 addition & 1 deletion lib/sequel/adapters/shared/mssql.rb
Expand Up @@ -146,7 +146,7 @@ def begin_transaction_sql
# Commit the active transaction on the connection, does not commit/release
# savepoints.
def commit_transaction(conn, opts={})
log_connection_execute(conn, commit_transaction_sql) unless @transactions[conn][:savepoint_level] > 1
log_connection_execute(conn, commit_transaction_sql) unless _trans(conn)[:savepoint_level] > 1
end

# SQL to COMMIT a transaction.
Expand Down
6 changes: 3 additions & 3 deletions lib/sequel/adapters/shared/mysql.rb
Expand Up @@ -223,7 +223,7 @@ def begin_new_transaction(conn, opts)
# Use XA START to start a new prepared transaction if the :prepare
# option is given.
def begin_transaction(conn, opts={})
if (s = opts[:prepare]) && (th = @transactions[conn])[:savepoint_level] == 0
if (s = opts[:prepare]) && (th = _trans(conn))[:savepoint_level] == 0
log_connection_execute(conn, "XA START #{literal(s)}")
th[:savepoint_level] += 1
else
Expand All @@ -246,7 +246,7 @@ def column_definition_sql(column)
# Prepare the XA transaction for a two-phase commit if the
# :prepare option is given.
def commit_transaction(conn, opts={})
if (s = opts[:prepare]) && @transactions[conn][:savepoint_level] <= 1
if (s = opts[:prepare]) && _trans[conn)[:savepoint_level] <= 1
log_connection_execute(conn, "XA END #{literal(s)}")
log_connection_execute(conn, "XA PREPARE #{literal(s)}")
else
Expand Down Expand Up @@ -335,7 +335,7 @@ def primary_key_from_schema(table)

# Rollback the currently open XA transaction
def rollback_transaction(conn, opts={})
if (s = opts[:prepare]) && @transactions[conn][:savepoint_level] <= 1
if (s = opts[:prepare]) && _trans(conn)[:savepoint_level] <= 1
log_connection_execute(conn, "XA END #{literal(s)}")
log_connection_execute(conn, "XA PREPARE #{literal(s)}")
log_connection_execute(conn, "XA ROLLBACK #{literal(s)}")
Expand Down
2 changes: 1 addition & 1 deletion lib/sequel/adapters/shared/postgres.rb
Expand Up @@ -447,7 +447,7 @@ def views(opts={})
# If the :prepare option is given and we aren't in a savepoint,
# prepare the transaction for a two-phase commit.
def commit_transaction(conn, opts={})
if (s = opts[:prepare]) && @transactions[conn][:savepoint_level] <= 1
if (s = opts[:prepare]) && _trans(conn)[:savepoint_level] <= 1
log_connection_execute(conn, "PREPARE TRANSACTION #{literal(s)}")
else
super
Expand Down

0 comments on commit fc0a285

Please sign in to comment.