Skip to content

cache.config -> cache.yaml - #13456

Open
bneradt wants to merge 2 commits into
apache:masterfrom
bneradt:cache-yaml-first-match
Open

bneradt wants to merge 2 commits into
apache:masterfrom
bneradt:cache-yaml-first-match

Conversation

@bneradt

@bneradt bneradt commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

cache.config needs to move to cache.yaml, with a supported migration
path for existing deployments. cache.yaml becomes the default format,
while cache.config remains available when explicitly selected.

This adds a shared cache parser and marshaller used by traffic_server
and traffic_ctl. The new traffic_ctl config convert cache command
converts legacy files to cache.yaml or writes the result to stdout.

This also addresses #7701 by giving cache.yaml ordered, first-match
semantics, so broader rules no longer compound actions after a specific
match. The legacy cache.config parser retains its additive behavior.

Fixes: #7701

Copilot AI lite review requested due to automatic review settings July 30, 2026 01:39
@bneradt bneradt added this to the 11.0.0 milestone Jul 30, 2026
@bneradt bneradt self-assigned this Jul 30, 2026

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bneradt
bneradt marked this pull request as draft July 30, 2026 02:00
@bneradt
bneradt force-pushed the cache-yaml-first-match branch from 08ede5a to cc239f8 Compare July 30, 2026 02:25
@bneradt
bneradt marked this pull request as ready for review July 30, 2026 02:26
Copilot AI review requested due to automatic review settings July 30, 2026 02:26

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@bneradt bneradt changed the title Add first-match cache.yaml rules cache.config -> cache.yaml Jul 30, 2026
@bneradt
bneradt force-pushed the cache-yaml-first-match branch from cc239f8 to ce8a0e7 Compare July 30, 2026 03:03
@maskit
maskit requested a review from Copilot July 30, 2026 17:55

Copilot AI 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.

Pull request overview

Copilot reviewed 42 out of 42 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

doc/developer-guide/cache-architecture/architecture.en.rst:481

  • This statement is too absolute: cache pinning is driven by the cache rule configuration selected by proxy.config.cache.control.filename. During migration, pinning can still be configured via legacy cache.config when explicitly selected, so the docs should not imply cache.yaml is the only option.
Objects can only be pinned via :file:`cache.yaml` and while
:ts:cv:`proxy.config.cache.permit.pinning` is set to non-zero (it is zero by

doc/developer-guide/cache-architecture/architecture.en.rst:105

  • The sentence mixes plural subject with singular verb ("are derived" ... "is recomputed") and it reads as if only cache.yaml can drive cache layout. ATS can still be configured to use legacy cache.config via proxy.config.cache.control.filename, so this paragraph should refer to the cache rule configuration generally and fix the grammar.

This issue also appears on line 480 of the same file.

The layout and structure of the cache spans, the cache volumes, and the cache
stripes that compose them are derived entirely from :file:`storage.yaml` and
:file:`cache.yaml` and is recomputed from scratch when the
:program:`traffic_server` is started. Therefore, any change to those files can
(and almost always will) invalidate the existing cache in its entirety.

doc/developer-guide/cache-architecture/data-structures.en.rst:101

  • CacheControlResult is used for both cache.yaml rules and legacy cache.config entries (depending on proxy.config.cache.control.filename). The description should avoid implying it only applies to cache.yaml.
   Holds the actions and match state from a rule in :file:`cache.yaml`.

@cmcfarlen
cmcfarlen self-requested a review August 3, 2026 22:50

@cmcfarlen cmcfarlen 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 core of this is well built — the first-match implementation in particular is subtler than it looks and it's correct. My concerns are all on the migration side: the default filename moves, and I don't think an existing deployment finds out what happened.

The design is sound

Worth saying explicitly since it's the part most likely to draw scrutiny: parsing YAML, re-serializing to legacy matcher text in build_matcher_config(), and feeding that to BuildTableFromString() is a pragmatic way to reuse ControlMatcher without forking it.

And the first-match semantics are implemented in the one way that actually works. CheckForMatch(h_rdata, result->matched_rule_line) resolves to (last_number < 0 || last_number > this->line_num) && CheckModifiers(...), so the lowest line number wins, and since build_matcher_config() emits rules in document order, ordering is preserved across the host / ip / regex / host_regex / url sub-tables rather than depending on which table ControlMatcher happens to consult first. That's the trap here and you avoided it.

I also checked two things that looked risky and aren't:

  • quote_matcher_value() escapes \ and ", and parseConfigLine()'s PARSE_VAL state unescapes exactly those inside quotes (MatcherUtils.cc:495-527). So regexes with backslashes survive the text round-trip.
  • A maximally-specified rule emits ~18 tokens against MATCHER_MAX_TOKENS = 40. Plenty of headroom.

1. An existing deployment silently loses every cache rule

Filenames.h flips the default:

-  constexpr const char *CACHE         = "cache.config";
+  constexpr const char *CACHE         = "cache.yaml";

Consider the common upgrade: cache.config on disk, no explicit proxy.config.cache.control.filename in records.yaml. After upgrade, load_cache_control_table() resolves cache.yaml, hits result.file_not_found, logs

Cannot open cache configuration /etc/trafficserver/cache.yaml

at DL_Warning, and returns the empty DONT_BUILD_TABLE table. Every rule the operator had stops applying, and the only signal is one warning naming a file they never created and don't expect to exist.

The failure is asymmetric in the bad direction: a never-cache rule quietly becoming "cache normally" is a correctness and potentially privacy problem, not a performance regression. Same for pin-in-cache and ttl-in-cache disappearing.

The fix is small and self-contained — when the configured path ends in .yaml/.yml and is absent, check for a sibling cache.config, and if it's there make the message say so:

Cannot open cache configuration /etc/trafficserver/cache.yaml, but
/etc/trafficserver/cache.config exists. cache.yaml is now the default;
convert with 'traffic_ctl config convert cache cache.config cache.yaml'
(note: cache.yaml uses first-match semantics), or set
proxy.config.cache.control.filename to cache.config.

That turns a silent misconfiguration into an actionable one, which for a default-flipping change feels like the minimum bar.

2. Nothing in the upgrading guide

The .. deprecated:: 11.0 block you added to the cache.config page is genuinely good — it names the converter and tells operators to review overlapping rules. But it's on the reference page for the legacy file, which is not where someone planning an upgrade looks.

whats-new.en.rst gets five lines, and that's a feature announcement, not an upgrade instruction. doc/release-notes/upgrading.en.rst isn't touched at all.

Having just written the 10.2.0 release notes and upgrading guide, this is squarely the class of change that upgrading exists for: the default config filename changed, an existing file is no longer read unless a record is set, and converting changes rule-matching behavior. All three belong there, ideally with the records setting spelled out as the no-op escape hatch for operators who want to defer.

3. The converter doesn't mention that it can't preserve behavior

convert_cache() parses, marshals, writes, and prints Converted <in> -> <out>. Searching src/config/ and src/traffic_ctl/ for first.match, additive, or semantic finds nothing.

The conversion is faithful syntactically and cannot be faithful semantically — a legacy file with two overlapping rules composed both actions, and the converted file will apply only the first. That asymmetry is the one thing the tool is uniquely positioned to say, at the moment the operator is paying attention.

Minimum viable version: if the input parsed to two or more rules, print a note pointing at the docs. Better: flag pairs that could both match — same primary key type, or one rule's match set being a subset of another's — and name the line numbers so the operator knows where to look. Even a crude over-approximation is more useful than silence, because the operator can rule out false positives and can't discover false negatives.

4. The legacy runtime path has no end-to-end coverage left

negative-caching.test.py and cache_config_reload.test.py were both converted to cache.yaml. After this PR the only cache.config references under tests/gold_tests/ are trafficserver.test.ext (the harness's file definition) and convert_cache/, which never starts ATS against one.

So the additive legacy parser — what every deployment runs today, and which this PR deliberately keeps supported — has nothing verifying that ATS still honors it. The unit tests are good on parsing and marshalling (six cases including full legacy field coverage and a round-trip), but none of them pin the runtime semantics, and that's where the two formats now deliberately differ.

A change that accidentally routed cache.config through the first-match path would pass CI today. Since divergent semantics is the headline of the PR, it deserves a test that fails when it stops being true — ideally a paired one: identical rule sets in both formats, asserting composed actions for .config and first-match-only for .yaml. Keeping one of the two converted tests on cache.config would also do.

Smaller items

  • Newlines aren't escaped. quote_matcher_value() handles \ and ", but matcher_config is line-oriented and a YAML value containing a newline (trivial with a quoted scalar) would split a rule across lines and misparse. Cheapest fix is rejecting embedded newlines in CacheConfigParser with a clear error.
  • convert_cache() doesn't check the output stream. out << yaml_output << '\n'; out.close(); then reports success. A full disk or quota yields a truncated cache.yaml plus Converted .... Worth testing out after close before printing.
  • Both the file and stdout paths append '\n' after to_yaml(). If to_yaml() already newline-terminates, every converted file gains a trailing blank line.
  • whats-new.en.rst and cache.config.en.rst each lose their trailing blank line — incidental churn.
  • The branch is 270 commits behind master and will need a rebase; whats-new.en.rst is a frequent conflict point, so sooner is easier.

@bneradt
bneradt force-pushed the cache-yaml-first-match branch from ce8a0e7 to 626eab0 Compare September 1, 2026 20:36
Copilot AI review requested due to automatic review settings September 1, 2026 20:36
@bneradt

bneradt commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback and force-pushed the rebased commit 626eab03d0:

  • Added an actionable startup warning when the configured YAML file is absent but a sibling cache.config exists, including the converter command and the legacy-record escape hatch.
  • Documented the new default, migration command, semantic difference, and legacy compatibility in the upgrading and cache configuration docs.
  • Made the converter warn when multiple legacy rules may change behavior under YAML first-match semantics.
  • Added paired runtime coverage demonstrating YAML first-match behavior and legacy additive behavior for equivalent rules.
  • Tightened converter behavior: reject embedded newlines, emit exactly one trailing newline, validate output/write completion, and cover /dev/full failure.
  • Rebased the PR onto current master.

Validation in the asfats5 container:

  • Full configure, format, build, and install: passed.
  • test_tsconfig "[cache][config]": 63 assertions in 6 test cases passed.
  • Focused AuTests cache-yaml and convert_cache: 2/2 passed.

Copilot AI 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.

🔵 Needs a closer look

Review details
  • Files reviewed: 44/44 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@bneradt
bneradt force-pushed the cache-yaml-first-match branch from 626eab0 to 25c6840 Compare September 1, 2026 21:15
Copilot AI review requested due to automatic review settings September 1, 2026 21:15

Copilot AI 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.

🟡 Changes recommended

The current YAML pipeline drops internal: false semantics due to incorrect std::optional<bool> presence checks, which can change rule matching behavior and conversion output.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 46/46 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread src/config/cache.cc Resolved
Comment thread src/proxy/CacheControl.cc Resolved
Copilot AI lite review requested due to automatic review settings October 2, 2026 18:05
@bneradt
bneradt force-pushed the cache-yaml-first-match branch from 0196d33 to 173069a Compare October 2, 2026 18:05

Copilot AI 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.

Comment thread src/proxy/CacheControl.cc Resolved
Comment thread src/config/cache.cc Resolved
@bneradt
bneradt force-pushed the cache-yaml-first-match branch from 173069a to f908b64 Compare October 26, 2026 20:53
Copilot AI lite review requested due to automatic review settings October 26, 2026 20:53

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@cmcfarlen cmcfarlen 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.

Thanks for working through all of this — the sibling cache.config warning, the converter's first-match warning, and the paired additive/first-match Uranium tests are exactly what I was hoping for, and the stream and newline fixes look right.

A few things before this goes in:

  1. The legacy exact-URL url= selector has no migration path. The runtime accepts it (http_dest_tags includes url), but CacheConfigParser's legacy reader reports it as an unknown key, and cache.yaml has no field for it. So traffic_ctl config convert cache fails on any file using it, and there's nothing to write by hand either. tests/uranium_tests/cache/replay/cache-exact-url.test.yaml (url=http://...{SERVER_HTTP_PORT}/exact action=never-cache) only passes because replay.py keeps it on cache.config. This was Copilot's 10/02 comment on cache.cc, which never got a reply. Adding an exact url match key, and converting that test to cache_yaml, would close it.
  2. The upgrading note is under "Upgrading to ATS v10.x › Changes to Features", right after the 10.0 JSON-RPC entry. It belongs in the v11.x section, probably "Configuration Changes".
  3. The branch conflicts with master, and this push predates the URTest job, so cache-config-additive and cache-yaml-first-match haven't run in CI yet. They're the tests that pin the semantic split, so a rebase plus [approve ci urtest] would be good.

On Copilot's 10/02 comment that first-match breaks across matcher types: I don't think it's right. CheckForMatch(h_rdata, result->matched_rule_line) only accepts a rule whose line comes before the current best match, and an accepted rule replaces the whole result. So a later dest_domain match from the host table is overwritten when the earlier url_regex rule matches in the regex pass, whatever order ControlMatcher::Match() visits the tables in.

Nit: cache.config.en.rst and whats-new.en.rst still drop their trailing blank line.

@bneradt
bneradt force-pushed the cache-yaml-first-match branch from f908b64 to 22965ba Compare November 3, 2026 16:31
Copilot AI lite review requested due to automatic review settings November 3, 2026 16:31
@bneradt

bneradt commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I rebased onto current master and force-pushed 22965ba.

  1. Exact-URL url= selector: cache.yaml now supports an exact url primary match key. It is parsed, converted from legacy url=, marshalled, and passed to the runtime URL table. cache-exact-url.test.yaml now uses cache_yaml, and the legacy-fields unit test round trips a url= rule.
  2. Upgrading note: moved from "Upgrading to ATS v10.x › Changes to Features" to the v11.x "Configuration Changes" section.
  3. Rebase: done. The only conflict was in tests/tools/uranium/tests/test_replay.py. I kept master's [None, False, True] stop_after_client parametrization and the PR's new cache-format test. The new URTest CI job will run cache-config-additive and cache-yaml-first-match on this push.
  4. Nit: cache.config.en.rst and whats-new.en.rst keep their trailing blank lines again.

I agree with your reading of Copilot's first-match comment and replied on that thread.

Local validation in a Fedora container: build, install, and docs build passed. 92 Cache ctests and 161 test_tsconfig|test_ControlMatcher|test_proxy ctests passed. 211 cache, convert, config_reload, and replay/services urtests passed. One failure was a microdns port collision from a concurrent run, and that test passed on rerun.

@bneradt
bneradt requested a review from cmcfarlen November 3, 2026 16:32
Copilot stopped reviewing on behalf of bneradt due to an error November 3, 2026 16:42

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@bneradt

bneradt commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

[approve ci urtest 3]

@bneradt

bneradt commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

[approve ci urtest]

@cmcfarlen cmcfarlen 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.

Thanks, both rounds are resolved, including exact url=, and you're right about CacheControl.cc:574; I'll resolve that thread. One remaining gap in R1.1: install_configs.cmake installs cache.yaml.default as cache.yaml when none exists (packages will do the same, since it's a new file), so an upgrade over an install with only a cache.config ends up with a valid cache: []. The file_not_found branch never runs, and the legacy never-cache rules are dropped silently. The uranium harness already works around exactly this. Could the sibling-cache.config warning also fire when the YAML yields 0 rules and a non-empty cache.config sits next to it?

Minor: dest_ip rules with overlapping ranges don't follow first-match, because IpMatcher keeps only the most recently added rule for an address. That's the same as legacy cache.config, so a doc caveat is enough. Also, the primary-key list in cache.yaml.default leaves out url.

@bryancall

Copy link
Copy Markdown
Contributor

[approve ci doxygen]

@bneradt
bneradt force-pushed the cache-yaml-first-match branch from 22965ba to ac18c44 Compare November 9, 2026 21:22
@bneradt

bneradt commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

[approve ci format]

@cmcfarlen

Copy link
Copy Markdown
Contributor

The last push looks like a rebase only. The 11-09 items are still open: the zero-rule cache.yaml next to a non-empty cache.config case (the installed default makes file_not_found unreachable on upgrade), url missing from the primary-key list in cache.yaml.default, and the dest_ip overlap caveat.

@bneradt
bneradt force-pushed the cache-yaml-first-match branch from ac18c44 to 4a7fedf Compare November 13, 2026 20:21
bneradt and others added 2 commits November 18, 2026 13:07
cache.config needs to move to cache.yaml, with a supported migration
path for existing deployments. cache.yaml becomes the default format,
while cache.config remains available when explicitly selected.

This adds a shared cache parser and marshaller used by traffic_server
and traffic_ctl. The new `traffic_ctl config convert cache` command
converts legacy files to cache.yaml or writes the result to stdout.

This also addresses apache#7701 by giving cache.yaml ordered, first-match
semantics, so broader rules no longer compound actions after a specific
match. The legacy cache.config parser retains its additive behavior.

Fixes: apache#7701

Co-authored-by: Codex GPT-6.1 Sol High
Co-authored-by: GPT-6 Astra Medium
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Doxygen rejects a second @section license label, so the Doxygen check
failed once cache.h and cache.cc both declared one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@bneradt
bneradt force-pushed the cache-yaml-first-match branch from 4a7fedf to efa880f Compare November 18, 2026 19:07
@bneradt

bneradt commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

@cmcfarlen Thanks, and sorry the last push was only a rebase. All three 11-09 items are addressed in 28ccf55, the main commit. Head is now efa880f, rebased onto current master.

  1. Rule-free cache.yaml next to a non-empty cache.config: the sibling check in CacheControl.cc now runs in two cases: when the configured YAML file is missing, and when it parses to zero rules. In both cases it warns if a cache.config in the same directory has at least one rule line, meaning a line that is not blank and not a comment. A stock, comment-only cache.config does not trigger it. The warning names both files, gives the converter command, and names the proxy.config.cache.control.filename escape hatch. Because it is part of table loading, it fires on reload as well as at startup. Two new Uranium tests cover this:

    • cache-yaml-empty-legacy-sibling sets up the upgrade layout: cache: [] plus a cache.config with a never-cache rule, and the filename left at its default. It asserts the warning is in diags.log, and that the response is still cached, which shows the legacy rule is not applied.
    • cache-yaml-empty-legacy-comments checks that a comment-only cache.config does not produce the warning.

    The upgrading guide now describes the warning too.

  2. url in the primary-key list: added to the comment in configs/cache.yaml.default.

  3. dest_ip overlap caveat: a note in cache.yaml.en.rst, under "First Matching Rule", explains it. When dest_ip ranges overlap, only the last-listed rule is considered for an address in the overlap, same as cache.config. The note suggests non-overlapping ranges or a secondary key.

The rebase also picks up the Ruff and cmakefmt format changes. The only reformatted files in this PR were src/config/CMakeLists.txt and src/proxy/CMakeLists.txt.

Local validation in a Fedora CI container: format, build, and install passed. 216 cache, convert_cache, config-reload, and replay/services urtests passed, including the two new ones. A first run at -n 12 hit port collisions from other runs sharing the host, and those tests passed on rerun.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When rewriting cache.config in YAML, make it not additive.

4 participants