Finish query only after the results are fully consumed#13055
Finish query only after the results are fully consumed#13055arhimondr merged 1 commit intotrinodb:masterfrom
Conversation
Why this change is needed?In fault tolerant execution we've been using a streaming (direct) exchange to deliver query results to coordinator. With #13025 query results will be delivered using a spooling exchange. Spooling exchanges are closed (wiped out) upon query completion (either success or a failure). It is important not to close a spooling exchange before the query results are fully consumed. To achieve that it is required to only transition a query to a This change also makes the behavior consistent with the |
|
What would happen if a client on purpose reads only a fraction of the result. I think this may be a common use case that a UI tool interacting with Trino (over JDBC or ODBC) just reads a fixed number of rows, up to some limit, even if the result is larger. Would query be marked as FAILED then in Trino? It should not be. |
|
@losipiuk it will be marked as |
38c3d4c to
2827f7d
Compare
core/trino-main/src/main/java/io/trino/execution/QueryStateMachine.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/execution/QueryStateMachine.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
looks like this should be separate commit.
There was a problem hiding this comment.
Or I guess I do not fully understand this change. Can you explain?
There was a problem hiding this comment.
That's a tricky one. For queries with no output stage (e.g.: DDL operations such as DROP TABLE) the exchange is still created. It has to be closed to allow query to finish, otherwise the client will be waiting of ExchangeClient#isBlocked and the query will never finish. The client is closed by the closeExchangeClientIfNecessary. However with this change the query will not transition to the FINISHED state before the results are consumed. So we have to close the ExchangeClient when a query is in FINISHING state to allow the client to pool the results and mark the query as resultsConsumed to allow it to finish.
losipiuk
left a comment
There was a problem hiding this comment.
LGTM but let's sync so I am sure I understand it correctly.
2827f7d to
ffc6dea
Compare
There was a problem hiding this comment.
Actually I prefered previous shape with explanation you put in the PR; maybe just convert it to comment in the code.
No we are closing exchange on ANY state change - which is weird. The question which arises why do we need to open it at all in the first place.
There was a problem hiding this comment.
No we are closing exchange on ANY state change - which is weird.
Yeah, it is weird. For DDL operations it can only be closed once query info is available (to figure out there is no output stage). Essentially this is simply to wait for the query info to become available.
The question which arises why do we need to open it at all in the first place.
I think it is mostly for convenience (creating ExchangeClient lazily is likely to add more complexity)
ffc6dea to
9caf607
Compare
|
Added a comment |
9caf607 to
9b212b4
Compare
|
CI: #1671 |
9b212b4 to
7dd8cb5
Compare
|
please squash before merging. |
This commit makes it consistent with QueryState#FINISHED documentation. This change is needed to allow spooling exchange to be used for query results delivery. Spooling exchanges in fault tolerant execution are closed on query completion. It is important not to close an exchange before the results are fully consumed.
7dd8cb5 to
48ceab5
Compare
This commit makes it consistent with QueryState#FINISHED documentation.
This change is needed to allow spooling exchange to be used for query
results delivery. Spooling exchanges in fault tolerant execution are
closed on query completion. It is important not to close an exchange
before the results are fully consumed.
Improvement
Core engine
With this change a query is considered finished successfully only when the query results are successfully consumed by the client. Before it was possible that a query might've been marked as successful even when client experienced a failure or dropped a connection.
Related issues, pull requests, and links
Documentation
(x) No documentation is needed.
( ) Sufficient documentation is included in this PR.
( ) Documentation PR is available with #prnumber.
( ) Documentation issue #issuenumber is filed, and can be handled later.
Release notes
( ) No release notes entries required.
(x) Release notes entries required with the following suggested text: