Skip to content

branch-4.1: [fix](filecache) convert blocks back to TTL when an expired TTL is extended #67971 - #68092

Open
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-67971-branch-4.1
Open

github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-67971-branch-4.1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #67971

…tended (#67971)

### What problem does this PR solve?

Issue Number: None

Related PR: None

Problem Summary:

`BlockFileCacheTtlMgr` decided whether to promote a tablet's cached
blocks into the TTL queue from `was_zero_ttl`, which is true only when
`_ttl_info_map` holds no entry for the tablet. Since the entry is erased
only when the tablet's TTL is zero, that flag really answers "has this
BE ever seen a non-zero TTL here", not "are the blocks outside the TTL
queue".

The expiration check demotes blocks back to NORMAL but leaves the
non-zero TTL in the map. So once a TTL expired, the promotion path was
closed for that tablet for good: extending the expired TTL to a value
that has not expired updated FE, Meta Service and `_ttl_info_map`, yet
the blocks stayed in the normal queue and no later round ever brought
them back. They were then evicted under the normal policy while `SHOW
CREATE TABLE` and `information_schema.file_cache_info` disagreed about
whether TTL applied. Nothing was logged, because the conversion was
never attempted.

### Release note

Fixed cached blocks staying out of the TTL queue when a table's expired
`file_cache_ttl_seconds` is extended to a value that has not expired.

### What is changed and how it works?

**1. Record what was applied instead of inferring it.** `TtlInfo`
carries `blocks_promoted` — true once this manager has put the tablet's
blocks into the TTL queue and nothing has taken them out since. It
records what the manager did, not what the blocks are, so it starts
false for a tablet seen for the first time after a restart, whose blocks
on disk may well be TTL already.

**2. Skip only when the TTL is still running and the blocks are already
promoted.** The two directions are not symmetric:

- *Promotion is edge triggered.* Once the blocks are in the TTL queue
nothing takes them out behind our back, so rescanning a tablet whose TTL
is still running is pure waste. This is also what makes a TTL rewritten
to another still-valid value free, which matters where the property is
rewritten on a schedule — the decision is a state comparison, not a
comparison of TTL values.
- *Demotion is level triggered.* Blocks can still land in the TTL queue
after a tablet was demoted, and `blocks_promoted` is per tablet, so it
cannot tell whether any have. Rescanning is the only way to collect
them.

| TTL state | `blocks_promoted` | action |
|---|---|---|
| running | true | skip |
| running | false | scan, promote |
| expired / none | true | scan, demote |
| expired | false | scan, demote |
| none | false | stop tracking the tablet |

**3. Serialize transitions per tablet.** Both background threads funnel
through `reconcile_tablet_blocks()`, serialized by a striped lock,
re-reading the tablet's state after taking it. The expiration check
previously decided from a snapshot of `_ttl_info_map` that could be a
full gc interval old, so it could demote blocks the update thread had
just promoted under a newly extended TTL, and neither thread would touch
them again. Its snapshot is now only a candidate list.

**4. Do not hold `_ttl_info_mutex` across the block scan.** It walks the
meta store and takes the cache lock once per block, which on a tablet
with a few thousand cached blocks blocked every other user of the map
for the duration.

**5. A failed conversion does not record success.**
`change_cache_type()` rewrites storage metadata and can fail; recording
the new state anyway left the tablet permanently mismatched, because
every later round then saw state and wants agreeing. `blocks_promoted`
is left alone unless every block converted, so the next round retries.

**6. Stop tracking a tablet that has settled.** A tablet with no TTL
whose blocks are not in the TTL queue is dropped from the map before the
transition check, so one that settles without needing a conversion still
stops being walked on every round.

Adds a `file_cache_ttl_mgr_ttl_info_map_size` bvar and an INFO line
naming the tablet, direction and block count on each conversion.
@github-actions
github-actions Bot requested a review from yiguolei as a code owner September 16, 2026 12:57
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 90.10% (91/101) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 74.45% (31458/42255)
Line Coverage 58.74% (350924/597449)
Region Coverage 55.51% (293112/528074)
Branch Coverage 56.31% (132185/234731)

@github-actions

Copy link
Copy Markdown
Contributor Author

PR approved by anyone and no changes requested.

@github-actions github-actions Bot added the approved Indicates a PR has been approved by one committer. label Sep 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor Author

PR approved by at least one committer and no changes requested.

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

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants