-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
RFC: implement transaction and session cancellation #17252
Conversation
cc @cockroachdb/sql-execution |
Thanks for your contribution.
I would strongly suggest that you write up an overview of your proposed approach in a RFC, I would be even OK to have it inside this PR, and gather some input from stakeholders about the approach before we can even check whether the code looks good. Reviewed 18 of 18 files at r1, 5 of 5 files at r2, 2 of 2 files at r3. pkg/server/status.go, line 994 at r2 (raw file):
Clarify what "it" means in this sentence. Clarify what "grabs" means in this sentence. pkg/server/status.go, line 1009 at r2 (raw file):
Place the pkg/sql/executor.go, line 388 at r2 (raw file):
The pkg/sql/executor.go, line 448 at r2 (raw file):
space missing between the parenthesis. pkg/sql/run_control_test.go, line 83 at r3 (raw file):
Make this test use multiple types of queries. You need to test:
pkg/sql/parser/sql.y, line 1257 at r1 (raw file):
Make a new non-terminal Comments from Reviewable |
My very strongly suggested approach to this would be to have a boolean flag in the session object set by query cancellation, and have the executor responsible for reading this flag at key points and be responsible for transitioning the txn in the aborted state. Review status: all files reviewed at latest revision, 6 unresolved discussions, some commit checks failed. Comments from Reviewable |
+1 to Rafa's concerns about races with ActiveQueries. One question: what happens if there's no active queries (or, only parallel ones that don't block the client) and the session is waiting to read data from the client (from pgwire)? Do we / should we send and error code to the client? I'd look at what we do when we're closing sessions while draining. Review status: all files reviewed at latest revision, 15 unresolved discussions, some commit checks failed. pkg/sql/executor.go, line 367 at r2 (raw file):
make sure you rebase on top of #17219 pkg/sql/executor.go, line 374 at r2 (raw file):
no need to return the bool. It's equal to pkg/sql/executor.go, line 387 at r2 (raw file):
what's the return value? pkg/sql/executor.go, line 413 at r2 (raw file):
the queryID is the key in that map. pkg/sql/executor.go, line 415 at r2 (raw file):
this comment is unnecessary. Putting it only invites questions about why you're not continuing to attempt to cancel the other queries. pkg/sql/executor.go, line 416 at r2 (raw file):
not sure what this comment is telling me. I'd remove it. It's usual to pass errors up the stack; it's common to not know how to handle them. pkg/sql/executor.go, line 417 at r2 (raw file):
no need to check cancelled here (or return in in the first place) pkg/sql/executor.go, line 422 at r2 (raw file):
join the next line to reduce the scope of err.
pkg/sql/executor.go, line 441 at r2 (raw file):
you're just spinning? Sleep a little, or find a way to trigger events when ActiveQueries changes. Comments from Reviewable |
f4947a2
to
766f926
Compare
[WIP] I've updated the branch, added draft RFC and the boolean flag suggested by @knz. |
791cfdc
to
903e25f
Compare
@itsbilal can you look at the code and suggest where to add the appropriate hooks? |
Review status: 0 of 26 files reviewed at latest revision, 16 unresolved discussions, some commit checks failed. pkg/sql/session.go, line 364 at r7 (raw file):
It would be a better idea to have this flag inside The executor could check for this flag (after statement execution errors out) and issue an automatic rollback instead of just marking the transaction and Comments from Reviewable |
21cc40b
to
f8fc173
Compare
6e6c1e4
to
29e5ce7
Compare
|
||
It is similar to the motivation behind query cancellation, currently it is possible to monitor sessions and queries, and cancelling queries. | ||
Extending this functionality with transaction cancellation would be a logical next step. | ||
It would be useful to cancel idle transactions for example. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this useful? I'm late to this party, but I'm having a hard time imagining a scenario where cancelling transactions (rather than queries, sessions) is useful in CRDB.
One instance would be releasing leases related to idle transactions. And it would also be a component of session cancellation, whenever that's built.
… On Aug 6, 2017, at 7:25 AM, Tamir Duberstein ***@***.***> wrote:
@tamird commented on this pull request.
In docs/RFCS/transaction_cancellation.md:
> @@ -0,0 +1,51 @@
+- Feature Name: Transaction Cancellation
+- Status: completed (PR [#17252](#17252))
+- Start Date: 2017-07-30
+- Author: Julian Gilyadov
+- RFC PR: [#17252](#17252)
+- Cockroach Issue: None
+
+# Motivation
+
+It is similar to the motivation behind query cancellation, currently it is possible to monitor sessions and queries, and cancelling queries.
+Extending this functionality with transaction cancellation would be a logical next step.
+It would be useful to cancel idle transactions for example.
Why is this useful? I'm late to this party, but I'm having a hard time imagining a scenario where cancelling transactions (rather than queries, sessions) is useful in CRDB.
—
You are receiving this because your review was requested.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Using a separate PR for the RFC and code change is an excellent idea. Thanks for this. I do agree that building on top of the existing RFC is a good choice. Andrei and I however both agree that the new RFC should contain a high-level short summary of what the existing cancellation features already do and how. |
Sorry I wasn't clear in my previous comment. When I wrote "building on top of the existing RFC" I meant leave the existing file as-is and create a new one "that builds on top". This new file should contain a high-level summary of the previous functionality. |
+1 to putting just the RFC in this PR. This is the way we generally do things. For file organization, I think a new file is better - with a summary and a link to the old one. The old one should also have a link to the new one. Review status: 0 of 1 files reviewed at latest revision, 64 unresolved discussions, some commit checks failed. docs/RFCS/20170814_cancel_txn_session.md, line 12 at r21 (raw file):
nit: style guide says wrap lines at 100 characters docs/RFCS/20170814_cancel_txn_session.md, line 17 at r21 (raw file):
Similarly? docs/RFCS/20170814_cancel_txn_session.md, line 37 at r21 (raw file):
s/finishes/finishing docs/RFCS/20170814_cancel_txn_session.md, line 37 at r21 (raw file):
I like this paragraph, but I think it needs a bit more context: please explain that currently a query cancellation does cancel the transaction (modulo the race you describe). Without this piece of information, the rest doesn't make sense to a layman reader. docs/RFCS/20170814_cancel_txn_session.md, line 86 at r21 (raw file):
it'd be cool if this example made it clear what state the session is in once the client gets the "transaction cancelled" error. I guess it should be in the
And have the example show that the client has to send a docs/RFCS/20170814_cancel_txn_session.md, line 156 at r21 (raw file):
the session_ids printed in the previous examples have dashes in them, but these query ids don't. What's the deal? docs/RFCS/20170814_cancel_txn_session.md, line 174 at r21 (raw file):
s/The transaction will transition immediately if there are no active queries./If there are no active queries, the KV transaction will be rolled back and the session will transition to the The point is to emphasize the two actions - the rollback (of the lower-level KV transaction - i.e. docs/RFCS/20170814_cancel_txn_session.md, line 176 at r21 (raw file):
how exactly will we ensure this? docs/RFCS/20170814_cancel_txn_session.md, line 177 at r21 (raw file):
I think we should explain here exactly how we're planning on doing that. I guess we'd just cancel the transaction's docs/RFCS/20170814_cancel_txn_session.md, line 182 at r21 (raw file):
what's the docs/RFCS/20170814_cancel_txn_session.md, line 185 at r21 (raw file):
cancelation of DistSQL queries is implemented. What made you believe that it isn't? docs/RFCS/20170814_cancel_txn_session.md, line 186 at r21 (raw file):
Would you mind going into more detail about what you were thinking here? Or, rather, what do you expect to happen and why? docs/RFCS/20170814_cancel_txn_session.md, line 187 at r21 (raw file):
what are you thinking of? What's the docs/RFCS/20170814_cancel_txn_session.md, line 190 at r21 (raw file):
How exactly will we do this? I guess we'll cancel the docs/RFCS/20170814_cancel_txn_session.md, line 230 at r21 (raw file):
well, I believe that So The protocol-level feature was not mentioned in the other RFC, and so I think it's time to mention it. Whether we want to implement it or not I'm not sure yet; still waiting for opinions from the other folks. Comments from Reviewable |
76f2789
to
0ab4bcd
Compare
Review status: 0 of 1 files reviewed at latest revision, 64 unresolved discussions, all commit checks successful. docs/RFCS/20170814_cancel_txn_session.md, line 230 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
This was discussed in at least one version of another cancellation RFC. The small key sizes make these functions difficult to support (especially when load balancers are involved). We may want to support these interfaces one day (since they're presumably built into postgres client drivers), but for now we should just support our own syntax with larger IDs and see how much demand there is for postgres-compatible cancellation. Implementing some mapping of 32- or 64-bit ids to queries would get its own RFC when/if we decide to do it. Comments from Reviewable |
Thanks for doing this. Is there any help needed here? |
4cfeb77
to
ffe2a8d
Compare
@andreimatei I updated the RFC to address your comments. |
Thanks for updating the RFC! |
ffe2a8d
to
54e059c
Compare
Review status: 0 of 1 files reviewed at latest revision, 64 unresolved discussions. docs/RFCS/20170814_cancel_txn_session.md, line 12 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. docs/RFCS/20170814_cancel_txn_session.md, line 17 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. docs/RFCS/20170814_cancel_txn_session.md, line 37 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. docs/RFCS/20170814_cancel_txn_session.md, line 37 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. docs/RFCS/20170814_cancel_txn_session.md, line 86 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. docs/RFCS/20170814_cancel_txn_session.md, line 156 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. docs/RFCS/20170814_cancel_txn_session.md, line 174 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Done. docs/RFCS/20170814_cancel_txn_session.md, line 176 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
I propose to introduce an docs/RFCS/20170814_cancel_txn_session.md, line 177 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
I propose to cancel all running queries by iterating all active queries under the docs/RFCS/20170814_cancel_txn_session.md, line 182 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
I pointed out the files. docs/RFCS/20170814_cancel_txn_session.md, line 185 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
It was outdated. Updated it.. Done. docs/RFCS/20170814_cancel_txn_session.md, line 186 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Initially, I planned to test a transaction with a long-running statement and a distributed one. The docs/RFCS/20170814_cancel_txn_session.md, line 187 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
Please reference my previous comment. docs/RFCS/20170814_cancel_txn_session.md, line 190 at r21 (raw file): Previously, andreimatei (Andrei Matei) wrote…
I updated it with your suggestion. docs/RFCS/20170814_cancel_txn_session.md, line 230 at r21 (raw file): Previously, bdarnell (Ben Darnell) wrote…
I added more details and arguments about if to support Comments from Reviewable |
54e059c
to
dd21a3d
Compare
dd21a3d
to
8dea507
Compare
@knz I referenced the query cancellation RFC(and PR) along with a high-level short summary of what the existing cancellation features already do and how. Let me know if a more in-depth summary should be added. |
Will be squshed soon.
Will be squashed soon.
Review status: 0 of 1 files reviewed at latest revision, 60 unresolved discussions, all commit checks successful. docs/RFCS/20170814_cancel_txn_session.md, line 186 at r21 (raw file): Previously, israelg99 (Julian Gilyadov) wrote…
So I think testing something that uses docs/RFCS/20170814_cancel_txn_session.md, line 11 at r24 (raw file):
the ... statement (singular) docs/RFCS/20170814_cancel_txn_session.md, line 55 at r24 (raw file):
grammar nit, feel free to ignore: your use of semicolons is... peculiar :) They're use is supposed to be close to that of periods, not that of commas. The following one, in front of "so" is also questionable. There, I think you simply want a period to separate out the conclusion from the previous statement: docs/RFCS/20170814_cancel_txn_session.md, line 65 at r24 (raw file):
What's this cluster thing about? What are you thinking of? Without more details, this use case seems very questionable to me. docs/RFCS/20170814_cancel_txn_session.md, line 223 at r24 (raw file):
Well, if we introduce this new field, what would its semantics be exactly? If a query comes while this field is set (but the state is otherwise I don't know if a new field is the best way to go here. What I'd try to do is:
I don't think we need to do anything special to cancel the running queries: canceling the txn context will cancel all the child queries' contexts (currently, the queries just use the transaction's context. In the future they'll be child (derived) contexts, but canceling the parent will still cancel them). Comments from Reviewable |
@israelg99 are you working on this anytime soon? Thanks |
@vivekmenezes probably not -- i am working with a company and unfortunately have no time for this PR.. |
@vivekmenezes does this mean that we should pull development of this feature back internally in our next release? |
this and transaction timeout are potential intern projects. |
Closing this since it's been abandoned. |
RFC for transaction and session cancellation - mentioned in query cancellation RFC and is a follow-up work to #17003.
cc @itsbilal