Skip to content

feat: support cache file manually eviction by filename for full file cache#1137

Merged
lihuiba merged 3 commits intoalibaba:release/0.9from
xiaoyang-hhh:cache_evict
Mar 4, 2026
Merged

feat: support cache file manually eviction by filename for full file cache#1137
lihuiba merged 3 commits intoalibaba:release/0.9from
xiaoyang-hhh:cache_evict

Conversation

@xiaoyang-hhh
Copy link
Contributor

What does this PR do?

This PR adds support for evicting specific cache files by filename through the evict(std::string_view filename) API.
This feature allows users to manually evict specific cached files without waiting for the automatic LRU eviction, providing better control over cache management.

Key Changes

fs/cache/full_file_cache/cache_pool.cpp

  • Implemented evict(std::string_view filename) method to evict a specific cache file by its path
  • The implementation:
    • Finds the file in the index
    • Truncates the file to 0 if it's not currently open
    • Calls afterFtrucate() to clean up and optionally unlink the file

fs/cache/test/cache_test.cpp

  • Added test cases for the new eviction functionality

}
if (err) {
ERRNO e;
LOG_ERROR("truncate(0) failed, name: `, ret: `, error code: `", filePath,
Copy link
Collaborator

Choose a reason for hiding this comment

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

simply

LOG_ERRNO_RETURN("truncate(0) failed, name: ", filePath);

(note its ERRNO, not ERROR)
and it will output errno and error message as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just output the error log here, no need to return.


if (err) {
ERRNO e;
LOG_ERROR("truncate(0) failed, name : `, ret : `, error code : `", fileName, err, e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

LOG_ERRNO_RETURN

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no need to return.

return false;
if (err) {
ERRNO e;
LOG_ERROR("unlink failed, name : `, ret : `, error code : `", iter->first, err, e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

LOG_ERRNO_RETURN

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no need to return.

@lihuiba lihuiba requested a review from EricHuangqx March 3, 2026 07:11
@xiaoyang-hhh xiaoyang-hhh requested a review from lihuiba March 3, 2026 07:24
@lihuiba lihuiba merged commit 8295630 into alibaba:release/0.9 Mar 4, 2026
12 checks passed
photonlibos pushed a commit that referenced this pull request Mar 4, 2026
…cache (#1137)

* feat: support file eviction by filename
lihuiba pushed a commit that referenced this pull request Mar 4, 2026
…cache (#1137) (#1141)

* feat: support file eviction by filename

Co-authored-by: xiaoyang-hhh <luxiaoyang.lxy@alibaba-inc.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants