AIP-103: Adding ability for per task state key retention from operators#66699
Open
amoghrajesh wants to merge 13 commits into
Open
AIP-103: Adding ability for per task state key retention from operators#66699amoghrajesh wants to merge 13 commits into
amoghrajesh wants to merge 13 commits into
Conversation
…4c-per-key-expiry-task-sdk
Co-authored-by: Wei Lee <weilee.rx@gmail.com>
…4c-per-key-expiry-task-sdk
…4c-per-key-expiry-task-sdk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Built on top of #66463, so only last commit is relevant.
Why?
The global
[state_store] default_retention_daysconfig applies one retention window to every task state key. Some keys have meaningfully different lifetimes, ie: a submitted job ID is useful for the life of a run, while a short lived lock key might need only hours. Adding an ability to express per-key retention without changing the global default for everything.Current behaviour
All task state keys written via
PUT /state/ti/{id}/{key}receiveexpires_at = now + default_retention_days, regardless of the individual key's intended lifetime as done in: #66463.Current behaviour
All task state keys written via
PUT /state/ti/{id}/{key}receiveexpires_at = now + default_retention_days, regardless of the individual key's intended lifetime.Proposed change
Adds an optional
retention_daysfield toTaskStatePutBody. The operator-supplied value always takes precedence over the global config:0-- never expire this key (expires_at = NULL), regardless of the global default.[state_store] default_retention_daysas before.Changes span across the full stack:
TaskStatePutBody,BaseStateBackend.set()/aset(),MetastoreStateBackend._set_task_state()/_aset_task_state(), and the execution API route.User implications / backcompat
None.
BaseStateBackend.set()andaset()gain a newretention_days: int | None = Nonekeyword argument.Usage:
backend.set(..., retention_days=7)to override the retention_days for that field.Testing
Using this dag to set a couple of task_states:
Output:
short_lived_keyhas expiry as tomorrow (may 12)long_lived_keyhas expiry as 05 June (25 days later)no_lifetime_keyhas no lifetime, ie: doesn't expiredefault_lifetime_keyhas lifetime as 30 days (2026-06-10 12:33:41) - defaultWas generative AI tooling used to co-author this PR?
{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.