Repository navigation
feat(gtf): cancel orphaned warehouse queries + dedicated reaper beat job - #43658
Conversation
Two related follow-ups to #43627: - Split reaping onto its own `reap_orphaned_tasks` beat schedule (short cadence) instead of riding `prune_tasks` (a heavy, infrequent retention delete); the two cadences conflicted. - Cancel the abandoned warehouse query of an orphaned task out-of-band. Live cancellation already runs an on_abort handler in the worker, but a dead worker can't; so the cancel handle (database id + engine cancel id) is now persisted on the task at capture — merged into the property cache so the existing is_abortable write flushes it (no extra write) — and the reaper reuses `cancel_chart_query` to kill the query before marking the task FAILURE. Best-effort and engine-gated, matching the live path.
|
Bito Automatic Review Skipped - Branch Excluded |
✅ 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 @@
## gaq-to-gtf #43658 +/- ##
=============================================
Coverage ? 79.27%
=============================================
Files ? 2890
Lines ? 166418
Branches ? 38456
=============================================
Hits ? 131935
Misses ? 32004
Partials ? 2479
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:
|
SUMMARY
Follow-up to #43627 (merged), closing the one gap it explicitly deferred and tightening the reaper's schedule.
1. Cancel the orphaned warehouse query. #43627 made async chart-data query tasks cancellable while the worker is alive (an
on_aborthandler runsdb_engine_spec.cancel_queryover a fresh connection). But when a worker dies, there's no live thread to run that handler, so the reaper only marked theTaskFAILUREand revoked the Celery job — the abandoned warehouse query kept running until the warehouse's own statement/idle timeout. Now the reaper cancels it out-of-band.2. Dedicated reaper beat job. Reaping was folded into
prune_tasks. Reaping wants a short cadence (detect a dead worker — and cancel its query — within ~a minute); retention pruning is a heavy, infrequent bulk DELETE. One shared cadence can't serve both, so reaping now runs on its ownreap_orphaned_tasksbeat schedule.How the orphan-cancel works
The reaper runs in a different process from the dead worker, so the engine cancel-id must be on the
Taskrow:TaskContext.set_cancellation(database_id, cancel_id)merges{cancel_database_id, cancel_query_id}into the property cache. It does not write: the task registers its abort handler immediately after, and thatis_abortablewrite already flushes the whole cache — so the handle is persisted in an existing write, no extra DB write on the hot path. Only engines that expose a cancel-id before execution (Postgres/MySQL/Snowflake/Redshift, as in the live path) persist a handle.ReapOrphanedTasksCommand._reapreads the handle, loads theDatabase, and reuses the existingcancel_chart_query(database, cancel_id)helper (fresh connection, id validation,gtf.query.cancel/gtf.query.cancel_failedmetrics) before the revoke + CAS→FAILURE. Best-effort: no handle, a missing database, or a cancel failure never blocks the FAILURE transition. A dead worker holds no lock on the row, so this is race-free.No new helper, config key, or migration —
cancel_chart_queryand the reaper already exist; this reuses them. The live abort path is unchanged (it still uses the in-memory closure).Scheduling change
reap_orphaned_tasksis a new Celery beat task;prune_tasksreverts to retention-only.CELERY_CONFIG.beat_schedulegains a commentedreap_orphaned_taskstemplate on a short interval (e.g. every minute), separate from theprune_tasksretention template. Docs/UPDATING updated.TESTING INSTRUCTIONS
tests/unit_tests/tasks/):TaskContext.set_cancellationmerges the handle into the cache (persisted by the ensuingis_abortablewrite, existing keys preserved); the capture sink callsset_cancellationbeforeon_abort(and neither without a cancel-id);_reapcallscancel_chart_querywith the persisted(database, cancel_id)when present, skips it when absent or the database is gone, and reaps regardless;reap_orphaned_tasksdelegates to the command.tests/integration_tests/tasks/commands/test_reap.py): an orphan with a persisted handle → the reaper invokescancel_chart_querywith the loadedDatabaseand still ends the rowFAILURE.reap_orphaned_tasksbeat +DISTRIBUTED_COORDINATION_CONFIG, a cancellable engine like Postgres): run an async chart query,kill -9the worker mid-query → withinGTF_ORPHAN_TASK_TIMEOUTthe task isFAILUREand the backend query is gone frompg_stat_activity.ADDITIONAL INFORMATION
GLOBAL_TASK_FRAMEWORK(async chart data also needsGLOBAL_ASYNC_QUERIES)cancel_*handle lives in the existingpropertiesJSON blob — no schema change)