Skip to content
This repository was archived by the owner on Apr 4, 2020. It is now read-only.

Conversation

@carbonin
Copy link
Member

@carbonin carbonin commented Jun 30, 2016

Nested transactions are not really supported at the database level.
Because of this, nesting transaction blocks can cause the outer block to be aborted which will cause later SQL statements to fail with the message:

PG::InFailedSqlTransaction: ERROR: current transaction is aborted, commands ignored until end of transaction block

This is currently the case with the BufferedCommitter's 1000 change transaction and the one started in the attempt_change method in the OneWayReplicator.

To deal with this the PostgreSQLAdapter#transaction method accepts a :requires_new option which uses save points to simulate nested transactions.

This change adds this option to the previously nested transaction in the OneWayReplicator

This will allow for the insert to fail (for example with a unique constraint error) and the outer transaction to continue.

More information about this option can be found at:
http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-transaction

Worked on this with @gtanzillo

https://bugzilla.redhat.com/show_bug.cgi?id=1348576

Nested transactions are not really supported at the database level.
Because of this, nesting transaction blocks can cause
the outer block to be aborted which will cause later SQL statements
to fail with the message:

PG::InFailedSqlTransaction: ERROR: current transaction is aborted,
commands ignored until end of transaction block

This is currently the case with the buffered_committer's 1000 change
transaction and the one started in the attempt_change method in the
OneWayReplicator.

To deal with this the PostgreSQLAdapter#transaction method accepts
a `requires_new` option which uses save points to simulate nested
transactions.

This change adds this option to the previously nested transaction
in the OneWayReplicator

This will allow for the insert to fail (for example with a unique
constraint error) and the outer transaction to continue.

More information about this option can be found at:
http://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/DatabaseStatements.html#method-i-transaction
@gtanzillo gtanzillo merged commit 97d5f9a into ManageIQ:rubyrep_1_2_0 Jun 30, 2016
Fryguy pushed a commit that referenced this pull request Jun 30, 2016
…action

Use the :requires_new option for nested transactions
(cherry picked from commit 97d5f9a)
carbonin added a commit to carbonin/manageiq that referenced this pull request Jul 6, 2016
This was required because rubyrep would open a transaction
per 1000 rows and also a transaction for each change it
replicated.

If the inner transaction failed for any reason, the outer
transaction would also be aborted because postgresql does
not really support nested transactions.

This would cause the replicate process to timeout because
no sql could then be processed in the aborted transaction.

ManageIQ/rubyrep#9
https://bugzilla.redhat.com/show_bug.cgi?id=1348576
@carbonin carbonin deleted the use_requires_new_for_nested_transaction branch July 15, 2016 20:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants