Repository navigation
fix(impala): stop SQL Lab queries while their results are being fetched - #45859
rebenitez1802 wants to merge 1 commit into
Conversation
Impala reports a streaming SELECT as finished once its rows can be fetched, so most of such a query runs while the worker reads results, after handle_cursor stopped polling. A stop in that phase marked the query stopped while Impala kept executing it and held its admission slot. The worker now checks for a committed stop between the result RPCs of a SQL Lab fetch and cancels the operation on its own cursor, as handle_cursor does while polling, and handle_cursor checks once more when polling ends. A failed check rolls its transaction back and lets the fetch continue, while a time limit raised during a check still propagates. The async SQLExecutor task reports a fetch that failed because of a stop as the stop rather than as an unhandled error, reading only the query's status so a genuine failure keeps the statement it was executing. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45859 +/- ##
=======================================
Coverage 84.70% 84.70%
=======================================
Files 3069 3069
Lines 205597 205665 +68
Branches 48327 48334 +7
=======================================
+ Hits 174148 174208 +60
- Misses 28157 28163 +6
- Partials 3292 3294 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
aminghadersohi
left a comment
There was a problem hiding this comment.
Two non-blocking issues in the new stop path: unrelated failures lose their diagnostics, and the documented timeout bound disappears at zero.
| level=ErrorLevel.ERROR, | ||
| ) | ||
| ) from ex | ||
| except Exception: |
There was a problem hiding this comment.
If Stop races a real fetch or result-conversion failure (e.g. MemoryError), this handler drops its traceback and error_sqllab_unhandled metric for every engine. Preserve diagnostics for errors unrelated to cancellation.
| RPC returns within Impala's `FETCH_ROWS_TIMEOUT_MS` query option (10 seconds by | ||
| default, available from Impala 3.4) even when no rows are ready, so a stop takes | ||
| effect within about `FETCH_ROWS_TIMEOUT_MS` plus `DB_POLL_INTERVAL_SECONDS`; | ||
| lowering either makes stops take effect sooner. Impala checks for cancellation between row batches, so a batch whose |
There was a problem hiding this comment.
FETCH_ROWS_TIMEOUT_MS=0 makes fetch requests wait indefinitely, so lowering it to zero can prevent Stop from being observed until the fetch returns. The tuning guidance needs to require a positive value.
| RPC returns within Impala's `FETCH_ROWS_TIMEOUT_MS` query option (10 seconds by | |
| default, available from Impala 3.4) even when no rows are ready, so a stop takes | |
| effect within about `FETCH_ROWS_TIMEOUT_MS` plus `DB_POLL_INTERVAL_SECONDS`; | |
| lowering either makes stops take effect sooner. Impala checks for cancellation between row batches, so a batch whose | |
| RPC returns within Impala's `FETCH_ROWS_TIMEOUT_MS` query option (10 seconds by | |
| default, available from Impala 3.4) when it is positive, even when no rows are ready, | |
| so a stop takes effect within about that timeout plus `DB_POLL_INTERVAL_SECONDS`. | |
| Lowering a positive timeout or the poll interval makes stops take effect sooner. | |
| Setting `FETCH_ROWS_TIMEOUT_MS=0` disables the timeout and can delay Stop until the | |
| fetch returns. Impala checks for cancellation between row batches, so a batch whose |
SUMMARY
On Impala, pressing Stop while SQL Lab was reading a query's results marked the query
stopped, but Impala kept executing it and held its admission slot until it finished.UPDATING.mdlisted this as a known gap of #45232.This is the common case for a long
SELECT, not an edge case. Impala reports a streamingSELECTasFINISHEDas soon as its rows can be fetched: about 0.1 s after submission on Impala 4.5.2, with or without result spooling.handle_cursorthen stops polling, and the rest of the query runs while the worker is insidefetch_data. Aggregations and CTAS stayRUNNINGwhile they work, so polling already covered them.Changes
handle_cursorpolled,fetch_datachecks for a committed stop between result RPCs, at most once perDB_POLL_INTERVAL_SECONDS.cancel_operation(), as fix(impala): stop SQL Lab queries through the live cursor only #45232 does while polling. There is no HTTP call to the coordinator and no second connection, so it also works where the web UI is unreachable or the internal-hosts opt-out is off.FETCH_ROWS_TIMEOUT_MS(10 s by default) even when no rows are ready. A stop therefore takes effect within aboutFETCH_ROWS_TIMEOUT_MS+DB_POLL_INTERVAL_SECONDS.handle_cursorchecks again as it finishes. This catches a stop committed during the last poll interval, or before an operation that is alreadyFINISHEDat its first poll.Database.execute_async) reports the stop. It no longer logs an unhandled ERROR with a traceback. Genuine failures keep the SQL of the statement that failed.handle_cursordid not poll.Known limit. Impala checks for cancellation between row batches. A single batch whose rows are slow to compute, such as an expensive function over one batch, runs to the end of that batch first. This is documented.
Overlap with draft #45845. It changes the same Impala engine spec and tests, and replaces the
SoftTimeLimitExceededimport withTIME_LIMIT_EXCEPTIONS. Whichever PR lands second needs to adapt to the other.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Not applicable; there are no UI changes. Here is the backend behaviour on Impala 4.5.2, for a Stop sent 5 s into the fetch of
SET BATCH_SIZE=1; SELECT sleep(1000) AS s, x FROM <200-row table>:stoppedstopped, no rows, no errorTESTING INSTRUCTIONS
Unit tests. They use a fake impyla cursor and need no driver.
Real cluster. These results come from the public Apache Impala 4.5.2 quickstart (
docker/quickstart.ymlat tag4.5.2of apache/impala), with PostgreSQL metadata, a separate Celery worker,IMPALA_CANCEL_QUERY_ALLOW_INTERNAL_HOSTS = False, andDB_POLL_INTERVAL_SECONDS = {"impala": 0.5}. At the default interval of 5 s, release takes up to about 5 s longer.stopped, 0 rows, no errorstoppedDatabase.execute_async+cancel()STOPPED, no worker ERROR logEach Stop was sent 5 s into the fetch, and Impala released the query at the end of the 10 s result RPC in flight. The following were unchanged:
RUNNING(released within 0.4–0.7 s);successresult.ADDITIONAL INFORMATION
🤖 Generated with Claude Code