-
Notifications
You must be signed in to change notification settings - Fork 164
feat: support cache file manually eviction by filename for full file cache #1137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -122,8 +122,31 @@ int FileCachePool::stat(CacheStat* stat, std::string_view pathname) { | |
| } | ||
|
|
||
| int FileCachePool::evict(std::string_view filename) { | ||
| errno = ENOSYS; | ||
| return -1; | ||
| auto fileIter = fileIndex_.find(filename); | ||
| if (fileIter == fileIndex_.end()) { | ||
| LOG_ERROR("Evict no such file , name: `", filename); | ||
| return 0; | ||
| } | ||
|
|
||
| const auto& filePath = fileIter->first; | ||
| auto lruEntry = fileIter->second.get(); | ||
| if (lruEntry->openCount == 0) { | ||
| lru_.mark_key_cleared(lruEntry->lruIter); | ||
| } | ||
| int err = 0; | ||
| { | ||
| photon::scoped_rwlock rl(lruEntry->rw_lock_, photon::WLOCK); | ||
| err = mediaFs_->truncate(filePath.data(), 0); | ||
| lruEntry->truncate_done = false; | ||
| } | ||
| if (err) { | ||
| ERRNO e; | ||
| LOG_ERROR("truncate(0) failed, name: `, ret: `, error code: `", filePath, | ||
| err, e); | ||
| // If truncate fails, we can attempt to remove the file directly | ||
| // in the afterFtrucate function. | ||
| } | ||
| return afterFtrucate(fileIter) ? 0 : -1; | ||
| } | ||
|
|
||
| int FileCachePool::evict(size_t size) { | ||
|
|
@@ -241,13 +264,6 @@ void FileCachePool::eviction() { | |
| if (err) { | ||
| ERRNO e; | ||
| LOG_ERROR("truncate(0) failed, name : `, ret : `, error code : `", fileName, err, e); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOG_ERRNO_RETURN
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to return. |
||
| // truncate to 0 failed means unable to free the file, it should not consider as a part | ||
| // of cache. Deal as it already release. | ||
| // The only exception is errno EINTR, means truncate interrupted by signal, should try | ||
| // again | ||
| if (e.no == EINTR) { | ||
| continue; | ||
| } | ||
| } | ||
| afterFtrucate(fileIter); | ||
| actualEvict -= fileSize; | ||
|
|
@@ -269,16 +285,18 @@ bool FileCachePool::afterFtrucate(FileNameMap::iterator iter) { | |
| } | ||
| if (0 == iter->second->openCount) { | ||
| auto err = mediaFs_->unlink(iter->first.data()); | ||
| ERRNO e; | ||
| LOG_ERROR("unlink failed, name : `, ret : `, error code : `", iter->first, err, e); | ||
| // unlik failed may caused by multiple reasons | ||
| // only EBUSY should may be able to trying to unlink again | ||
| // other reason should never try to clean it. | ||
| if (err && (e.no == EBUSY)) { | ||
| return false; | ||
| if (err) { | ||
| ERRNO e; | ||
| LOG_ERROR("unlink failed, name : `, ret : `, error code : `", iter->first, err, e); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOG_ERRNO_RETURN
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to return. |
||
| // unlink failed may caused by multiple reasons | ||
| // only EBUSY should may be able to trying to unlink again | ||
| // other reason should never try to clean it. | ||
| if (err && (e.no == EBUSY)) { | ||
| return false; | ||
| } | ||
| lru_.remove(iter->second->lruIter); | ||
| fileIndex_.erase(iter); | ||
| } | ||
| lru_.remove(iter->second->lruIter); | ||
| fileIndex_.erase(iter); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
simply
(note its ERRNO, not ERROR)
and it will output errno and error message as well.
There was a problem hiding this comment.
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.