Skip to content

Conversation

mfmarche
Copy link
Contributor

run_transaction utilizes the special 'cockroach_restart' protocol, as per: https://www.cockroachlabs.com/blog/nested-transactions-in-cockroachdb-20-1/

In order to support nested transactions, the cockroach_restart protocol for nested transactions can be related on versions after v20.1.

The motivation for this change was to allow multiple nested transactions to occur over the same engine connection and high level transaction (BEGIN/COMMIT). This allows one nested transaction to perform an INSERT or UPDATE, while subsequent transactions could retrieve that result (before the final COMMIT). This primarily works around conditions in sqlalchemy, where one would like to perform an orm.flush(), but cannot, when utilizing the cockroach run_transaction model.

By default the run_transaction defaults to using the cockroach_restart protocol, so no observed behavior is seen to current users.

mfmarche and others added 2 commits May 15, 2025 13:34
run_transaction utilizes the special 'cockroach_restart' protocol, as
per: https://www.cockroachlabs.com/blog/nested-transactions-in-cockroachdb-20-1/

In order to support nested transactions, the cockroach_restart protocol
for nested transactions can be related on versions after v20.1.

The motivation for this change was to allow multiple nested transactions
to occur over the same engine connection and high level
transaction (BEGIN/COMMIT). This allows one nested transaction to
perform an INSERT or UPDATE, while subsequent transactions could
retrieve that result (before the final COMMIT). This primarily works
around conditions in sqlalchemy, where one would like to perform an
orm.flush(), but cannot, when utilizing the cockroach run_transaction
model.

By default the run_transaction defaults to using the cockroach_restart
protocol, so no observed behavior is seen to current users.

Signed-off-by: Mike Marchetti <[email protected]>
@gordthompson gordthompson linked an issue May 16, 2025 that may be closed by this pull request
@mfmarche
Copy link
Contributor Author

mfmarche commented Jun 4, 2025

thanks for the fixes @gordthompson

Copy link
Collaborator

@gordthompson gordthompson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks okay to me

@gordthompson gordthompson requested a review from rafiss June 10, 2025 12:14
@rafiss
Copy link
Contributor

rafiss commented Jun 10, 2025

Thanks for your contribution!

@rafiss rafiss merged commit 01945de into cockroachdb:master Jun 10, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow commit() within run_transaction() callback
3 participants