Skip to content

Allow DBDagBag TTL cache eviction without a size cap - #69774

Open
aeroyorch wants to merge 4 commits into
apache:mainfrom
aeroyorch:dbdagbag-ttl-only-cache
Open

Allow DBDagBag TTL cache eviction without a size cap#69774
aeroyorch wants to merge 4 commits into
apache:mainfrom
aeroyorch:dbdagbag-ttl-only-cache

Conversation

@aeroyorch

@aeroyorch aeroyorch commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Allow DBDagBag TTL cache eviction without a size cap (i.e. cache_size=0, cache_ttl>0).

Related to #69001 and #69007

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Claude Opus 4.8 to analyze the impact of this change in terms of docs/code.


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {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.

@aeroyorch
aeroyorch requested review from XD-DENG and ashb as code owners July 12, 2026 12:04
@aeroyorch
aeroyorch force-pushed the dbdagbag-ttl-only-cache branch 2 times, most recently from 379aa9e to a112469 Compare July 12, 2026 12:12
@aeroyorch aeroyorch changed the title Allow DBDagBag TTL cache eviction without a size cap Allow DBDagBag TTL cache eviction without a size cap Jul 12, 2026

@SameerMesiah97 SameerMesiah97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one nit. Looks good otherwise.

Comment thread airflow-core/src/airflow/models/dagbag.py Outdated
@aeroyorch

Copy link
Copy Markdown
Contributor Author

Just one nit. Looks good otherwise.

Thanks for the review! Changes already implemented

@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 15, 2026
@jason810496
jason810496 self-requested a review July 16, 2026 13:03
@aeroyorch
aeroyorch requested a review from SameerMesiah97 July 18, 2026 09:53
@lohyenshen

Copy link
Copy Markdown

hi, may I know what airflow version would this be released to?

@aeroyorch
aeroyorch force-pushed the dbdagbag-ttl-only-cache branch from 5b5ca6c to d65c199 Compare July 25, 2026 15:24

@vatsrahul1001 vatsrahul1001 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DBDagBag fix itself looks right, but I don't think it's reachable from the actual config path yet. create_dag_bag() in api_fastapi/common/dagbag.py still does:

if cache_size <= 0:
    return DBDagBag(cache_size=0)

That early-return fires whenever dag_cache_size <= 0 and never even reads cache_ttl_config, so setting dag_cache_size = 0 + dag_cache_ttl = 3600 in airflow.cfg still ends up as a plain unbounded dict with no eviction. test_create_dag_bag_cache_modes still asserts exactly that (the "size_zero_unbounded" case expects dict/_use_cache=False for cache_size=0, cache_ttl=3600), and config.yml's dag_cache_size description still says 0 means "unbounded dict, no eviction" with no mention of TTL-only mode.

Could you also update create_dag_bag() to pass cache_ttl through when cache_size<=0, add a case to test_create_dag_bag_cache_modes covering that combo, and touch up the config.yml wording? Otherwise this fix isn't actually reachable by anyone configuring it through airflow.cfg.

@aeroyorch
aeroyorch force-pushed the dbdagbag-ttl-only-cache branch from d65c199 to bebd4df Compare July 31, 2026 08:23
@aeroyorch
aeroyorch force-pushed the dbdagbag-ttl-only-cache branch 2 times, most recently from 68f1a7a to 2432fa4 Compare August 2, 2026 10:43
@aeroyorch

aeroyorch commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

The DBDagBag fix itself looks right, but I don't think it's reachable from the actual config path yet. create_dag_bag() in api_fastapi/common/dagbag.py still does:

if cache_size <= 0:
    return DBDagBag(cache_size=0)

That early-return fires whenever dag_cache_size <= 0 and never even reads cache_ttl_config, so setting dag_cache_size = 0 + dag_cache_ttl = 3600 in airflow.cfg still ends up as a plain unbounded dict with no eviction. test_create_dag_bag_cache_modes still asserts exactly that (the "size_zero_unbounded" case expects dict/_use_cache=False for cache_size=0, cache_ttl=3600), and config.yml's dag_cache_size description still says 0 means "unbounded dict, no eviction" with no mention of TTL-only mode.

Could you also update create_dag_bag() to pass cache_ttl through when cache_size<=0, add a case to test_create_dag_bag_cache_modes covering that combo, and touch up the config.yml wording? Otherwise this fix isn't actually reachable by anyone configuring it through airflow.cfg.

Thanks for the review. Changes already implemented :)

@aeroyorch
aeroyorch requested a review from vatsrahul1001 August 3, 2026 08:01
@eladkal eladkal added this to the Airflow 3.3.1 milestone Aug 4, 2026
@eladkal eladkal added type:bug-fix Changelog: Bug Fixes backport-to-v3-3-test Backport to v3-3-test labels Aug 4, 2026
@vatsrahul1001

vatsrahul1001 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

LGTM!, can be merged after code owners review

@vatsrahul1001

Copy link
Copy Markdown
Contributor

Moving to 3.3.2 as this is still pending code owner review and do not want to rush on merging this as it not critical

@aeroyorch

Copy link
Copy Markdown
Contributor Author

Moving to 3.3.2 as this is still pending code owner review and do not want to rush on merging this as it not critical

No problem. In the meantime, I can work on some of the other items to fix #69001

Comment thread airflow-core/src/airflow/api_fastapi/common/dagbag.py
Comment thread airflow-core/src/airflow/config_templates/config.yml
Comment thread airflow-core/docs/faq.rst Outdated
@aeroyorch
aeroyorch force-pushed the dbdagbag-ttl-only-cache branch from c55fa9a to 1a6f6e7 Compare August 8, 2026 15:17
@aeroyorch
aeroyorch requested a review from kaxil August 8, 2026 15:18

@ColtenOuO ColtenOuO left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and Thanks for the improvement! I actually just noticed this issue myself, and was glad to see someone was already working on a fix!

Just a small idea, feel free to take it or leave it if it doesn't quite fit!

Would it make sense to move the warning logs into DBDagBag.__init__ itself? To fully close out #69001, this change will eventually need to be wired up to the Scheduler too , and at that point we'd want to warn users about the exact same negative-value cases again. If the warning lived inside DBDagBag.__init__ from the start, it'd be a lot easier to keep things consistent as more callers get hooked up down the road , one place to maintain, and no risk of some future caller quietly forgetting to warn.

The trade-off is we'd lose the ability to tell the user exactly which config option was the problem (e.g. [api] dag_cache_size vs. a future [scheduler] dag_bag_cache_size)

@aeroyorch

Copy link
Copy Markdown
Contributor Author

LGTM and Thanks for the improvement! I actually just noticed this issue myself, and was glad to see someone was already working on a fix!

Just a small idea, feel free to take it or leave it if it doesn't quite fit!

Would it make sense to move the warning logs into DBDagBag.__init__ itself? To fully close out #69001, this change will eventually need to be wired up to the Scheduler too , and at that point we'd want to warn users about the exact same negative-value cases again. If the warning lived inside DBDagBag.__init__ from the start, it'd be a lot easier to keep things consistent as more callers get hooked up down the road , one place to maintain, and no risk of some future caller quietly forgetting to warn.

The trade-off is we'd lose the ability to tell the user exactly which config option was the problem (e.g. [api] dag_cache_size vs. a future [scheduler] dag_bag_cache_size)

Thanks for the review!

Fair point, but I'd rather leave it as is for now, the trade-off you mention is the deciding one for me: keeping it at the call site lets us name the actual config option that's wrong, which is what the user needs to fix.

Happy to revisit when the Scheduler part lands for #69001.

@aeroyorch
aeroyorch force-pushed the dbdagbag-ttl-only-cache branch from 1a6f6e7 to 28a8c01 Compare August 12, 2026 23:21

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind giving more context as to why we are doing this. If you use case is "LRU evicts my hot dags too aggressively", tweaking the settings for your use case is probably better.

It looks like we are introducing back the memory leak this bounded cache was fixing in the first place. I don't think we should allow unbouded cache there.

@aeroyorch

Copy link
Copy Markdown
Contributor Author

Do you mind giving more context as to why we are doing this. If you use case is "LRU evicts my hot dags too aggressively", tweaking the settings for your use case is probably better.

It looks like we are introducing back the memory leak this bounded cache was fixing in the first place. I don't think we should allow unbouded cache there.

Hi Pierre, sure.

I don't think this brings back the leak. Today cache_size=0 is a plain dict with no eviction at all. With this change, cache_size=0 + cache_ttl>0 creates a real TTLCache. That evicts exactly what grows and keeps the hot ones. Defaults don't change.

Tuning the size doesn't really help here: the scheduler cycles through all active dag_version_ids, so any cap below the active set evicts each key just before it's needed again. @kaxil raised this in the #69007 review and @potiuk asked for TTL eviction without a size cap in DBDagBag as a first step.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v3-3-test Backport to v3-3-test ready for maintainer review Set after triaging when all criteria pass. type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants