-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow commit() within run_transaction() callback #25
Comments
The callback passed to We need |
Thanks for the explanation. Would you agree that cockroachdb forces one to use rather unnatural patterns in one's sqlalchemy code? Do you foresee the situation improving? Consider the following example code that sets a config option in the database if not already set:
This code (and any other that calls
That illustrates the kind of sweeping changes that would be required throughout our sqlalchemy codebase. |
Yes, handling transaction restarts in this way requires intrusive changes to many apps. We've made some changes that reduce the likelihood of transaction restarts, so you might be able to get by without surrounding everything in a retry loop, but these restarts remain more common with CockroachDB than in other databases and I think you'll still want retry handling. I appreciate the feedback about potential interfaces; I've never used the My recommendation for now is to think of If
Since the entire function is now in one transaction, a decorator form of |
@bdarnell firstly, thanks for all this effort. The response from you and the rest of the cockroach team has been stellar.
This sounds perfect. I don't want to dwell on the example I gave because honestly that is the only function in our entire codebase which performs more than one transaction, and as you elegantly showed, we can trivially rewrite it as a single transaction. Would you consider reopening this issue in the light of your suggested patch? Alternatively, one could open a new issue to track the implementation thereof. |
I'll reopen, but it's generous to call what I said above a "patch". I don't know exactly what the change would look like. |
I'd like to come back to this now that I have a bit more experience with cockroachdb-python and SQLAlchemy. Firstly, what you have right now is one of two correct ways to go about it. The cockroachdb-python package' The SQLAlchemy's nested transaction API has two different styles in which it can be used. The first style is as a context manager:
The second style is more manual. It requires one to explicitly issue exactly one
The relevant quote from the SQLAlchemy docs is:
~ http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html#using-savepoint In my case, I would like to call The exact code is quite tailored to our code base but I've reproduced it below anyway as it might help further the discussion.
|
It seems error prone to require that the callback run What happens if you end up calling |
Interesting and insightful questions, thank you.
Right now I'm leaning towards saying "cockroachdb doesn't support nested transactions inside other nested transactions" and punt on the nesting depth issue until the database supports depth of greater than 2 (ie., the outer transaction and the nested transaction therein.) If you mean "rollback unless
That raises an exception along the lines of "Transaction is already closed."
In my case I opted to require a single explicit I would say it is more error prone, yes. In our project I discovered a couple of functions that called That said, this approach complies with the SQLAlchemy docs and the explicit I don't think one way is better than the other: each have trade-offs to consider. |
We definitely don't support more than 1 nested transaction. My point is that with your version of
Raising an exception (after rolling back to put the connection back in a clean state!) would be fine too (but you're not doing it here).
Why does it matter that you know that inside the callback instead of in the function that called In a clean-slate application, I'd argue that the design in which |
I'm also interested in nested transaction support, since my application uses the decorator form of |
It's tracked in the main repo as cockroachdb/cockroach#10735 although it's not currently on the roadmap. |
I am using Django with cockroachDB,while execute command
|
Django is not yet supported. This is tracked in cockroachdb/cockroach#25608 |
Any help needed on this? |
I don't think anyone's actively working on this, so if you'd like to prepare a PR, feel free. The main remaining concern I have, as I stated in my last comment is that if we have two variants of the Feedback from additional users of the sqlalchemy Also, in more recent versions of CockroachDB, the chance of transaction retries has been greatly reduced. Many applications may find that they're now OK without an explicit retry loop (in particular, single-statement transactions will never experience retry errors), or with a simple retry loop that doesn't do complex |
Roger that. As far as Django is concerned I'm thinking it may be worthwhile to pursue a specific Django DB module that can favorably leverage roach rationale. If however the goal is to make CockroachDB a more universal PostgreSQL dropin implementing some core features - I can no doubt do some use case analysis with my current workloads as well as contribute once I wrap my head around things. My workload also consists of an older implementation of OpenERP (Hopefully migrating to Odoo soon) and some other custom Python and Perl websites that are backed by PostgreSQL. I do use |
For django, there has been some movement: see the last few comments on #14 |
Running the following yields
psycopg2.InternalError: SAVEPOINT not supported except for COCKROACH_RESTART
I believe this is due to https://github.com/cockroachdb/cockroachdb-python/blob/master/cockroachdb/sqlalchemy/transaction.py#L54.
Why do we need
savepoint_state.cockroach_restart
? Considering that CockroachDB supports no other savepoint name, why not hard-code it and drop the conditional in the following functions:https://github.com/cockroachdb/cockroachdb-python/blob/master/cockroachdb/sqlalchemy/dialect.py#L158
Steps to reproduce:
Then run the following code:
https://gist.github.com/gpaul/648189354975992a2c285143d08be88a
This gives the following output using
cockroachdb-python v0.1
:https://gist.github.com/gpaul/14fa2967c42d4ccf6b223322a7967476
The text was updated successfully, but these errors were encountered: