-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: add support to terminate all running queries #3944
feat: add support to terminate all running queries #3944
Conversation
You can now issue `TERMINATE ALL` to terminate all running queries. BREAKING CHANGE: `ALL` is now a reserved word and can not be used for identifiers without being quoted.
Sidenote since this isn't part of the PR, but I feel like a good way to achieve this kind of behavior would be to introduce some kind of namespacing abstraction (or whatever we want to call it). Then you'd just DROP NAMESPACE nsp CASCADE; This approach requires more intention, and a namespacing capability would be useful in many other ways as well. |
ksql-parser/src/main/antlr4/io/confluent/ksql/parser/SqlBase.g4
Outdated
Show resolved
Hide resolved
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.
I'd like to get some alternatives before we do this (i.e. see inline comment or @derekjn's comment about namespaces)
@@ -46,6 +46,7 @@ statement | |||
| PRINT (identifier| STRING) printClause #printTopic | |||
| (LIST | SHOW) QUERIES EXTENDED? #listQueries | |||
| TERMINATE QUERY? identifier #terminateQuery | |||
| TERMINATE ALL #terminateQuery |
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.
what about changing the semantics of TERMINATE <foo>
to use regex instead? That seems much more powerful and we don't need to introduce any new reserved words. Should also be backwards compatible I think
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.
I kind of feel like that could be a slippery slope. e.g. do we introduce regex semantics elsewhere in the grammar? How do users know where they can use regexes and where they can't?
In terms of selectively performing an operation on a number of objects based on a condition, other databases often use catalogs. e.g.,
SELECT terminate(query_id) FROM query_catalog WHERE <condition>
Which I think is a great pattern but obviously not possible for us.
Personally my vote here would be to completely do away with TERMINATE
and just make DROP
drop the object and its underlying query. It doesn't seem like TERMINATE
is useful for users, because as far as I know a terminated query can't be restarted anyways. So it seems to serve as a workaround for the problem of not being able to DROP CASCADE
a stream or table.
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.
The slippery slope is fair... that's why I'd like to see these things discussed before adding it 😂
In terms of selectively performing an operation on a number of objects based on a condition, other databases often use catalogs. e.g.,
SELECT terminate(query_id) FROM query_catalog WHERE <condition>Which I think is a great pattern but obviously not possible for us.
(off topic) The wheels in my mind are turning 😈 I think we should expose a query_catalog as a KSQL table! It's basically a materialization on the command topic. I'm about to create a ticket for this because I think we need to change the command topic to have table semantics anyway.
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.
Proper catalogs would be amazing and would open up all kinds of other operational possibilities. Catalogs also really empower tools, automation etc.
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.
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.
unresolving so that this thread is more visible when people refer back to it.
@big-andy-coates some tangential topics obviously emerged in the PR discussion, but just to be clear I'm fine with introducing |
Awesome discussion. Agree with all that has been said. Given we're in a period of flux anyway, how do people (mainly @agavra as he's blocked the PR), feel about merging this for now. (As its better than what we have). Then work on the catalog stuff, (which will likely take time)? I think there are pros and cons to merging / not merging. Not arguing strongly either way, just weakly in favour of merging as I find it useful to have this functionality, so likely others will to until something better comes along. It's also a trivial change. |
Yeah I suppose that's fine - I just wanted to see if other people had more alternatives before we merged it; I'm just worried that if we merge it we may never get rid of it 😉 . I'll give this a full review today. |
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.
What do you think about having TERMINATE ALL
be shorthand for distributing individual TERMINATE <query>
for all queries? See my comment below (#3944 (comment)).
ksql-rest-app/src/main/java/io/confluent/ksql/rest/server/computation/CommandIdAssigner.java
Show resolved
Hide resolved
...rc/test/java/io/confluent/ksql/rest/server/computation/InteractiveStatementExecutorTest.java
Show resolved
Hide resolved
ksql-rest-app/src/test/java/io/confluent/ksql/rest/server/resources/KsqlResourceTest.java
Show resolved
Hide resolved
Conflicting files ksql-rest-app/src/test/java/io/confluent/ksql/rest/server/computation/InteractiveStatementExecutorTest.java
As per discussion confluentinc#3944 (comment) This PR switching the `TERMINATE ALL` functionality to write a `TERMINATE <querId>` command to the command topic for each active query, rather than a single `TERMINATE ALL` command. The reasoning behind this is that it we _want_ the command topic to be key compacted, and such a design works better with this plan.
Description
While investigating an race condition around creating streams I was pained by the process of clearing down my KSQL instance so that I can re-run my test. Before I could drop any sources I had to
show queries
and then cut / past each query intoTERMINATE <id>
statements. A right pain!You can now issue
TERMINATE ALL
to terminate all running queries.cc @derekjn @MichaelDrogalis for product review
BREAKING CHANGE:
ALL
is now a reserved word and can not be used for identifiers without being quoted.This should help with #2177 too. Not a solution, but helps...
We may choose to add
DROP ALL
as well. Meaning to reset your KSQL cluster you just need to executeTERMINATE ALL; DROP ALL;
Testing done
usual
Reviewer checklist