Repository navigation
fix(gtf): wait for the task lock instead of failing concurrent submits - #43492
Conversation
Several charts (or a chart's identical queries) can resolve to the same query_cache_key — hence the same SHARED task and dedup_key — and submit at once (a Deck.GL dashboard trips this readily). task_lock acquired the dedup lock fail-fast (SET NX), so the winner created the task while every concurrent submitter that should simply JOIN it errored out with "Lock already taken", failing the chart. Make task_lock block-and-wait: retry the acquire until the holder releases, then join the now-existing task. Bounded by the lock TTL so a holder that crashed without releasing is waited out (the lock auto-expires) rather than blocking forever, and released with the acquisition's own token (ownership-checked).
|
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. |
… poll loop Replace the bounded retry-poll with CoordinationService.wait_for_signal: the acquire parks on the lock's release-signal Redis Stream and retries the SET NX when the holder releases (event-driven, no busy-poll), and release now notify()s that stream so a waiter wakes immediately. This reuses the same await/notify mechanism GTF task-completion already uses — the plumbing existed, the lock just wasn't wired to it. Both deployment modes are covered by the one call: wait_for_signal is event-driven with a coordination backend and falls back to polling the acquire without one (so DB-metastore deployments still wait rather than fail). notify() is guarded on is_backend_defined() since there's no stream to signal otherwise. The wait window is sized comfortably above the TTL + stream block interval so a lock orphaned by a crashed holder is still waited out at TTL expiry.
Subscriber count captures distinct subscribers but misses a subscriber resubmitting the same task, so it undercounts how often a SHARED task's work is reused. Add a dedupe_count in the task's existing properties JSON (no new column): seeded to 0 on creation and bumped whenever a submit finds an existing task and joins it — whether it becomes a new subscriber or resubmits as an existing one (both reuse the work rather than re-create it). The increment runs under the dedup lock, so the read-modify-write can't race. Found while testing the Deck.GL demo dashboard, where three charts share one query object → one SHARED task with two joins (dedupe_count = 2).
When a task's dedupe_count is > 0 (other submissions reused it instead of running a new query), show a copy icon + the count in the Details column, with a tooltip explaining it. Conditional like the other Details indicators — unique tasks show nothing. Adds dedupe_count to the frontend TaskProperties type.
A copy icon read as "copy to clipboard"; a plus reads as "N more submissions joined this task", matching the dedupe semantics.
|
/review |
Code Review Agent Run #49e41cActionable Suggestions - 0Additional Suggestions - 1
Filtered by Review RulesBito filtered these suggestions based on rules created automatically for your feedback. Manage rules.
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## gaq-to-gtf #43492 +/- ##
==============================================
- Coverage 78.91% 78.86% -0.06%
==============================================
Files 2884 2883 -1
Lines 165197 164798 -399
Branches 38150 38076 -74
==============================================
- Hits 130364 129962 -402
- Misses 32381 32389 +8
+ Partials 2452 2447 -5
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
Targets
gaq-to-gtf. Loading a Deck.GL chart (and dashboards generally) could fail with a spurious{"message": "Lock already taken"}error.Several charts — or a chart's identical queries — can resolve to the same
query_cache_key, so they map to the same SHARED GTF task and the samededup_key, and submit concurrently.task_lockacquired that dedup lock fail-fast (RedisSET NX), so the first submitter won the lock and created the task, while every other concurrent submitter — which should simply join/subscribe to that shared task — hitLockAlreadyHeldExceptionand errored out, failing the chart.Found while testing the Deck.GL demo dashboard, where three charts share the same query object — so all three resolve to one SHARED task and submit at once; the two that lost the lock race errored with "Lock already taken".
The fix — wait for the lock instead of failing.
task_locknow blocks and waits, then joins the now-existing task. The wait is delegated toCoordinationService.wait_for_signal: event-driven on the lock's release-signal Redis Stream when a coordination backend is configured (releasenotify()s it), and a poll fallback otherwise — reusing the same await/notify mechanism GTF task-completion already uses. It's bounded (past the TTL) so a holder that crashed without releasing is waited out via the lock's auto-expiry rather than blocking forever, and released with the acquisition's own token (ownership-checked).Bonus — track and surface dedupe hits. Every submit that joins an existing task (a new subscriber or an existing subscriber's resubmit) now bumps a
dedupe_counton the task'sproperties(seeded to 0 at creation, no new column). When it's > 0 the Task List Details column shows a plus icon + the count with a tooltip, so you can see when one shared task served several chart requests.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
Task List Details showing the
+1dedupe indicator on hover:TESTING INSTRUCTIONS
pytest tests/unit_tests/tasks/test_locks.py— a held lock is retried then acquired (concurrent submit joins); a lock still held past the wait window re-raises; andnotifyis skipped without a coordination backend.pytest tests/integration_tests/tasks/commands/test_submit.py -k joins_existing— a resubmit joins the existing task and bumpsdedupe_count(seeded 0 → 1).npm run test -- src/pages/TaskList/TaskList.test.tsx— the Details column shows the dedupe indicator whendedupe_count > 0.GLOBAL_ASYNC_QUERIESon — the charts load instead of erroring with "Lock already taken", and the shared task shows a dedupe count.ADDITIONAL INFORMATION
GLOBAL_ASYNC_QUERIES